//*******************
//* Global variables
//********************

var rightX       	= 0;
var rightY       	= 0;
var leftX        	= 0;
var leftY       	= 0;
var SubCounter   	= 0;
var HiperCounter	= 0;
var MenuCounter  	= 0;
var SubMenuWidth 	= 0;
var HiperMenuWidth 	= 0;
var MenuWidth 		= 0;
var MenuHeight 	    = 0;
var MenuColor       = "white";
var itemBgColor2  	= "red";
var itemBgColor   	= "black";
var lastMenu		= null;
var lastParent   	= "zero";
var lastHiper   	= null;
var topOffset		= 0;
var leftPos   		= new Array();
var MenuNumber2Name	= new Array();
var NoOfSubmenus 	= new Array();
var NoOfHipermenus 	= new Array();
var MenuName2Number	= new Array();
var HTMLstr="";
var hiperParent = null;

/* alert(window.innerHeight);
alert(window.innerWidth);
alert(window.outerHeight);
alert(window.outerWidth);
window.scrollByLines(10); */

window.onerror=new Function(" return true")
 
//***********************************************************************
//*
//*
//* Function initMenu()                                             
//*
//*
//**********************************************************************


function initMenu()
{
	//alert("ENTER initMenu()");

	MenuWidth      = parseInt((win_width-90)/6);
	SubMenuWidth   = MenuWidth;
	HiperMenuWidth = SubMenuWidth;
	
	MenuHeight = parseInt(win_height/25);
	topOffset  = MenuHeight;
	
        leftPos[1] = 0;
	leftPos[2] = leftPos[1]+MenuWidth+6;
	leftPos[3] = leftPos[2]+MenuWidth+6;
	leftPos[4] = leftPos[3]+MenuWidth+6;
	leftPos[5] = leftPos[4]+MenuWidth+6;
	leftPos[6] = leftPos[5]+MenuWidth+6;

   //alert(topOffset);
}


//***********************************************************************
//*
//*
//* Function Menu()                                             
//*
//*
//**********************************************************************


function Menu()
{
  //alert("ENTER Menu()");

  this.menuFont 	 = MenuFont;
  this.bgColor 		 = itemBgColor;
  this.fontColor 	 = MenuColor;
  this.addItem    	 = addItem;
  this.addSubItem 	 = addSubItem;
  this.addHiperItem 	 = addHiperItem ;
  this.showMenu   	 = showMenu;
  this.mainPaneBorder 	 = 1;
  this.subMenuPaneBorder = 1;
  this.subMenuPaneWidth  = SubMenuWidth;
  this.subMenuHighlightWidth = this.subMenuPaneWidth;
  
  lastMenu 	= null;
  rightY 	= 0;
  leftY 	= 0;
  leftX 	= 0;
  

  HTMLstr = "<br><br> ";
  HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
  HTMLstr += "\n";

  if (n4)               HTMLstr += "<layer name='MainTable'>\n";          
  if (my_ie) 		HTMLstr += "<div id='MainTable' style='position: absolute;  top: 0; left: 0; '>\n";
  if (moz || moznu) 	HTMLstr += "<div id='MainTable' style='position: absolute; color: "+MenuColor+"; top: 0; left: 0; '>\n";
    
  
  if (n4) HTMLstr += "<table width='95%' bgcolor='"+this.bgColor+"' border='"+this.mainPaneBorder+"'>\n";
  //else  HTMLstr += "<table NOWRAP width='96%' bgcolor='"+this.bgColor+"' border='"+this.mainPaneBorder+"'>\n";
  else  HTMLstr += "<table NOWRAP width='"+parseInt(win_width-60)+"' bgcolor='"+this.bgColor+"' border='"+this.mainPaneBorder+"'>\n";


  
  HTMLstr += "<tr>";
  if (n4) HTMLstr += "<td>";
  HTMLstr += "<!-- MAIN MENU STARTS -->\n";
  HTMLstr += "<!-- MAIN_MENU -->\n";
  HTMLstr += "<!-- MAIN MENU ENDS -->\n";
  if (n4) 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 (my_ie || moz) HTMLstr+= "</div>\n";
  if (n4)  HTMLstr+= "</layer>\n";
  
  HTMLstr += "<!-- HIPER MENU STARTS -->\n";
  HTMLstr += "<!-- HIPER_MENU -->\n";
  HTMLstr += "<!-- HIPER MENU ENDS -->\n";

  HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
  
  if (my_ie) 
    {
      HTMLstr += "<div id='ShowHide' style=' ";
      HTMLstr += "position: absolute; ";
      HTMLstr += "left: "+parseInt(win_width-45)+"; ";
      HTMLstr += "top: 0; ";
      HTMLstr += "cursor: pointer; ";
      HTMLstr += "visibility: "+fShow+"; ";
      HTMLstr += " '>\n";
      //HTMLstr += "<table bgcolor='"+this.bgColor+"' border=0>\n";
      //HTMLstr += "<tr><td>";
      HTMLstr += "<a name=a_ShowHide title='showHide' ";
      HTMLstr += " onclick=f_minmax() onmouseout=eye_out() onmouseover=eye_over() >";
      HTMLstr += "<IMG alt='Show/Hide Menu' border=0 name=img_eye src='pics/on.gif'></a>" ;
      //HTMLstr += "</td>";
      //HTMLstr += "</tr>\n";
      //HTMLstr += "</table>\n";
      HTMLstr+= "</div>\n";
    }
  else if (moz || moznu) {
    
//    HTMLstr += "<table width='2%' bgcolor='"+this.bgColor+"' border=0>\n";
//    HTMLstr += "<tr><td>";
    HTMLstr += "<div id='ShowHide' style=' ";
    HTMLstr += "position: absolute; ";
    HTMLstr += "left: "+parseInt(win_width-45)+"; ";
    HTMLstr += "top: 5; ";
    HTMLstr += "cursor: pointer; ";
    HTMLstr += "visibility: "+fShow+"; ";
    HTMLstr += " '>\n";
    HTMLstr += "<a name=a_ShowHide title='click to Show/Hide Menu' ";
    HTMLstr += " onclick=f_minmax() onmouseout=eye_out() onmouseover=eye_over() >";
    HTMLstr += "<IMG alt='ShowHide' border=0 name=img_eye src='pics/on.gif'></a>" ;
    HTMLstr+= "</div>\n";
    //HTMLstr += "</td></tr></table>\n";
  }

//alert("EXIT Menu");
}

//***********************************************************************
//*
//*
//* Function addItem()                                             
//*
//*
//**********************************************************************

function addItem(idItem, text, hint, location, altLocation)
{
  //alert("ENTER: addItem()");
  var Lookup = "<!-- ITEM "+idItem+" -->";
  
	SubCounter = 0;
	MenuCounter +=1;
	MenuName2Number[idItem] = MenuCounter;
	MenuNumber2Name[MenuCounter] = idItem;

  if (HTMLstr.indexOf(Lookup) != -1)
    {
      alert(idParent + " already exist");
      return;
    }
  
  var MENUitem = "";
  MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
  
  if (n4)
    {
      MENUitem += "<ilayer name="+idItem+">";
      MENUitem += "<a href='.' class=clsMenuItemNS ";
      MENUitem += " onmouseover=\"displaySubMenu('"+idItem+"')\" onclick=\"return false;\">";
      MENUitem += "&nbsp;";
      MENUitem += text;
      MENUitem += "</a>";
      MENUitem += "</ilayer>";
    }
  else if (my_ie)
    {
      MENUitem += "<td NOWRAP align=center ";
      MENUitem += "width='"+MenuWidth+"' ";
      MENUitem += " >\n";
		MENUitem += "<div id='"+idItem+"' onmouseover=col_over('"+idItem+"') onmouseout=col_out('"+idItem+"')";
		MENUitem += " style='font: "+this.menuFont+" ";
		MENUitem += "width: "+MenuWidth+" ";
		MENUitem += "color: "+MenuColor+" ";
		MENUitem += "background: "+this.bgColor+" '>\n";
		MENUitem += "<a class=clsMenuItemIE ";
		if (hint != null)			MENUitem += "title='"+hint+"' ";
		if (location != null)
		{
			MENUitem += "href='"+location+"' ";
			MENUitem += "onmouseover=\"hideAll()\" ";
		}
		else
		{
			if (altLocation != null)	MENUitem += "href='"+altLocation+"' ";
			else               			MENUitem += "href='.' ";
			MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
			MENUitem += "onclick=\"return false;\" "
		}
		MENUitem += ">";
		MENUitem += "&nbsp;\n";
		MENUitem += text;
		MENUitem += "</a>\n";
		MENUitem += "</div>\n";
		MENUitem += "</td>\n";
    }
  //mozilla 
  else if (moz || moznu)
    {
      MENUitem += "<td NOWRAP align=center ";
      MENUitem += "width='"+MenuWidth+"' ";
      MENUitem += " >\n";
      MENUitem += "<div id='"+idItem+"' onmouseover=col_over('"+idItem+"') onmouseout=col_out('"+idItem+"') ";

/*      MENUitem += " style=' position: absolute ";
      MENUitem += "top: 0 ";
      MENUitem += "font: "+this.menuFont+" ";
	  MENUitem += "color: "+MenuColor+" ";
      MENUitem += "background: "+this.bgColor+" '";
      */

      MENUitem += ">\n";
      MENUitem += "<a class=clsMenuItemMoz ";
      if (hint != null)   MENUitem += "title='"+hint+"' ";
      if (location != null)
	  {
	  	MENUitem += "href='"+location+"' ";
	 	 MENUitem += "onmouseover=\"hideAll()\" ";
	  }
      else
	  {
	  if (altLocation != null)	    MENUitem += "href='"+altLocation+"' ";
	  else                  	    MENUitem += "href='.' ";
	  MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
	  MENUitem += "onclick=\"return false;\" "
	  }
      MENUitem += ">";
      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);  
  //alert("RETURN::addItem");
	return;
  
} // end of addItem


//***********************************************************************
//*
//*
//* Function addSubItem()                                             
//*
//*
//**********************************************************************


function addSubItem(idParent, text, hint, location)
{
  var MENUitem = "";
  var subId; 
  
  if(lastParent == "zero")
  	{ 
  		MenuCounter = 0; 
  		SubCounter = 0;
  	}
  
  if (idParent != lastParent) 
    {
      MenuCounter += 1;
      lastParent=idParent;
      SubCounter = 0;      
    }

  SubCounter += 1;
  NoOfSubmenus[idParent]=SubCounter;
  subId = idParent+"submenu"+SubCounter;
  
  var 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 (n4)
	{
	  MENUitem += "\n";
	  MENUitem += "<layer id='"+idParent+"submenu' visibility=hide bgcolor='"+this.bgColor+"'>\n";
	  MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' ";
      MENUitem += " width="+this.subMenuPaneWidth +">\n";
	  MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	  MENUitem += "</table>\n";
	  MENUitem += "</layer>\n";
	  MENUitem += "\n";
	}
      if (my_ie)
	{
	MENUitem += "\n";
	MENUitem += "<div id='"+idParent+"submenu' style=' ";
	MENUitem += "position: absolute; ";
	MENUitem += "visibility: "+fHide+"; ";
	MENUitem += "top: "+topOffset+"; ";
	MENUitem += "left: "+leftPos[MenuCounter]+"; ";
	MENUitem += "color: "+MenuColor+";  ";
//	MENUitem += "height: "+MenuHeight+"; ";
	MENUitem += "background: "+this.bgColor+"; ";
	MENUitem += "width: "+SubMenuWidth+"; ";
	MENUitem += "font: "+this.menuFont+"; '>\n";
	MENUitem += "<table NOWRAP border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' ";
	MENUitem += " width="+SubMenuWidth +" ";
	MENUitem += " >\n";
	MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	MENUitem += "</table>\n";
	MENUitem += "</div>\n";
	MENUitem += "\n";
	//alert(MENUitem)
			
	}
      if (moz || moznu)
	{
	MENUitem += "\n";
	MENUitem += "<div id='"+idParent+"submenu' style=' ";
	MENUitem += "position: absolute; ";
	MENUitem += "visibility: "+fHide+"; ";
	MENUitem += "top: "+topOffset+"; ";
	MENUitem += "left: "+leftPos[MenuCounter]+"; ";
	MENUitem += "color: "+MenuColor+"; ";
//	MENUitem += "height: "+MenuHeight+"; ";
	MENUitem += "background: "+this.bgColor+"; ";
	MENUitem += "width: "+SubMenuWidth+"; ";
	MENUitem += "font: "+this.menuFont+"; '>\n";
	MENUitem += "<table NOWRAP border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' ";
	MENUitem += " width="+SubMenuWidth +" ";
	MENUitem += " >\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 (n4)  MENUitem = "<tr><td><a class=clsMenuItemNS title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>\n";
  else if (my_ie)
  {
   	MENUitem  = "<tr><td NOWRAP align=center ";
   	MENUitem += "width='"+MenuWidth+"' ";
	MENUitem += "><div id='"+subId+"' onmouseover=mouseOverSub('"+subId+"') ";
   	MENUitem += "onmouseout=mouseOutSub('"+subId+"') ";
   	MENUitem += "style=' position: absolute ";
	MENUitem += "color: "+MenuColor+" ";
	MENUitem += "background: "+this.bgColor+" ";
	MENUitem += "visibility: "+fHide+" ";
	MENUitem += "top: "+topOffset+" ";
	MENUitem += "left: "+leftPos[MenuCounter]+"; ";
	MENUitem += "width: "+this.subMenuHighlightWidth+" ";
	MENUitem += "height: "+MenuHeight+" ";	
	MENUitem += "font: "+this.menuFont+" ";
	MENUitem += "'>\n";
	
	MENUitem += "<a class=clsMenuItemIE ";

   if (hint != null)		MENUitem += " title='"+hint+"' ";
   if (location != null)	MENUitem += " href='"+location+"' ";
   else                   MENUitem += " href='.' onclick=\"return false;\"";

   MENUitem += " >"+text+"</a>";
   MENUitem += "\n<!-- ITEM "+subId+" -->\n";
   MENUitem += "</div></td></tr>\n";
   MENUitem += "\n";	
 //  alert(MENUitem );	
  }   
  else if(moz || moznu  ) 
  {
   	MENUitem  = "<tr><td NOWRAP align=center ";
   	MENUitem += "width='"+MenuWidth+"' ";
	MENUitem += "><div id='"+subId+"' onmouseover=mouseOverSub('"+subId+"') ";
  	MENUitem += "onmouseout=mouseOutSub('"+subId+"') ";
   
   /*
    MENUitem += "style='position: absolute ";
	MENUitem += "color: "+MenuColor+" ";
	MENUitem += "background: "+this.bgColor+" ";
	MENUitem += "visibility: "+fHide+" ";
	MENUitem += "top: "+topOffset+" ";
	MENUitem += "left: "+leftPos[MenuCounter]+"; ";
	MENUitem += "width: "+this.subMenuHighlightWidth+" ";
	MENUitem += "height: "+MenuHeight+" ";	
	MENUitem += "font: "+this.menuFont+" ";
	*/
	MENUitem += "'>\n";
    MENUitem += "<a class=clsMenuItemMoz ";

    if (hint != null)		MENUitem += " title='"+hint+"' ";
    if (location != null)	MENUitem += " href='"+location+"' ";
    else                   MENUitem += " href='.' onclick=\"return false;\"";
    MENUitem += " >"+text+"</a>";
    MENUitem += "\n<!-- ITEM "+subId+" -->\n";
    MENUitem += "</div></td></tr>\n";
    }

  MENUitem += "<!-- END OF ITEM "+subId+" -->\n\n";
  MENUitem += Lookup;
  HTMLstr = HTMLstr.replace(Lookup, MENUitem);  
  
} // end of addSubItem


//***********************************************************************
//*
//*
//* Function addHiperItem()                                             
//*
//*
//**********************************************************************

function addHiperItem(idParent,row, text, hint, location)
{
	var MENUitem = "";
  	var hiperId;
	var hiperParent ="";
	var subLeft =0,subTop=0;

	//alert("ENTER:AddHiperIItem");
	hiperParent = idParent+"submenu"+row.toString();
  	
  	if(lastParent == "zero")
  	{ 
  		HiperCounter=0; 
  	}
  
  if ( hiperParent != lastParent) 
    {
      //MenuCounter += 1;
      lastParent=hiperParent ;
      HiperCounter= 0;      
    }

  	HiperCounter += 1;
  	NoOfHipermenus[hiperParent]=HiperCounter;
  	hiperId = hiperParent+HiperCounter;
	subTop= parseInt(row*MenuHeight+HiperCounter);		

 	subLeft=parseInt(leftPos[MenuName2Number[idParent]]+SubMenuWidth);

  
/*  Lookup = "<!-- ITEM "+idParent+" -->";
  if (HTMLstr.indexOf(Lookup) == -1)
    {
      alert(idParent + " not found");
      return;
    }
  */
    
  var Lookup = "<!-- NEXT ITEM OF HIPER MENU "+ hiperParent+" -->";
  
  if (HTMLstr.indexOf(Lookup) == -1)
    {
      if (n4)
	{
	  MENUitem += "\n";
	  MENUitem += "<layer id='"+hiperParent+"hiper' visibility=hide bgcolor='"+this.bgColor+"'>\n";
	  MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuPaneWidth+">\n";
	  MENUitem += "<!-- NEXT ITEM OF HIPER MENU "+ hiperParent+" -->\n";
	  MENUitem += "</table>\n";
	  MENUitem += "</layer>\n";
	  MENUitem += "\n";
	}
      if (my_ie)
	{
		MENUitem += "\n";
		MENUitem += "<div id='"+hiperParent+"hiper' style=' ";
		MENUitem += "position: absolute; "
		MENUitem += "visibility: "+fHide+"; ";
		MENUitem += "top: "+subTop+"; ";
		MENUitem += "left: "+subLeft+"; ";
//		MENUitem += "height: "+MenuHeight+"; ";
		MENUitem += "background: "+this.bgColor+"; ";
		MENUitem += "width: "+SubMenuWidth+"; ";
  	    MENUitem += "color: "+MenuColor+" ";
		MENUitem += "font: "+this.menuFont+"; '>\n";
		MENUitem += "<table NOWRAP border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' ";
		MENUitem += "width="+SubMenuWidth+">\n";
		MENUitem += "<!-- NEXT ITEM OF HIPER MENU "+ hiperParent+" -->\n";
		MENUitem += "</table>\n";
		MENUitem += "</div>\n";
		MENUitem += "\n";		
	}
      if (moz || moznu)
	{
		//subTop= parseInt(row*23+HiperCounter);		
	   	MENUitem += "\n";
		MENUitem += "<div id='"+hiperParent+"hiper' ";
		MENUitem += "style=' position: absolute; "
		MENUitem += "visibility: "+fHide+"; ";
		MENUitem += "top: "+subTop+"; ";
		MENUitem += "left: "+subLeft+"; ";
		// MENUitem += "height: "+MenuHeight+"; ";
		MENUitem += "background: "+this.bgColor+"; ";
		MENUitem += "color: "+MenuColor+"; ";
		MENUitem += "width: "+SubMenuWidth+"; ";
		MENUitem += "font: "+this.menuFont+"; '";
		
		MENUitem += ">\n";
		MENUitem += "<table NOWRAP border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' ";
		MENUitem += "width="+SubMenuWidth+">\n";
		MENUitem += "<!-- NEXT ITEM OF HIPER MENU "+ hiperParent+" -->\n";
		MENUitem += "</table>\n";
		MENUitem += "</div>\n";
		MENUitem += "\n";		
	}
      MENUitem += "<!-- HIPER_MENU -->\n";
      //alert(MENUitem);
      HTMLstr = HTMLstr.replace("<!-- HIPER_MENU -->\n", MENUitem);
    }
  
  Lookup = "<!-- NEXT ITEM OF HIPER MENU "+ hiperParent+" -->\n";

  if (n4)  MENUitem = "<tr><td><a class=clsMenuItemNS title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>\n";
  else if (my_ie)
  {
    MENUitem  = "<tr><td NOWRAP  align=center VALIGN = TOP ";
	//MENUitem += "height="+MenuHeight+" ";
	 MENUitem += "width="+SubMenuWidth+" >\n";
    MENUitem += "<div id='"+hiperId+"' ";
    MENUitem += "onmouseover=col_over('"+hiperId+"') onmouseout=col_out('"+hiperId +"') style=' ";
	 MENUitem += "position: relative ";
	 MENUitem += "color: "+MenuColor+" ";
	 MENUitem += "background: "+this.bgColor+" ";
	 MENUitem += "visibility: "+fHide+" ";
	 MENUitem += "width: "+this.subMenuHighlightWidth+" ";
 MENUitem += "height: "+parseInt(MenuHeight+20)+" ";
	 MENUitem += "font: "+this.menuFont+" ";
//	 MENUitem += "cursor: hand; ";
	  MENUitem += " '>\n";
	 MENUitem += "<a class=clsMenuItemIE ";

	 if (hint != null)		MENUitem += " title='"+hint+"' ";
   if (location != null)	MENUitem += " href='"+location+"' ";
   else                   MENUitem += " href='.' onclick=\"return false;\"";
	 
    MENUitem += ">"+text+"</a></div></td></tr>\n";
    MENUitem += "\n";		
  }   
  else if(moz || moznu ) 
  {
	 MENUitem  = "<tr><td NOWRAP align=center ";
	 MENUitem += "width="+SubMenuWidth+" >\n";
    MENUitem += "<div id='"+hiperId+"' ";
    MENUitem += "onmouseover=col_over('"+hiperId+"') onmouseout=col_out('"+hiperId +"')  ";
	/*
	 MENUitem += "style=' position: relative; ";
	 MENUitem += "color: "+MenuColor+"; ";
	 MENUitem += "background: "+this.bgColor+"; ";
	 MENUitem += "visibility: "+fHide+"; ";
	 MENUitem += "width: "+this.subMenuHighlightWidth+"; ";
	 MENUitem += "font: "+this.menuFont+"; ";
	 MENUitem += "cursor: hand; '";
	 */
	 MENUitem += ">\n";
	 MENUitem += "<a class=clsMenuItemMoz ";
    MENUitem += " title='"+hint+"' href='"+location+"'>"+text+"</a></div></td></tr>\n";
    MENUitem += "\n";		
    }
  MENUitem += "<!-- END OF ITEM "+hiperId+" -->\n\n";
  MENUitem += Lookup;
  HTMLstr = HTMLstr.replace(Lookup, MENUitem);
  
}

//***********************************************************************
//*
//*
//* Function showMenu()                                             
//*
//*
//**********************************************************************

function showMenu()
{
	//alert("ENTER::showMenu()");
	lastParent = null;
	lastHiper  = null;
	lastMenu=null;
	document.writeln(HTMLstr);
	//alert("RETURN::showMenu()");
	return;
}


//***********************************************************************
//*
//*
//* Function mouseOutSub()                                             
//*
//*
//**********************************************************************

function mouseOutSub(subId)
{
  col_out(subId);
  //hideAll();
}

//***********************************************************************
//*
//*
//* Function mouseOverSub()                                             
//*
//*
//**********************************************************************

function mouseOverSub(subId )
{
  //alert("mouseOverSub");
  col_over(subId);
  displayHiperMenu(subId);
}

//***********************************************************************
//*
//*
//* Function displayHiperMenu()                                             
//*
//*
//**********************************************************************

function displayHiperMenu(subId)
{
	//alert("displaying hiper"+subId);
 	var hipermenu;
  	var i=1;

	hipermenu   = subId+"hiper";
	hiperParent = subId.slice(0,subId.indexOf("submenu"));

   //alert("subId="+subId+" hipermenu="+hipermenu+" hiperParent="+hiperParent );
   //alert(parseInt(document.all[subId].offsetHeight));
   //alert(parseInt(document.all[subId].offsetTop));


  if (n4)
    { // *********************Netscape 4.x **************
	   if(document.layers["MainTable"].document.layers[idMainMenu] != null)
		{
			  /* submenu =document.layers["MainTable"].document.layers[idMainMenu+"submenu"];			
			  if (lastMenu != null && lastMenu != submenu) hideAll();
			  submenu.left =document.layers["MainTable"].document.layers[idMainMenu].pageX;
			  submenu.top  = document.layers["MainTable"].document.layers[idMainMenu].top + 25;
			  submenu.visibility = fShow;
			  leftX  = document.layers["MainTable"].document.layers[idMainMenu+"submenu"].left;
			  rightX = leftX + document.layers["MainTable"].document.layers[idMainMenu+"submenu"].clip.width;
			  leftY  = document.layers["MainTable"].top+document.layers["MainTable"].document.layers[idMainMenu+"submenu"].clip.height;
			  rightY = leftY; */
		} 
		else 
		{
		  alert("something is wrong: submenu is null !");
		}
	} 
  else if (my_ie && document.all[hipermenu] ) 
    {
		document.all[hipermenu].style.visibility = fShow;

		if (lastHiper != null && lastHiper != hipermenu   ) 
					document.all[lastHiper].style.visibility = fHide;

		//document.all[subId].style.top = parseInt(document.all[hiperParent].offsetTop);

		leftX  = parseInt(6+findPosX(document.all[subId])+document.all[subId].offsetWidth);
		
		leftY  = parseInt(findPosY(document.all[subId])-2);
		//leftY -= parseInt(document.body.scrollTop);
	   //leftY = parseInt(document.all[subId].offsetTop)+document.body.scrollTop;
	   
	   rightX = parseInt(leftX+SubMenuWidth);
		rightY = parseInt(leftY);
		rightY += parseInt(document.all[hipermenu].offsetHeight);
		
		//rightY -= parseInt(document.body.scrollTop);
		//rightY = parseInt(leftY +NoOfHipermenus[subId]*MenuHeight);

		document.all[hipermenu].style.top  = parseInt(leftY);
		document.all[hipermenu].style.left = parseInt(leftX);
  
		lastMenu = hipermenu;
		lastParent = hiperParent +"submenu";
		lastHiper = hipermenu;		
		
		//alert(document.body.scrollTop);
		//alert(document.all[hipermenu].offsetHeight);
		//alert(leftY);
		//alert(leftY+" "+ parseInt(findPosY(document.all[subId])-2)+" "+parseInt(document.body.scrollTop));	
	 }
  else if ( (moz || moznu) && (document.getElementById(hipermenu) != null))
    {
  		document.getElementById(hipermenu).style.visibility = fShow;

		if (lastHiper != null && lastHiper != hipermenu   ) 
					document.getElementById(lastHiper).style.visibility = fHide;
  

		leftX  = parseInt(4+findPosX(document.getElementById(subId))+document.getElementById(subId).offsetWidth);
		leftY  = parseInt(findPosY(document.getElementById(subId))-5); 
		rightX = parseInt(leftX+SubMenuWidth);
		rightY = parseInt(leftY)+parseInt(document.getElementById(hipermenu).offsetHeight);
		
		document.getElementById(hipermenu).style.top  = leftY;
		document.getElementById(hipermenu).style.left = leftX;  

		lastMenu = hipermenu;
		lastParent = hiperParent +"submenu";
		lastHiper = hipermenu;	
		//alert(parseInt(document.getElementById(hipermenu).offsetHeight));		
    }


}

//***********************************************************************
//*
//*
//* Function displaySubMenu()                                             
//*
//*
//**********************************************************************

function displaySubMenu(idMainMenu)
{
  var submenu;
  var i=1;

  submenu = idMainMenu+"submenu";
  lastParent = idMainMenu;

  //alert("kolko submenija="+NoOfSubmenus[idMainMenu]);
  
  if (n4)
    { // *********************Netscape 4.x **************
	   if(document.layers["MainTable"].document.layers[idMainMenu] != null)
		{
			submenu = document.layers["MainTable"].document.layers[idMainMenu+"submenu"];			
			if (lastMenu != null && lastMenu != submenu) hideAll();
			submenu.left =document.layers["MainTable"].document.layers[idMainMenu].pageX;
			submenu.top  = document.layers["MainTable"].document.layers[idMainMenu].top + 25;
			submenu.visibility = fShow;
			leftX  = document.layers["MainTable"].document.layers[idMainMenu+"submenu"].left;
			rightX = leftX + document.layers["MainTable"].document.layers[idMainMenu+"submenu"].clip.width;
			leftY  = document.layers["MainTable"].top+document.layers["MainTable"].document.layers[idMainMenu+"submenu"].clip.height;
			rightY = leftY;
			lastMenu = submenu;
		} 
		else 
		{
		  alert("something is wrong: submenu is null !");
		}
	} 
  else if (my_ie) 
    {
		if (lastMenu   != null && lastMenu != submenu) hideAll();
		if (lastHiper  != null) document.all[lastHiper].style.visibility = fHide;
  		if (lastParent != null && lastParent != submenu && lastParent!= idMainMenu) 	
  				document.all[lastParent].style.visibility = fHide;

		document.all[submenu].style.visibility = fShow;				


		leftY	 = parseInt(document.all[idMainMenu].offsetTop)+4/3*parseInt(document.all[idMainMenu].offsetHeight);
		leftX  = parseInt(document.all[submenu].style.left);
		rightX = parseInt(leftX + SubMenuWidth);
		rightY = parseInt(leftY)+parseInt(document.all[submenu].offsetHeight);
		lastMenu = submenu;	

		//alert(document.all[submenu].style.top);
		document.all[submenu].style.top = parseInt(leftY);
										
	//			alert(rightY+" "+leftY);

		//rightY = parseInt(leftY+NoOfSubmenus[idMainMenu]*MenuHeight);
		//alert(document.all[idMainMenu].offsetHeight);
		//alert(document.all[submenu].offsetTop);

		
    }
  else if (moz || moznu)
    {
    if (document.getElementById(submenu) != null)
	   {		  
  		  if (lastMenu   != null && lastMenu != submenu) hideAll();
		  if (lastHiper  != null) document.getElementById(lastHiper).style.visibility = fHide;
  		  if (lastParent != null && lastParent != submenu && lastParent != idMainMenu) 
  		  			document.getElementById(lastParent).style.visibility = fHide;

		  	document.getElementById(submenu).style.visibility = fShow;
		  	
			leftY	 = parseInt(document.getElementById(idMainMenu).offsetTop);
			leftY	+= 4/3*parseInt(document.getElementById(idMainMenu).offsetHeight);
		  	leftX  = parseInt(document.getElementById(submenu).style.left);
		  	rightX = parseInt(leftX+SubMenuWidth);
			rightY = parseInt(leftY)+parseInt(document.getElementById(submenu).offsetHeight);

			document.getElementById(submenu).style.top	= leftY;

		  	lastMenu = submenu;
		  	lastHiper = null;	
		  	//alert(parseInt(document.getElementById(submenu).offsetHeight));
		  	//alert("leftX= "+leftX+" leftY="+leftY+" rightX="+rightX+" rightY="+rightY);
	    }
    }
  
}


//***********************************************************************
//*
//*
//* Function col_over()                                             
//*
//*
//**********************************************************************
function col_over(idItem)
{
	if (n4) document.layers[idItem].style.bgColor = itemBgColor2;
	else if (my_ie) 
	{
	  if (document.all[idItem]!= null ) document.all[idItem].style.backgroundColor = itemBgColor2;
	  else alert("item doesn't exist !!");
	}
	else if (moz || moznu) 
	{
	  if (document.getElementById(idItem)) document.getElementById(idItem).style.backgroundColor = itemBgColor2;
	}
}


//***********************************************************************
//*
//*
//* Function col_out()                                             
//*
//*
//**********************************************************************
function col_out(idItem)
{
	if (n4)                  document.layers[idItem].style.bgColor = itemBgColor;
	else if (my_ie)          document.all[idItem].style.backgroundColor = itemBgColor;
	else if (moz || moznu)   
		if (document.getElementById(idItem))
			document.getElementById(idItem).style.backgroundColor = itemBgColor;	
}



//***********************************************************************
//*
//*
//* Function eye_out()                                             
//*
//*
//**********************************************************************

function eye_out()
{
  if (my_ie)
    {	
      if(document.all["MainTable"].style.visibility == fHide) 	document.images["img_eye"].src='pics/off.gif'; 
      else  document.images["img_eye"].src='pics/on.gif'; 
    }
  else if (moz || moznu) 
    {
      if (document.getElementById("MainTable").style.visibility == fHide)	document.images["img_eye"].src='pics/off.gif';
      else 	document.images["img_eye"].src='pics/on.gif'; 
    }
  else if (n4) 
  {  
  	if(document.layers["MainTable"].style.visibility == fHide) 	document.images["img_eye"].src='pics/off.gif'; 
      else  document.images["img_eye"].src='pics/on.gif'; 
  }
  
}


//***********************************************************************
//*
//*
//* Function eye_over()                                             
//*
//*
//**********************************************************************
function eye_over()
{
if (my_ie || moz || moznu || n4)
	{	
	    document.images["img_eye"].src='pics/on_off.gif'; 
	}
}



//***********************************************************************
//*
//*
//* Function f_minmax()                                            
//*
//*:: togles menu visibility ::
//**********************************************************************
function f_minmax()
{
  if (my_ie)
    {	
      if(document.all["MainTable"].style.visibility == fHide) 	document.all["MainTable"].style.visibility = fShow;
      else	document.all["MainTable"].style.visibility = fHide;
    }
  else if (moz || moznu)    
  	{
      if (document.getElementById("MainTable").style.visibility == fHide) document.getElementById("MainTable").style.visibility = fShow;
      else document.getElementById("MainTable").style.visibility = fHide;
    }
  else if (n4)
    {	
      if(document.layers["MainTable"].style.visibility == fHide) 	document.layers["MainTable"].style.visibility = fShow;
      else	document.layers["MainTable"].style.visibility = fHide;
    }

}

//***********************************************************************
//*
//*
//* Function f_hide()                                            
//*
//*:: hides menu visibility ::
//**********************************************************************
function f_hide()
{
  if (my_ie)
    {	
      document.all["MainTable"].style.visibility = fHide;
    }
  else if (moz || moznu)    
  	{
      document.getElementById("MainTable").style.visibility = fHide;
    }
  else if (n4)
    {	
      	document.layers["MainTable"].style.visibility = fHide;
    }

}


//***********************************************************************
//*
//*
//* Function calculateSumOffset()                                             
//*
//*
//**********************************************************************
function calculateSumOffset(idItem, offsetName)
{
  var totalOffset = 0;
  var item = eval('idItem');

  if (moz)
    {    }
  else
    {
	  do
		{
		  totalOffset += eval('item.'+offsetName);
		  item = eval('item.offsetParent');
		} 
      while (item != null);
    }
 return totalOffset;
}


//***********************************************************************
//*
//*
//* Function hideAll()                                             
//*
//*
//**********************************************************************
function hideAll()
{
  if (lastMenu != null)
  {
    if (moz) 	      document.getElementById(lastMenu).style.visibility= fHide;
    else if (my_ie)  document.all[lastMenu].style.visibility = fHide; 
    else
    {
     lastMenu.visibility = fHide;
	  lastMenu.left = 0;
	 }
  }
}


//***********************************************************************
//*
//*
//* Function updateIt()                                             
//*
//*
//**********************************************************************
function updateIt(e)
{
      var lastParentHeight = 0;
	//alert("ENTER::updateIt");
	 if (my_ie)
    	{
	      var x = window.event.clientX;
	      var y = window.event.clientY;
	//alert(x+" "+y+" "+leftX+" "+leftY+" "+rightX+" "+rightY+" scrollTop="+document.body.scrollTop);

      if (lastParent != null ) lastParentHeight = parseInt(document.all[lastParent].offsetHeight);
   	else lastParentHeight = MenuHeight;
     
 if ( lastMenu != null ) 
 {
     if (lastMenu.indexOf("hiper") == -1) 
     {
	      if (x > rightX || x < leftX )	       hideAll();
   	   else if (y > rightY || y<(leftY-lastParentHeight)) hideAll();   	   
     }
	  else 
	  {

		 	if (x > rightX || x < leftX-SubMenuWidth) 
		 	{
		 		hideAll();
		 		lastHiper = null;
				displaySubMenu(lastMenu.slice(0,lastMenu.indexOf("submenu")));
				
		 	}
   	   else if (y > rightY+MenuHeight-document.body.scrollTop || (y<leftY-document.body.scrollTop)) 
   		{
	   		hideAll();
		 		lastHiper = null;
				displaySubMenu(lastMenu.slice(0,lastMenu.indexOf("submenu")));
			}
   	}//end else
   }
  }
  if (n4)
    {
      var x = e.pageX;
      var y = e.pageY-20;
      
      if (x > rightX || x < leftX) hideAll();
      else if (y > rightY) hideAll();
    }
  if(moz || moznu)
    {
      var x = e.clientX;
      var y = e.clientY;
   	if (lastParent != null  ) lastParentHeight = parseInt(document.getElementById(lastParent).offsetHeight);
   	else lastParentHeight = MenuHeight;

	if ( lastMenu != null ) 
	{
     if (lastMenu.indexOf("hiper") == -1) 
     {
	    if (x > rightX || x < leftX )	       hideAll();
   	   else if (y > rightY || y<(leftY-lastParentHeight-5)) hideAll();   	   
     }
	  else 
	  {
		 if (x > rightX || x < leftX-SubMenuWidth) 
		 	{
		 		hideAll();
				displaySubMenu(lastMenu.slice(0,lastMenu.indexOf("submenu")));
				lastHiper = null;

		 	}
   	    else if (y > rightY+MenuHeight-pageYOffset || y<leftY-pageYOffset) 
   		{
	   		hideAll();
				lastHiper = null;
				displaySubMenu(lastMenu.slice(0,lastMenu.indexOf("submenu")));
		}
   	} //end else
   } //end if
  }	
 //alert("RETURN::updateIt");
  return;
}


//***********************************************************************
//*
//*
//* Function resizeD()                                             
//*
//*
//**********************************************************************
function resizeD()
{
 //alert("ENTER::resizeD");  
 if(moz || moznu) 
 	{
	var sURL = unescape(window.location.pathname);
	//alert(sURL );
	window.location.replace(sURL);
		}
 else {
	 	var sURL = unescape(window.location.pathname);
		window.location.replace(sURL);
		//window.location.reload( true );   
	 }
}

//***********************************************************************
//*
//*
//* Function findPosX()                                             
//*
//*
//**********************************************************************

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

//***********************************************************************
//*
//*
//* Function findPosY()                                             
//*
//*
//**********************************************************************
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}






//***********************************************************************
//*
//*
//* start the menu                                            
//*
//*
//**********************************************************************

if (my_ie)
  {
    document.body.onclick=hideAll;
    document.body.onscroll=hideAll;
    document.body.onmousemove=updateIt;
    window.onresize=resizeD;
    //window.onresize=  window.location.reload( false );

    //document.body.onresiye=window.body.reload;
  }
else if (n4 )
  {
    document.onmousedown=hideAll;
    window.captureEvents(Event.MOUSEMOVE);
    window.onmousemove=updateIt;
  }
else if(moz || moznu)
  {
    window.onclick=hideAll
    window.onscroll=hideAll;
    window.onresize=resizeD;
    window.onmousemove=updateIt;
   //document.addEventListener("mousemove", updateIt, true);

  }


initMenu();

