	var UA=navigator.userAgent, w = window, d = document, t, s="", st="";
	
	var is_gecko=/gecko/i.test(UA);
	var is_opera=/opera/i.test(UA);
	var is_ie=/msie/i.test(UA)&&!is_opera&&!(/mac_powerpc/i.test(UA));
	var is_ie5=is_ie&&/msie 5\.[^5]/i.test(UA);
	var is_mac_ie=/msie.*mac/i.test(UA);
	var is_khtml=/Konqueror|Safari|KHTML/i.test(navigator.userAgent);
	
	var hideDelay = 10;
	var chain = new Array();
	
	var cItemId = -1;
	var cItemId_Old = -1;
	var cId = -1;
	var cParentId = -1;
	var cLevel = -1;
	var cPosition = "";
	
	//-----------------------------------------------------------
/*	d.write('<FORM name="statusForm">');
	d.write('cItemId: <input type="text" value="0" name="cItemId"><br>');
	d.write('cId: <input type="text" value="0" name="cId"><br>');
	d.write('cParentId: <input type="text" value="0" name="cParentId"><br>');
	d.write('cLevel: <input type="text" value="0" name="cLevel"><br>');
	d.write('cPosition: <input type="text" value="0" name="cPosition"><br>');
	d.write('chain: <input type="text" value="0" name="cChain"><br>');
	d.write('other1: <input type="text" value="0" name="cOther1" size="100"><br>');
	d.write('other2: <input type="text" value="0" name="cOther2" size="100"><br>');
	d.write('</FORM>');
	viewStatus();*/
	
//-- Create menu ---------------------------------------
function createMenu(menuMnemo) {

	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);
	var direction = getDirection(menuMnemo);
	
	// set location and width MainTable
	switch(menuMnemo) {
	  case "usermenu":
		var loc = "center";	
		var width = 170;
	  break;
	  case "mainmenu":
		var loc = "center";	
		var width = 170;
	  break;
	  case "topmenu":
		var loc = "center";	
		var width = '';
	  break;
	  
	}

	s="<TABLE id='"+prefix+"Table' cellpadding='0' cellspacing='0' class='"+prefix+"Table' border='0' width='"+width+"' align='"+loc+"'>";
	if (direction=="h") s+="<TR>";
	d.write(s);
	
	//--- Check on left and right image ------------------
	for(i=0; i<menu.length; i++) 
	{
	  if (menu[i][1]==0) 
	  {
	    s='';
		if (direction=="v") s+="<TR>";
		s+="<TD valign='top'>";
		
		//-- get class ---------------
		  if (menu[i][7]=='active') 
		  	cl = prefix + "ItemActive"; 
		  else 
		  	cl = prefix + "Item";
			
		s+="<DIV style='position:relative'>";
		s+="<table id='"+prefix+"Item"+i+"' class='"+cl+"' cellpadding='0' cellspacing='0' border='0' width='"+width+"'";
		s+="onmouseover=\"itemOver('"+menuMnemo+"', -1, "+i+")\" onmouseout=\"itemOut('"+menuMnemo+"', -1, "+i+")\"";
		if (menu[i][6]!='') s+=" onclick=\"itemClick('"+menu[i][6]+"')\"";
		s+="><tr>";	

		//----- LeftBlock -----
		s+="<td id='"+prefix+"lb"+i+"' class='"+getBlockClass(menuMnemo, -1, i, "left")+"'>"+getInnerHTML(menuMnemo, -1, i, "left")+"</td>";
		//----- Title ------------		
		s+="<td class='"+prefix+"Title'>"+menu[i][5]+"</td>";	
		//----- RightBlock ----
		s+="<td id='"+prefix+"rb"+i+"' class='"+getBlockClass(menuMnemo, -1, i, "right")+"'>"+getInnerHTML(menuMnemo, -1, i, "right")+"</td>";
		
		s+="</tr></table>";		  
		d.write(s);

		// -- create submenu -------
		if (menu[i][2]==1) {
			st = "";
			createSubMenu(menuMnemo, i, 0, 0);
			d.write(st);
		}
		s="</DIV>";
		
		s+="</TD>";
		// for vertical menu
		if (direction=="v") s+="</TR>";
		d.write(s);
	  }
	}
	// for horizontal menu
	  if (direction=="h") s+="</TR>";
	
	s+="</TABLE>";
	d.write(s);
}

//-- Create sub menus -----------------------------------
function createSubMenu(menuMnemo, ind, row, counter) {

	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);
	var direction = getDirection(menuMnemo);
	
	// get width
	Width = getWidth(menuMnemo, ind);

	// get top and left
	if (direction=="h") {
		var top = 18;
		var left = 0; 
	} else {
		var top = 0;
		var left = 149; 
	}
	if (menu[ind][3]!=0) {
		var top = 0;
		var left = Width+2;
	}

    st+="<DIV id='"+prefix+"subMenu"+ind+"' style='top:"+top+"px; left:"+left+"px; position:absolute; visibility:hidden'>";
	st+="<table id='"+prefix+"subTable"+ind+"' class='"+prefix+"subTable' width='"+Width+"' cellpadding='0' cellspacing='0' border='0'>";
	
	//------------------------------------------
	counter = 0;
	while (row<menu.length) {
	  if (menu[row][1]==menu[ind][0]) {
	  	counter++;
		st+="\n\r<tr><td>";
		if (menu[row][7]=='active') cl = prefix + "subItemActive"; else cl = prefix + "subItem";

		st+="<DIV style='position:relative' style='width:"+Width+"'>";
		st+="<table id='"+prefix+"subItem"+ind+"_"+row+"' width='"+Width+"' class='"+cl+"' cellpadding='0' cellspacing='0' border='0'";
		st+="onmouseover='itemOver(\""+menuMnemo+"\", "+ind+","+row+")' onmouseout='itemOut(\""+menuMnemo+"\", "+ind+","+row+")' "; 			
		
		if (menu[row][6]!='') st+=" onclick=\"itemClick('"+menu[row][6]+"')\"";
		
		st+="><tr>";

		//----- LeftBlock -----
		st+="<td id='"+prefix+"lb"+ind+"_"+row+"' class='"+getBlockClass(menuMnemo, ind, row, "left")+"'>"+getInnerHTML(menuMnemo, ind, row, "left")+"</td>";
		//----- Title ------------		
		st+="<td class='"+prefix+"subTitle' valign='middle'>"+menu[row][5]+"</td>";	
		//----- RightBlock ----
		st+="<td id='"+prefix+"rb"+ind+"_"+row+"' class='"+getBlockClass(menuMnemo, ind, row, "right")+"'>"+getInnerHTML(menuMnemo, ind, row, "right")+"</td>";
		
		st+="</tr></table>";
		if (menu[row][2]==1) {
			createSubMenu(menuMnemo, row, 0, counter);
		}
		st+="</DIV>";

		st+="</td></tr>";
	  }
	  row++;
	}
	st+="</table>";
	st+="</DIV>";
	
	return st;
}

//-- Return menu style (icon|char) -------------------------
function getMenuStyle(menuMnemo) {
	switch (menuMnemo) {
		case "usermenu": return "sub"; break;
		case "mainmenu": return "sub"; break;
		case "topmenu": return "sub"; break;
	}
	return "sub";
}

//-- Return block class ----------------------------
function getBlockClass(menuMnemo, ind1, ind2, pos) {
	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);

	if (ind1==-1) 
		var Id = ind2;
	else
		var Id = ind1+'_'+ind2;
	
	if (menu[ind2][1]==0) var pre=''; else var pre='sub';	
	
	var cl="";
	if (menu[ind2][7]=='over') cl='Over';
	if (menu[ind2][7]=='active') cl='Active';	
	
	var block = 'Left';  
	if (pos=='right') block = 'Right';
	
	return prefix+pre+block+cl;
}


//-- Return char ---------------------------------------
function getInnerHTML(menuMnemo, ind1, ind2, pos) {
	
	var menu = eval("window."+menuMnemo);
	

	//----  With sub icon (only right) ------------------------
	if ( (getMenuStyle(menuMnemo)=='sub') && (menu[ind2][2]==1) && (pos=='right') ) {
		if (menuMnemo=="topmenu") {
		  switch (menu[ind2][7]) {
		  	case "over": 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "&nbsp;";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "&raquo;";
			break;
			case "active": 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "&nbsp;";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "&raquo;";
			break;
			default: 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "&nbsp;";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "&raquo;";
			break;
		  }
		}
		if (menuMnemo=="mainmenu") {
		  switch (menu[ind2][7]) {
		  	case "over": 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "<img src='/images/mr.gif' width='4' height='4' border='0'>";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "<img src='/images/mr.gif' width='4' height='4' border='0'>";
			break;
			case "active": 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "<img src='/images/mr.gif' width='4' height='4' border='0'>";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "<img src='/images/mr.gif' width='4' height='4' border='0'>";
			break;
			default: 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "<img src='/images/mr.gif' width='4' height='4' border='0'>";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "<img src='/images/mr.gif' width='4' height='4' border='0'>";
			break;
		  }
		}
		if (menuMnemo=="usermenu") {
		  switch (menu[ind2][7]) {
		  	case "over": 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "&raquo;";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "&raquo;";
			break;
			case "active": 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "&raquo;";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "&raquo;";
			break;
			default: 
			  //- main menu ---------
			  if (menu[ind2][1]==0) return "&raquo;";
			  //- sub menu ----------
			  if ((menu[ind2][1]!=0)) return "&raquo;";
			break;
		  }
		}
	}
	
	//--- Left & Right -------------------------------------------
	if (menuMnemo=="topmenu") {
	  switch (menu[ind2][7]) {
	  	case "over": 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "&raquo;"; 
		  if ((pos=="right")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		break;
		case "active": 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "&raquo;"; 
		  if ((pos=="right")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		break;
		default: 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "&raquo;"; 
		  if ((pos=="right")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		break;
	  }
	}
	if (menuMnemo=="mainmenu") {
	  switch (menu[ind2][7]) {
	  	case "over": 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "<img src='/images/castle.gif' width='10' height='12' border='0'>";
		  if ((pos=="right")&&(menu[ind2][1]==0)) return ""; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return ""; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return ""; 
		break;
		case "active": 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "<img src='/images/castle.gif' width='10' height='12' border='0'>";
		  if ((pos=="right")&&(menu[ind2][1]==0)) return "";  
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return ""; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return ""; 
		break;
		default: 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "<img src='/images/castle.gif' width='10' height='12' border='0'>";
		  if ((pos=="right")&&(menu[ind2][1]==0)) return ""; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return ""; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return ""; 
		break;
	  }
	}
	if (menuMnemo=="usermenu") {
	  switch (menu[ind2][7]) {
	  	case "over": 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  if ((pos=="right")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		break;
		case "active": 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "<font color='#FFFFFF'><b>&raquo;</b></font>"; 
		  if ((pos=="right")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return "<font color='#FFFFFF'><b>&raquo;</b></font>"; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		break;
		default: 
		  //- main menu ---------
		  if ((pos=="left")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  if ((pos=="right")&&(menu[ind2][1]==0)) return "&nbsp;"; 
		  //- sub menu ----------
		  if ((pos=="left")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		  if ((pos=="right")&&(menu[ind2][1]!=0)) return "&nbsp;"; 
		break;
	  }
	}
	return '';
}

//-- Menu item over ------------------------------------
function itemOver(menuMnemo, i, j) {

	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);

  	cLevel = menu[j][3];
	cPosition = "menu";
	if (cLevel==0) chain = new Array();
	chain[cLevel] = j;
  	viewStatus();

	if (menu[j][2]==1) {
		hideSelects(menuMnemo, j);
		el = d.getElementById(prefix+"subMenu"+j);
		el.style.left = getLeftPosition(menuMnemo, j)-1;
		el.style.visibility="visible";
	}

	//if (menu[j][7]!='active') itemSetStyle(menuMnemo, i, j, 1);
	itemSetStyle(menuMnemo, i, j, 1);
	
	if ( (cLevel>0)&&(chain[cLevel-1]==i)&&(menu[i][7]!='active') ) {
		var ind2 = chain[cLevel-1];
		if (cLevel==1) 
			var ind1 = -1;
		else
			var ind1 = chain[cLevel-2];
		itemSetStyle(menuMnemo, ind1, ind2, 1);
	}
}

//-- Menu item out ------------------------------------
function itemOut(menuMnemo, i, j) {

	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);

  	cLevel = -1;
	cPosition = "out";
	chain[cLevel] = j;
  	viewStatus();

	t = setTimeout("hideAll('"+menuMnemo+"')", hideDelay);

	//if (menu[j][7]!='active') itemSetStyle(menuMnemo, i, j, 0);
	itemSetStyle(menuMnemo, i, j, 0);
}


//-- set style for item ---------------------------------
function itemSetStyle(menuMnemo, i, j, status) {

	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);

	var itemStatus='';
	
	switch(status) {
		case 0: menu[j][7]=''; break;
		case 1: itemStatus='Over'; menu[j][7]='over'; break;
		case 2: itemStatus='Active'; break;
	}
	
	if (menu[j][1]==0) {
	  	d.getElementById(prefix+"Item"+j).className = prefix + "Item"+ itemStatus;
		// left block
		var obj = d.getElementById(prefix+"lb"+j);
		obj.className = getBlockClass(menuMnemo, i, j, "left");
		obj.innerHTML = getInnerHTML(menuMnemo, i, j, "left");
		// right block
		var obj = d.getElementById(prefix+"rb"+j);
		obj.className = getBlockClass(menuMnemo, i, j, "right");
		obj.innerHTML = getInnerHTML(menuMnemo, i, j, "right");
	} else {
	  	d.getElementById(prefix+"subItem"+i+"_"+j).className = prefix + "subItem" +itemStatus;	
		// left block
		var obj = d.getElementById(prefix+"lb"+i+"_"+j);
		obj.className = getBlockClass(menuMnemo, i, j, "left");
		obj.innerHTML = getInnerHTML(menuMnemo, i, j, "left");
		// right block
		var obj = d.getElementById(prefix+"rb"+i+"_"+j);
		obj.className = getBlockClass(menuMnemo, i, j, "right");
		obj.innerHTML = getInnerHTML(menuMnemo, i, j, "right");
	}
}


//-- hide submenus and items --------------------
function hideAll(menuMnemo) {
	
	var menu = eval("window."+menuMnemo), st='';
	var prefix = getPrefix(menuMnemo);
	
	showSelects();
	// hide submenu
	for (var i=0; i<menu.length; i++) {

	  if (menu[i][2]==1) {
	    
		if ( (menu[i][3]>=cLevel)&&(chain[cLevel]!=i) || (cPosition=="out"))  {
			el = d.getElementById(prefix+"subMenu"+i);
			el.style.visibility="hidden";
		} else {
			//el.style.visibility="visible";
			hideSelects(menuMnemo, i);
		}
	  }
	
	  if ( (i==chain[menu[i][3]])&&(menu[i][7]=='over') ) {
	  	var hide = 0;
	  	if (cPosition=="out") hide = 1;
		if (cLevel<menu[i][3]) hide = 1;
		if (hide == 1) {
			var ind2 = i;
			if (menu[i][3]==0) 
				var ind1 = -1;
			else
				var ind1 = chain[menu[i][3]-1];
			itemSetStyle(menuMnemo, ind1, ind2, 0);
		}
	  }
	  
	  if ( (i!=chain[menu[i][3]])&&(menu[i][7]=='over') ) {
			var ind2 = i;
			if (menu[i][3]==0) 
				var ind1 = -1;
			else
				var ind1 = chain[menu[i][3]-1];
			itemSetStyle(menuMnemo, ind1, ind2, 0);
	  }	
	}
}

//-- Item click -----------------------------------------
function itemClick(Link) {
	window.location.href=Link;
}

//---- Return submenu width ----------------
function getWidth(menuMnemo, ind) {
	
	var menu = eval("window."+menuMnemo);
	var width=20;
	
	for (ii=0; ii<menu.length; ii++) 
	  if (menu[ii][1]==menu[ind][0]) {
	    if (menu[ii][5].length>width) width=menu[ii][5].length;
	  }
	width = width*7;
	if (width>180) width=180;
  	return width;
}

//---- Return submenu left position ----------------
function getLeftPosition(menuMnemo, ind) {
	
	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);
	
	if (cLevel==0) 
		var width = d.getElementById(prefix+"Table").width;
	else
		var width = d.getElementById(prefix+"subTable"+chain[cLevel-1]).width;
  	return width;
}

function viewStatus() {
/*	d.statusForm.cItemId.value=cItemId;
	d.statusForm.cId.value=cId;
	d.statusForm.cParentId.value=cParentId;
	d.statusForm.cLevel.value=cLevel;
	d.statusForm.cPosition.value=cPosition;
	var ss='';
	for (var k=0; k<chain.length; k++) ss+=chain[k]+'|';
	d.statusForm.cChain.value=ss;*/
}

//---- Return menu prefix ---------------
function getPrefix(menuMnemo) {
  switch (menuMnemo) {
	case "topmenu": return "TM"; break;
	case "mainmenu": return "MM"; break;
	case "usermenu": return "UM"; break;
	case "bottommenu": return "BM"; break;
  }
}

//---- Return menu direction ------------
function getDirection(menuMnemo) {
  switch (menuMnemo) {
	case "topmenu": return "h"; break;
	case "mainmenu": return "v"; break;
	case "usermenu": return "v"; break;
	case "bottommenu": return "h"; break;
  }
}

//-- Return object left position -----
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;
}

//-- Return object top position ------
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;
}

//-- Hide all select objects ---------------------------
function hideSelects(menuMnemo, ind) {
	
  if (is_ie) {	
	var menu = eval("window."+menuMnemo);
	var prefix = getPrefix(menuMnemo);
	
	var aSelect = d.getElementsByTagName("SELECT");
	if (aSelect.length>0) {
	    //-- Search submenu top, left, width, height  ----
		var obj = d.getElementById(prefix+"SubMenu"+ind);
		var menuTop = findPosY(obj);
		var menuLeft = findPosX(obj);
		var menuWidth = obj.offsetWidth;
		var menuHeight = obj.offsetHeight;
		var menuRight = menuLeft+menuWidth;
		var menuBottom = menuTop+menuHeight;
		//alert("Top="+menuTop+"; Left="+menuLeft+"; Right="+menuRight+"; Bottom="+menuBottom);
		
		for (ii=0; ii<aSelect.length; ii++) { 
		  //-- Search select top, left, width ----
			var objTop = findPosY(aSelect[ii]);
			var objLeft = findPosX(aSelect[ii]);
			var objWidth = aSelect[ii].offsetWidth;
			var objRight = objLeft+objWidth;
			var objBottom = objTop + 10;
			//alert("Top="+objTop+"; Left="+objLeft+"; Right="+objRight+"; Bottom="+objBottom);

			var hide = 0;			
			if (((menuLeft>objLeft) && (menuLeft<objRight)) || 
				((menuRight>objLeft) && (menuRight<objRight)) ||
				((menuLeft<objLeft) && (menuRight>objRight)) ) {
				
				if ( (menuTop<objBottom) && (menuBottom>objBottom) ) hide=1;
				if ( (menuTop<objBottom) && (menuBottom>objTop) && (menuBottom<objBottom) ) hide=1;
				if ( (menuBottom<objBottom) && (menuTop>objTop) && (menuTop<objBottom) ) hide=1;
			}
			if (hide==1) aSelect[ii].style.visibility="hidden";
		}
	}
  }	
}

//-- Show all select objectd ----------------------------
function showSelects() {
  if (is_ie) {
	var aSelect = d.getElementsByTagName("SELECT");
	for (var ii=0; ii<aSelect.length; ii++) aSelect[ii].style.visibility="visible";
  }
}

