//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(sNav_)
{
    var sNav    =sNav_.toLowerCase ();
    var sPage   ="";
    //alert ("NavBar(" +sNav +")");

    switch (sNav)
    {
        case "home":        sPage   ="nav-home";            break;
        case "freetrial":   sPage   ="nav-freetrial";       break;
        case "geoselection":sPage   ="nav-geoselection";    break;
        case "geoanalysis": sPage   ="nav-geoanalysis";     break;
        case "userpoints":  sPage   ="nav-userpoints";      break;
        case "sitehelp":    sPage   ="nav-help";            break;
        case "subscribe":   sPage   ="nav-subscribe";       break;
    }

    if (sPage !="")
        NavBarSet (sPage);
}


function NavBarSet (sItem)
{
    var oNav    =document.getElementById (sItem);

    //alert ("NavBarSet [" +sItem +"]  [" +oNav +"]");
    if (oNav)
    {
        var sItemSel    =sItem +"-selected"
        oNav.childNodes[0].href ="javascript: NavBarDoNothing(\'" +sItemSel +"\')";
        oNav.id =sItemSel;
        oNav.className +=" nav-item-selected";
    }
}

function NavBarDoNothing (sItem)
{
    var oNav    =document.getElementById (sItem);

    if (oNav)
    {
        oNav.childNodes[0].style.cursor ="default";
    }
    document.body.style.cursor ="default";
}

/* Borrowed from eMarketer */
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
<!--//--><![CDATA[//><!--

sfHover = function()
{
    var sNav    =document.getElementById("nav");

    if (sNav)
    {
        var sfEls =sNav.getElementsByTagName("li");

        for (var i=0; i<sfEls.length; i++)
        {
            sfEls[i].onmouseover=function()
            {
                this.className+=" sfhover";

                if(this.id == "nav-help")
                {
                    var NavHelpObj = document.getElementById("nav-help").childNodes[2];
                    var oElement = NavHelpObj;
                    var NavHelpObjLeft = ((NavHelpObj.offsetWidth / 2) * -1) + 1;

                    if (oElement.parentElement)
                    {
                        while (oElement.parentElement != null)
                        {
                           oElement = oElement.parentElement;
                           NavHelpObjLeft += oElement.offsetLeft;
                        }
                    }

                    var oElement = NavHelpObj;
                    var NavHelpObjTop = oElement.offsetTop - 5;

                    if (oElement.parentElement)
                    {
                        while (oElement.parentElement != null)
                        {
                           oElement = oElement.parentElement;
                           NavHelpObjTop += oElement.offsetTop;
                        }
                    }

                    /*if(! document.getElementById('NavBarFrame'))
                    {
                        var NavBarFrameObj = document.createElement("iframe");
                        NavBarFrameObj.id = "NavBarFrame";
                        NavBarFrameObj.name = "NavBarFrame";
                        NavBarFrameObj.style.position = "absolute";
                        NavBarFrameObj.style.zIndex = "10";
                        NavBarFrameObj.style.border = "0px";
                        NavBarFrameObj.style.width = document.getElementById("nav-help").childNodes[2].offsetWidth;
                        NavBarFrameObj.style.height = document.getElementById("nav-help").childNodes[2].offsetHeight;
                        NavBarFrameObj.frameBorder="0";
                        NavBarFrameObj.allowTransparency="";
                        NavBarFrameObj.style.left = NavHelpObjLeft + "px";
                        NavBarFrameObj.style.top = NavHelpObjTop + "px";
                        document.body.appendChild(NavBarFrameObj);
                    }
                    else
                    {
                        document.getElementById('NavBarFrame').allowTransparency="";
                        document.getElementById('NavBarFrame').style.left = NavHelpObjLeft + "px";
                        document.getElementById('NavBarFrame').style.top = NavHelpObjTop + "px";
                        parent.frames['NavBarFrame'].document.body.style.backgroundColor = "#ffffff";
                    }*/
                }
            }
            sfEls[i].onmouseout=function()
            {
                this.className=this.className.replace(new RegExp(" sfhover\\b"), "");

                if(document.getElementById('NavBarFrame') != null)
                {
                    document.getElementById('NavBarFrame').allowTransparency="true";
                    parent.frames['NavBarFrame'].document.body.style.backgroundColor = "transparent";
                }
            }
        }
    }
}

if (window.attachEvent)
    window.attachEvent("onload", sfHover);

//--><!]]>

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;
}
