if (document.getElementById)    {n=0;ie=1;fShow="visible";fHide="hidden";}
if (document.layers) {n=1;ie=0;fShow="show";   fHide="hide";}

//window.onerror=new Function("return true")
////////////////////////////////////////////////////////////////////////////
// Function Menu()                                                        //
////////////////////////////////////////////////////////////////////////////
rightX = 0;

function Menu()
{
	this.bgColor     = "#FFFFFF";

	this.mainPaneBorder = 0;
	this.subMenuPaneBorder = 0;

	this.addItem        = addItem;
	this.addSubItem_Def = addSubItem_Def;
       this.displaySubMenu_Sub = displaySubMenu_Sub;
	this.displaySubMenu_Def = displaySubMenu_Def;
	this.showMenu       = showMenu;

       //this.MenuPaneWidth    = 350;
	//this.subMenuPaneWidth = 350;

	lastmenu = null;
	lastmenu_sub2 = null;
	
	rightY = 0;
	leftY = 0;
	leftX = 0;

	HTMLstr = "";
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	//HTMLstr += "\n";
	if (ie) HTMLstr += "<div id=\"MainTable\" style=\"position:ralative; visibility:show\">\n";
	HTMLstr += "<table width='782' border='0' cellspacing='0' cellpadding='0'>\n";
	//HTMLstr += "bgcolor='"+this.bgColor + "' "
	//HTMLstr += "border='"+this.mainPaneBorder+"'>\n";
	HTMLstr += "<tr>";
	// Main Menu
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	// First class Menu
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	// Second class Menu
	HTMLstr += "<!-- SUB2 MENU STARTS -->\n";
	HTMLstr += "<!-- SUB2_MENU -->\n";
	HTMLstr += "<!-- SUB2 MENU ENDS -->\n";
	HTMLstr += "\n";
	if (ie) HTMLstr+= "</div>\n";

	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}
function addItem(idItem, twidth, image, width, height, border, hint, location, altLocation, hSun)
{
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1)
	{
		alert(idItem + " already exist");
		return;
	}

	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (ie)
	{
		MENUitem += "<td width=\"" + twidth + "\" border='0' >\n";
		MENUitem += "<div id='"+idItem+"' style='position:absolute " + 
			         "; width:" +
			        twidth + 
			        "; font: "+this.menuFont+";'>\n";
		if(idItem.indexOf("NULL") == -1) {
			if (location != null)
			{
				MENUitem += "<a ";
				//MENUitem += "class=clsMenuItemIE ";
				if (hint != null)
					MENUitem += "title='"+hint+"' ";
				MENUitem += "href='"+location+"' target='_parent'";
				MENUitem += " onmouseover=\"HidAll_Def()\" ";
			}
			else
			{

				if (hSun == 0) {
					
					MENUitem += "<a ";
					if (altLocation != null)
						MENUitem += "href='"+altLocation+"' target=\"_parent\"";
					else
						MENUitem += "href='#'  style='cursor:default'";
					MENUitem += " onmouseover=\"displaySubMenu_Def('"+idItem+"')\" ";
					//MENUitem += "onclick=\"return false;\" ";
					
				} else {

					MENUitem += "<a ";
					if (altLocation != null)
						MENUitem += "href='"+altLocation+"' target=\"_parent\"";
					else
						MENUitem += "href='#' ";
					MENUitem += " onmouseover=\"displaySubMenu_Def('"+idItem+"')\" ";
					//MENUitem += "onclick=\"return false;\" ";
				}
			
			}
			MENUitem += ">";
			//alert(MENUitem);
		}
		MENUitem += "<img src=\"" + image + "\" ";
		MENUitem += "width=\"" + width + "\" ";
		MENUitem += "height=\"" + height + "\" ";
		MENUitem += "border=\"" + border + "\">";
		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);
}

function addSubItem_Def(idParent, image, iwidth, iheight, text, width, height, border, hint, location, classLevel, inumber)
{
	var MENUitem = "";
	var menu_left = 0;
	var menu_top = 0;

	var idItem = "";
	i = 1;
	while(i <= classLevel) {
		idItem = idParent + "_Sub";
		i++;
	}
	if(classLevel == 2) {
		idItem = idItem + inumber;
	}
	Lookup = "\n<!-- ITEM "+idParent+" -->\n";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	if(classLevel == 1) {
		Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idItem +" -->";
	}
	if(classLevel == 2) {
		Lookup = "<!-- NEXT ITEM OF SUB2 MENU "+ idItem +" -->";
	}
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		if (ie)
		{
			MENUitem += "\n";
			if(classLevel == 1) {
				MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idItem +" -->\n";
				MENUitem += "<div id='" + 
							idItem + 
							"' style='position:absolute; visibility: hidden; width: " +
							width +
							"; font: "+this.menuFont +
							"; top: 0" + 
							"; left: 0" +
							"z-index:1; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000" +
							"'>\n";
			}
			if(classLevel == 2) {
				MENUitem += "<!-- NEXT ITEM OF SUB_2 MENU "+ idItem +" -->\n";
				MENUitem += "<div id='" + 
							idItem + 
							"' style='position:absolute; visibility: hidden; width: " +
							width +
							"; font: "+this.menuFont +
							"; top: 0" + 
							"; left: 0" +
							"z-index:1; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000" +
							"'>\n";
			}
			MENUitem += "<table bgcolor='" +
				        this.bgColor +
				        "' width=" +
				        width+
				        " cellspacing='0' cellpadding='0' style='border:solid 1px #7BC7E7;boder-bottom:solid 0px #7BC7E7;'>\n";
			if(classLevel == 1) {
				MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			}
			if(classLevel == 2) {
				MENUitem += "<!-- NEXT ITEM OF SUB2 MENU "+ idItem +" -->\n";
			}

			MENUitem += "</table>\n";
			MENUitem += "</div>\n";
			MENUitem += "\n";
			if(classLevel == 1) {
				MENUitem += "<!-- SUB_MENU -->\n";
				HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
			}
			if(classLevel == 2) {
				MENUitem += "<!-- SUB2_MENU -->\n";
				HTMLstr = HTMLstr.replace("<!-- SUB2_MENU -->\n", MENUitem);
			}

		}
	}
	//alert(MENUitem);
	//alert(HTMLstr.substring(HTMLstr.length / 2, HTMLstr.length -1));	
	if(classLevel == 1) {
		Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	}
	if(classLevel ==2) {
		Lookup = "<!-- NEXT ITEM OF SUB2 MENU "+ idItem +" -->\n";
	}
	if (ie) { 
		if (location != null)
		{
			MENUitem = "<tr><td style='border-bottom:solid 1px #7BC7E7;padding-left:9px;' bgcolor='#42AADE'>";
			MENUitem += "<img src='";
			MENUitem += image;
			MENUitem += "' width='";
			MENUitem += iwidth;
			MENUitem += "' height='";
			MENUitem += iheight;
			MENUitem += "'>";
			MENUitem += "<a ";
			//MENUitem += "class = clsMenuItemIE ";
			MENUitem += (" href='"+location+"' target='_parent' ");
			/*
			if(classLevel == 1) {
				MENUitem += "onmouseover=\"HidAll_Def()\" ";
			}
			if(classLevel == 2) {
				//MENUitem += "onmouseover=\"HidSub()\" ";
			}
			*/
			MENUitem += ">";
			MENUitem += text;
			MENUitem += "</a><br></td></tr>\n";
		}
		else
		{
			MENUitem = "<tr><td style='border-bottom:solid 1px #7BC7E7;padding-left:9px;' bgcolor='#42AADE' >";
			MENUitem += "<img src='";
			MENUitem += image;
			MENUitem += "' width='";
			MENUitem += iwidth;
			MENUitem += "' height='";
			MENUitem += iheight;
			MENUitem += "'>";
			MENUitem += "<a ";
			//MENUitem += "class = clsMenuItemIE ";
			MENUitem += " href='#' ";
			if(classLevel == 1) {
				if(inumber != 0) {
					//MENUitem += "onmouseover=\"displaySubMenu_Sub('" + idItem + inumber + "')\" ";
				}
			}
			MENUitem += "onclick=\"return false;\" "
			MENUitem += ">&nbsp;";
			MENUitem += text;
			MENUitem += "</a><br></td></tr>\n";
		}
		MENUitem += Lookup;
		HTMLstr = HTMLstr.replace(Lookup, MENUitem);

	}
	//alert(HTMLstr.substring(HTMLstr.length / 2, HTMLstr.length -1));	
}

function showMenu()
{
	document.writeln(HTMLstr);
	if (document.getElementById)
	{
		document.body.onclick=HidAll_Def;
		document.body.onscroll=HidAll_Def;
		document.body.onmousemove=updateIt;
	}
}

////////////////////////////////////////////////////////////////////////////
// Private declaration
function displaySubMenu_Def(idMenu)
{
	if (ie) {
 		idSub = idMenu + "_Sub";

		menu = eval(idMenu);
		submenu = eval(idMenu, ".style");
		submenu.left = calculateSumOffset(menu, 'offsetLeft');
		submenu.top  = calculateSumOffset(menu, 'offsetTop') + 24;
			
		// Add 2005.4.28
		if(lastmenu != null) {	
			lastmenu.visibility = "hidden";
		}
		if(document.all[idSub] != null) {
			document.all[idSub].style.left = calculateSumOffset(menu, 'offsetLeft');
			document.all[idSub].style.top  = calculateSumOffset(menu, 'offsetTop') + 24;
			document.all[idSub].style.visibility = "visible";
			leftX  = document.all[idSub].style.posLeft;
			rightX = leftX + document.all[idSub].offsetWidth;

			leftY  = document.all[idSub].style.posTop +
		       	  document.all[idSub].offsetHeight;
			rightY = leftY;
			lastmenu = document.all[idSub].style;
		} else {
			lastmenu = null;
		}
	}
	//alert("leftX="+leftX+"rightX="+rightX+"testY="+document.all[idSub].style.posTop+"leftY"+leftY);
}
function displaySubMenu_Sub(idMenu)
{
	if(ie) {
		idParMenu = idMenu.substring(0, idMenu.length - 1);
		x = parseInt(idMenu.substring(idMenu.length - 1, idMenu.length));
		menu = eval(idParMenu);
		document.all[idMenu].style.left = calculateSumOffset(menu, 'offsetLeft') + 
			                              document.all[idParMenu].offsetWidth + 5;
		document.all[idMenu].style.top  = calculateSumOffset(menu, 'offsetTop') + 
										  15 * (x - 1);
			                              
		document.all[idMenu].style.visibility = "visible";
		
		leftX = document.all[idParMenu].style.posLeft;
		rightX = document.all[idMenu].style.posLeft + document.all[idMenu].offsetWidth;
		leftY = document.all[idMenu].style.posTop + 
                document.all[idMenu].offsetHeight;
		rightY = leftY;
		
	}
	lastmenu = document.all[idParMenu].style;
	if(lastmenu_sub2 != document.all[idMenu].style && lastmenu_sub2 != null) {
		lastmenu_sub2.visibility = "hidden";
		lastmenu_sub2 = null;
	}	
	lastmenu_sub2 = document.all[idMenu].style;
}
function HidAll_Def()
{
	if(lastmenu != null) {
		lastmenu.visibility = "hidden";
	}
	if(lastmenu_sub2 != null) {
		lastmenu_sub2.visibility = "hidden";
	}
	//lastmenu = null;
	//lastmenu_sub2 = null;

}

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 (ie)
	{
		var x = window.event.clientX;
		var y = window.event.clientY;
		//alert("x="+x+"y="+y+"rightY="+rightY);
		if (x >= rightX || x <= leftX) HidAll_Def();
		else if (y > rightY) HidAll_Def();
		//else lastmenu.visibility = "visible";
	}
}
/*
if (document.all)
{
	document.body.onclick=HidAll_Def;
	document.body.onscroll=HidAll_Def;
	document.body.onmousemove=updateIt;
}
*/

