//<SCRIPT LANGUAGE=javascript>
<!--
var openMenus = new Array();// Currently open menu stack

// Utility Functions

function getAbsLeft(elem)
{
	var x = elem.offsetLeft;
	var e = elem;
	
	while (e.offsetParent)
	{
		x += e.offsetParent.offsetLeft;
		e = e.offsetParent;
	}
	
	return x;
}

function getAbsTop(elem)
{
	var y = elem.offsetTop;
	var e = elem;
	
	while (e.offsetParent)
	{
		y += e.offsetParent.offsetTop;
		e = e.offsetParent;
	}
	
	return y;
}

function mouseInObject(elem)
{
	var left = getAbsLeft(elem);
	var top = getAbsTop(elem);
	var y = window.event.y + document.body.scrollTop;

	return (window.event.x >= left && window.event.x <= left + elem.offsetWidth &&
		y >= top && y <= top + elem.offsetHeight);
}

// menuPop()
// Pops a menu off the stack
function menuPop()
{
	var menu = openMenus[openMenus.length - 1];
	if (menu) menu.style.visibility = "hidden";
	openMenus.length -= 1;
}

// setMenu()
// Called when the mouse passes over the parent element. This closes menus down the stack until the
// specified menu is found.
function setMenu(menu)
{
	var bContinue = true;
	
	// menu is the TD, so first locate its table
	var tblParent = menu.parentElement.parentElement.parentElement;	
	var tblSub = document.all(menu.id + "_T");
	
	// cycle through the array until we either find this table, or run out of
	// items on the stack
	while (bContinue)
	{
		if (openMenus.length == 0)
bContinue = false;		// Root menu...we may exit
		else
		{
if (openMenus[openMenus.length - 1].id == tblParent.id) return;		// Parent is at top of stack

if (openMenus.length - 2 >= 0)
{
// See if the leading (i.e. parent) menu is the same parent as this menu
if (openMenus[openMenus.length - 2].id == tblParent.id)
{
// Yes...now see if the trailing (i.e. child) menu is the same as the current item's.
if (tblSub && openMenus[openMenus.length - 1].id == tblSub.id) return;	// No change is necessary
}

// At the very least, we pop the trailing menu off
menuPop();
}
else
{
// Last chance...one menu left, is it the same as the current item's?
if (tblSub && openMenus[openMenus.length - 1].id == tblSub.id) return;
menuPop();
}
		}
	}
}

// setRootMenu()
// Sets the root menu, clearing the stack if necessary
function setRootMenu(menu)
{
	if (openMenus.length == 0) return;

	var tblCurr = document.all(menu.id + "_T");
	if (tblCurr)
	{
		if (openMenus[0].id != tblCurr.id)
		{
while (openMenus.length > 0) menuPop();
		}
	}
}

// showMenu()
// Makes the specified menu ID (i.e. table) visible, if present.
function showMenu(parentElem, bBelow)
{	
	var sub = document.all(parentElem.id + "_T");
	if (sub)
	{
		if (bBelow)
		{
// Align at bottom of element, adjusting for the side of the window if necessary
if (getAbsLeft(parentElem) + sub.offsetWidth > document.body.offsetWidth - 2)
// Position menu up to right side of window
sub.style.left = getAbsLeft(parentElem) + parentElem.offsetWidth - sub.offsetWidth;
else
// Position menu at left of root menu
sub.style.left = getAbsLeft(parentElem);

sub.style.top = getAbsTop(parentElem) + parentElem.offsetHeight;
		}
		else
		{
// Align to the right of the element, adjusting for the side of the window if necessary.
if (getAbsLeft(parentElem) + parentElem.offsetWidth + sub.offsetWidth > document.body.offsetWidth)
// Position menu on left side of menu
sub.style.left = getAbsLeft(parentElem) - sub.offsetWidth;
else
// Position menu at right of menu
sub.style.left = getAbsLeft(parentElem) + parentElem.offsetWidth;

sub.style.top = getAbsTop(parentElem);
		}

		if (sub.style.visibility != "visible")
		{
openMenus[openMenus.length] = sub;
sub.style.visibility = "visible";
		}
	}
}

// checkMousePos()
// Cycles through the visible menus and their root cells to see if the mouse has left the menus.
function checkMousePos()
{

	var ix = openMenus.length - 1;
	while (ix >= 0)
	{
		// See if mouse is in the menu table first...
		if (mouseInObject(openMenus[ix])) return;
		
		// Now check table's root cell (necessary for menu roots only)
		if (ix == 0)
		{
var tdid = String(openMenus[ix].id).substr(0, openMenus[ix].id.length - 2);
var td = document.all(tdid);
if (mouseInObject(td)) return;
		}
		
		ix--;
	}

	// Not in any of the menus...close them all
	while (openMenus.length > 0) menuPop();
}
//-->

//<SCRIPT LANGUAGE=javascript EVENT=onscroll FOR=window>
	while (openMenus.length > 0) menuPop();
