//----------------------------------------------------------------
function mOvr(src,clrOver) 
{ 
if (!src.contains(event.fromElement)) 
	{
		src.bgColor = clrOver; 
	}
}

function mOut(src,clrIn) 
{
	if (!src.contains(event.toElement))
	{
		src.style.cursor = 'default'; src.bgColor = clrIn;
	}
}

if (document.all)    {n=0;ie=1;fShow="visible";fHide="hidden";}
if (document.layers) {n=1;ie=0;fShow="show";   fHide="hide";}

topY = 0;rightX = 0;bottomY = 0;leftX = 0;
lastMenu = null;
var mstyle;
//----------------------------------------------------------------
function MenuStyle()
{
	this.bgColor     = "#0770D1";
	this.menuFont;
	this.menuFontIE  = "9pt ËÎÌå";
	this.menuFontNS  = "9pt ËÎÌå";

	this.clsMenuItemIE = "class=clsMenuItemIE";
	this.clsMenuItemNS = "class=clsMenuItemNS";

	this.mainMenuWidth = "772";

	this.mainMenuBorder = 0;
	this.subMenuBorder  = 0;
	this.menuDelta = 2;

	this.subMenueWidth = 170;

	this.bMenuStatic = 0;

	this.TranslateStyle = TranslateStyle;
}

function TranslateStyle()
{
	if (n)  this.menuFont = this.menuFontNS;
	if (ie) this.menuFont = this.menuFontIE;
}

//----------------------------------------------------------------
function Menu(ms)
{
	ms.TranslateStyle();
	mstyle = ms;

	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.showMenu   = showMenu;
	this.displaySubMenu = displaySubMenu;



	HTMLstr = "";
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "\n";

	//if (ie)
	//{
	//  if (mstyle.bMenuStatic > 0) HTMLstr += "<div id='SmartMenu'>\n";
	//  else HTMLstr += "<div id='SmartMenu'>\n";
	//}
	//if (n)
	//{
	//  if (mstyle.bMenuStatic > 0) HTMLstr += "<layer name='SmartMenu'><layer name='SmartMenuPane'>\n";
	//  else  HTMLstr += "<ilayer name='SmartMenu'><layer name='SmartMenuPane'>\n";
	//}

	//HTMLstr += "<table ";
	//if (mstyle.mainMenuWidth != null)
	//{
	//  HTMLstr += "width='"+mstyle.mainMenuWidth+"' ";
	//}
	//HTMLstr += "border='"+mstyle.mainMenuBorder+"' cellspacing=0>\n";
	//HTMLstr += "<tr><td bgcolor="+mstyle.bgColor+" valign='middle'>\n";

	HTMLstr += "<div id='SmartMenu'><table border=0 cellspacing=0 cellpadding=0 align=center><tr><td>\n";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	HTMLstr += "</td></tr></table></div>\n";

	//HTMLstr += "</td></tr>\n";
	//HTMLstr += "</table>\n";

	//if (ie) HTMLstr+= "\n";
	//if (n)
	//{
	//  if (mstyle.bMenuStatic > 0) HTMLstr+= "</layer></layer>\n";
	//  else HTMLstr+= "</layer></ilayer>\n";
	//}
	//HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";

	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}
//----------------------------------------------------------------
function addItem(idItem, text, hint, location, altLocation)
{
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1)
	{
		alert(idParent + " already exist");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (!ie)//zp add
	{
		MENUitem += "<td>\n";
		MENUitem += "<a ";
		MENUitem += " href='"+location+"' ";
		MENUitem += "><img border=0 src="+text+"></img></a>\n";
		MENUitem += "</td>\n";
	}
	else
	{
		MENUitem += "<td>\n";
		MENUitem += "<div id='"+idItem+"'>\n";
		MENUitem += "<a ";
		//if (hint != null)
		//	MENUitem += "title=\""+hint+"\" ";
		MENUitem += " href='"+location+"' ";
		MENUitem += "onmouseover=\"hideAll();"
		if( altLocation !="none")
			MENUitem +="displaySubMenu('"+idItem+"');";
		MENUitem +="\" ";
		//if (location != null)
		//	MENUitem += "onclick=\"return false;\" "
		MENUitem += "><img border=0 src="+text+"></img></div></a>\n";		
		MENUitem += "</td>\n";
	}
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";

	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}
//----------------------------------------------------------------
function addSubItem(idParent, text, hint, location, frame)
{
	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 (n)
		{
			MENUitem += "\n";
			MENUitem += "<layer id='"+idParent+"submenu' visibility=hide bgcolor='"+mstyle.bgColor+"'>\n";
			MENUitem += "<table border=0 cellspacing=1 bgcolor=#666666 width="+mstyle.subMenuWidth+">\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</layer>\n";
			MENUitem += "\n";
		}
		if (ie)
		{
			MENUitem += "\n";
			MENUitem += "<div id='"+idParent+"submenu' style='position:absolute; height=10; visibility: hidden; width: "+mstyle.subMenuWidth+"; font: "+mstyle.menuFont+"; top: -300;'>\n";
			MENUitem += "<table border=0 cellspacing=1 bgcolor=#cccccc width="+mstyle.subMenuWidth+"  style='filter: Alpha(Opacity=90)' >\n";
			MENUitem += "<tr><td align=middle width=4 bgColor=#1C62D7 rowSpan=100>"
		        //MENUitem += "<p align=center><br>"
		        //MENUitem += "<br><br><br></font></p>"
		        MENUitem += "</td>"

			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 (n)
        {
	  	MENUitem = "<td><a "
	  	if (hint != null)
			MENUitem += "title=\""+hint+"\" ";		
		MENUitem +=mstyle.clsMenuItemNS+" href='"+location+"'";
	  	if (frame!=null) MENUitem += " target='"+frame+"'";
	  	MENUitem += ">"+text+"</a><br></td></tr>\n";
        }
	if (ie)
        {
          if (location !=null)
          {
	  	MENUitem = "<td bgcolor=#EEEEEE class=tdmenu height=25 onmouseover=\"mOvr(this,'#FFFFFF');\" onmouseout=\"mOut(this,'#EEEEEE');\">&nbsp;&nbsp;<a class='menu' href='"+location+"'";
	  	//if (hint!=null)  MENUitem += " title=\""+hint+"\"";
	  	if (frame!=null) MENUitem += " target='"+frame+"'";
	  	MENUitem += ">"+text+"</a></td></tr>\n";
	  }
	  else
	  {
	  	MENUitem = "<tr><td height=1 bgcolor=#eeeeee></td></tr>\n";
	  }
        }
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);
}
//----------------------------------------------------------------
function showMenu()
{
	document.writeln(HTMLstr);
	//if (mstyle.bMenuStatic > 0) UpdateIt();
}

function displaySubMenu(idMainMenu)
{
	var menu;
	var submenu;
	//if (n)
	//{
	//	submenu = document.layers[idMainMenu+"submenu"];
	//	smp = document.layers["SmartMenu"].document.layers["SmartMenuPane"];

	//	submenu.left = smp.document.layers[idMainMenu].pageX;
	//	submenu.top  = document.layers["SmartMenu"].pageY+smp.clip.height;
	//	submenu.visibility = fShow;

	//	leftX  = submenu.left;
	//	rightX = leftX + submenu.clip.width;

	//	topY    = document.layers["SmartMenu"].pageY;
	//	bottomY = topY+document.layers["SmartMenu"].clip.height+submenu.clip.height;
	//} else if (ie) {
		menu = eval(idMainMenu);
		submenu = eval(idMainMenu+"submenu.style");
		
		smp = document.all["SmartMenu"];

		var calxx=calculateSumOffset(menu, 'offsetLeft');
		if(calxx >screen.width -mstyle.subMenuWidth)
			submenu.left = calxx-mstyle.subMenuWidth+54;
		else
			submenu.left = calxx;
		//submenu.left = submenu.left -160;
		
		submenu.top = calculateSumOffset(document.all["SmartMenu"], 'offsetTop')+smp.offsetHeight+mstyle.menuDelta;
		submenu.visibility = fShow;

		leftX  = document.all[idMainMenu+"submenu"].style.posLeft;
		rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth;
		

		topY    = document.all["SmartMenu"].offsetTop;
		bottomY = topY+document.all["SmartMenu"].offsetHeight+
				document.all[idMainMenu+"submenu"].offsetHeight;
	//}
	lastMenu = submenu;
}

function hideAll()
{
	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;
}

function updateIt(e)
{
	if (ie)
	{
		var x = window.event.clientX;
		var y = window.event.clientY+document.body.scrollTop;

		if (x > rightX || x < leftX) hideAll();
		else if (y < topY || y > bottomY) hideAll();
	}
	if (n)
	{
		var x = e.pageX;
		var y = e.pageY;

		if (x > rightX || x < leftX) hideAll();
		else if (y > bottomY || y < topY) hideAll();
	}
}
//----------------------------------------------------------------
function UpdateIt()
{
  if (ie) document.all["SmartMenu"].style.top = document.body.scrollTop;
  //if (n)  document.layers["SmartMenu"].top    = top.pageYOffset;
  setTimeout("UpdateIt()", 200);
}


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;
}
//----------------------------------------------------------------
