function MM_showHideLayers() { //v6.0 
var i,p,v,obj,args=MM_showHideLayers.arguments; 
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; 
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; } 
obj.visibility=v; } 
} 
function MM_findObj(n, d) { //v4.01 
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
if(!x && d.getElementById) x=d.getElementById(n); return x; 
} 

		//browser detection
		
		if (document.all) {n=0;ie=1;ns6=0;fShow="visible";fHide="hidden";}//ie
		else if (document.getElementById){n=0;ie=0;ns6=1;fShow="";fHide="hidden";}//ns6
		else if (document.layers) {n=1;ie=0;ns6=0;fShow="show";fHide="hide";}//ns4
  
		ie4 = 0;
		if (ie) {
			if ((navigator.appName == "Microsoft Internet Explorer") && 
				(navigator.appVersion.search("5.") == -1)) {
				ie4=1;
			}
		} 
		//Initialize variables used in displaySubMenu function
//		windowWidth = document.body.offsetWidth;
//		offsetX = 10 -(windowWidth - 760) / 2;
//		if (offsetX > 0) { offsetX = 0 };
//		alert(offsetX);
		rightX = 0 ;
		leftY = 0;
		leftX = 0;
		lastMenu = null;
		//create the menu
		function Menu(){
			this.addItem    = addItem;
			this.addSubItem = addSubItem;
			this.showMenu   = showMenu;
			this.bgColor    = "#FFA23F";	
			this.mainPaneBorder = 0;
			this.subMenuPaneBorder = 0;
			this.subMenuPaneWidth = 180;
			lastMenu = null;
			
			HTMLstr = "";
			HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->";
			HTMLstr += "";
 			if((ie) || (ns6)) {
				HTMLstr += "<div align='center' id='MainTable' style='position:relative'><table align='center' width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td>"; 
			}

			// setup top and beginning of table			
			HTMLstr += "<table align='center' width='760' border='0' cellspacing='0' cellpadding='0'>";
			HTMLstr += "<tr><td valign='top' bgcolor='#FF6531' class='menu'>";

//			if (n) HTMLstr += "<td bgcolor='#336699'> ";
			HTMLstr += "<!-- MAIN MENU STARTS -->";
			HTMLstr += "<!-- MAIN_MENU -->";
			HTMLstr += "<!-- MAIN MENU ENDS -->";
//			if (n) HTMLstr += "</td>";
			HTMLstr += "</tr>";
			HTMLstr += "</table>";
			HTMLstr += "<!-- SUB MENU STARTS -->";
			HTMLstr += "<!-- SUB_MENU -->";
			HTMLstr += "<!-- SUB MENU ENDS -->";
 			if((ie) || (ns6)) {
			 	HTMLstr += "</td></tr></table></div>";
			}
//			HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->";
		}
		

		//add drop-down container
		function addItem(idItem, text, hint, location, altLocation, nosub){
			var Lookup = "<!-- ITEM "+idItem+" -->";
			if (HTMLstr.indexOf(Lookup) != -1){
				alert(idParent + " already exist");
				return;
			}
			var MENUitem = "";
			MENUitem += "<!-- ITEM "+idItem+" -->";
			if (n){
				MENUitem += "<td class='menu' nowrap bgcolor='#FF6531' width=0><ilayer name="+idItem+">";
				if (location != null) {
					MENUitem += "<a href='"+location+"' class=clsMenuItemNS ";
				}
				else {
					MENUitem += "<a href='.' class=clsMenuItemNS ";
			 	}
				if (nosub == null) {
					MENUitem += "onmouseover=\"imgOn('" +idItem+ "Image');displaySubMenu('"+idItem+"')\"";
				}
				else {
					MENUitem += "onmouseover=\"imgOn('" +idItem+ "Image');\"";
				}
				MENUitem += " onMouseOut=\"imgOff('" +idItem+ "Image');\"";

				MENUitem += ">";
				MENUitem += text;
				MENUitem += "</a>";
				MENUitem += "</ilayer></td>";
			}
			else{//IE or NS6
				// setup beginning of each menu item
				MENUitem += "<td class='menu' align='center' nowrap bgcolor='#FF6531'>";
//				MENUitem +=	"<img src='/images/blank.gif' width='"+width+"' height='1' alt='' border='0'><br>";
			
//				MENUitem += "<td>";
				MENUitem += "<div id='"+idItem+"' style='position:relative; font: "+this.menuFont+";'>";
				MENUitem += "<font face='Verdana,Arial,Helvetica,sans-serif' size='-2' STYLE='font-size:10px' color='#FFFFFF'>";
				MENUitem += "<a ";
				
				if(ie)
					MENUitem += "class=clsMenuItemIE ";
				if(ns6)
					MENUitem += "class=clsMenuItemNS6 ";
					
				if (hint != null)
					MENUitem += "title='"+hint+"' ";
				if (location != null){
					MENUitem += "href='"+location+"' ";
				//	MENUitem += "onmouseover=\"hideAll()\" ";
					if (nosub == null) {
						MENUitem += "onmouseover=\"imgOn('" +idItem+ "Image');displaySubMenu('" +idItem+ "')\" ";
				//		MENUitem += "onclick=\"return false;\" "
					}
					else {
						MENUitem += "onmouseover=\"imgOn('" +idItem+ "Image');\"";
					}
					MENUitem += "onmouseout=\"imgOff('" +idItem+ "Image');\"";
				}
				else{
					if (altLocation != null)
						MENUitem += "href='"+altLocation+"' ";
					else
						MENUitem += "href='.' ";
					MENUitem += "onmouseover=\"imgOn('"+idItem+"Image');displaySubMenu('"+idItem+"')\" ";
				//	MENUitem += "onclick=\"return false;\" "
					MENUitem += "onmouseout=\"imgOff('" +idItem+ "Image');\"";
				}
				MENUitem += ">";
				MENUitem += text;
				MENUitem += "</a>";
				MENUitem += "</font>";
				MENUitem += "</div>";
				MENUitem += "</td>";
			}
			MENUitem += "<!-- END OF ITEM "+idItem+" -->";
			MENUitem += "<!-- MAIN_MENU -->";
		
			HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->", MENUitem);
		}
		
		//add sub-menu items to applicable drop-down containor
		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){
				if (n){
					MENUitem += "<layer id='"+idParent+"submenu' visibility=hide bgcolor='"+this.bgColor+"'>";
					MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuPaneWidth+">";
					MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
					MENUitem += "</table>";
					MENUitem += "</layer>";
				}
				else{//IE or NS6
					MENUitem += "<div id='"+idParent+"submenu' style='position:absolute; background-color: "+this.bgColor+"; visibility: hidden; width: "+this.subMenuPaneWidth+"; top: -300;'>";
					MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuPaneWidth+">";
					MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
					MENUitem += "</table>";
					MENUitem += "</div>";
				}
				MENUitem += "<!-- SUB_MENU -->";
				HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->", MENUitem);
			}
		
			Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
			if (n)  {
				MENUitem = "<tr><td class='menu'><a class=clsMenuItemNS title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>";
			}
			else //IE or NS6
				if(ie)
					MENUitem = "<tr><td class='menu'><a class=clsMenuItemIE title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>";
				if(ns6)
					MENUitem = "<tr><td class='menu'><a class=clsMenuItemNS6 title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>";
			MENUitem += Lookup;
			HTMLstr = HTMLstr.replace(Lookup, MENUitem);
		
		}
		
		//write out main menu bar
		function showMenu(){
			if (n){
			document.writeln(HTMLstr);
			}
			else {
			document.getElementById("TopNavBar").innerHTML = HTMLstr; 
			}
		//	document.writeln(HTMLstr);
		}
		
		//show submenu, and then calculate its x and y coordinates
		function displaySubMenu(idMainMenu){
			var menu;
			var submenu;
			if (n){
				submenu = document.layers[idMainMenu+"submenu"];
				if (lastMenu != null && lastMenu != submenu) hideAll();
				submenu.left = document.layers[idMainMenu].pageX;
				submenu.top  = document.layers[idMainMenu].pageY + 18; //+ document.layers[idMainMenu].clip.height
				submenu.visibility = fShow;
				submenu.zIndex=10;
				leftX  = document.layers[idMainMenu+"submenu"].left;
				rightX = leftX + document.layers[idMainMenu+"submenu"].clip.width;
				leftY  = document.layers[idMainMenu+"submenu"].top+document.layers[idMainMenu+"submenu"].clip.height;
			} else if (ns6) {
				menu = document.getElementById(idMainMenu);		
				submenu = document.getElementById(idMainMenu+"submenu");
				if (lastMenu != null && lastMenu != submenu) hideAll();
				submenu.style.left = calculateSumOffset(menu, 'offsetLeft');
				submenu.style.top  = document.getElementById(idMainMenu).offsetHeight + 1;
				submenu.style.visibility = fShow;
				leftX  = calculateSumOffset(menu, 'offsetLeft');
				rightX =leftX + document.getElementById(idMainMenu+"submenu").offsetWidth;
				leftY = getComputedStyle(document.getElementById(idMainMenu+"submenu"), null).getPropertyValue('top');
 				leftY  += document.getElementById(idMainMenu+"submenu").offsetHeight + window.pageYOffset + 86 + 1;
				MM_showHideLayers('sortBox','','hide');
			} else if (ie) { 
				menu = eval(idMainMenu);
				submenu = eval(idMainMenu+"submenu.style");
				if (lastMenu != null && lastMenu != submenu) hideAll();			
				submenu.left = calculateSumOffset(menu, 'offsetLeft');
				submenu.top  = document.all[idMainMenu].offsetHeight + 1;
				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  + 86 +1;
				MM_showHideLayers('sortBox','','hide');
			}
			lastMenu = submenu;
		}
		
		//hide the submenunope
		
		function hideAll(){
			if (ns6){
				if (lastMenu != null) 
					{MM_showHideLayers('sortBox','','show');lastMenu.style.visibility = fHide;}
			}else{
				if (lastMenu != null) 
					{MM_showHideLayers('sortBox','','show');lastMenu.visibility = fHide;}
			}		
		}
		
		//used to calculate position of a submenu
		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;
		}
		
		//close menu on mouse out of menu containor
		function updateIt(e){
			if (ns6){
//				var x = e.pageX + offsetX;
				var x = e.pageX;
				var y = e.pageY;
				if (x > rightX || x < leftX) hideAll();
				else if (y > leftY) hideAll();
			}
			 else if (ie){
				var x = window.event.clientX;
				var y = window.event.clientY;
				if (x > rightX || x < leftX) hideAll();
				else if (y > leftY) hideAll();
			}
			else if (n){
//				var x = e.pageX + offsetX;
				var x = e.pageX;
				var y = e.pageY;
				if (x > rightX || x < leftX) hideAll();
				else if (y > leftY) hideAll();
			}
		}
		
