//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
var display_url=0

// global menu object
var menuobj, submenuobj, ie5, ns6, menuclick = false;

function showmenuie5(e, menuname)
{
	// is another menu already open?
	if ((menuobj != "undefined") && menuobj && (menuobj.style.visibility == "visible"))
	{
		menuobj.style.visibility = "hidden";
		menuobj = null
	}
	// is submenu already open? if yes, kill it
	hidesubmenuie5();

	ie5=document.all&&document.getElementById
	ns6=document.getElementById&&!document.all
	if (ie5||ns6)
	{
		//menuobj=document.getElementById("menuname")
		menuobj = document.all[menuname];
	}

	//Find out how close the mouse is to the corner of the window
	var rightedge=ie5? document.body.clientWidth-e.clientX : window.innerWidth-e.clientX
	var bottomedge=ie5? document.body.clientHeight-e.clientY : window.innerHeight-e.clientY

	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<menuobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
		menuobj.style.left=ie5? document.body.scrollLeft+e.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth
	else
		//position the horizontal position of the menu where the mouse was clicked
		menuobj.style.left=ie5? document.body.scrollLeft+e.clientX : window.pageXOffset+e.clientX

	//same concept with the vertical position
	if (bottomedge<menuobj.offsetHeight)
		menuobj.style.top=ie5? document.body.scrollTop+e.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight
	else
		menuobj.style.top=ie5? document.body.scrollTop+e.clientY : window.pageYOffset+e.clientY

	menuobj.style.visibility="visible"

	// indicate user clicked to see menu
	menuclick = true;

	return false
}

function showsubmenuie5(e, submenuname)
{
	// if a submenu already exists, kill it.
	hidesubmenuie5();

	submenuobj = document.all[submenuname];
	if (menuobj && (menuobj != "undefined") && menuobj.style.visibility == "visible")
	{
		// menuobj is the parent menu
		submenuobj.style.left = parseInt(menuobj.style.left) + parseInt(menuobj.style.width)*99/100;
		// ugliest hack ever
		if (submenuname == "reportssummarysalesdaily")
		{
			submenuobj.style.top = menuobj.style.top;
		}
		else
		{
			submenuobj.style.top = parseInt(menuobj.style.top) + (20 * 6);
		}
		submenuobj.style.visibility = "visible";
	}
	return false;
}


function hidemenuie5(e)
{
	if (menuclick)
	{
		// menu is now being shown because user clicked
		// so don't hide. return.
		menuclick = false;
		return;
	}

	if ((menuobj != "undefined") && (menuobj) && (menuobj.style.visibility == "visible"))
	{
		menuobj.style.visibility="hidden"
		menuobj = null;
	}
	hidesubmenuie5();
}

function hidesubmenuie5()
{
	if ((submenuobj != "undefined") && (submenuobj) && (submenuobj.style.visibility == "visible"))
	{
		submenuobj.style.visibility="hidden"
		submenuobj = null;
	}
}

function highlightie5(e)
{
	var firingobj=ie5? e.srcElement : e.target
	if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems")
	{
		if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node

		firingobj.style.backgroundColor="highlight"
		firingobj.style.color="white"

		if (display_url==1)
			window.status=e.srcElement.url
	}
}

function hightlightie5showsubmenu(e, submenuname)
{
	showsubmenuie5(e, submenuname);
	highlightie5(e);
}

function highlightie5killsubmenu(e, flag)
{
	highlightie5(e)
	if (!flag)
		return;
	hidesubmenuie5();
}

function lowlightie5(e)
{
	var firingobj=ie5? e.srcElement : e.target
	if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems")
	{
		if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node

		firingobj.style.backgroundColor=""
		firingobj.style.color="black"
		window.status=''
	}
}

function lowlightie5killsubmenu(e, flag)
{
	lowlightie5(e);
	if (!flag)
		return;
	hidesubmenuie5();
}

function jumptoie5(e)
{
	var firingobj=ie5? e.srcElement : e.target
	if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems")
	{
		if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode

		if (firingobj.getAttribute("target"))
			window.open(firingobj.getAttribute("url"),firingobj.getAttribute("target"))
		else
			window.location=firingobj.getAttribute("url")
	}
}

document.onclick=hidemenuie5;
