var selTab, LastTip;

function CreateMenu(vID) {
 var i,o,x,bStart;

  if (vID==null) {
    bStart=true;
    vID=GetCookie("MnuID");
    if (vID=="" || vID==null) vID=1;
  }
  
  for (i=0;i<t.length;i++) {	
    if (t[i].ID==vID) {
//   selTab=new tab(t[i].ID,t[i].Name,"#008AFF" ,t[i].SelColor);
      selTab=new tab(t[i].ID,t[i].Name,t[i].BgColor,t[i].SelColor);
      break;
    }
  }
  o='<table bgcolor="008AFF" color="008AFF" cellspacing="0" cellpadding="3" height="20" border="0"><tr>';
	for (i=0;i<m.length;i++) {
		if (m[i].ID==selTab.ID) {
			o+="<span class=\"menu\"><td class=\"menua\" nowrap style=\"cursor:pointer; color: #FFFF99;\" id=\"br"+m[i].Target+"\"";
			if (m[i].URL!="") o+=" onClick=\"self.location.href='"+m[i].URL+"'\" onmouseout=\"this.style.backgroundColor='';this.style.color='#FFFF99'\"";
			if ((m[i].URL!="") || (m[i].Target!="")) {
				o+=" onmouseover=\""
				if (m[i].URL!="") o+="this.style.backgroundColor='"+selTab.SelColor+"';this.style.color='#FFFF99';"				
				if (m[i].Target!="") o+="ShowPD("+m[i].Target+");"
				o+="\"";
			}
			if ((m[i].Desc!="") && (m[i].Desc!=null)) o+=" title=\""+m[i].Desc+"\"";
			o+=" style=\"cursor:pointer;color:#FFFF99;\">&nbsp;&nbsp;"+m[i].Name+"&nbsp;&nbsp;</td></span>";
		}
	}
	o+="</tr></table>"
	if (bStart) {
		document.open();
		document.write(o);
		document.close();
		}
	else {
		document.all["mnuMain"].innerHTML=o;
		document.all["mnuBar"].style.backgroundColor=selTab.BgColor;
		document.cookie="MnuID="+vID+";path=/;"; 
	}
	//document.all["mnuBar"].style.backgroundColor=selTab.BgColor;
}

function ShowPD(vID) {
	var i,o;

	o="<table id=\"brt\" style=\"position:absolute;left=90; background-color:"+selTab.BgColor+"; \" width=110 border=0>"
	for (i=0;i<m.length;i++) {
		if (m[i].ID==vID) {
			if (m[i].Name=="-") o+="<tr><td id=\"brd"+i+"\" height=1 style=\"background-color:#0D4FF9;\"></td></tr>";
			else if (m[i].URL=="title") o+="<tr><td id=\"brd"+i+"\" style=\"font-weight:bold;color:Yellow;\">"+m[i].Name+"</td></tr>";
			else {
				o+="<tr><td nowrap id=\"brd"+i+"\" style=\"cursor:pointer; color:#F5F7E3;\"";
				if (m[i].URL!="") o+=" onClick=\"self.location.href='"+m[i].URL+"'\" onmouseover=\"this.style.backgroundColor='"+selTab.SelColor+"';this.style.color='#F5F7E3';\" onmouseout=\"this.style.backgroundColor='';this.style.color='#F5F7E3';\"";
				if ((m[i].Desc!="") && (m[i].Desc!=null)) o+=" title=\""+m[i].Desc+"\"";
				o+=">"+m[i].Name+"</td></tr>";
			}	
		}
	}
	o+="</table>"	
	mnuPD.innerHTML=o;
	mnuPD.style.top="173px";
	
	mnuPD.style.left = findPosX(document.getElementById("br"+vID))+'px';
	showElement("SELECT",false);
	showElement("APPLET",false);
	mnuPD.style.display="";
}

function HidePD(e) {	
	var scrObj;
	if(document.all)
		scrObj = event.srcElement;
	else
		scrObj = SrcFromEvent(e);
	if ((scrObj.id.substr(0,2)!="br") && scrObj.id!='menuPD' && scrObj.tagName!='TBODY') {
		var obj = document.getElementById("mnuPD");
		if(obj && obj.style.display!='none'){
			//alert(scrObj.tagName);
			HidePDEx(obj);
		}
	}
}

function HidePDEx(obj) {	
	obj.style.display="none";
	showElement("SELECT",true);
	showElement("APPLET",true);	
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
			if(document.all) break;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function GetCookie(sCookie)
{
	var i, aCrumb, aCookie;

  aCookie = document.cookie.split(";");
  for (var i=0; i < aCookie.length; i++)
  {  	
    var aCrumb = aCookie[i].split("=");
    if (aCrumb[0].substr(0,1)==" ") aCrumb[0]=aCrumb[0].substr(1);
    if (sCookie == aCrumb[0]) return unescape(aCrumb[1]);
  }
  return null;
}

function showElement(elmID, bShow)
{
	var obj;
	var elems = document.all ? document.all.tags(elmID) : document.getElementsByTagName(elmID);
	
	for (i = 0; i < elems.length; i++)
	{
		obj = elems[i];
		if (!obj || !obj.offsetParent) continue;
		if (bShow) obj.style.visibility = "";
		else obj.style.visibility = "hidden";
	}
}

function SrcFromEvent(e){
	if(!e) return null;
	if (navigator.appName == "Microsoft Internet Explorer" && e.srcElement) {
      return e.srcElement;
  } else if(e.target) {  // is mozilla/netscape
      // need to crawl up the tree to get the first "real" element
      // i.e. a tag, not raw text
      var o = e.target;
      while (!o.tagName) {
          o = o.parentNode;
      }
      return o;
  }
  return e;
}
