//Includes functions for Navigation bar and Buttons

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

dropDownBottomX = 0;
dropDownBottomY = 0;

var CurrentNavHighlight;

function GetPassHeight(lessHeight,minHeight)
{
    if (document.layers) {
        returnHeight = window.innerHeight - lessHeight;
        if (returnHeight <= minHeight) {
            returnHeight = minHeight
        }
        return returnHeight;
    }
    else if (document.all) {
        returnHeight = document.body.clientHeight - lessHeight;
        if (returnHeight <= minHeight) {
            returnHeight = minHeight
        }
        return returnHeight;

    }
    else return(300);
}

function GetPassWidth(lessWidth,minWidth)
{
    if (document.layers) {
        returnHeight = window.innerWidth - lessWidth;
        if (returnWidth <= minWidth) {
            returnWidth = minWidth
        }
        return returnWidth;
    }
    else if (document.all) {
        returnWidth = document.body.clientWidth - lessWidth;
        if (returnWidth <= minWidth) {
            returnWidth = minWidth
        }
        return returnWidth;

    }
    else return(300);
}

function NavBar(TurnOnNavHighlight) { //Call these functions from onload in the body of pages with a nav bar
    CurrentNavHighlight = TurnOnNavHighlight;
    NavSetup(); //Highlight appropriate nav button
}

var UnavailButtons = "UnavailableButtons";

function HighlightButton(sButtonName) {
    if (sButtonName != 'X' && Finder(UnavailButtons,sButtonName) <= 1) {
        document.getElementById(sButtonName + 'ButtonText').className='buttonfonth';
        MM_swapImage(sButtonName + 'ButtonLeft','','images/buttons/button_h_part_left.gif',sButtonName + 'ButtonRight','','images/buttons/button_h_part_right.gif',1);
        MM_swapImage(sButtonName + 'ButtonClusterLeft','','images/buttons/button_h_cluster_part_left.gif',sButtonName + 'ButtonClusterRight','','images/buttons/button_h_cluster_part_right.gif',1);
        document.getElementById(sButtonName + 'ButtonMid').className='midhighlight';
    }
}

function UnHighlightButton(sButtonName) {
    if (sButtonName != 'X' && Finder(UnavailButtons,sButtonName) <= 1) {
        document.getElementById(sButtonName + 'ButtonText').className='buttonfont';
        MM_swapImage(sButtonName + 'ButtonLeft','','images/buttons/button_part_left.gif',sButtonName + 'ButtonRight','','images/buttons/button_part_right.gif',1);
        MM_swapImage(sButtonName + 'ButtonClusterLeft','','images/buttons/button_cluster_part_left.gif',sButtonName + 'ButtonClusterRight','','images/buttons/button_cluster_part_right.gif',1);
        document.getElementById(sButtonName + 'ButtonMid').className='midstandard';
    }
}

function UnavailButton(sButtonName) {
    UnavailButtons = UnavailButtons +','+ sButtonName
    if (sButtonName != 'X') {
        document.getElementById(sButtonName + 'ButtonText').className='buttonfontu';
        MM_swapImage(sButtonName + 'ButtonLeft','','images/buttons/button_u_part_left.gif',sButtonName + 'ButtonRight','','images/buttons/button_u_part_right.gif',1);
        MM_swapImage(sButtonName + 'ButtonClusterLeft','','images/buttons/button_u_cluster_part_left.gif',sButtonName + 'ButtonClusterRight','','images/buttons/button_u_cluster_part_right.gif',1);
        document.getElementById(sButtonName + 'ButtonMid').className='midunavail';
    }
}

function AvailButton(sButtonName) {
    UnavailButtons = Remover(UnavailButtons,sButtonName);
    UnHighlightButton(sButtonName);
}


function Finder(item,SearchChar) {
    var _item=item.split(","+SearchChar);
  return(_item.length);
}

function Remover(item,SearchChar) {
    var _ret="";
    var _item=item.split(","+SearchChar);
    for(var i=0;i<_item.length;i++) {
        _item[i]+="";
        _ret+=_item[i];
    }
  return(_ret);
}

function DNowHighlightNav(sButtonName) {
    if(sButtonName == 'SiteHelpButton') {
        MoveLayers('SiteHelp');
        MM_showHideLayers('HelpLayer','','show');
    }
    else
        MM_showHideLayers('HelpLayer','','hide');

    document.getElementById(sButtonName + 'Text').className = 'ButtonTextHighlight';
    document.getElementById(sButtonName).className = sButtonName+'Highlight';
}

function DNowUnHighlightNav(sButtonName) {
    var currentButton = CurrentNavHighlight+'Button';
    if(currentButton != sButtonName) {
        document.getElementById(sButtonName + 'Text').className = 'ButtonText';
        document.getElementById(sButtonName).className = sButtonName;
    }
}

function HighlightNav(sButtonName) {
    if (sButtonName != 'X') {
        document.getElementById(sButtonName + 'ButtonText').className='navfonth';
        document.getElementById(sButtonName + 'ButtonMid').className='midnavhighlight';
    }
}

function UnHighlightNav(sButtonName,UnHighlightNavAll,NavBarColor) {
    if (CurrentNavHighlight != sButtonName) {
        if (document.layers) {
            UnHighlightNav2(sButtonName,NavBarColor)
        }
        if (document.getElementById&&!document.all) {
            UnHighlightNav2(sButtonName,NavBarColor)
        }
        else {
            if (UnHighlightNavAll == "Yes") {
                UnHighlightNav2(sButtonName,NavBarColor)
            }
            if ((document.all.HelpLayer.style.visibility != "visible")/*&&(document.all.DataLayer.style.visibility != "visible")*/) {
                UnHighlightNav2(sButtonName,NavBarColor)
            }
        }
    }
    //else {
    //  UnHighlightNav2(sButtonName)
    //}
}

function UnHighlightNav2(sButtonName,NavBarColor) {
    if(!NavBarColor)
        NavBarColor = 'default';
    document.getElementById(sButtonName + 'ButtonText').className='navfont';
    document.getElementById(sButtonName + 'ButtonMid').className='midnav'+NavBarColor;
}

function NavSetup() { //Check navform on each page to highlight button of current section of site
    if(document.body.id == 'DNowVersion') {
        DNowHighlightNav(CurrentNavHighlight+'Button');
        return;
    }
    else {
        HighlightNav(CurrentNavHighlight);
        return;
    }
}


function MoveLayers(activeLayerName) {
    if(parseInt(navigator.appVersion) < 4) return;
    if(document.layers) {
        document.layers.HelpLayer.left = GetAbsLeft(document.getElementById('SiteHelpButtonLeft'));
        if(document.body.id == 'DNowVersion')
            document.layers.HelpLayer.top = GetAbsTop(document.getElementById('SiteHelpButtonLeft'))+78;
        else
            document.layers.HelpLayer.top = GetAbsTop(document.getElementById('SiteHelpButtonLeft'))+16;
        //document.layers.DataLayer.left = GetAbsLeft(document.getElementById('DataInfoButtonLeft'));
        //document.layers.DataLayer.top = GetAbsTop(document.getElementById('DataInfoButtonLeft'))+16;
    }
    else {
        document.all.HelpLayer.style.pixelLeft = GetAbsLeft(document.getElementById('SiteHelpButtonLeft'));
        if(document.body.id == 'DNowVersion')
            document.all.HelpLayer.style.pixelTop = GetAbsTop(document.getElementById('SiteHelpButtonLeft'))+78;
        else
            document.all.HelpLayer.style.pixelTop = GetAbsTop(document.getElementById('SiteHelpButtonLeft'))+16;
        //document.all.DataLayer.style.pixelLeft = GetAbsLeft(document.getElementById('DataInfoButtonLeft'));
        //document.all.DataLayer.style.pixelTop = GetAbsTop(document.getElementById('DataInfoButtonLeft'))+16;
    }
    dropDownBottomX = GetAbsLeft(document.getElementById(activeLayerName+'Bottom'));
    dropDownBottomY = GetAbsTop(document.getElementById(activeLayerName+'Bottom'));
}


function HideDropdowns() { //Hide dropdowns layers
    MM_showHideLayers('HelpLayer','','hide');
}

function highlightDDMenu(obj, num) {
    obj.style.color = '#FFFFFF';
    document.getElementById('dditem'+num).className = 'ddmenucellsHighlight';
}

function unhighlightDDMenu(obj, num) {
    obj.style.color = '#666666';
    document.getElementById('dditem'+num).className = 'ddmenucells';
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0  //DreamWeaver canned code
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0  //DreamWeaver canned code
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ShowHideLayers(layername,vis) {

}

function GetAbsTop(oElement)
{

    var nRet = oElement.offsetTop;

    if (oElement.offsetParent)
    {
        while (oElement.offsetParent != null)
        {
            oElement = oElement.offsetParent;
            nRet += oElement.offsetTop;
        }
    }
    return nRet;
}

function GetAbsLeft(oElement)
{
    var nRet = oElement.offsetLeft;
    if (oElement.parentElement)
    {
        while (oElement.parentElement != null)
        {
            oElement = oElement.parentElement;
            nRet += oElement.offsetLeft;
        }
    }
    return nRet;
}

function checkEdge() {
    if ( typeof( document.all.HelpLayer ) == 'object') {
    if ((document.all.HelpLayer.style.visibility == "visible")/*||(document.all.DataLayer.style.visibility == "visible")*/) {
        var mouseX = window.event.clientX;
        var mouseY = window.event.clientY;
        if (mouseY < (45 - document.body.scrollTop)) {
            HideDropdowns();
            if(document.body.id != 'DNowVersion')
                UnHighlightNav('SiteHelp','Yes');
            //UnHighlightNav('DataInfo','Yes');
        }
        if (mouseY > dropDownBottomY + (5 - document.body.scrollTop)) {
            HideDropdowns();
            if(document.body.id != 'DNowVersion')
                UnHighlightNav('SiteHelp','Yes');
            //UnHighlightNav('DataInfo','Yes');
        }
        if (mouseX < dropDownBottomX-2) {
            HideDropdowns();
            if(document.body.id != 'DNowVersion')
                UnHighlightNav('SiteHelp','Yes');
            //UnHighlightNav('DataInfo','Yes');
        }
        if (mouseX > dropDownBottomX+161) {
            HideDropdowns();
            if(document.body.id != 'DNowVersion')
                UnHighlightNav('SiteHelp','Yes');
            //UnHighlightNav('DataInfo','Yes');
        }
    }
    }
}


document.body.onclick=HideDropdowns;
document.body.onscroll=HideDropdowns;
document.body.onmousemove=checkEdge;