/******
/ Public Global Methods
*******/ 
// Open hyperlink in a window
function newBrowserWin(theUrl,theWin,theFeatures){
    var theWin = window.open(theUrl,theWin,theFeatures);
    if(!theWin.opener) theWin.opener = self;
    if(theWin.focus) theWin.focus();
}
// Open hyperlink in a center aligned window
function newBrowserWinII(theLeft,theTop,theWidth,theHeight,theWin,theFeatures,theUrl){
    var left = theLeft;
    var top  = theTop;
    if(left == 0){left=(screen.width-theWidth)/2}   // center horizontal if theLeft is zero
    if(top == 0){top=(screen.height-theHeight)/4}   // center vertical if theTop is zero
    var features="height="+theHeight+",width="+theWidth+",top="+top+",left="+left;
    if(theFeatures != ""){features=features+","+theFeatures}
    var theWin = window.open(theUrl,theWin,features);
    if(!theWin.opener) theWin.opener = self;
    if(theWin.focus) theWin.focus();
}
// Show div layer
function showDiv(id) {
    document.getElementById(id).style.visibility = "visible";
    document.getElementById(id).style.display    = "block";
}
// Hide div layer
function hideDiv(id) {
    document.getElementById(id).style.visibility = "hidden";
    document.getElementById(id).style.display    = "none";
}
// Show or hide (toggle) div layer
function showHideDiv(id) {
    if(document.getElementById(id).style.visibility == "hidden"){showDiv(id)}
    else{hideDiv(id)}
}
// Highlight table row (onmouseover or onmouseout)
function highlightrow(id,bgcolor) {
    document.getElementById(id).style.backgroundColor = bgcolor;
}
// Change lable on button
function changeButton(button){
	button.value = "Wait...";
}
/******
/ Private Global Methods
*******/ 
var indexTop  = 0;
var mouseposx = 0;
var mouseposy = 0;
var lyrPageAlign  = 0;
var lyrPageWidth  = 0;
var lyrPageHeight = 0;
var prevUniqueID  = 0;
var prevCalloutID = 0;
var prevKeywordID = 0;
var prevCalloutX  = 0;
var prevCalloutY  = 0;
// Detect browser agent
function browseragent() {
    var b = navigator.appName
    if (b=="Netscape") this.b = "ns"
    else if (b=="Microsoft Internet Explorer") this.b = "ie"
    else this.b = b
    this.v = parseInt(navigator.appVersion)
    this.ns  = (this.b=="ns" && this.v>=4)
    this.ns5 = (this.b=="ns" && this.v==5)
    this.ie  = (this.b=="ie" && this.v>=4)
}
// Set x, y coordinates on event
function setcoordinatesXY(e) {
    if (browseragentobj.ns5){mouseposx=e.clientX;mouseposy=e.clientY;}
    else if (browseragentobj.ns){mouseposx=e.pageX;mouseposy=e.pageY;}
    else{mouseposx=event.x;mouseposy=event.y;}
}
function showEntity(id) {
    indexTop += 10;
    elementID = document.getElementById(id)
    elementID.style.zIndex     = indexTop;
    elementID.style.visibility = "visible";
    elementID.style.display    = "block";
}
function hideEntity(id) {
    elementID = document.getElementById(id)
    elementID.style.visibility = "hidden";
    elementID.style.display    = "none";
}
function showHideEntity(id,hideAll,pos,end) {
    elementID = document.getElementById(id)
    if(hideAll==1){
        if(pos==1 && elementID.style.visibility == "hidden"){hideAllEntities(hideAll);showEntity(id);}
        else if (elementID.style.visibility == "hidden"){showEntity(id)}
        else if(pos==end && elementID.style.visibility == "visible"){hideAllEntities(hideAll);}
    }
    else{
        if(elementID.style.visibility == "hidden"){showEntity(id);}
        else{hideEntity(id);}
    }
}
function togglecallout(id,uniqueID){
    calloutID = document.getElementById(id)
    if(prevCalloutID != 0 && id != prevCalloutID){
        document.getElementById(prevCalloutID).style.visibility = "hidden";
        document.getElementById(prevCalloutID).style.display = "none";
    }
    if (prevCalloutID == id && prevUniqueID == uniqueID && calloutID.style.visibility == "visible"){
        calloutID.style.visibility = "hidden";
        calloutID.style.display = "none";
    }
    else{
        // browser window size
        var browserWidth = 0;
        if( typeof( window.innerWidth ) == 'number' ){
            browserWidth = window.innerWidth
            browserHeight = window.innerHeight
        }
        else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
            browserWidth = document.documentElement.clientWidth
            browserHeight = document.documentElement.clientHeight
        }
        else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
            browserWidth = document.body.clientWidth;
            browserHeight = document.body.clientHeight;
        }
        // adjust x coordinate if pages is aligned center/top or center/middle
        if((lyrPageAlign == 1 || lyrPageAlign == 2) && lyrPageWidth < browserWidth){
            var dx = (browserWidth-lyrPageWidth) / 2;
            mouseposx += dx;
        }
        // adjust y coordinate if pages is aligned center/middle
        if(lyrPageAlign == 2 && lyrPageHeight < browserHeight){
            var dy = (browserHeight-lyrPageHeight) / 2;
            mouseposy += dy;
        }
        // element size
        var elementWidthStr = calloutID.style.width.substring(0,calloutID.style.width.length-2);
        var elementWidth = elementWidthStr * 1;
        // open callout inside existing layer
        if (uniqueID == 0){
            var prevGlossaryXStr = prevCalloutX.substring(0,prevCalloutX.length-2);
            var prevGlossaryX = prevGlossaryXStr * 1;
            // callout x-position
            if (browserWidth-prevGlossaryX < 0)
                calloutID.style.left = prevGlossaryX - (elementWidth/2) + "px"
            else if (browserWidth-prevGlossaryX < elementWidth)
                calloutID.style.left = prevGlossaryX - 25 - (elementWidth - (browserWidth-prevGlossaryX)) + "px"
            else
                calloutID.style.left = prevGlossaryX - 5 + "px";
            // glossary y-position
            calloutID.style.top = prevCalloutY;
        }
        // open callout at new x,y coordinates
        else{
            // callout x-position
            if (browserWidth-mouseposx < 0)
                calloutID.style.left = mouseposx - (elementWidth/2) + "px"
            else if (browserWidth-mouseposx < elementWidth)
                calloutID.style.left = mouseposx - 25 - (elementWidth - (browserWidth-mouseposx)) + "px"
            else
                calloutID.style.left = mouseposx - 5 + "px";
            // callout y-position
            calloutID.style.top = mouseposy + 10 + "px";
        }
        // Show callout
        calloutID.style.visibility = "visible";
        calloutID.style.display = "block";
    }
    prevUniqueID  = uniqueID;   
    prevCalloutID = id;
    prevCalloutX  = calloutID.style.left;
    prevCalloutY  = calloutID.style.top;
}
function showcallout(id){
    document.getElementById("calloutDiv").style.visibility = "hidden";
    document.getElementById("calloutDiv").style.display = "none";
    document.getElementById("calloutDiv").innerHTML = document.getElementById("desc" + id).innerHTML;
    document.getElementById("calloutDiv").style.zindex = 100000;
    document.getElementById("calloutDiv").style.visibility = "visible";
    document.getElementById("calloutDiv").style.display = "block";
}
function showcalloutXY(id,x,y){
    calloutID = document.getElementById(id)
    calloutID.style.left = x + 18 + "px";
    calloutID.style.top = y + 18 + "px";
    calloutID.style.visibility = "visible";
    calloutID.style.display = "block";
}
function hidecallout(id){
    document.getElementById(id).style.visibility = "hidden";
    document.getElementById(id).style.display = "none";
}
function highlightkeyword(id){
    document.getElementById(id).style.color = "red";
    if(prevKeywordID != 0 && id != prevKeywordID)
        document.getElementById(prevKeywordID).style.color = "blue";
    prevKeywordID = id;
}
function lyrImageSwap(id,src){
    document.getElementById(id).src = src;
}
function changeButton(button){
    button.value = "Wait...";
}
// overwrite function to hide all event element layers
function hideAllEntities(hideAll) {return true}

