/**
* MLSIMenu 08MAR2003 Version 1.0
* Michael Redding, March 2003
* Copyright (c) 2003 Rapattoni Corp.

* based on mm_menu.js
* by andy finnell, March 2002
* Copyright (c) 2000-2002 Macromedia, Inc.
*
* based on menu.js
* by gary smith, July 1997
* Copyright (c) 1997-1999 Netscape Communications Corp.
*
* Netscape grants you a royalty free license to use or modify this
* software provided that this copyright notice appears on all copies.
* This software is provided "AS IS," without a warranty of any kind.
*/

function IMenu(label, nm, mw)
{//alert('MLSIMenu - IMenu(label, nm, mw)'); //return;
	this.version = "020320 [Menu; mm_menu.js]";
	this.type = "Menu";
	this.label = " " + label;
	this.menuName = nm;
	this.menuWidth = mw;
	this.menuItemHeight = 18;
	this.fontSize = 12;
	this.fontWeight = "plain";
	this.fontFamily = "Arial, Helvetica, sans-serif";
	this.fontColor = "#0040A8";
	this.fontColorHilite = "#FFFFFF";
	this.bgColor = "#555555";
	this.menuBorder = 1;
	this.menuBgOpaque = true;
	this.menuItemBorder = 0;
	this.menuItemIndent = 0;
	this.menuItemBgColor = "#FFFFFF";
	this.menuItemVAlign = "middle";
	this.menuItemHAlign = "left";
	this.menuItemPadding = 3;
	this.menuItemSpacing = 0;
	this.menuLiteBgColor = "#FFFFFF";
	this.menuBorderBgColor = "#777777";
	this.menuHiliteBgColor = "#0040A8";
	this.menuContainerBgColor = "#CCCCCC";
	this.childIMenuIcon = "/arrows.gif";
	this.submenuXOffset = -5;
	this.submenuYOffset = 7;
	this.submenuRelativeToItem = true;
	this.vertical = true;
	this.hideOnMouseOut = true;
	this.hideTimeout = 3000;
	this.items = new Array();
	this.actions = new Array();
	this.childIMenus = new Array();
	this.addIMenuItem = addIMenuItem;
	this.addIMenuSeparator = addIMenuSeparator;
	this.writeIMenus = writeIMenus;
	this.showIMenu = showIMenu;
	this.onIMenuItemOver = onIMenuItemOver;
	this.onIMenuItemAction = onIMenuItemAction;
	this.hideIMenu = hideIMenu;
	this.hideChildIMenu = hideChildIMenu;
	if(!window.IMenus) window.IMenus = new Array();
	window.IMenus[this.label] = this;
	window.IMenus[window.IMenus.length] = this;
	if(!window.activeIMenus) window.activeIMenus = new Array();
}

function addIMenuItem(label, action)
{//alert('MLSIMenu - addIMenuItem(label, action)'); //return;
	this.items[this.items.length] = label;
	this.actions[this.actions.length] = action;
}

function addIMenuSeparator()
{//alert('MLSIMenu - addIMenuSeparator()'); //return;
	this.items[this.items.length] = "separator";
	this.actions[this.actions.length] = "";
	this.menuItemBorder = 0;
}

function IMenuFIND(item)
{//alert('MLSIMenu - IMenuFIND(item)'); //return;
	if(document.all) return(document.all[item]);
	if(document.getElementById) return(document.getElementById(item));
	return(false);
}

function writeIMenus(container)
{//alert('MLSIMenu - writeIMenus(container)'); return;
	if(window.triedToWriteIMenus) return;

	if(document.frames("MLSIMenuIFrame").document.all)
	{
		document.frames("MLSIMenuIFrame").document.body.innerHTML = '<span id="menuIContainer"></span>';

		container = document.frames("MLSIMenuIFrame").document.all("menuIContainer");
	}

	window.imHideIMenuTimer = null;
	if(!container) return;
	window.triedToWriteIMenus = true; 
	container.isContainer = true;
	container.IMenus = new Array();
	for(var i = 0; i < window.IMenus.length; i++) container.IMenus[i] = window.IMenus[i];

	window.IMenus.length = 0;

	parent.dMLSIMenuBuildHTMLStartTime =  new Date();
	//alert(parent.frames('Page_Header').sIMenuContent);
	container.innerHTML = parent.frames('Page_Header').sIMenuContent;
	parent.dMLSIMenuBuildHTMLEndTime =  new Date();

	parent.dMLSIMenuSetDimensionsStartTime =  new Date();
	parent.dMLSIMenuSetDimensionsEndTime =  new Date();

	document.onmouseup = mouseupIMenu;
	window.mmWroteIMenu = true;
}

function showIMenu(imenu, x, y, child, imgname)
{//alert('MLSIMenu - showIMenu(imenu, x, y, child, imgname)'); //return;
	if(!window.mmWroteIMenu) return;

	IM_clearTimeout();
	if(imenu)
	{
		var obj = document.frames("MLSIMenuIFrame").document.all(imgname) || document.frames("MLSIMenuIFrame").document.images[imgname] || document.frames("MLSIMenuIFrame").document.links[imgname] || document.frames("MLSIMenuIFrame").document.anchors[imgname];

		x = IM_moveXbySlicePos(x, obj);
		y = IM_moveYbySlicePos(y, obj);
	}

	if(document.frames("MLSIMenuIFrame").document.all("imenuItem0"))
	{
		var l = imenu.imenuLayer || imenu;
		hideActiveIMenus();
		if(typeof(l) == "string")
			l = document.frames("MLSIMenuIFrame").document.all(l);
		window.ActiveIMenu = l;
		var s = l.style;
		s.visibility = "inherit";
		if(x != "relative")
		{
			document.all.MLSIMenuIFrame.style.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
			document.all.MLSIMenuIFrame.style.left = document.all.MLSIMenuIFrame.style.pixelLeft + 'px';
			
			s.pixelLeft = 0;
			s.left = s.pixelLeft + 'px';
		}

		if(y != "relative")
		{
			document.all.MLSIMenuIFrame.style.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
			document.all.MLSIMenuIFrame.style.top = document.all.MLSIMenuIFrame.style.pixelTop + 'px';

			s.pixelTop = 0;
			s.top = s.pixelTop + 'px';
		}

		var iLeft = 0, iTop = 0;
		iLeft = l.Menu.menuItemPadding + l.Menu.menuItemIndent;
		iTop = ((l.Menu.menuItemHeight / 2) - (l.Menu.fontSize / 2) - 1);

		document.all.MLSIMenuIFrame.style.width = parseInt(2 * iLeft + l.Menu.menuWidth - 2, 10) + 'px';
		document.all.MLSIMenuIFrame.style.height = l.style.pixelHeight + 'px';

		l.Menu.xOffset = parent.document.body.scrollLeft;
		l.Menu.yOffset = parent.document.body.scrollTop;

		document.all.MLSIMenuIFrame.style.display = "";
	}

	if(imenu)
		window.activeIMenus[window.activeIMenus.length] = l;
	IM_clearTimeout();
}

function hideActiveIMenus()
{//alert('MLSIMenu - hideActiveIMenus()'); //return;
	if(!window.activeIMenus) return;

	for(var i=0; i < window.activeIMenus.length; i++)
	{
		if(!window.activeIMenus[i]) continue;

		if(window.activeIMenus[i].visibility && window.activeIMenus[i].Menu && !window.mmIsOpera)
		{
			window.activeIMenus[i].visibility = "hidden";
			window.activeIMenus[i].Menu.container.visibility = "hidden";
			window.activeIMenus[i].Menu.container.clip.left = 0;
		}
		else if(window.activeIMenus[i].style)
		{
			var s = window.activeIMenus[i].style;
			s.visibility = "hidden";
			s.left = '-200px';
			s.top = '-200px';
		}
	}

	if(window.ActiveIMenuItem)
		hideIMenu(false, false);

	document.all.MLSIMenuIFrame.style.display = "none";
	window.activeIMenus.length = 0;
}

function onIMenuItemOver(e, l)
{//alert('MLSIMenu - onIMenuItemOver(e, l)'); //return;
	IM_clearTimeout();
	l = l || this;
	a = window.ActiveIMenuItem;
	
	if(l.style && l.Menu)
	{
		if(a)
		{
			a.style.backgroundColor = a.saveColor;
			if(a.hilite) a.hilite.style.visibility = "hidden";
			if(a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
		}
		
		if(l.isSeparator) return;

		l.style.backgroundColor = l.menuHiliteBgColor;
		l.zIndex = 1;
		if(l.Menu.bgImageOver)
			l.style.background = "url(" + l.Menu.bgImageOver +")";

		if(l.hilite)
		{
			l.hilite.style.visibility = "inherit";
			if( l.hiliteShim )
				l.hiliteShim.style.visibility = "visible";
		}

		l.focusItem.style.pixelTop = l.style.pixelTop;
		l.focusItem.style.top = l.focusItem.style.pixelTop + 'px';
		l.focusItem.style.pixelLeft = l.style.pixelLeft;
		l.focusItem.style.left = l.focusItem.style.pixelLeft + 'px';
		l.focusItem.style.zIndex = l.zIndex +1;
		l.Menu.hideChildIMenu(l);
	}
	else return;

	window.ActiveIMenuItem = l;
}

function hideChildIMenu(hcmLayer)
{//alert('MLSIMenu - hideChildIMenu(hcmLayer)'); //return;
	IM_clearTimeout();
	var l = hcmLayer;
	for(var i = 0; i < l.Menu.childIMenus.length; i++)
	{
		var theLayer = l.Menu.childIMenus[i];
		theLayer = document.frames("MLSIMenuIFrame").document.all(theLayer);
		theLayer.style.visibility = "hidden";
		if(theLayer.Menu.menuItemHAlign != 'left')
		{
			for(var j = 0; j < theLayer.Menu.menuItemLayers.length; j++)
			{
				var itemLayer = theLayer.Menu.menuItemLayers[j];
				if(itemLayer.textShim) itemLayer.textShim.style.visibility = "inherit";
			}
		}
		theLayer.Menu.hideChildIMenu(theLayer);
	}

	var iLeft = 0;
	iLeft = l.Menu.menuItemPadding + l.Menu.menuItemIndent;
	if(l.childIMenu)
	{
		var childIMenu = l.childIMenu;

		if(document.frames("MLSIMenuIFrame").document.all("imenuItem0"))
		{
			childIMenu = document.frames("MLSIMenuIFrame").document.all(l.childIMenu);
			var imenuLayer = document.frames("MLSIMenuIFrame").document.all(l.Menu.imenuLayer);
			var s = childIMenu.style;
			s.zIndex = imenuLayer.style.zIndex + 1;
			s.pixelTop = imenuLayer.style.pixelTop + l.Menu.submenuYOffset;

			if(l.Menu.vertical)
			{
				if(l.Menu.submenuRelativeToItem) s.pixelTop += l.style.pixelTop;
				s.pixelLeft = l.style.pixelWidth + imenuLayer.style.pixelLeft + l.Menu.submenuXOffset;
				s.left = s.pixelLeft + 'px';
			}
			else
			{
				s.pixelTop += l.style.pixelTop;
				if( l.Menu.submenuRelativeToItem ) s.pixelLeft = imenuLayer.style.pixelLeft + l.style.pixelLeft + l.style.pixelWidth + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
				else s.pixelLeft = (imenuLayer.style.pixelWidth - 4 * l.Menu.menuBorder) + imenuLayer.style.pixelLeft + l.Menu.submenuXOffset;
				s.left = s.pixelLeft + 'px';
			}

			childIMenu.style.visibility = "inherit";

			//document.all.MLSIMenuIFrame.style.backgroundColor = "transparent";
			//document.all.MLSIMenuIFrame.allowTransparency = "true";
			//document.frames("MLSIMenuIFrame").document.body.style.backgroundColor = "transparent";
			//document.frames("MLSIMenuIFrame").document.body.allowTransparency = "true";
			document.all.MLSIMenuIFrame.style.pixelWidth = 2 * iLeft + 30 + l.Menu.menuWidth + imenuLayer.style.pixelWidth;
		}
		else return;

		window.activeIMenus[window.activeIMenus.length] = childIMenu;
	}
	else
	{
		//document.all.MLSIMenuIFrame.style.backgroundColor = "#FFFFFF";
		//document.all.MLSIMenuIFrame.allowTransparency = "false";
		//document.frames("MLSIMenuIFrame").document.body.style.backgroundColor = "#FFFFFF";
		//document.frames("MLSIMenuIFrame").document.body.allowTransparency = "false";
		if(l.Menu.label == " root")
		{
			document.all.MLSIMenuIFrame.style.pixelWidth = parseInt(2 * iLeft + l.Menu.menuWidth - 2, 10);
		}
	}
}

function mouseoutIMenu()
{//alert('MLSIMenu - mouseoutIMenu()'); //return;
	if((navigator.appName == "Microsoft Internet Explorer") && (IM_getExplorerVersion() < 4.5))
		return true;
	hideIMenu(false, false);
	return true;
}

function mouseupIMenu(e)
{//alert('MLSIMenu - mouseupMenu(e)'); //return;
	hideIMenu(true, e);
	hideActiveIMenus();
	return true;
}

function hideIMenu(mouseup, e)
{//alert('MLSIMenu - hideIMenu(mouseup, e)'); //return;
	var a = window.ActiveIMenuItem;

	if(window.ActiveIMenu && document.frames("MLSIMenuIFrame").document.all("imenuItem0"))
	{
		if(a)
		{
			a.style.backgroundColor = a.saveColor;
			if(a.hilite) a.hilite.style.visibility = "hidden";
			if(a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
		}
	}
	if(!mouseup && window.ActiveIMenu)
	{
		if(window.ActiveIMenu.Menu) {
			if(window.ActiveIMenu.Menu.hideOnMouseOut) IM_startTimeout();
			return(true);
		}
	}
	return(true);
}

function doHideIMenu()
{//alert('MLSIMenu - doHideIMenu()'); //return;
	if(!imDHFlag || !window.ActiveIMenu) return;

	var elapsed = new Date() - mmStart;
	var timeout = window.ActiveIMenu.Menu.hideTimeout;

	if(elapsed < timeout)
	{
		window.imHideIMenuTimer = setTimeout("doHideIMenu()", timeout+100-elapsed);
		return;
	}
	imDHFlag = false;
	hideActiveIMenus();
	window.ActiveIMenuItem = 0;
}

function onIMenuItemAction(e, l)
{//alert('MLSIMenu - onIMenuItemAction(e, l)'); //return;
	l = window.ActiveIMenuItem;
	if(!l) return;
	hideActiveIMenus();
	if(l.imaction) eval("" + l.imaction);
	window.ActiveIMenuItem = 0;
}

function IM_clearTimeout()
{//alert('MLSIMenu - IM_clearTimeout()'); //return;
	if(window.imHideIMenuTimer)
		clearTimeout(window.imHideIMenuTimer);
	window.imHideIMenuTimer = null;
	imDHFlag = false;
}

function IM_startTimeout()
{//alert('MLSIMenu - IM_startTimeout()'); //return;
	if(window.ActiveIMenu)
	{
		mmStart = new Date();
		imDHFlag = true;
		window.imHideIMenuTimer = setTimeout("doHideIMenu()", window.ActiveIMenu.Menu.hideTimeout);
	}
}

function IM_moveXbySlicePos(x, img)
{//alert('MLSIMenu - IM_moveXbySlicePos(x, img)'); //return;
	var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
	var macIE45 = document.all && !onWindows && IM_getExplorerVersion() == 4.5;
	var par = img;
	var lastOffset = 0;
	while(par)
	{
		if(par.leftMargin && ! onWindows) x += parseInt(par.leftMargin);
		if((par.offsetLeft != lastOffset) && par.offsetLeft) x += parseInt(par.offsetLeft);
		if(par.offsetLeft != 0) lastOffset = par.offsetLeft;
		par = macIE45 ? par.parentElement : par.offsetParent;
	}

	return x;
}

function IM_moveYbySlicePos(y, img)
{//alert('MLSIMenu - moveYbySlicePos (y, img)'); //return;
	var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
	var macIE45 = document.all && !onWindows && IM_getExplorerVersion() == 4.5;
	var par = img;
	var lastOffset = 0;
	while(par)
	{
		if(par.topMargin && !onWindows) y += parseInt(par.topMargin);
		if((par.offsetTop != lastOffset) && par.offsetTop) y += parseInt(par.offsetTop);
		if(par.offsetTop != 0) lastOffset = par.offsetTop;
		par = macIE45 ? par.parentElement : par.offsetParent;
	}		

	return y;
}

function IM_getExplorerVersion()
{//alert('MLSIMenu - IM_getExplorerVersion()'); //return;
	var ieVers = parseFloat(navigator.appVersion);
	if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
	var tempVers = navigator.appVersion;
	var i = tempVers.indexOf( 'MSIE ' );
	if( i >= 0 )
	{
		tempVers = tempVers.substring( i+5 );
		ieVers = parseFloat( tempVers ); 
	}
	return ieVers;
}

