// CopyRight 2000 APEX International

//To see what kind of browser does the user browse this page
if (document.all)    {bNescape=0;bIE=1;fShow="visible";fHide="hidden";}
if (document.layers) {bNescape=1;bIE=0;fShow="show";   fHide="hide";}

var isLastMenu = null;
var r_X = 0;
var r_Y = 0;
var l_Y = 0;
var l_X = 0;

window.onerror=new Function("return true")

//Public Function
//APEXMenu()
function APEXMenu()
{
	this.bgColor    = "#0000b0";
	this.BorderColor= "#ffffff";
	this.BorderColorDark = "#000000";
	this.Border = 1;
	
	this.subMenubgColor= "#0000b0";
	this.subMenuBorderColor= "#ffecab";
	this.subMenuBorderColordark= "#ffecab";
	this.subMenuBorder = 1;	
	this.subMenuWidth = 90;
	

    this.AddMenu    = AddMenu;
	this.AddSubMenu = AddSubMenu;
	this.showMenu   = showMenu;
	
	HTMLstr = "";
	HTMLstr += "<!-- APEXMENU BEGINS -->\n";
	HTMLstr += "\n";
	if (bIE) HTMLstr += "<DIV id='APEXMainTable'>\n";
	HTMLstr += "<TABLE height=20 width='100%' bgcolor='"+this.bgColor+"' border='"+this.Border+"' cellspacing=0 bordercolor='"+this.BorderColor+"' bordercolordark='"+this.BorderColorDark+"'>\n";
	HTMLstr += "<TR>";
	if (bNescape) HTMLstr += "<TD>&nbsp;";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	if (bNescape) HTMLstr += "</TD>";
	HTMLstr += "</TR>\n";
	HTMLstr += "</TABLE>\n";
	HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	if (bIE) HTMLstr+= "</DIV>\n";

	HTMLstr += "<!-- APEXMENU ENDS -->\n";
}


//AddMenu(idItem, text, hint, location, alternativeLocation)
//idItem:	id of this menu
//text:     title of this menu
//hint:     text described this menu(when mouse move on this menu)
//location: URL of this menu, null means no hyperlink
//hasSubMeun:does this menu item has sub menu
//URLtraget: the target frame name or special target values(_balnk, _parent, _self, _top)
function AddMenu(idItem, text, hint, location, hasSubMenu,URLtarget)
{
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1)
	{
		alert(idParent + " already exist");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (bNescape)
	{
		MENUitem += "<ILAYER name="+idItem+">";
		MENUitem += "<A href='.' class=clsMenuItemNS onmouseover=\"displaySubMenu('"+idItem+"')\" onclick=\"return false;\"><FONT class=clsMenuItemNS>";
		MENUitem += "&nbsp;";
		MENUitem += text;
		MENUitem += "</A>";
		MENUitem += "</ILAYER>";
	}
	if (bIE)
	{
		MENUitem += "<TD align=center>\n";
		MENUitem += "<DIV id='"+idItem+"' style='position:relative;'>\n";
		MENUitem += "<A ";
		MENUitem += "class=clsMenuItemIE ";

		if (hint != null)
			MENUitem += "title='"+hint+"' ";
		if (!hasSubMenu)
			MENUitem += "onmouseover=\"hideAll()\" ";
		else
			MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
		if (location != null)
			MENUitem += "href='"+location+"' ";
		else
		{
			MENUitem += "href='.' ";
			MENUitem += "onclick=\"return false;\" "
		}
		MENUitem += "target='"+URLtarget+"' >";
		MENUitem += "&nbsp;\n";
		MENUitem += text;
		MENUitem += "</A>\n";
		MENUitem += "</DIV>\n";
		MENUitem += "</TD>\n";
	}
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";

	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}


//AddSubMenu(idParent, text, hint, location)
//idParent: id of parent menu
//text:     title of this menu
//hint:     text described this menu(when mouse move on this menu)
//location: URL of this menu
//URLtraget: the target frame name or special target values(_balnk, _parent, _self, _top)
function AddSubMenu(idParent, text, hint, location, URLtarget)
{
	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)
	{
		if (bNescape)
		{
			MENUitem += "\n";
			MENUitem += "<layer id='"+idParent+"submenu' visibility=hide bgcolor='"+this.bgColor+"'>\n";
			MENUitem += "<table border='"+this.subMenuBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuWidth+">\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</layer>\n";
			MENUitem += "\n";
		}
		if (bIE)
		{
			MENUitem += "\n";
			MENUitem += "<div id='"+idParent+"submenu' style='position:absolute; visibility: hidden; width: "+this.subMenuWidth+"; top: -300;'>\n";
			MENUitem += "<table border='"+this.subMenuBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuWidth+" cellspacing=0>\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";
	if (bNescape)  MENUitem = "<tr><td bgcolor='"+this.subMenubgColor+"'><a class=subMenuItemNS title='"+hint+"' href='"+location+"' target='"+URLtarget+"' >"+text+"</a><br></td></tr>\n";
	if (bIE) MENUitem = "<tr bgcolor='"+this.subMenubgColor+"'><td><a class=subMenuItemIE title='"+hint+"' href='"+location+"' target='"+URLtarget+"' >"+text+"</a><br></td></tr>\n";
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}

function SendMeTop(){
  if (document.all){
    document.all["APEXMainTable"].style.top = document.body.scrollTop;
    setTimeout("SendMeTop()", 200);
  }
}

function showMenu()
{
	document.writeln(HTMLstr);
}


//Private Function
function displaySubMenu(idMainMenu)
{
	var menu;
	var submenu;
	if (bNescape)
	{
		submenu = document.layers[idMainMenu+"submenu"];
		if (isLastMenu != null && isLastMenu != submenu) hideAll();
		submenu.left = document.layers[idMainMenu].pageX - 0;
		submenu.top  = document.layers[idMainMenu].pageY + 25;
		submenu.visibility = fShow;

		l_X  = document.layers[idMainMenu+"submenu"].left;
		r_X = l_X + document.layers[idMainMenu+"submenu"].clip.width;
		l_Y  = document.layers[idMainMenu+"submenu"].top+
			document.layers[idMainMenu+"submenu"].clip.height;
		r_Y = l_Y;
	} else if (bIE) {
		menu = eval(idMainMenu);
		submenu = eval(idMainMenu+"submenu.style");
		submenu.left = calculateSumOffset(menu, 'offsetLeft') - 0;
		submenu.top  = menu.style.top + 122;
		submenu.visibility = fShow;
		if (isLastMenu != null && isLastMenu != submenu) hideAll();

		l_X  = document.all[idMainMenu+"submenu"].style.posLeft;
		r_X = l_X + document.all[idMainMenu+"submenu"].offsetWidth;

		l_Y  = document.all[idMainMenu+"submenu"].style.posTop+
			document.all[idMainMenu+"submenu"].offsetHeight;
		r_Y = l_Y;
	}
	isLastMenu = submenu;
}

function hideAll()
{
	if (isLastMenu != null) {isLastMenu.visibility = fHide;isLastMenu.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;
}

function updateIt(e)
{
	if (bIE)
	{
		var x = window.event.clientX;
		var y = window.event.clientY;

		if (x > r_X || x < l_X) hideAll();
		else if (y > r_Y) hideAll();
	}
	if (bNescape)
	{
		var x = e.pageX;
		var y = e.pageY;

		if (x > r_X || x < l_X) hideAll();
		else if (y > r_Y) hideAll();
	}
}

if (document.all)
{
	document.body.onclick=hideAll;
	document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;
}

if (document.layers)
{
	document.onmousedown=hideAll;
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=updateIt;
}