var starting;
var childs=new Array(null);
var holder;
layerCount=0;
lastvisible="";
showed=false;
onemore=false;
nn = (document.layers)?true:false;
ie = (document.all)?true:false;
ns6 = false;
if(!ie) ns6=(document.getElementById)?true:false;
function getID() { return "yxLayer"+(++layerCount)+""; }
function currID() { return layerCount; }

function CreateRoot()
{
  var _holder=null;
  if (ie) {
    var layerID=getID();
        width = window.document.body.clientWidth;
        height = window.document.body.clientHeight;
    document.body.insertAdjacentHTML("BeforeEnd",('<div id="'+layerID+'" style="position:absolute; left:0; top:0; width:'+width+'; background-color:#ffffff; height:0; visibility:visible; z-index:0;"></div>'));
    _holder=document.all[layerID];
    _holder.css=_holder.style;
  }
  else {
   if(!ns6) {
    _holder=new Layer(1);
    _holder.zIndex=0;
    _holder.visibility="visible";
    _holder.left=0; _holder.top=0;
    _holder.resizeTo(230,16);
    _holder.css=_holder;
   }
  }
  return _holder;
}

function makeLay(_holder,layerID,_x,_y,_width,_content,_color) {
  if(_holder)
    _holder.insertAdjacentHTML("BeforeEnd",(_content));
}

function makeLayer(_holder,_x,_y,_width,_content,_color,vs) {
  var layer=null;
  _index=layerCount;
    layerID=getID();
  if (ie) {
    _holder.insertAdjacentHTML("BeforeEnd",('<div id="'+layerID+'" style="position:absolute; left:'+_x+'; top:'+_y+'; width:'+_width+((_color!="")?('; background-color:'+_color):"")+'; visibility:visible; z-index:'+_index+';">'+_content+'</div>'));
    layer=_holder.document.all[layerID];
    layer.css=layer.style;
  }
  else {
   if(ns6) {
    layer=document.createElement("DIV");
    layer.style.left=String(_x)+"px";
    layer.style.top=String(_y)+"px";
//    layer.style.visibility="hidden";
    layer.style.width=String(_width)+"px"
    layer.style.position="absolute"
    layer.style.zIndex="0";
    layer.zIndex="0"
   }
   else {
    layer=new Layer(_width,_holder);
    layer.zIndex=_index;
    layer.visibility=vs;
    layer.left=_x; layer.top=_y;
    with (layer.document) {
      open(); writeln(_content); close();
    }
    if (_color!="") { layer.bgColor=_color; }
//      alert(layer.name);
    layer.css=layer;
   }
  }
  return layer;
}


function HideNS6Menus()
{
 menucount=childs.length
 for(i=0;i<menucount;i++) { HideNS6Menu(i);}
 lastvisible="";
}

function HideNS6Menu(menunum)
{
  menutable=document.getElementById("menutable"+String(menunum))
  if(menutable) menutable.style.visibility="hidden";
}

function ShowNS6Menu(menunum)
{
  menutable=document.getElementById("menutable"+String(menunum))
  if(menutable) { 
    menutable.style.visibility="visible";
    lastvisible=menunum;
  }
}

function NS6MouseOver(e)
{
 menuimg=e.target
 menuid=menuimg.getAttribute("id")
 imgname=menuimg.getAttribute("imgname")
 menuimg.src=imgname+"_.gif"
 menucount=childs.length
 for(i=0;i<menucount;i++) {
  idstr="menuimg"+String(i)
  if(idstr==menuid) ShowNS6Menu(i)
  else HideNS6Menu(i);
 }
}

function NS6MouseOut(e)
{
 menuimg=e.target
 imgname=menuimg.getAttribute("imgname")
 menuimg.src=imgname+".gif"
}

function NS6MouseMove(e)
{
 if(lastvisible!="")    {
// alert(String(e.pageX) + "," + String(e.pageY) )
   x=e.pageX;
   y=e.pageY;
   menudiv=document.getElementById("menudiv"+String(lastvisible));
   if(menudiv) {
     hleft=parseInt(menudiv.style.left);  
     hright=hleft+parseInt(menudiv.style.width)
     htop=parseInt(menudiv.style.top);
     hheight=htop+parseInt(menudiv.getAttribute("menuheight"))

     if(x>=hleft && x<=hright && y>=htop && y<=hheight) return;
//     alert("Hide menu called")
     HideNS6Menus();
   }
 }
}

function check(e)
{
  if(ie)
  {
    obj=document.elementFromPoint(event.x,event.y);
    if (obj && obj.id) { if(obj.id!="commontext" && obj.id!="tdbold") ShowLayer(obj.id);}
    else if(lastvisible) hidelayer();
  }
  else
  {
    if(onemore){onemore=false;return;}
    if(lastvisible!="")
        {
         x=e.pageX;
         y=e.pageY;
         hx=holder.left+childs[lastvisible].left;
         hw=hx+childs[lastvisible].document.width;
         hy=holder.top;
         hh=hy+childs[lastvisible].document.height+16;
//       alert(x+"="+hx+";"+x+"="+hw+";"+y+"="+hy+";"+y+"="+hh+";res= "+(x>hx && x<hw && y>hy && y<hh));
         if((x>hx && x<hw && y>hy && y<hh))
           return;
         hidelayer();
        }
  }
}
function hidelayer()
{
  if(ie)
  {obj=eval('document.all.d'+lastvisible);obj.style.visibility='hidden';}
  else
  {
    childs[lastvisible].visibility="hidden";
        holder.resizeTo(230,16);
        lastvisible="";
  }
}

function ShowLayer(name,obj,pic)
{
  if(ie)
  {
    if(lastvisible!="" && lastvisible!=name)
        {obj=eval('document.all.d'+lastvisible);obj.style.visibility='hidden';}
        obj=eval('document.all.d'+name);obj.style.visibility='visible';lastvisible=name;
  }
  if(nn)
  {
//    alert(lastvisible)
    alert(obj.name+" "+pic);
    change(obj,pic);
    if(lastvisible!="" && lastvisible!=name)
          hidelayer()
        onemore=true;
    holder.resizeBy(0,childs[name].document.height)
    childs[name].visibility="show";
        lastvisible=name;
  }
}

function createNS6menu(params,path)
{
  absmenux=Number(params[0])//-62;
  absmenuy=Number(params[1])//-175;
  image=params[2];
  imagelink=params[3];
  if (path!="")
    image1=path+params[2];
  else
    image1="img/"+params[2];

  menu_num=childs.length;
  layer=new makeLayer(holder,absmenux,absmenuy,66,"","","show");
  layer.setAttribute("id","menudiv"+String(menu_num))
  childs[menu_num]=layer;

  anchor=document.createElement("A")
  anchor.href=imagelink
  img=document.createElement("IMG")
//  img.style.width="66px"
//  img.style.height="36px"
  img.style.border="0px"
  img.src=image1+".gif"
  img.name=image
  img.addEventListener("mouseover",NS6MouseOver,false); 
  img.addEventListener("mouseout",NS6MouseOut,false); 
  img.setAttribute("id","menuimg"+String(menu_num))
  img.setAttribute("imgname",image1)
  anchor.appendChild(img)
  layer.appendChild(anchor)

  menuheight=36;
 
  docBody = document.getElementsByTagName("body").item(0)
  myTable = document.createElement("TABLE")
  myTable.setAttribute("id","menutable"+String(menu_num))
  myTable.border = 0
  myTable.setAttribute("width","100%")
  myTable.setAttribute("cellspacing","0px")
  myTable.setAttribute("cellpadding","0px")
  myTableBody = document.createElement("TBODY")
  for (i = 4; i < params.length; i+=2) {
    row = document.createElement("TR")
    row.setAttribute("bgcolor","#ffffff")
    row.style.height="24px"
    cell = document.createElement("TD")
    img=document.createElement("IMG")
    img.style.width="10px"
    img.style.height="1px"
    img.style.border="0px"
    cell.appendChild(img)
    row.appendChild(cell)
    cell = document.createElement("TD")
    cell.style.width="100%"
    anchor=document.createElement("A");
    anchor.setAttribute("class","menu")
    anchor.href=params[i+1]
    textNode = document.createTextNode(params[i])
    anchor.appendChild(textNode)
    cell.appendChild(anchor);
    row.appendChild(cell)
    cell = document.createElement("TD")
    img=document.createElement("IMG")
    img.style.width="10px"
    img.style.height="1px"
    img.style.border="0px"
    cell.appendChild(img)
    row.appendChild(cell)
    myTableBody.appendChild(row)
    menuheight+=36
  }
  row = document.createElement("TR")
  row.setAttribute("bgcolor","#ffffff")
  cell = document.createElement("TD")
  cell.colSpan=3;
  img=document.createElement("IMG")
  img.src = "img/dropmenu_bottom.gif";
  img.style.width="120px"
  img.style.height="6px"
  img.style.border="0px"
  menuheight+=8

  cell.appendChild(img)
  row.appendChild(cell)
  myTableBody.appendChild(row)
  myTable.appendChild(myTableBody)
  myTable.style.visibility="hidden"
  layer.appendChild(myTable);
  layer.setAttribute("menuheight",String(menuheight)+"px")
  docBody.appendChild(layer);
}


function createmenu(params,path)
{
  if(ns6) createNS6menu(params,path);
  else {
    absmenux=params[0];
    absmenuy=params[1];
        image=params[2];
        imagelink=params[3];
        if (path!="")
          image1=path+params[2];
        else
          image1="img/"+params[2];
    layerID=getID();
        if(ie)
        {
          menu='<div style="position:absolute; width:86; top:'+absmenuy+'; left:'+absmenux+'; visibility:visible;"><a class=noline href='+imagelink+' onmouseover="javascript:change(document.'+image+',\''+image1+'_.gif\')" onmouseout="javascript:change(document.'+image+',\''+image1+'.gif\')"><img name='+image+' id='+layerID+' src="'+image1+'.gif" border=0></a></div>';
          menu=menu+'<div id="d'+layerID+'" style="position:absolute;width:200; top:'+(absmenuy+37)+'; left:'+absmenux+'; visibility:hidden;"><table width=100% cellpadding=0 border=0 cellspacing=0>';
          for(i=4;i<params.length;i+=2)
          {
            menu=menu+'<tr bgcolor=#ffffff><td id="'+layerID+'">&nbsp;&nbsp;</td><td id="'+layerID+'"><a class=menu id="'+layerID+'" href="'+params[i+1]+'">'+params[i]+'</a></td></tr>';
          }
          menu=menu+'<tr><td colspan=2><img src="img/dropmenu_bottom.gif" width=200 height=10 border=0 alt=""></td></tr></table></div>';
          makeLay(holder,layerID,absmenux,absmenuy,86,menu,"");
        }
        else
        {
          next=childs.length;
          nextn=next+1;
          header='<a href='+imagelink+' onmouseover="javascript:ShowLayer('+nextn+',document.'+image+',\''+image1+'_.gif\')" onmouseout="javascript:change(document.'+image+',\''+image1+'.gif\')"><img name='+image+' src="'+image1+'.gif" width="86" height="16" border="0"></a>';
          childs[next]=new makeLayer(holder,absmenux-176,absmenuy-52,86,header,"","show");
          next=childs.length;
          menu="";
          menu=menu+'<table width=100% cellpadding=0 border=0 cellspacing=0>';
          for(i=4;i<params.length;i+=2)
          {
            menu=menu+'<tr bgcolor=#ffffff><td>&nbsp;&nbsp;</td><td><a class=fnt href="'+params[i+1]+'">'+params[i]+'</a></td></tr>';
          }
          menu=menu+'<tr><td colspan=2><img src="img/dropmenu_bottom.gif" width=86 height=16 border=0 alt=""></td></tr></table></div>';
          childs[next]=new makeLayer(holder,absmenux-176,absmenuy-35,86,menu,"","hidden");
        }
  }     
}


function start()
{
  holder=CreateRoot();

  if(nn) holder.moveTo(176,52);
  StartMenu();
  if(ie)
    document.body.onmousemove=check;
  else  {
     if(ns6) {
       docBody = document.getElementsByTagName("body").item(0);
       docBody.addEventListener("mousemove",NS6MouseMove,false); 
     }
     else {
       window.captureEvents(Event.MOUSEMOVE);
       window.onmousemove=check;
     }  
  }
  preloadImages();
}

function menustart()
{
  start();

  if(document.login && document.login.userid) {
    document.login.userid.focus();
    document.onkeydown=CheckLogin;
  }
}


if(nn)
  window.onLoad=menustart;
else
  window.onload=menustart;
