var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed

var ie5=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden)
{
	if (ie5||ns6)
	dropmenuobj.style.left=dropmenuobj.style.top=-500
	//- uncomment the following line, if you want mouseover dropdownmenu -- first line should be uncommented for mouseover, second for mouseclick
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
	{
	    //if (e.type=="click" && obj.visibility==hidden || e.type=="click")
        obj.visibility=visible;
        showChildren(); // used for flexscroll implementation
	}
	else if (e.type=="click")
		obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
	var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
	dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
	edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
	var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
	var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
	edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
	edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
	}
	}
	return edgeoffset
}

function dropdownmenu(obj, e, dropmenuID)
{
	//If there is no CartRollDownPath, do nothing
//	if (CartRollDownPath == "")
//	{
//		return clickreturnvalue();
//	}

	if (window.event)
		event.cancelBubble=true;
	else if (e.stopPropagation)
		e.stopPropagation();

	if (typeof dropmenuobj!="undefined" && dropmenuobj != null) //hide previous menu
	{
		dropmenuobj.style.visibility="hidden";
		clearhidemenu();
	}

	if (ie5||ns6){
		obj.onmouseout=delayhidemenu
		dropmenuobj=document.getElementById(dropmenuID)

		//Instantiating the Msxml2 object to retrieve menu options from MenuOptions.aspx
//		var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
//		XmlHttp.Open("GET", CartRollDownPath, false); //CartRollDown.aspx
//		XmlHttp.Send();
//		var strHtml = XmlHttp.responseText;
//		
//		if (strHtml.indexOf("id=\"MenuOptions\"") > 0) //its not an error page.. continue
//		//if (strHtml.indexOf("id=\"CartCourseList\"") > 0) //its not an error page.. continue
//		{
//			//strHtml = strHtml.substring(strHtml.indexOf('<div')+22,strHtml.indexOf('</div>'));
//			strHtml = strHtml.substring(strHtml.indexOf('<div'),strHtml.indexOf('</div>') + 6);
//			dropmenuobj.innerHTML=strHtml;
//		}
//		else //its an error page or client has already clicked a menu item in the options menu
//		{
//			if (strHtml.indexOf("id=\"EmptyMenu\"") > 0)
//			{
//			    return clickreturnvalue()
//			}
//			
//			if (strHtml.indexOf("id=\"hdSessionTimeout\" size=\"1\" value=\"true\"") > 0) //its a session timeout
//			{               
//			     
//				window.open("Login.aspx","_self"); //reloading the page
//				return clickreturnvalue()	
//			}
//			else //its some other error
//			{
//			
//				window.open("errorPage.aspx","_self");
//				return clickreturnvalue()
//			}
//		}
		///////////////////////////////////////////////////////////////////

		if (dropmenuobj != null)
		{
			if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
			dropmenuobj.onmouseover=clearhidemenu
			dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
			showhide(dropmenuobj.style, e, "visible", "hidden")
			dropmenuobj.x=getposOffset(obj, "left")
			dropmenuobj.y=getposOffset(obj, "top")
			dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
			dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
		}
	}
	return clickreturnvalue();
}

function clickreturnvalue(){
	if ((ie5||ns6) && !enableanchorlink) return false
	else return true
}

function contains_ns6(a, b) {
	while (b.parentNode)
	if ((b = b.parentNode) == a)
		return true;
	return false;
}

function dynamichide(e){
	if (ie5&&!dropmenuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}

function delayhidemenu(){
	delayhide=setTimeout("if(dropmenuobj != null) {dropmenuobj.style.visibility='hidden'; dropmenuobj.style.zIndex='-100'; showChildren();}",disappeardelay)
}

// the following code is used for flexscroll implementation; used to show/hide children of dropmenuobj based on dropjenuobj's visibility status
function showChildren()
{
    if (dropmenuobj.childNodes != null)
    {
        var index;
        for (index = 0; index < dropmenuobj.childNodes.length; index++)
        {
            var child = dropmenuobj.childNodes[index];
            if (child.style != null) // this check is needed for Firefox because not all childNodes are divs in Firefox
            {
                 child.style.visibility = dropmenuobj.style.visibility;
                // if this div contains a flexscroll, need to update so that the scroll hides
                if (child.className.indexOf("flexcroll") >= 0 && child.scrollUpdate)
                    child.scrollUpdate();     
           }
        }
    }
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
	{
		dropmenuobj.style.zIndex='200';		
		clearTimeout(delayhide);
	}
}
