//Timer, clear menu.
var tm1;

function InitMenu()
   {
     var bar = menuBar.children     
     for(var i=0;i < bar.length;i++) 
        {
          var menu=eval(bar[i].menu)
          var Items = menu.children
          if(Items.length==0)
            continue;
          menu.style.visibility = "hidden"
          bar[i].onmouseover = new Function("ShowMenu("+bar[i].id+")")
         
          for(var j=0; j<Items.length; j++)
            {
              var menuItem = eval(Items[j].id)
                
                if(menuItem.menu != null)
                   { 
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    FindSubMenu(menuItem.menu)}
               
                 if(menuItem.cmd != null) 
                   {
                   menuItem.onclick = new Function("Do("+menuItem.id+")") } 
                   
              menuItem.onmouseover = new Function("highlight("+Items[j].id+")")
            
            }    
        
        }  
   }

function FindSubMenu(subMenu)
   {
         var menu=eval(subMenu)
         var Items = menu.children
          for(var j=0; j<Items.length; j++)
            {
              menu.style.visibility = "hidden"
              var menuItem = eval(Items[j].id)
              
              
              if(menuItem.menu!= null)
                 {
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    FindSubMenu(menuItem.menu)
                 }

                 if(menuItem.cmd != null) 
                   {
                   menuItem.onclick = new Function("Do("+menuItem.id+")") } 
                  
              menuItem.onmouseover = new Function("highlight("+Items[j].id+")")
                 
            }  
   } 

function ShowMenu(obj)
   {
     onItem();
     HideMenu(menuBar)
     var menu = eval(obj.menu)
     var bar = eval(obj.id)
     bar.className="barOver"
     menu.style.visibility = "visible"
     menu.style.pixelTop =  obj.getBoundingClientRect().top + obj.offsetHeight + Bdy.scrollTop
     menu.style.pixelLeft = obj.getBoundingClientRect().left + Bdy.scrollLeft
   }

function highlight(obj)
   {
     var PElement = eval(obj.parentElement.id)
     if(PElement.hasChildNodes() == true)
     { 
       var Elements = PElement.children
       for(var i=0;i<Elements.length;i++)
       {
          TE = eval(Elements[i].id)
         // alert(TE.className);
         // TE.className = "menuItem"
       }
      } 
    // obj.className="ItemMouseOver"
     window.defaultStatus = obj.title
     ShowSubMenu(obj)
   }

function Do(obj)
   {
    var cmd = eval(obj).cmd	
    window.navigate(cmd)
     
   }

function HideMenu(obj)
  {
  
        if(obj.hasChildNodes()==true)
              {  
                 var child = obj.children     
                 
                 for(var j =0;j<child.length;j++)
                  {
                     if (child[j].className=="barOver")
                     {
                         var bar = eval(child[j].id)
                         bar.className="Bar"
                     }
                      
                     if(child[j].menu != null)
                       {
                          var childMenu = eval(child[j].menu)
                          if(childMenu.hasChildNodes()==true) 
                               HideMenu(childMenu)
                          
                           childMenu.style.visibility = "hidden" 
                         }
                  }
              
              }
   }
   
  function HideMenuList(obj)
  {
      obj.style.visibility = "hidden" 
  }
   
  function ShowSubMenu(obj)
  {
     PMenu = eval(obj.parentElement.id)
     HideMenu(PMenu)
     if(obj.menu != null)
     {
     	var menu = eval(obj.menu)
   	  	menu.style.visibility = "visible"
     	menu.style.pixelTop =  obj.getBoundingClientRect().top + Bdy.scrollTop
     	menu.style.pixelLeft = obj.getBoundingClientRect().right + Bdy.scrollLeft
     	if(menu.getBoundingClientRect().right > window.screen.availWidth )
       		menu.style.pixelLeft = obj.getBoundingClientRect().left - menu.offsetWidth
    }
  } 
  
  function out(obj){
     clearTimeout(tm1);     
     tm1 = setTimeout("InitMenu()", 1000);
  }
  
  function onItem(){     
       clearTimeout(tm1);
  }
  	
  	function showPopMenu (obj) {
		hidePopMenu("");
		
		objSubMenu=eval("document.all."+obj.id+"_sub.style");
		var tdposition = getTDPosition(obj);
	    objSubMenu.top = tdposition[0];
	    var childTd = eval("document.all." + obj.id + "_sub_td");
	    if (childTd != null)
	    	objSubMenu.left = tdposition[1] - childTd.clientWidth;
	    objSubMenu.visibility="visible";
	
	}
	
	function getTDPosition(e){ 
			var t=e.offsetTop; 
			var l=e.offsetLeft; 
			while(e=e.offsetParent)
			{ 
				t+=e.offsetTop; 
				l+=e.offsetLeft; 		
			} 
			var rec = new Array(1);
			rec[0] 	= t;
			rec[1]	= l;
			return rec
		}
	
	function hidePopMenu (obj) {
		if (obj == "") {
	
			for (var i=0; i<subMenu.length; i++) {
				objMenu=eval("document.all."+subMenu[i]);
				objSubMenu=eval("document.all."+subMenu[i]+"_sub.style");
				objSubMenu.visibility="hidden";
			}
	
		} else {
			objMenu=eval("document.all."+obj);
			objSubMenu=eval("document.all."+obj+"_sub.style");
			objSubMenu.visibility="hidden";
		}
	}
  	
  	function changeclassname( td_id , classname){
		var td_id_obj = eval( "document.all." + td_id + "_link" );
		td_id_obj.className = classname;
	}
	
	function openWindow(link, ispop)
	{
		if (ispop == 'pop')
			window.open(link);
		else
			window.location.href = link;	
	}
  
  	var tm2;
	function mouseover_item(td_item)
	{
		<!--item 选项的背景色-->
		td_item.style.backgroundColor="#E3A5A5";
		<!--item后面的小方框id-->
		var bgtd = eval('document.all.' + td_item.id + '_bg');
		bgtd.style.backgroundColor="#CE6D6B";
		<!--item 链接的id-->		
		var linktd = eval('document.all.' + td_item.id + '_link');					
		linktd.className = "tree_white";
		
		clearTimeout(tm2);	
		showPopMenu(td_item);
		
	}
	
	function mouseout_item(td_item, preClass, linkClass)
	{
		td_item.style.backgroundColor=preClass;
		var bgtd = eval('document.all.' + td_item.id + '_bg');
		bgtd.style.backgroundColor="#FFEBEF";
		<!--item 链接的id-->		
		var linktd = eval('document.all.' + td_item.id + '_link');					
		linktd.className = linkClass;
		
		clearTimeout(tm2);     
		tm2 = setTimeout("hidePopMenu('" + td_item.id + "')", 500);
	}
	
	function mouseout_div(div_item)
	{
		clearTimeout(tm2);
		tm2 = setTimeout("hidePopMenu('" + div_item + "')", 500);
	}
	
	function onPopMenu(){     
       clearTimeout(tm2);
    }
  
  	/**
	 * bg - 	bgcolor
	 * id - 	node id 用于弹出菜单的对应。
	 * space -	图片前面的空格
	 * imgName - 	图片名称
	 * imgWidth - 	图片宽度
	 * imgHeight -	图片高度
	 * link - 		点击td时的链接
	 * linkStyle - 	链接的样式表
	 * isPop - 		是否弹出 
	 * name - 		菜单名称
	 * sep - 		二级菜单之间的分割
	 * level - 		菜单级别
	 * isSelected -	是否选择了该一级菜单
	 */          
  function TreeItem(bg, id, space, imgName, imgWidth, imgHeight, link, linkStyle, isPop, name, sep, level, isSelected)
  {
  	this.bg = bg;
  	this.id = id;
  	this.space = space;
  	this.imgName = imgName;
  	this.imgWidth = imgWidth;
  	this.imgHeight = imgHeight;
  	this.link = link;
  	this.linkStyle = linkStyle;
  	this.isPop = isPop;
  	this.name = name;
  	this.sep = sep;
  	this.level = level;
  	this.isSelected = isSelected;
  }
  
  function writeTreeItem(item)
  {
  	
	if(item.name !="广告管理"){
		document.writeln("<tr>");
		document.writeln("<td bgcolor=\"" + item.bg + "\"");
		document.write(" height=22 ");
		if (item.isSelected != 'true' || item.level != '1')
			document.write(" onmouseover=\"mouseover_item(this)\" onMouseout=\"mouseout_item(this, \'" + item.bg + "\', \'" + item.linkStyle + "\')\"");
		
		if (item.isPop == 'true')
			document.write(" onclick=\"window.open(\'" + item.link + "\')\" ");
		else		
			document.write(" onclick=\"window.location.href=\'" + item.link + "\'\" ");
		
		document.write(" id=\"p" + item.id + "\" style=\"cursor:hand;\" >");
		document.write(item.space);
		//document.write("<img src=\"..\/images\/head_space.gif\" width=" + item.space + ">");
		document.writeln("<img align=absMiddle src=\"..\/images\/" + item.imgName + "\" width=\"" + item.imgWidth + "\" height=\"" + item.imgHeight + "\">");
		if(isIE6())	    
			document.writeln("<a href=\"#\" id=\"p" + item.id + "_link\" class=\"" + item.linkStyle + "\" >" + item.name + "<\/a> ");
		else
			document.writeln("<a href=\"" + item.link + "\" id=\"p" + item.id + "_link\" class=\"" + item.linkStyle + "\" >" + item.name + "<\/a> ");	    
		document.writeln("<\/td><td width=\"1\" bgcolor=\"#ffffff\"><\/td><td id=\"p" + item.id + "_bg\" width=\"11\" bgcolor=\"#FFEBEF\"><\/td> ");
		document.writeln("<\/tr> ");
		document.writeln("<tr>");
		document.writeln("<td align=middle height=1 bgcolor=\"#EFD3D6\"><img height=1 src=\"..\/images\/\" width=141><\/td><\/tr>");
		document.writeln("<tr>  ");
		document.writeln("<td align=middle bgcolor=#FFFFFF height=\"1\">  ");
		document.writeln("<\/td>");
		document.writeln("<\/tr>")
	}
  }
  
   
  function writeTree(tree)
  { 
  	for(var i = 0; i < tree.length; i++)
  	{
  		var item = tree[i];
  		writeTreeItem(item);
  	}
  }
  
  
  function PopMenu(id, popMenuItems)
  {
  	this.id = id;
  	this.popMenuItems = popMenuItems;
  }
  
  function PopMenuItem(id, link, isPop, name)
  {
  	this.id = id;
  	this.name = name;
  	this.link = link;
  	this.isPop = isPop;
  }
  
  function writePopMenuItem(popItem)
  {
   	document.writeln("				<tr>				");
	document.write("					<td id=\"pop_");
	document.write(popItem.id);
	document.write("\" nowrap ");
	document.writeln("						onmouseover=\"this.style.backgroundColor=\'#E3A5A5\';changeclassname( this.id,  \'tree_white\' );\" ");
	document.writeln("						onmouseout=\"this.style.backgroundColor=\'#ffffff\';changeclassname( this.id, \'popmenu_itemlink\' );\" ");
	if (popItem.isPop == '1')
	{
		document.write(" onClick=\"window.open(\'" + popItem.link + "\');\"");
	}
	else
	{
		document.write("						onClick=\"window.location.href=\'");
		document.write(popItem.link);
		document.write("\',\'\';\" ");
	}
	document.writeln("						style=\"cursor:hand;\">&nbsp;&nbsp;");
	document.write("					  <a id=\"pop_");
	document.write(popItem.id);
	document.write("_link\" ");
	if(isIE6()) 
		document.writeln("					  	 href=\"#\" ");
	else
		document.writeln("					  	 href=\"" + popItem.link + "\" ");
	document.writeln("					  	 class=\"popmenu_itemlink\" ");
	document.writeln("					  	 onmouseover=\"this.className=\'tree_white\'\" ");
	document.writeln("					  	 onmouseout=\"this.className=\'popmenu_itemlink\'\"");
	document.writeln("					  	 ");
	document.writeln("					  	 >");
	document.write(popItem.name);
	document.writeln("					  <\/a>&nbsp;&nbsp;");
	document.writeln("					<\/td>				");
	document.writeln("				<\/tr>");
	
  }
  
  function writePopMenu(popMenu)
  {
  	document.write("<div id=\"p");
  	document.write(popMenu.id);
  	document.write("_sub\" onmouseover=\"onPopMenu()\" onmouseout=\"mouseout_div(\'p");
  	document.write(popMenu.id);
  	document.write("\')\" style=\"position:absolute;z-index:1; top:241px; visibility: hidden;\">");
  	var popItems = popMenu.popMenuItems;
  	if (popItems.length == 0)
  	{
  		document.write("</div>");
  		return;
  	}
	document.writeln("<table cellspacing=\"1\" cellpadding=\"0\" border=\"0\" bgcolor=\"#000000\" width=\"100\">");
	document.writeln("<tr>");
	document.writeln("	<!--td width=\"3\"><img src=\"\/cn\/images\/1pix.gif\" border=\"0\" height=\"1\" width=\"3\"><\/td-->");
	document.write("	<td id=\"p");
	document.write(popMenu.id);
	document.write("_sub_td\" bgcolor=\"#ffffff\" align=\"center\">");
	document.writeln("		<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">");
	document.writeln("		<tr>");
	document.writeln("			<td>");
	document.writeln("				<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">");
	
	for(var i = 0; i < popItems.length; i++)
  	{
  		var popItem = popItems[i];
  		writePopMenuItem(popItem);
  	}
	
	document.writeln("        	   	<\/table>");
	document.writeln("			<\/td>");
	document.writeln("		<\/tr>");
	document.writeln("		<\/table>");
	document.writeln("	<\/td>");
	document.writeln("<\/tr>");
	document.writeln("<\/table></div>\r\n");
  }
  
  function writePopMenus(popMenus)
  {
  	for(var i = 0; i < popMenus.length; i++)
  	{
  		var popMenu = popMenus[i];
  		writePopMenu(popMenu);
  	}
  }
  
  //获得客户端的IE版本是否是IE6
  function isIE6(){
  	var ie = window.clientInformation.appVersion.indexOf("6.0");
  	if(ie == -1 ) return false
  	return true;
  }