var ns   = (navigator.appName == 'Netscape');
var ie   = (navigator.appName == 'Microsoft Internet Explorer');
var ns4  = (ns && parseInt(navigator.appVersion) >= 4 && parseInt(navigator.appVersion)<5);
var ie4  = (ie && parseInt(navigator.appVersion) >= 4);
var ie5  = (ie4 && navigator.appVersion.indexOf("MSIE 5.")!=-1);
var ns5  = (ns && parseInt(navigator.appVersion) >= 5);
var oper = (window.opera != null);

// Menu colors
var menuBkColor = '#ffffff'; //'#626262';  // #AAFF99
var lightBorder = '#C8C8C8';  // #C86697
var darkBorder  = '#292929';  // #520029

function CreateMenu(n,x,y,w,str,url,url2,parent){
   var s,ch,lt;
   if (ns4) {lt="LAYER";} else {lt="DIV";}

   if (ns4) {
      if (parent==null || parent=="") {
         s='<'+lt+' id=menu'+n+' left='+x+' top='+y+' width='+w+' visibility=hide onmouseover="showMenus(\'menu'+n+'\',\'on\',\'\')" onmouseout="killMenus(\'menu'+n+'\')">';}
      else {
         s='<'+lt+' id=menu'+n+' left='+x+' top='+y+' width='+w+' visibility=hide onmouseover="showMenus(\'menu'+n+','+parent+'\',\'on\',\'\')" onmouseout="killMenus(\'menu'+n+','+parent+'\')">';}
      }
   else {
      s='<'+lt+' id=menu'+n+' style="VISIBILITY: hidden; Z-INDEX: '+n+'; POSITION: absolute; LEFT: '+x+'px; TOP: '+y+'px; WIDTH: '+w+'px;">';}

   s+='<table border=0 cellspacing=0 cellpadding=0 width=100% bgcolor=' + menuBkColor + '>';
   s+='<tr><td bgcolor=' + lightBorder + '><img src="images/spacer.gif" width=2 height=2></td><td bgcolor=' + lightBorder + ' width=100%><img src="images/spacer.gif" width=2 height=2></td><td><img src="images/spacer.gif" width=2 height=2></td></tr>'
   s+='<tr><td bgcolor=' + lightBorder + '><img src="images/spacer.gif" width=2 height=2></td><td class="submenu">'; // bgcolor="#ffffff">';
   s+='<table border=0 cellspacing=0 cellpadding=0 width=100% style="font-size:11px;">';
   s+='<tr><td><IMG SRC="images/subMenuDelimiter.gif" WIDTH='+(w-8)+' HEIGHT=2></td></tr>';

   var mitems  = str.split('|');
   var urls    = url.split('|');
   var menuUrl = url2.split('|');
   var linkURL = '#';
   for (i=0;i<mitems.length;i++) {
      turl=String(urls[i]);
      mtype=String(urls[i]).substring(0,4);

      // show checked image
      if (turl == "#") {
         ch='<IMG SRC="images/subMenuCheck.gif" width=7 height=7>'; }
      else {
         ch='<IMG SRC="images/spacer.gif" width=7 height=7>'; }

      // build a menu line
      if (mtype=="menu") {
         if (menuUrl[i]!="") {
            linkURL = menuUrl[i]; }
         else {
            linkURL = '#'; }
         if (ns4) {
            s+='<tr><td onmouseover="showMenus(\'menu'+n+','+urls[i]+'\',\'on\',\'\')" !onmouseout="showMenus(\''+urls[i]+'\',\'off\')">' + ch + '<a href="' + linkURL + '">'+mitems[i]+'</a><IMG SRC="images/subMenuArrow.gif" width=7 height=7 border=0>';}
         else {
            s+='<tr><td onmouseover="showMenus(\'menu'+n+','+urls[i]+'\',\'on\',\'\')" onmouseout="killMenus(\'menu'+n+','+urls[i]+'\')">' + ch + '<a href="' + linkURL + '">'+mitems[i]+'</a><IMG SRC="images/subMenuArrow.gif" width=7 height=7 border=0>';}
      }
      else if (parent==null || parent=="") {
         s+='<tr><td onmouseover="showMenus(\'menu'+n+'\',\'on\',\'\')" onmouseout="killMenus(\'menu'+n+'\')">' + ch + '<a href="'+turl+'">'+mitems[i]+'</a>';}
      else {
         // If it is as new table line then the menu disappears
         // s+='<tr><td onmouseover="showMenus(\''+parent+',menu'+n+'\',\'on\',\'\')" onmouseout="killMenus(\''+parent+',menu'+n+'\')"><a href="'+turl+'">'+mitems[i]+'</a></td></tr>';}
         s+='<tr><td onmouseover="showMenus(\''+parent+',menu'+n+'\',\'on\',\'\')" onmouseout="killMenus(\''+parent+',menu'+n+'\')">' + ch + '<a href="'+turl+'">'+mitems[i]+'</a>';}

      // If it is as new table's line then the menu disappears
      s+='<br>';

      if (i!=mitems.length-1) {
         // s+='<tr><td width=' + w + ' height=4><IMG SRC="images/subMenuDelimiter.gif" width='+(w-6)+' height=4></td></tr>'; }
         s+='<IMG SRC="images/subMenuDelimiter.gif" width='+(w-6)+' height=4></td></tr>'; }
   }

   s+='</table></td>';
   s+='<td bgcolor=' + darkBorder + '><img src="images/spacer.gif" width=2 height=2></td></td></tr>';
   s+='<tr><td><img src="images/spacer.gif" width=2 height=2></td><td bgcolor=' + darkBorder + ' colspan=2><img src="images/spacer.gif" width=2 height=2></td></td></tr>';
   s+='</table>'
   s+='</'+lt+'>\n';
   document.write(s);
   LMoveTo('menu'+n,x,y);
}

function LMoveTo(ly,X,Y){
	if(ie4){
		document.all[ly].style.pixelLeft=X;
		document.all[ly].style.pixelTop=Y;
	} else if(oper){
		var el = document.getElementById(ly);
 		el.style.pixelLeft=X;
		el.style.pixelTop=Y;
	} else if(ns5){
		var el = document.getElementById(ly);
 		el.style.left=X;
		el.style.top=Y;
	} else if(ns4){
		document.layers[ly].left=X;
		document.layers[ly].top=Y;
	}
}

function LShow(ly){
	if (ie4){ document.all[ly].style.visibility='visible';
	} else if(ns4){ document.layers[ly].visibility='show';
	} else if(oper || ns5){ document.getElementById(ly).style.visibility='visible';}
}

function LGetVis(ly){
	if(((ie4 || oper) && document.all[ly].style.visibility=='visible')||(ns4 && document.layers[ly].visibility=='show')){ return(1);
	} else { return(0); }
}

function LHide(ly){
	if(ie4){ document.all[ly].style.visibility='hidden';
	} else if(ns4){ document.layers[ly].visibility='hide';
	} else if(oper|| ns5){ document.getElementById(ly).style.visibility='hidden';}
}

function LToggle(ly){
	if(ie4){ if(document.all[ly].style.visibility == 'hidden') {document.all[ly].style.visibility = 'visible';} else {document.all[ly].style.visibility = 'hidden';}
	} else if(ns4) {if(document.layers[ly].visibility == 'hide') {document.layers[ly].visibility = 'show';} else {document.layers[ly].visibility = 'hide';}} 
else if(oper|| ns5){if(document.getElementById(ly).style.visibility == 'hidden') {document.getElementById(ly).style.visibility = 'visible';} else {document.getElementById(ly).style.visibility = 'hidden';};}
}

var layertimer;
var lastmenues;
var active = 0;

function killMenus(strWen, strStatus){
	layertimer = setTimeout("showMenus('"+strWen+"', 'off')", 500);
	return false;
}
function killMenusNS(strWen){
if (ns4) { killMenus(strWen); }
}

function showMenus(strWen, strStatus, strCoord) {
	if(strStatus == "on"){
		if(layertimer){ clearTimeout(layertimer) }
	}
	var tempWen = strWen.split(",");
	var strOut="";

	if(DOCloaded) {
		clearTimeout(active);
		if(lastmenues){
			tempLastmenues = lastmenues.split(",");
			for (i=0;i<tempLastmenues.length;i++) {LHide(tempLastmenues[i]);}
			lastmenues = null;
		}
		if(strStatus=="on"){
		    if(strCoord!=null && strCoord!=""){
		        tempCoord = strCoord.split("|")
		    }
			tempActualLayers=strWen.split(",")
			for (i=0; i < tempWen.length; i++){
    		    if(strCoord!=null && strCoord!=""){
                    T = tempCoord[i].split(",")
                    if (T[0]!="" && T[1]!=""){
    			        LMoveTo(tempActualLayers[i], T[0], T[1]);
    			    }
    		    }
              LShow(tempActualLayers[i])
            }
			lastmenues = strWen;
		}
	} else {
		active = setTimeout("showMenus('" + strWen + "','" + strStatus + "','" + strCoord + "')",2000);
	}
	return false;
}

