/*********************************************
 * File:     TopNav.js
 * Author:   Two Brilliant, Inc.
 * Created:  ajk, 10/20/2004
 * Modified: initials, date, description
//*********************************************/

//declare global variables
var postponeHide = null;
var timeTillHide = 200;
var curMenu = null;
var elsRef=getElementReference();


//function to change element style
function changeStyle(elObj,newStyle)
{
    if (typeof(elObj) != "undefined")
    {
        if (typeof(elObj.className) != "undefined")
        {
            elObj.className = newStyle;
        }
    }
    return true;
}

//function to change visibility of div
function changeVis(obj, e, visVal, hideVal)
{
    if (elsRef != null)
    {
        obj.style.left= -500;
        obj.style.top = -500;
        if (e.type=="mouseover")
        {
            obj.visibility=visVal;
            obj.style.display = "block";
        }
        else 
        {
            obj.visibility=hideVal;
            obj.style.display = "none";
        }
    }
}

//function to ensure that the current target element is not the element that caused menu to display. For pure DOM browsers.
function checkTarget(curTarget, relTarget) 
{
    while (relTarget.parentNode)
    {
	    if ((relTarget = relTarget.parentNode) == curTarget)
	    {
	        return true;
	    }
    return false;
    }
}

//function ensures item appears in the proper location relative to the rowser's edge
function clearbrowseredge(obj, whichedge)
{
    var edgeoffset=0
    if (whichedge=="rightedge"){
    var windowedge=document.all && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
    curMenu.contentmeasure=curMenu.offsetWidth
    if (windowedge-curMenu.x < curMenu.contentmeasure)
    edgeoffset=curMenu.contentmeasure-obj.offsetWidth
    }
    else{
    var windowedge=document.all && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
    curMenu.contentmeasure=curMenu.offsetHeight
    if (windowedge-curMenu.y < curMenu.contentmeasure)
    edgeoffset=curMenu.contentmeasure+obj.offsetHeight
    }
    return edgeoffset
}

//function to clear the timeout that postpones hiding the menu
function clearPostponeHideMenu()
{
    if (typeof(postponeHide!="undefined"))
    {
        clearTimeout(postponeHide);
    }
}

//function to hide the div on a timeout
function divHide(e,divname)
{
	//get div object
	if (divname != null)
	{
		curMenu = getObject(divname);
	}
	
    //ensure have a current menu to refer to
    if ((curMenu == null) || (elsRef == null))
    {
        //beat it
        return false;
    }
    
    //hide based upon supported object model
    if (elsRef == document.all)
    {
        if (!curMenu.contains(e.toElement))
        {
            postponeHideMenu();
        }
    }
    else
    {
        if (elsRef == document.getElementById)
        {
            var bSpawnCheck = checkTarget(e.currentTarget, e.relatedTarget);
            if ((e.currentTarget != e.relatedTarget) && (bSpawnCheck == false))
            {
                postponeHideMenu();
            }
        }
    }
}

//function to just make the menu disappear, no questions asked
function divHideQuick(somediv)
{
	if ((typeof(somediv) != "undefined") && (somediv != null))
	{
		somediv.style.display = "none";
	}
}

//function to display dropdown menu
function doDropDown(obj, e, divID)
{
    //cancel event perculation
    if (window.event) 
    {
	//alert("window.event");						// IE sees this
        event.cancelBubble=true
    }
    else 
    {
	//alert("!window.event...else statement");	// FF sees this
        if (e.stopPropagation) 
        {
            e.stopPropagation()
        }
    }
    
    //clear the timeout for hiding the menu
    clearPostponeHideMenu();
    
    //get the div object
    var calledMenu=getDivObject(divID);
    if (curMenu != calledMenu)
    {
    	divHideQuick(curMenu);
    	curMenu = calledMenu;
    }

    //show
    if ((elsRef != null) && (curMenu != null))
    {
        //set visibility
        changeVis(curMenu, e, "visible", "hidden");
        
        //set offsets
        curMenu.x=getOffset(obj, "left");
        curMenu.y=getOffset(obj, "top");


		
			var rightEdge = curMenu.x - clearbrowseredge(obj, "rightedge"); 
			//next value was changes by saw on 6/21, was 150
	        curMenu.style.left = rightEdge + 164 +"px";
	        var bottomEdge = (curMenu.y - clearbrowseredge(obj, "bottomedge")) + obj.offsetHeight;
			//next value was changed by saw 6/21 135
	        curMenu.style.top = bottomEdge + 127 +"px";
			
		
        //return
        return false;
    }
    else
    {
        return true;
    }
}

//function to find object in the DOM
function getObject(objName)
{
	//initialize return value
	var foundObj = null;
	
	//check if IE first. If not then, check DOM. Only IE and Mozilla are supported.
/*	if (typeof(document.all[objName]) != "undefined")
	{
	    foundObj = document.all[objName];
	}
	else
	{
*/	
		//get by element ID
        if (typeof(document.getElementById(objName)) != "undefined")
        {
        	foundObj = document.getElementById(objName);
        }
//	}
	
	//return
	return foundObj;
}

//function to get div object
function getDivObject(someid)
{
    //initialize return value
    var foundObj = null;
    
    //scram if don't have the proper objects
    if (someid == "")
    {
        return foundObj;
    }
    if (elsRef == null)
    {
        return foundObj;
    }
    
    //get object if can
    if (elsRef == document.all)
    {
        if (typeof(elsRef[someid]) != "undefined")
        {
            foundObj = elsRef[someid];
        }
    }
    else
    {
        if (typeof(document.getElementById(someid)) != "undefined")
        {
            foundObj = document.getElementById(someid);
        }
    }
    
    //return
    return foundObj;
}

//function to get element reference object for browser
function getElementReference()
{
    //initialize return value
    var brobj = null;

    //set reference
    if (typeof(document.all) != "undefined")
    {
        brobj = document.all;
    }
    else
    {
        if (typeof(document.getElementById) != "undefined")
        {
            brobj = document.getElementById;
        }
    }
    
    //return
    return brobj;
}

//function to get navlink from genpage.asp lookup table
function getNavLink(lookupname)
{
    //init return value
    var navlink = "#";
    
    if (typeof(lookup) != "undefined")
    {
        if (typeof(lookup[lookupname]) != "undefined")
        {
            navlink = lookup[lookupname];
        }
        else
        {
        	navlink = lookup["All &raquo;"];
        }
    }//end null lookup table check
    
    //return
    return navlink;
}

//function to get offset position of element
function getOffset(divObj, offsettype)
{
    //initialize return value
    var totaloffset = divObj.offsetTop;
    if (offsettype == "left")
    {
        totaloffset = divObj.offsetLeft;
    }

    //check if need to count parent element offset
    var parElem=divObj.offsetParent;
   /* while (parElem != null)
    {
        totaloffset = totaloffset + parElem.offsetTop;
        if (offsettype == "left")
        {
            totaloffset = totaloffset + parElem.offsetLeft;
        }
        parElem = parElem.offsetParent;
    }*/
	

    //return
    return totaloffset;
}

//function to hide the menu
function hidemenu()
{
    if (typeof(curMenu)!="undefined")
    {
        if ((elsRef != null) && (curMenu != null))
        {
            //curMenu.style.visibility="hidden";
            curMenu.style.display="none";
        }
    }
}

//function to check comptibility mode of the browser
function iecompattest()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//function to postpone hiding the menu while the user's cursor is over it
function postponeHideMenu()
{
    if (elsRef != null)
    {
        postponeHide=setTimeout("hidemenu()",timeTillHide)
    }
}

//function to set initial current div
function setCurMenu(someid)
{
    //curMenu = getDivObject(someid);
}

