// JavaScript Document
var ns6=document.getElementById&&!document.all
var ie5=document.all
var menuItemClicked = 0;

//Global Variables
var agt = navigator.userAgent.toLowerCase();
window.mmIsOpera = agt.indexOf("opera") != -1;
window.hideTimeout = 100;
window.mmHideMenuTimer = null;
window.mmStart = null;
window.mmDHFlag = false;

function FIND(item) {
	if( window.mmIsOpera ) return(document.getElementById(item));
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}
function getExplorerVersion() {
	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;
}
function contains(p, c) {
  while (c.parentNode)
    if ((c = c.parentNode) == p)
      return true;
  return false;
}
function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	while (item)
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	}
	return totalOffset;
}

function Menu(label, mw, id, mt, sl) 
{
	this.type = mt; //1=horizontal, 2=vertical
	this.slide = sl; //1=down, 2=up, 3=left, 4=right
	this.menuWidth = mw;
	this.menuId = id;
	this.menuItemHeight = 10;
	this.fontSize = "10px";
	this.fontWeight = "bold";
	this.fontFamily = "verdana";
	this.fontColor = "#ffffff";
	this.fontColorHilite = "#000000";
	this.bgColor = "#0160A7"; //"#ffffff"; //"#ebebeb"; //#CE0000"; //"#ffffff";
	this.bgColorHilite = "#ebebeb";
	this.borderColor = "#DADADA"
	this.border = 1;
	this.childMenuIcon = "arrows.gif";
	this.downArrowIcon = "tridown.gif";
	this.submenuXOffset = (this.border) * -1 - 2;
	this.submenuYOffset = (this.border) * -1 + 2;
	this.padLeft = 5;
	this.padTop = Math.floor((this.menuItemHeight - 10) / 2 - 2);
	this.items = new Array();
	this.itemIds = new Array();
	this.actions = new Array();
	this.childMenus = new Array();
	this.hideOnMouseOut = true;
	this.hideTimeout = 100;
	this.selectedItem = 0;
	this.addMenuItem = addMenuItem;
	this.writeMenus = writeMenus;
	this.onMenuItemOver = onMenuItemOver;
	this.onMenuItemAction = onMenuItemAction;
	this.onMenuItemOut = onMenuItemOut;
	//this.hideMenu = hideMenu;
	this.showChildMenu = showChildMenu;
	this.hideChildMenu = hideChildMenu;
	//this.hideAllChildMenu = hideAllChildMenu;
	this.buildMenu = buildMenu;
	//this.buildChildMenu = buildChildMenu;
	//this.buildTopMenu = buildTopMenu;
	this.positionAt = positionAt;
	if (!window.menus) window.menus = new Array();
	this.label = "" + label;
	window.menus[this.label] = this;
	window.menus[window.menus.length] = this;
	if (!window.activeMenus) window.activeMenus = new Array();
}

function addMenuItem(label, action, id) {
	this.items[this.items.length] = label;
	this.actions[this.actions.length] = action;
	this.itemIds[this.itemIds.length] = id;
}

function writeMenus(container) {
	if (window.triedToWriteMenus) return;
	var agt = navigator.userAgent.toLowerCase();
	window.mmIsOpera = agt.indexOf("opera") != -1;
	if (document.all || document.hasChildNodes || window.mmIsOpera) {
		document.writeln('<span id="menuContainer"></span>');
		container = FIND("menuContainer");
	}
	window.mmHideMenuTimer = null;
	if (!container) return;	
	window.triedToWriteMenus = true; 
	container.isContainer = true;
	container.menus = new Array();
	for (var i=0; i<window.menus.length; i++) 
		container.menus[i] = window.menus[i];
	window.menus.length = 0;
	
	var dbg = ""
	for (var x=0; x<container.menus.length; x++) {
		var menuLayer = FIND(container.menus[x].menuId);
		var menu = container.menus[x];
		
		menuLayer.Menu = menu;
		var s = menuLayer.style;
		s.zindex = 1;
		/*s.fontFamily = menu.fontFamily;
		s.fontSize = menu.fontSize;
		s.fontWeight = menu.fontWeight;
		s.color = menu.fontColor;
		s.backgroundColor = menu.bgColor;
		s.cursor = "hand";*/
		
		menu.menuLayer = menuLayer;
		menu.menuItemLayers = new Array();
		var top = 0;
		var left = 0;
		for (var i=0; i<menu.items.length; i++) {
			var l = FIND(menu.itemIds[i]);
			l.Menu = menu;
			l.Menu.menuItemLayers[l.Menu.menuItemLayers.length] = l;
			l.upColor = menu.bgColor;
			l.overColor = menu.bgColorHilite;
			l.upFontColor = menu.fontColor;
			l.overFontColor = menu.fontColorHilite;
			l.action = menu.actions[i];
			l.childMenu = 0;
			s = l.style;
			s.height = 17;
			s.fontFamily = menu.fontFamily;
			s.fontSize = menu.fontSize;
			s.fontWeight = menu.fontWeight;
			s.color = menu.fontColor;
			s.backgroundColor = menu.bgColor;
			//s.paddingLeft = "5px";
			//s.paddingRight = "5px";
			s.paddingTop = "1px";
			s.cursor = "hand";
			s.width = "100%";

			if (menu.items[i].label){
				var childLayer = FIND(menu.items[i].menuId);
				l.childMenu = 1;
				l.childLayer = childLayer;
				l.Menu.childMenus[l.Menu.childMenus.length] = l.childLayer;
			}
			l.onmouseover = onMenuItemOver;
			//l.onmouseout = MM_startTimeout; //onMenuItemOut;
			l.onmouseup = onMenuItemAction;
		}
		menuLayer.onmouseover = MM_clearTimeout;
		menuLayer.onmouseout = MM_startTimeout;
	}

	//if (document.captureEvents) document.captureEvents(Event.MOUSEUP);
	//if (document.addEventListener) document.addEventListener("mouseup", onMenuItemOver, false);
	document.onmouseup = MM_startTimeout; //mouseupMenu;
	window.mmWroteMenu = true;
}

function onMenuItemOut(e) {
	//if ((navigator.appName == "Microsoft Internet Explorer") && (getExplorerVersion() < 4.5))
		//return true;
	MM_startTimeout();
	return true;
}

function onMenuItemOver(e) {
	MM_clearTimeout();
	//restoreActiveMenuItem();
	
	//l = (e)?e.target:window.event.srcElement;
	//if (!l) {window.status = "target not found"; return false;}
	l = this;
	//window.status = "this = " + l.id;	
	if (l.style) {
		//window.status = l.action;
		hideChildMenu(l);
		l.style.backgroundColor = l.overColor;
		l.style.color = l.overFontColor;
		l.zIndex = 1;
		l.Menu.selectedItem = l;
		l.Menu.showChildMenu(l);
	} else return;
	window.ActiveMenuItem = l;
	window.event.cancelBubble = true;
}

function onMenuItemAction(e) {
	l = window.ActiveMenuItem;
	if (!l) return;
	hideDisplayedMenus();
	if (l.action) {
		//eval("" + l.action);
		menuItemClicked = 1;
		window.location = l.action;
	}
	//window.ActiveMenuItem = 0;
}

function MM_clearTimeout() {
	//window.status = "MM_clearTimeout Called " + window.event.srcElement.id;
	if (window.mmHideMenuTimer) clearTimeout(window.mmHideMenuTimer);
	window.mmHideMenuTimer = null;
	window.mmDHFlag = false;
}

function MM_startTimeout() {
	//window.status = "MM_startTimeout Called " + window.event.srcElement.id;
	window.mmStart = new Date();
	window.mmDHFlag = true;
	window.mmHideMenuTimer = setTimeout("mmDoHide()", window.hideTimeout);
}

function mmDoHide() {
	//window.status = "mmDoHide Called. mmDHFlag = " + window.mmDHFlag;
	if (!window.mmDHFlag) return; // || !window.ActiveMenu) return;
	var elapsed = new Date() - window.mmStart;
	var timeout = window.hideTimeout; //window.ActiveMenu.Menu.hideTimeout;
	if (elapsed < timeout) {
		window.mmHideMenuTimer = setTimeout("mmDoHide()", timeout+100-elapsed);
		return;
	}
	window.mmDHFlag = false;
	hideDisplayedMenus();
	//window.ActiveMenuItem = 0;
}

/*function hideAllChildMenu(menuLayer) {
	var l = menuLayer;
	for (var i=0; i < l.Menu.childMenus.length; i++) {
		var theLayer = l.Menu.childMenus[i];
		if (theLayer.Menu.selectedItem){
			var s = theLayer.Menu.selectedItem;
			s.style.color = s.upFontColor;
			s.style.backgroundColor = s.upColor;
			theLayer.Menu.selectedItem = 0;
		}
		theLayer.style.visibility = "hidden";
		hideAllChildMenu(theLayer);
	}
}*/

function hideChildMenu(menuLayer) {
	var l = menuLayer;
	if (l.Menu.selectedItem){
		var s = l.Menu.selectedItem;
		if (s == l) return;
		if (s.childMenu) {
			hideChildMenu(s.childLayer);
			s.childLayer.style.visibility = "hidden";
		}
		s.style.color = s.upFontColor;
		s.style.backgroundColor = s.upColor;
		l.Menu.selectedItem = 0;
	}
}

function showChildMenu(hcmLayer) {
	//MM_clearTimeout();
	var l = hcmLayer;
	hideChildMenu(l);
	if (l.childMenu) {
		var childLayer = l.childLayer;
		var menuLayer = l.Menu.menuLayer;
		var slide = l.childLayer.Menu.slide;
		if (slide == 1){
			//find the left position
			var offLeft = 0;
			var p = l;
			while (p)
			{
				offLeft += p.offsetLeft;
				p = p.offsetParent;
			}
			offRight = offLeft + l.offsetWidth;
			offRight += l.Menu.border;
			if ((offLeft + childLayer.offsetWidth) > 780) {
				offLeft = offRight - childLayer.offsetWidth;
				//window.status = "Item Width = " + l.offsetWidth + " menu width = " + childLayer.offsetWidth;
			}
			else {
				offLeft -= l.Menu.border;
			}
			
			//find the top position
			var offTop = 0;
			var p = l;
			while (p)
			{
				offTop += p.offsetTop;
				p = p.offsetParent;
			}
			offTop += l.offsetHeight; //+ l.Menu.border;
			
			var s = childLayer.style;
			s.zIndex = menuLayer.style.zIndex + 1;
			s.top = offTop + 'px';
			s.left = offLeft + 'px';
			//s.left = offLeft1 + 'px';
			s.visibility = "inherit";
		}
		else if (slide == 4){
			var s = childLayer.style;
			s.zIndex = menuLayer.style.zIndex + 1;
			if (document.all || window.mmIsOpera) {
				s.pixelTop = menuLayer.style.pixelTop + l.Menu.submenuYOffset;
				s.pixelTop += l.style.pixelTop;
				s.top = s.pixelTop + 'px';
				s.pixelLeft = menuLayer.style.pixelWidth + menuLayer.style.pixelLeft + l.Menu.submenuXOffset;
				s.left = s.pixelLeft + 'px';
			} else {
				var top = parseInt(menuLayer.style.top) + l.Menu.submenuYOffset;
				var left = 0;
				top += parseInt(l.style.top);
				left = parseInt(menuLayer.style.width) + parseInt(menuLayer.style.left) + l.Menu.submenuXOffset;
				s.top = top + 'px';
				s.left = left + 'px';
			}
			s.visibility = "inherit";
		}
	}
}

function hideDisplayedMenus() {
	//var yy = (!window.displayedMenus) ? "False" : "True";
	//window.status = "hideDisplayedMenus Called window.displayedMenus = " + yy;

	if (!window.displayedMenus) return;
	var a = window.ActiveMenuItem;
	if (a) {
		a.style.color = a.upFontColor;
		a.style.backgroundColor = a.upColor;
	} 
	window.ActiveMenuItem = 0;
	for (var i=0; i < window.displayedMenus.length; i++) {
		if (!displayedMenus[i]) continue;
		hideChildMenu(displayedMenus[i]);
	}
	return;
}

/*function display(menu,x,y)
{
	l = FIND(menu.menuId);
	if(!l) return false;
	l.style.pixelLeft = x;
	l.style.pixelTop  = y;
	l.style.visibility = "visible";
	
	l.Menu.xOffset = document.body.scrollLeft;
	l.Menu.yOffset = document.body.scrollTop;
	if (!window.displayedMenus) window.displayedMenus = new Array();
	window.displayedMenus[window.displayedMenus.length] = l;
}*/

var quote = "\"";
var vbcrlf = "\n";
var html = ""
var defMw = 100
var cw = 8
//var styleTop = " style=\"position:absolute; visibility:visible; "
var styleTop = " style=\"visibility:visible; "
var styleOut = " style=\"position:absolute; visibility:hidden; "
var styleIn = " style=\"position:absolute; visibility:inherit; "
function buildMenu(){
	var menu = this;
	var idMenu = menu.menuId;
	var htm = "";
	var top = "";

	if (menu.type == 1) { //horizontal menu
		top += "<div id=" + quote + idMenu + quote + styleOut + quote + ">" + vbcrlf;
		top += "<table width=780 border=0 cellpadding=0 cellspacing=0>" + vbcrlf;
		top += "<tr><td bgcolor='" + menu.borderColor + "'>" + vbcrlf;
		top += "<table width=100% border=0 cellpadding=0 cellspacing=" + menu.border + ">" + vbcrlf;
		top += "<tr>" + vbcrlf;
		
		var itmCnt = 0;
		var idItm = "";
		
		for(var i = 0; i < menu.items.length; i++){
			idItm = idMenu + "_itm_" + itmCnt;
			if (menu.items[i].label) {
				var mnChild = menu.items[i];
				mnChild.buildMenu();
				var labChild = menu.items[i].label;
			}
			else {
				var labChild = menu.items[i];
			}
			labChild = "&nbsp;" + labChild + "&nbsp;";
			htm = htm + "<td><div id=" + quote + idItm + quote + ">" + labChild + "</div></td>" + vbcrlf;
			itmCnt = itmCnt + 1;
		}
		top += htm + "</tr></table></td></tr></table></div>" + vbcrlf;
		document.writeln(top);
	}
	else if (menu.type == 2) { //vertical menu
		top += "<div id=" + quote + idMenu + quote + styleOut + quote + ">" + vbcrlf;
		//top += "<table border=" + menu.border + " cellpadding=0 cellspacing=0 bordercolor=" + menu.borderColor + " bgcolor=" + menu.bgColor + ">" + vbcrlf;
		top += "<table border=0 cellpadding=0 cellspacing=0>" + vbcrlf;
		top += "<tr><td bgcolor='" + menu.borderColor + "'>" + vbcrlf;
		top += "<table border=0 cellpadding=0 cellspacing=" + menu.border + ">" + vbcrlf;
		
		var itmCnt = 0;
		var idItm = "";
		
		for(var i = 0; i < menu.items.length; i++){
			idItm = idMenu + "_itm_" + itmCnt;
			if (menu.items[i].label) {
				var mnChild = menu.items[i];
				mnChild.buildMenu();
				var labChild = menu.items[i].label;
			}
			else {
				var labChild = menu.items[i];
			}
			labChild = "&nbsp;" + labChild + "&nbsp;";
			htm = htm + "<tr><td><div id=" + quote + idItm + quote + ">" + labChild + "</div></td></tr>" + vbcrlf;
			itmCnt = itmCnt + 1;
		}
		top += htm + "</table></td></tr></table></div>" + vbcrlf;
		document.writeln(top);
	}
}
/*function buildChildMenu(){
	var menu = this;
	for(var i = 0; i < menu.items.length; i++){
		if (menu.items[i].label) {
			var mnChild = menu.items[i];
			mnChild.buildMenu();
		}
	}
}
function buildTopMenu(){
	var menu = this;
	var idMenu = menu.menuId;
	var htm = "";
	var top = "";

	top += "<div id=" + quote + idMenu + quote + styleTop + quote + " align='center'>" + vbcrlf;
	top += "<table border=" + menu.border + " cellpadding=0 cellspacing=0 bordercolor=" + menu.borderColor + " bgcolor=" + menu.bgColor + ">" + vbcrlf;
	top += "<tr>" + vbcrlf;
	
	var itmCnt = 0;
	var idItm = "";
	
	for(var i = 0; i < menu.items.length; i++){
		idItm = idMenu + "_itm_" + itmCnt;
		if (menu.items[i].label) {
			var labChild = menu.items[i].label;
		}
		else {
			var labChild = menu.items[i];
		}
		htm = htm + "<td><div id=" + quote + idItm + quote + ">" + labChild + "</div></td>" + vbcrlf;
		itmCnt = itmCnt + 1;
	}
	top += htm + "</table></div>" + vbcrlf;
	document.writeln(top);
}*/
function AddToDisplayedMenus(menu)
{
	l = FIND(menu.menuId);
	if (!window.displayedMenus) window.displayedMenus = new Array();
	window.displayedMenus[window.displayedMenus.length] = l;
}

function positionAt(holder) {
	var l = FIND(holder);
	//window.status = "w = " + l.offsetWidth;
	var ow = l.offsetWidth;
	var me = this.menuLayer;
	//window.status = "me.w = " + me.offsetWidth;
	var bw = me.offsetWidth;
	//var xdef = Math.floor((ow - bw) / 2);
	var xdef = 0;
	
	//find the left position
	/*var offLeft = 0;
	var p = l;
	while (p)
	{
		offLeft += p.offsetLeft;
		p = p.offsetParent;
	}*/
			
	//find the top position
	var offTop = 0;
	var p = l;
	while (p)
	{
		offTop += p.offsetTop;
		p = p.offsetParent;
	}
			
	var s = me.style;
	s.top = offTop + 'px';
	s.left = xdef + 'px';
	s.visibility = "visible";
	//document.write("<h2>" + offTop + "</h2>");
}

