var agt = navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
		&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var is_nav4 = (is_nav && (is_major == 4));
	var is_gecko = (agt.indexOf('gecko') != -1);
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3    = (is_ie && (is_major < 4));
	var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
	var is_ie5up  = ((is_ie && !is_ie3 && !is_ie4) | (agt.indexOf('konqueror') != -1));

subMenuTopOffset = 17;
leftX=0; rightX=0; topY=0; bottomY=0;
curSubMenu = null;
curItem = null;
//window.onerror=new Function("return true")

function Menu()
{	this.menuProp  = "align='center' font-family='Arial,sans-serif' width='100%' bgcolor='white' border='1' bordercolor='#008080' bordercolorlight='#90C8C0' bordercolordark='#005050' cellspacing='0' cellpaging='8'"
	this.subMenuProp  = "font-family='Arial,sans-serif' bgcolor='gray' border='1' bordercolor='#008080' bordercolorlight='#90C8C0' bordercolordark='#005050' cellspacing='0' cellpaging='0'"
	if (is_ie4) {this.subMenuProp +=" width='120'"}
	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.showMenu   = showMenu;
	
	HTMLstr = "";
//	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "<table " + this.menuProp + ">\n";
	HTMLstr += "<tr>";
//	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->";
//	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
//	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB MENU -->\n";
//	HTMLstr += "<!-- SUB MENU ENDS -->\n";
//	HTMLstr += "<!-- MENU PANE DECLARATION ENDS -->\n";
}

function addItem(idItem, text, hint, location)
{
//	var Lookup = "<!-- ITEM " + idItem + " -->";
//	if (HTMLstr.indexOf(Lookup) != -1)
//	{	alert(idItem + " already exist");
//		return;}

	var MENUitem = "<!-- ITEM " + idItem + " -->";

	if (is_nav4)
		{MENUitem += "<td><ilayer name='" + idItem + "'>";
		if (location != null)
		{	MENUitem += "<a class='MenuItem' href='" + location + "' onmouseover=\"hideAll()\" ";}
		else
		{	MENUitem += "<a class='MenuItem' href='.' ";
			MENUitem += "onmouseover=\"displaySubMenu('" + idItem + "')\" ";
			MENUitem += "onclick=\"return false;\" ";}
		if (hint != null) {	MENUitem += "title='" + hint + "' ";}
		MENUitem += ">&nbsp;" + text;
		MENUitem += "</a></ilayer></td>\n";}

	if (is_ie4 || is_ie5up || is_gecko)
		{MENUitem += "<td><div id='" + idItem + "' class='MenuItem' style='position: relative;'>";
		if (location != null)
			{MENUitem += "<a href='" + location + "' onmouseover=\"hideAll()\" ";}
		else
			{if (is_gecko)
				{MENUitem += "<a nohref style='cursor: pointer' ";}
			else
				{MENUitem += "<a nohref style='cursor: hand' ";}
			MENUitem += "onmouseover=\"displaySubMenu('" + idItem + "')\" ";
			MENUitem += "onclick=\"displaySubMenu('" + idItem + "')\" ";}
		if (hint != null) {	MENUitem += "title='" + hint + "' ";}
		MENUitem += ">&nbsp;" + text;
		MENUitem += "</a></div></td>\n";}

//	MENUitem += "<!-- END OF ITEM " + idItem + " -->\n";
	MENUitem += "<!-- MAIN_MENU -->";

	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->", MENUitem);
}

function addSubItem(idParent, text, hint, 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";
		if (is_nav4)
			{MENUitem += "<layer id='" + idParent + "submenu' visibility='hide' z-index='1'>\n";}
		if (is_ie4 || is_ie5up || is_gecko)
			{MENUitem += "<div id='" + idParent + "submenu' style='position: absolute; visibility: hidden; z-index: 1'>\n";}
		MENUitem += "<table " + this.subMenuProp + "><tr><td>\n";
		MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
		MENUitem += "</td></tr></table>\n";
		if (is_nav4)
			{MENUitem += "</layer>\n";}
		if (is_ie4 || is_ie5up || is_gecko)
			{MENUitem += "</div>\n";}
		MENUitem += "\n";
		MENUitem += "<!-- SUB MENU -->";
		HTMLstr = HTMLstr.replace("<!-- SUB MENU -->", MENUitem);}
	if (text == "LineBreak")
	{	MENUitem = "<hr>\n";}
	else
	{	MENUitem = "<a class=MenuItem title='" + hint + "' href='"+location+"' target='_top' >" + text + "</a><br>\n";}
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);
}

function showMenu()
	{document.writeln(HTMLstr);}

function displaySubMenu(idMainMenu)
	{if (is_nav4)
		{if (curSubMenu != document.layers[idMainMenu+"submenu"]) {hideAll();}

		curSubMenu = document.layers[idMainMenu+"submenu"]
		
		leftX  = document.layers[idMainMenu].pageX;
		topY  = document.layers[idMainMenu].pageY;

		curSubMenu.left = leftX;
		curSubMenu.top  = topY + subMenuTopOffset;
		curSubMenu.visibility = "show";

		rightX = leftX +curSubMenu.clip.width;
		bottomY = curSubMenu.top + curSubMenu.clip.height;}
	if (is_ie4)
		{if (curSubMenu != document.all[idMainMenu+"submenu"]) {hideAll();}
		curSubMenu = document.all[idMainMenu+"submenu"];
		curItem = document.all[idMainMenu];
		curItem.style.color = "000000"

		leftX = calculateSumOffset(curItem, 'offsetLeft');
		topY = calculateSumOffset(curItem, 'offsetTop');

		curSubMenu.style.left = leftX;
		curSubMenu.style.top  = topY + subMenuTopOffset;
		curSubMenu.style.visibility = "visible";

		rightX = leftX + 150;
		bottomY = curSubMenu.offsetTop + curSubMenu.offsetHeight;}
	if (is_ie5up || is_gecko)
		{if (curSubMenu != document.getElementById(idMainMenu+"submenu")) {hideAll();}
		curSubMenu = document.getElementById(idMainMenu+"submenu");
		curItem = document.getElementById(idMainMenu);
		curItem.style.color = "000000"

		leftX = curItem.offsetLeft + curItem.offsetParent.offsetLeft;
		topY = curItem.offsetTop + curItem.offsetParent.offsetTop;

		curSubMenu.style.left = leftX;
		curSubMenu.style.top  = topY + subMenuTopOffset;
		curSubMenu.style.visibility = "visible";

		rightX = leftX + curSubMenu.offsetWidth;
		bottomY = curSubMenu.offsetTop + curSubMenu.offsetHeight;}}

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;}

function hideAll()
	{if (curSubMenu != null)
		{if (is_nav4)
			{curSubMenu.visibility = "hide";}
		if (is_ie4 || is_ie5up || is_gecko)
			{curItem.style.color = "FFFFFF"; curSubMenu.style.visibility = "hidden";}}}

function updateIt(e)
	{if (is_nav4)
		{var x = e.pageX;
		var y = e.pageY;
		if (x > rightX || x < leftX) hideAll();
		else if (y > bottomY || y < topY) hideAll();}
	if (is_ie4 || is_ie5up)
		{var x = window.event.clientX;
		var y = window.event.clientY;
		if (x > rightX || x < leftX) hideAll();
		else if (y > bottomY || y < topY) hideAll();}
	if (is_gecko)
		{var x = e.clientX;
		var y = e.clientY;
		if (x > rightX || x < leftX) hideAll();
		else if (y > bottomY || y < topY) hideAll();}}

function showToolbar() {}

if (is_nav4)
	{document.onmousedown=hideAll;
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=updateIt;}
if (is_ie4 || is_ie5up)
	{document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;}
if (is_gecko)
	{document.onmousemove=updateIt;}
