dom=(document.getElementById) ? true:false;
nn4=(document.layers) ? true:false;
ie=(document.all) ? true:false;
ie4=(!dom && ie) ? true:false;

var t=false,tout=500;
var T=0;

brdcol='#3261A9';
tabcol='#FFCC00';
ligcol='#FFFFFF';
mnucol='#163059';

tt2o='<table border="0" cellspacing="0" cellpadding="2" width="100%">';
tw1o='<table border="0" cellspacing="0" cellpadding="0" width="1"><tr><td width="1" valign="top" align="right">';
th1o='<table border="0" cellspacing="0" cellpadding="0"><tr><td height="1">';
tc='</td></tr></table>';
divstyle=' style="position:absolute;visibility:hidden;z-index:5000;cursor:hand;"';
astyle=' style="font-family:arial,helvetica;font-size:12px;text-decoration:none;color:'+mnucol+';"';

var divs='',dfilled=false;
var cx,cy;

function mdiv(name,ttl,lev,links)
{
 this.name=name;      // object id (elemId)
 this.ttl=ttl;        // menu title
 this.lev=lev;        // menu level
 this.links=links;    // names & links array
 this.filled=false;   // filled?
 this.on=false;       // visibility flag
 this.con=0;          // child visibility flag
 this.toff=false;     // wait for unvisible flag
 this.t=false;        // timeout flag (set=true)
 this.T=0;            // timeout var
 return this;
}


function showElem(elemId){
 var i,x;
 if(dom)document.getElementById(elemId).style.visibility = "visible";
 else if(ie4)document.all[elemId].style.visibility = "visible";
 else if(nn4)document.layers[elemId].visibility = "show";
 x=findIByName(elemId);if(x>=0)divz[x].on=true;
 x=findParentByName(elemId);if(x>=0)divz[x].con++;
 for(i=0;i<divz.length;i++)
  if(divz[i].name!=elemId){divz[i].toff=true;hideElem(divz[i].name);}
}


function hideElem(elemId){
 var x,y;
 x=findIByName(elemId);
 if((x>=0)&&divz[x].on){
  if(divz[x].t){divz[x].t=false;clearTimeout(divz[x].T);}
  if((divz[x].con<1)&&(divz[x].toff)){
   if(dom)document.getElementById(elemId).style.visibility = "hidden";
   else if(ie4)document.all[elemId].style.visibility = "hidden";
   else if(nn4)document.layers[elemId].visibility = "hide";
   divz[x].on=false;
   divz[x].toff=false;
   y=findParentByName(elemId);
   if(y>=0){
    if(divz[y].con>0)divz[y].con--;
    if(divz[y].toff)hideElem(divz[y].name);
   }
  }
 }
}


function sett(i,j){
 if(nn4)ldn(i,j);
 divz[i].toff=true;
 if(!divz[i].t){divz[i].t=true;divz[i].T=setTimeout("hideElem('"+divz[i].name+"')",tout);}
}


function clt(i,j){
 if(nn4)lup(i,j);
 divz[i].toff=false;
 if(divz[i].t){divz[i].t=false;clearTimeout(divz[i].T);}
}


function lup(i,j){
 var x;
 divz[i].toff=false;
 if(dom)document.getElementById(divz[i].name+j).style.background = ligcol;
 else if(ie4)document.all[divz[i].name+j].style.background = 'FFFFFF';

 x=findIByName(divz[i].links[j+1]);
 if(x>=0)wsub(x,1,1);
}


function ldn(i,j){
 var x;
 if(dom)document.getElementById(divz[i].name+j).style.background = tabcol;
 else if(ie4)document.all[divz[i].name+j].style.background = tabcol;

 x=findIByName(divz[i].links[j+1]);
 if(x>=0)wsub(x,0,1);
}


function filld(i)
{
var j;
if(!divz[i].filled)
{
 if(dom||ie4)o1=' onmouseover="clt('+i+',0)" onmouseout="sett('+i+',0)"';else o1='';

 txt='<table border="0" cellspacing="0" cellpadding="0" bgcolor="'+tabcol+'"'+o1+'><tr><td colspan="2" bgcolor="'+brdcol+'" height="1">'+th1o+tc+'</td></tr><tr><td bgcolor="'+brdcol+'" width="1">'+tw1o+tc+'</td><td><table border="0" cellspacing="0" cellpadding="0">';

 for(j=0;j<divz[i].links.length;j+=2)
 if(divz[i].links[j]=='')txt+='<tr><td colspan="2" height="1" bgcolor="'+brdcol+'">'+th1o+tc+'</td></tr>';
 else{
  if(divz[i].links[j+1].substr(0,2)=='lv')ndiv='<div'+divstyle+' id="'+divz[i].links[j+1]+'"></div>';
  else ndiv='';

  href="golink('"+divz[i].links[j+1]+"')";
  if(nn4){ndiv='';h1='';} else h1=' onclick="'+href+'"';
  href='"javascript:'+href+'"';
  //bg=" style=\"background:url('/pic/menuarrow.gif') right center;background-repeat: no-repeat;>\"";

  if(dom||ie4)lpp=' onmouseOver="lup('+i+','+j+')" onmouseOut="ldn('+i+','+j+')"';
   else lpp='';
  if(nn4)o2=' onmouseover="clt('+i+','+j+')" onmouseout="sett('+i+','+j+')"';else o2='';

  txt+='<tr><td>'+tt2o+'<tr><td id="'+divz[i].name+j+'"'+lpp+h1+' nowrap="nowrap">'+
  '<a'+o2+' href='+href+astyle+'>'+divz[i].links[j]+'</a>'+
  '</td></tr></table></td><td width="1" bgcolor="'+brdcol+'" valign="top">'+tw1o+ndiv+tc+'</td></tr>';
 }
 txt+='</table></td></tr><tr><td colspan="2" bgcolor="'+brdcol+'" height="1">'+th1o+tc+tc;

 //xd=window.open('about:blank','xd','');
 //document.write(txt);

 if(dom){
  document.getElementById(divz[i].name).innerHTML=txt;
 }
 else if(ie4){
  document.all[divz[i].name].innerHTML=txt;
 }
 else if(nn4){
  w=document.layers[divz[i].name];
  w.document.open(); w.document.write(txt); w.document.close();
 }
 divz[i].filled=true;
}
}

function locate(i){
if(nn4){
 w=document.layers[divz[i].name];
 if(divz[i].lev==0){if(cx>28)cx-=20;w.left=cx;w.top=cy+12;}
 else{w.left=cx+40;w.top=cy-6;}
}
}

function wsub(i,x,l)
{
 if(divz[i].t){divz[i].t=false;clearTimeout(divz[i].T);}
 if((x==1)&&(!divz[i].on)){
  if(!dfilled){dfilled=true;fillall();}
  locate(i);
  showElem(divz[i].name);
 }
 else if((x==0)&&(!divz[i].t)&&(divz[i].on)){
  divz[i].toff=true;divz[i].t=true;divz[i].T=setTimeout("hideElem('"+divz[i].name+"')",tout);
 }
}


function write_table()
{
 //xd=window.open('about:blank','xd','');
 d=document;
 d.open();
 d.write('<table border="0" cellspacing="0" cellpadding="0"><tr>');

 for(i=0;i<divz.length;i++)if(divz[i].lev==0)d.write('<td colspan="2" height="1"></td>');
 d.write('<td height="1"></td></tr><tr>');

 for(i=0;i<divz.length;i++)if(divz[i].lev==0){
  onms=' onmouseover="wsub('+i+',1,0)" onmouseout="wsub('+i+',0,0)"';
  o1='';o2=''; if(dom||ie4)o1=onms; else o2=onms;

  d.write('<td width="1"></td><td class="mcell" height="20" bgcolor="'+brdcol+'" align="center"'+o1+'>'+
  '<a href="javascript:empt()" class="m1"'+o2+'>'+divz[i].ttl+'</a></td>');
 }
 d.write('<td>&nbsp;</td></tr><tr>');

 for(i=0;i<divz.length;i++)if(divz[i].lev==0)d.write('<td colspan="2" height="1" valign="bottom"><div id="'+divz[i].name+'"'+divstyle+'></div></td>');
 d.write('<td height="1">'+tc);

 if(nn4)for(i=0;i<divz.length;i++)if(divz[i].lev>0)d.write('<div id="'+divz[i].name+'"'+divstyle+'></div>');
}


function golink(href){if((href!='')&&(href.substring(0,2)!='lv'))location=href;}


function sortdiv(){
 var i,j,tmp=new mdiv("","",0,new Array());
 for(i=0;i<divz.length-1;i++)for(j=i+1;j<divz.length;j++)if(divz[i].lev>divz[j].lev)
  {tmp=divz[i];divz[i]=divz[j];divz[j]=tmp;}
}

function fillall(){
 var i;
 sortdiv();
 //for(i=0;i<divz.length;i++)if((divz[i].lev==0)||(findParentByName(divz[i].name)>=0))filld(i);
 for(i=0;i<divz.length;i++)filld(i);
}


function findIByName(name){
 n=-1; for(i=0;i<divz.length;i++)if(divz[i].name==name)n=i;
 return n;
}

function findParentByName(name){
 n=-1; for(i=0;i<divz.length;i++)for(j=1;j<divz[i].links.length;j+=2)if(divz[i].links[j]==name)n=i;
 return n;
}

function empt(){}

function saveXY(evnt){cx=evnt.pageX;cy=evnt.pageY;}

if(nn4){
 window.captureEvents(Event.MOUSEMOVE);
 window.onmousemove=saveXY;
}
