window.onerror=new Function("return true")
fShow="visible";
fHide="hidden";
rightX = 0;

function Menu()
{
	this.bgColor     				= "#000000";
	this.mouseoverColor 			= "#608062";
	this.menuFont 				= "Arial";
	this.fontColor   				= "white";	
	this.addItem   				= addItem;
	this.addSubItem			= addSubItem;
	this.showMenu   			= showMenu;
	this.mainPaneBorder 		= 0;
	this.itemWidth 				= 90;
	this.subMenuPaneBorder 	= 0;
	this.subMenuPaneWidth 		= 170;
	
	lastMenu = null;
	lastItem = screen.width - 315; // (screen width) minus (width of the logo image plus width of spacer)
	
	rightY = 0;
	leftY = 0;
	leftX = 0;
	
	
	
	HTMLstr = "";
	// build the menu system skeleton
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "\n";
	HTMLstr += "<div id='MainTable' style='position:relative visibility:show; left:0px; top:0px;'>\n";
	HTMLstr += "<table  bgcolor='white' cellpadding=2 cellspacing=0  border='"+this.mainPaneBorder+"'>\n";
	HTMLstr += "<tr align=center nowrap>";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- LAST_ITEM -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	HTMLstr+= "</div>\n";
	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}

function addItem(idItem, text, hint, functname, location, thisWidth)
{
	if (thisWidth == null) {
		thisWidth = this.itemWidth;
	}
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1)
	{
		alert(idParent + " already exists");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";	
	MENUitem += "<td nowrap bgcolor='"+this.bgColor+"' width="+thisWidth+" onmouseover=\"bgColor='"+this.mouseoverColor+"'\" onmouseout=\"bgColor='"+this.bgColor+"'\" style=\"position:relative; cursor:hand; font-size:smaller; font-weight:bold; font-family:"+this.menuFont+"; color:"+this.fontColor+";\">\n";
	MENUitem += "<div id='"+idItem+"' ";
	if (hint != null)
		MENUitem += "title='"+hint+"' ";
	if (functname != null)
		MENUitem += "onclick='javascript:hideLast();"+functname+"(\""+location+"\");' ";
	else
		MENUitem += "onclick='javascript:displaySubMenu('"+idItem+"');' ";
	MENUitem += "onmouseover=\"hideLast();displaySubMenu('"+idItem+"')\" ";
	MENUitem += ">";
	MENUitem += text;
	MENUitem += "</div>\n";
	MENUitem += "</td>\n";
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";
	lastItem = lastItem - this.itemWidth;
	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}

function addSubItem(idParent, text, hint, functname, location)
{
	var MENUitem = "";
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		MENUitem += "\n";
		MENUitem += "<div id='"+idParent+"submenu' style='position:absolute; visibility: hidden; width: "+this.subMenuPaneWidth+"; top: 25;left:100;'>\n";
		MENUitem += "<table  onmouseleave='javascript:hideLast()' border='"+this.subMenuPaneBorder+"' style='border-right:solid 1px white;' cellspacing=0 width="+this.subMenuPaneWidth+">\n";
		MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
		MENUitem += "</table>\n";
		MENUitem += "</div>\n";
		MENUitem += "\n";
		MENUitem += "<!-- SUB_MENU -->\n";
		HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
	}
	
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	MENUitem = "<tr nowrap><td width=10 onmouseover='javascript:hideLast()' >&nbsp;</td><td style='border-bottom:solid 1px white;border-left:solid 1px white;' bgcolor='"+this.bgColor+"' onclick='javascript:hideLast();"+functname+"(\""+location+"\");' onmouseover=\"bgColor='";
	MENUitem += this.mouseoverColor+"'\" onmouseout=\"bgColor='"+this.bgColor+"';\" style='position:relative; cursor:hand;";
	MENUitem += " font-size:smaller; font-weight:bold; font-family:"+this.menuFont+"; color:"+this.fontColor+";' title='"+hint;
	MENUitem += "' >&nbsp;"+text+"</td></tr>\n";
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);
	
}

function showMenu()
{
	HTMLstr = HTMLstr.replace("<!-- LAST_ITEM -->\n","<td bgcolor='#000000'>&nbsp;</td>\n");
	document.writeln(HTMLstr);
}

function displaySubMenu(idMainMenu)
{
	var menu;
	var submenu;
	menu = eval(idMainMenu);
	submenu = eval(idMainMenu+"submenu.style");
	// set the amount to move the dropdown menu to the right of the main item
	submenu.left = calculateSumOffset(menu, 'offsetLeft') + 0;
	// set the amount to drop the dropdown menus, from the top of the screen
	submenu.top  = menu.style.top+23; 
	submenu.visibility = fShow;
	
	leftX  = document.all[idMainMenu+"submenu"].style.posLeft;
	rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth;		
	leftY  = document.all[idMainMenu+"submenu"].style.posTop + document.all[idMainMenu+"submenu"].offsetHeight;
	rightY = leftY;
	lastMenu = submenu;
}

function hideLast()
{
	if (lastMenu != null) {
		lastMenu.visibility = fHide;
		lastMenu.left = 0;
	}
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

document.body.onscroll=hideLast;
