﻿

function SetMenuItemsFaceBox(xDiv){
    var spans = document.getElementById(xDiv).getElementsByTagName("a");
    for(i = 0; i < spans.length; i++){
        if (spans[i].getAttribute('href').substr(0,4) == 'http') {
            spans[i].setAttribute('rel', 'facebox');
            //alert(spans[i].getAttribute('href').substr(0,4));
        }
    }
}

function toggleLayer( whichLayer ){
    var elem, vis;  
    if( document.getElementById ) // this is the way the standards work
        elem = document.getElementById( whichLayer );  
    else if( document.all ) // this is the way old msie versions work      
        elem = document.all[whichLayer];  
    else if( document.layers ) // this is the way nn4 works    
        elem = document.layers[whichLayer];  
    vis = elem.style;  // if the style.display value is blank we try to figure it out here  
    if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
    vis.display = (vis.display==''||vis.display=='block')?'none':'block';
 }

 function toggleLayer2(whichLayer, state) {
     var elem, vis;
     if (document.getElementById) // this is the way the standards work
         elem = document.getElementById(whichLayer);
     else if (document.all) // this is the way old msie versions work      
         elem = document.all[whichLayer];
     else if (document.layers) // this is the way nn4 works    
         elem = document.layers[whichLayer];
     vis = elem.style;  // if the style.display value is blank we try to figure it out here  
     if (state == 1) {
         vis.display = 'block';
     } else {
        vis.display = 'none';
    }   
 }

function HideAllDivs(xDiv){
    var spans = document.getElementById(xDiv).getElementsByTagName("div");
    for(i = 0; i < spans.length; i++){
        var str = spans[i].id;
        if (str.search(/_pnl/i) > -1) {
            spans[i].style.display = 'none';
        }
    }
}

function ShowSingleDiv(xDivContainer, xDivToShow){
    HideAllDivs(xDivContainer);
    toggleLayer(xDivToShow);
}

function ClearAndSetLinkClass(xDiv, xLink){
    var spans = document.getElementById(xDiv).getElementsByTagName("a");
    for(i = 0; i < spans.length; i++){
        spans[i].className='';
    }
    
    document.getElementById(xLink).className='selected';
}

function ClearAndSetLinkClass2(xDiv, xLink) {
    var spans = document.getElementById(xDiv).getElementsByTagName("a");
    for (i = 0; i < spans.length; i++) {
        spans[i].className = 'PillFilter_filter ';
    }

    document.getElementById(xLink).className = 'PillFilter_filter  Tabset_selected';
}

function SetItemValue(xHidden, xValue){
    document.getElementById(xHidden).value= xValue;
}

function SetSelected(xthis, xHidden){
    if (document.getElementById(xHidden).value == 0) {
        xthis.style.backgroundColor='#6D84B4'; 
        xthis.style.color='#FFFFFF';
        document.getElementById(xHidden).value = 1;
    } else {
        xthis.style.backgroundColor='#FFFFFF'; 
        xthis.style.color='#000000';
        document.getElementById(xHidden).value = 0;
    }
}

function CopyDivToClipboard(thisObj)
    {
    var div = document.getElementById(thisObj);
    div.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange) {
        controlRange = document.body.createControlRange();
        controlRange.addElement(div);
        controlRange.execCommand('Copy');
    }
    div.contentEditable = 'false';
    alert('The Template has been copied to the clipboard. Paste it into an excel spreadsheet.')
}

function CopyDivToClipboard2(inElement) {
    if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range && BodyLoaded == 1)
            range.execCommand('Copy');
    } else {
        var flashcopier = 'flashcopier';
        if (!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard=' + escape(inElement.value) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
    alert('The Template has been copied to the clipboard. Paste it into an excel spreadsheet.')
}

function CopyDivToClipboard3(xDiv) {
    // setup single ZeroClipboard object for all our elements
    clip = new ZeroClipboard.Client();
    clip.setHandCursor(true);

    // assign a common mouseover function for all elements using jQuery
    $('div.' + xDiv).mouseover(function() {
        // set the clip text to our innerHTML
        clip.setText(this.innerHTML);

        // reposition the movie over our element
        // or create it if this is the first time
        if (clip.div) {
            clip.receiveEvent('mouseout', null);
            clip.reposition(this);
        }
        else clip.glue(this);

        // gotta force these events due to the Flash movie
        // moving all around.  This insures the CSS effects
        // are properly updated.
        clip.receiveEvent('mouseover', null);
    });

    // add an event handler which fires after text is copied to the clipboard
    // and change the color of the underlying DOM element
    clip.addEventListener('complete', function(client, text) {
        alert('The Template has been copied to the clipboard. Paste it into an excel spreadsheet.')
    });
}

function SetBackground(xDIV, xColour, bShowHand) {
    document.getElementById(xDIV).style.backgroundColor = xColour;
    if (bShowHand == 'true') {
        document.getElementById(xDIV).style.cursor = 'pointer';
    }
}

function BoldFont(xDIV, bBold) {
    if (bBold == 'true') {
        document.getElementById(xDIV).style.fontWeight = 'bold';
    } else {
        document.getElementById(xDIV).style.fontWeight = 'normal';
    }
}

function setFocus(xObject) {
    document.getElementById(xObject).focus();
}

function SetObjectData(xOBJ, sData) {
    var div = document.getElementById(xOBJ);
    //alert(sData);
    div.data = sData;
    div.outerHTML = div.outerHTML.replace("mypage.aspx", sData);
}

function getPageScroll() {
    if (self.pageYOffset) {
        return this.isFrame ? parent.pageYOffset : self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        return document.documentElement.scrollTop;
    } else if (document.body) {
        return document.body.scrollTop;
    }
}

function getPageSize() {
    var xScroll, yScroll, windowWidth, windowHeight;
    if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.getElementsByTagName("html").item(0).offsetWidth;
        yScroll = document.getElementsByTagName("html").item(0).offsetHeight;
        xScroll = (xScroll < document.body.offsetWidth) ? document.body.offsetWidth : xScroll;
        yScroll = (yScroll < document.body.offsetHeight) ? document.body.offsetHeight : yScroll;
    }
    if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.getElementsByTagName("html").item(0).clientWidth;
        windowHeight = document.getElementsByTagName("html").item(0).clientHeight;
        windowWidth = (windowWidth == 0) ? document.body.clientWidth : windowWidth;
        windowHeight = (windowHeight == 0) ? document.body.clientHeight : windowHeight;
    }
    var pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;
    var pageWidth = (xScroll < windowWidth) ? windowWidth : xScroll;
    return new Array(pageWidth, pageHeight, windowWidth, windowHeight);
}

function CentreTheDivOnTheScreen(xDIV) {

    var pageSize = getPageSize();
    var leftOffset = 250;
    //var topOffset = getPageScroll()[1] + (getPageHeight() / 10);
    var topOffset = getPageScroll() + (pageSize[3] / 15);
    var o = document.getElementById(xDIV);
    var r = o.style;
    //r.top = topOffset + 'px';
    r.top = '30' + 'px';
    r.left = leftOffset + 'px';
    //alert(topOffset);
}

function Tabset(id, selectedId) {
    if (!Tabset.instances) { Tabset.instances = {}; }
    Tabset.instances[id] = this;
    onunloadRegister(function() { Tabset.instances = {} });
    this.id = id;
    this.selectedId = selectedId;
}

Tabset.getInstance = function(id) {
    if (Tabset.instances && Tabset.instances[id]) { return Tabset.instances[id]; }
    return null;
}

Tabset.prototype.getFullTabId = function(tabId) { return this.id + '_' + tabId; }
Tabset.prototype.selectTab = function(tabId, func, beforeClickFunc) {
    if (beforeClickFunc && !beforeClickFunc()) { return false; }
    if (this.selectedId) { this.lastSelected = this.selectedId; CSS.removeClass(ge(this.selectedId), 'Tabset_selected'); }
    this.selectedId = tabId;
    CSS.addClass(ge(this.selectedId), 'Tabset_selected');
    if (func) { return func(); }
    return true;
}

Tabset.prototype.unselect = function() { if (this.selectedId) { CSS.removeClass($(this.selectedId), 'Tabset_selected'); } }
Tabset.prototype.hasTabElem = function(id) { return ge(this.id + '_' + id); }
Tabset.prototype.getTabElem = function(id) { return $(this.id + '_' + id); }

//if (window.Bootloader) { Bootloader.done(["js\/tabs\/tabset.js"]); }

function PrintThisPage(divtoprint, width) {
    var sOption = "toolbar=no,location=no,directories=no,menubar=no,";
    sOption += "scrollbars=yes,width=750,height=600,left=100,top=25";

    var sWinHTML = document.getElementById(divtoprint).innerHTML;



    var winprint = window.open("", "", sOption);
    winprint.document.open();
    winprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    winprint.document.write('<html>');
//    winprint.document.write('<script src=jqueryapps/jquery/jquery-1.3.2.min.js type=text/javascript></script>');
    winprint.document.write('<link href=css/StyleSheet.css rel=stylesheet type=text/css />');
//    winprint.document.write('<script src=jqueryapps/rcorners/js/jquery.curvycorners.source.js type=text/javascript></script>');
//    winprint.document.write('<script src=js/rounded.js type=text/javascript></script>');
    winprint.document.write('<body id="datacontent" style=padding:0px;>');
    winprint.document.write('<div style="width:');
    winprint.document.write(width);
    winprint.document.write(';">');
    winprint.document.write(sWinHTML);
    winprint.document.write('</div>');
    winprint.document.write('</body></html>');
    winprint.print();
    winprint.document.close();
    winprint.focus();
}