/*******************************************************************************
		阿赖菜单控件程序OfficeXP风格版 由赖国欣设计于2003年5月，保留所有权利！
*********************************************************************************/
var MAX_Z_INDEX=30
var col_menu=[]; //menu collection
var time1=null;
function alai_menu_xp(width,imagelist)
{
	var menu=this ;
	
	this.backgroudiframe=document.createElement("iframe");//iframe 放到每个menu 下面 以使得不被select 遮避 added by vampire 2008-3-18
	this.backgroudiframe.style.display="none"
	if(document.all)
	{
		document.body.insertAdjacentElement("beforeEnd",this.backgroudiframe);
	}
	else
	{
		document.body.appendChild("beforeEnd",this.backgroudiframe);
	}
	 

	this.copywrite="Copywrite by Alai(杭州方欣修改版) (c)2007，All right reserved!"
	this.item=[]   //子节点
	this.isShow=false  //是否是显示的
	
	
	this.bar=null  //   
	this.body=document.createElement("table")    //创建造一个table做为body
	this.imagelist=imagelist    //图片列表
	var icons=imagelist==null?[]:imagelist.item
	if(document.all)
	{
		document.body.insertAdjacentElement("beforeEnd",this.body)  //插入到html的body里
	}
	else
	{
		document.body.appendChild("beforeEnd",this.body)  //插入到html的body里
	}
	this.body.style.cssText="position:absolute;;border-collapse:collapse;border-spacing:1;border:1px solid #A5A9AC;background-color:white;color:black;display:none;shadow(color=gray,direction=135);table-layout:fixed;filter:progid:DXImageTransform.Microsoft.Shadow(color='#cccccc', Direction=135, Strength=4);"
	this.body.style.pixelWidth=width==null?100:width
	
	var run=function(cmd,a0,a1,a2)
	{
		if(typeof(cmd)=="string")
		{
			try{return eval(cmd);}catch(E){alert("run script string error:\n"+cmd);}
		}
		else if(typeof(cmd)=="function"){return cmd(a0,a1,a2);}
	}
	this.add=function(Text,ico,exeType,exeArg,target)
	{ 
		var item=menu.body.insertRow();//增加一个行
	// item.background=       //在每个item后面加一个iframe
		item.style.cssText="font-size:12px;cursor:default;height:24;"
		 // item.backgroundframe=document.createElement("iframe");
		 // item.backgroundframe.style.display="none";
	
		var col1=item.insertCell()   //增加一个格子a
		var col2=item.insertCell()  //增加一个格子b
		col2.innerHTML=Text  // a 内写上 传入的text
		col2.style.cssText="height:24px;padding-left:5px;width:100%;"     //定义a内的样式 
		col1.style.cssText="width:28px;background-color:#cae0ef;height:24px;text-align:center; display:none;"  //定义b内的样式
		var icon=new Image()   // new 一个image 对象 
		if(typeof(ico)=="string")if(icons[ico]!=null)ico=icons[ico].src    //选择图片
		if(ico!=null && ico!=""){icon.src=ico;col1.insertAdjacentElement("afterBegin",icon);}
		item.subMenu=null  //定填加项的父节点为null 
	//	item.backgroundiframe=document.body.insertAdjacentHTML("beforEnd","<iframe src='www.sohu.com'> </iframe>"); //
		item.enable=true  //  是否为 可用
		item.execute=new Function();  // 定义个一个新函数
		item.remove=function(){item.removeNode(true);}    //定义remove函数 为去掉其子节点
		exeType=exeType==null?"":exeType    //执行类型 
		switch(exeType.toLowerCase())
		{
			case "hide":   //如果为hidden 则 把menu  隐藏
				item.execute=function(){menu.hide();}
				break;
			case "url":  //如果为url 
				if(typeof(exeArg)!="string")break;   //如果参数不为string 类型退出 
				if(target==null||target=="")target="_blank"; //如果target 为空或者为null 定义target为空白页面
				item.execute=function(){menu.hide();open(exeArg,target);}//
				break;
			case "js"://  如果是js 
				if(typeof(exeArg)!="string")break;// 
				item.execute=function(){menu.hide();eval(exeArg)}  //执行之 
				break;
			case "sub":  //如果是
				if(typeof(exeArg.body)=="undefined")break;
				item.execute=function(){menu.show(exeArg);}//添加子节点在这里增加代码 使得div能住select vampire
				col2.innerHTML ="<span style='width:90%;'>"+col2.innerHTML+"</span><span style='font-family:Wingdings 3;'>}</span>";
				item.subMenu=exeArg;
				break;			
		}
		menu.item[menu.item.length]=item
		item.onmouseover=function()
		{
			if(time1!=null)
			{
				clearTimeout(time1);
			}
			col1.style.backgroundColor="#59A4D5"
			item.style.color=item.enable?"black":"gray";
			item.style.backgroundColor="#afdaff";
			item.style.cursor="hand";
			//col1.style.border=col2.style.border="1 solid #f90"
			col1.style.borderRight=col2.style.borderLeft="0"
			hideAllItem(menu)
			if(item.subMenu!=null)menu.show(item.subMenu)
		}
		item.onmouseout=function()
		{
			//col1.style.backgroundColor="#f00"
			icon.style.filter=""
			item.style.backgroundColor="white";
			col1.style.border=col2.style.border=""
			time1=setTimeout("hideMeun()",200);	
		}
		item.onmousedown=item.onmouseup=function(){event.cancelBubble=true;}
		item.onclick=function(){event.cancelBubble=true;menu.hide();if(target!="")eval(target);}
		return item
	}
	this.addLink=function(url_,text,target,icon)
	{
		if(text==null || text=="")text=url_
		if(target==null || target=="")target="_blank"
		return menu.add(text,icon,"url",url_,target)
	}
	this.seperate=function(){var row=menu.body.insertRow();row.style.cssText="padding-left:0;font-size:12px;height:8; cursor:default;width:100%;border:0;";row.insertCell().style.cssText="width:28;background-color:#f00;height:100%;text-align:center;";var cell=row.insertCell();cell.style.cssText="height:8;padding-left:5;text-align:right;";cell.innerHTML="<hr width='97%'>";}
	this.show=function() //show 时候在下面加一iframe 
	{ 
		

		var a=arguments;
		var x,y,m=menu.body   //m为table 
	  var backgroundframe1=menu.backgroudiframe
	  var menufd=menu // vampire by  added 
	 
	
		if(a.length==0) 
		{
			x=event.clientX+document.body.scrollLeft+document.body.scrollLeft
			y=event.clientY+document.body.scrollTop
		}
		else if(a.length==1 && typeof(a[0])=="object")
		{
			if(typeof(a[0].body)!="undefined")//说明传递的是menu 参数
			{
				menufd=a[0]
				m=a[0].body  
				backgroundframe1=a[0].backgroudiframe
				//alert(backgroundframe1)
				m.style.display="block"
				if(m.style.pixelWidth<document.body.offsetWidth-event.x)
				{	x=menu.body.style.pixelLeft+menu.body.offsetWidth-5}
				else
				{	x=menu.body.style.pixelLeft-m.style.pixelWidth-5}
				if(m.offsetHeight<document.body.offsetHeight-event.clientY)
				{	y=event.clientY+document.body.scrollTop-event.offsetY}
				else
				{	
				y=event.clientY-m.offsetHeight+document.body.scrollTop-event.offsetY
				}
			}
			else
			{
				x=event.clientX+document.body.scrollLeft-event.offsetX-2
				y=event.clientY+document.body.scrollTop+a[0].offsetHeight-event.offsetY-4
			}
		}
		else if(a.length==2 && typeof(a[0])=="number" && typeof(a[1])=="number")
		{
			x=a[0];y=a[1];
		}
		else{alert("arguments type or number not match!");return;}
		for(var i=0;i<menu.item.length;i++)menu.item[i].style.color=menu.item[i].enable?"black":"gray"
		
		m.style.pixelLeft=x;
		m.style.pixelTop=y+11;
		m.style.display="block";
		m.style.zIndex=MAX_Z_INDEX+2
		
		if(typeof(backgroundframe1)=="object")
		{		
		 backgroundframe1.style.width=m.style.width;   //设置背景iframe的宽度
		backgroundframe1.style.height=24*menufd.item.length+'px'; //设置背景iframe的高度
		
			backgroundframe1.style.scrolling='no';
		//开始设置背景的位置  
	
		//alert(m.style.left);
	
		backgroundframe1.style.position="absolute"
	//	alert(m.style.left);
		//document.write(m.style.left);
		//alert(m.offsetLeft)
		//alert(backgroundframe1.offsetLeft); 
		backgroundframe1.style.left=m.style.left;
		backgroundframe1.style.top=m.style.top;
		
		//backgroundframe1.offsetTop=m.offsetTop;
	//	backgroundframe1.style.zIndex=MAX_Z_INDEX+1;
		//呈现 
		backgroundframe1.style.display="block"; 			
		}
	//	alert(m.tagName);
	//document.write(m.outerHTML);
	
		
		
		menu.isShow=true;
		if(menu.bar!=null)
		{
			
			menu.bar.style.width=menu.bar.innerHTML.length*21
			//menu.bar.style.filter="progid:DXImageTransform.Microsoft.gradient(startColorstr=#98b8da, endColorstr=#1861ad);"
		}
		event.cancelBubble=true;
	}
	this.hide=function()
	{
		menu.body.style.display="none";
		menu.backgroudiframe.style.display="none";
		menu.isShow=false;
		if(menu.bar!=null)
		{	
			menu.bar.style.cssText="font-size:13px;cursor:hand; font-weight:bold;margin:0 3 0 3;padding:6 4 2 13; background:transparent url(DesktopModules/Winstar.WebParts.Navigation/images/mainNav_line.gif) left center no-repeat; text-align:center;height:23;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff0000, endColorstr=#e3f4ea)"
			menu.bar.style.width=menu.bar.innerHTML.length*21
			menu.bar.style.filter=""
		}
	}
	this.hideAll=function(){for(var i=0;i<col_menu.length;i++)col_menu[i].hide();}
	this.hideOthers=function(){for(var i=0;i<col_menu.length;i++)if(col_menu[i]!=menu)col_menu[i].hide();}
	col_menu[col_menu.length]=this
	document.body.onclick=this.hideAll
}
//创建一个主层
function menu_bar_xp(top,left) 
{
	var mb=this   //mb 主层对象
	this.item=[]
	this.menu=[] 
	this.body=document.createElement("div")
	if(document.all)
	{
		objTD.insertAdjacentElement("beforeEnd",this.body)
	}
	else
	{
		objTD.appendChild("beforeEnd",this.body)
	}
	this.body.style.cssText="position:static;cursor:default;padding:2 0 0 0; background-position:top; background-repeat:repeat-x; BACKGROUND-IMAGE: url(images/MenuBg.gif);height:26px;z-index:5;font-weight:bold;font-size:13px;color:black;top:"+top+";left:"+left
	
	var headeritem=document.createElement("span")
	if(document.all)
	{
		mb.body.insertAdjacentElement("beforeEnd",headeritem)
	}
	else
	{
		mb.body.appendChild("beforeEnd",headeritem)
	}
	headeritem.style.cssText="padding:0;text-align:center;height:20;background-position:top; background-repeat:no-repeat; BACKGROUND-IMAGE: url(images/seperator.gif);font-weight:bold;font-size:13px;"
	
			
	this.add=function(Text,menu,exefunc)
	{
		var chkShow=function(){for(var i=0;i<mb.menu.length;i++)if(mb.menu[i].isShow)return true;return false;}
		if(menu != "")
		{	
			var item=document.createElement("span") //插入一个spn 做为子菜单
			if(document.all)
			{
				mb.body.insertAdjacentElement("beforeEnd",item)
			}
			else
			{
				mb.body.appendChild("beforeEnd",item)
			}			
			item.style.cssText="font-size:13px; cursor:hand; font-weight:bold;margin:0 3 0 3;padding:6 4 2 13;text-align:center;height:23; background:transparent url(DesktopModules/Winstar.WebParts.Navigation/images/mainNav_line.gif) left center no-repeat; color:#000;"			
			item.innerHTML=Text 			
			item.style.width=Text.length*21
			item.onmouseover=function()
			{
				this.style.border="1 solid #0B2565"
				this.style.backgroundColor="#B7BED3";							
				event.cancelBubble=true;
				menu.show(item);	//显示子菜单
				if(time1!=null)
				{
					clearTimeout(time1);
				}
				if(chkShow()){for(var i=0;i<col_menu.length;i++)col_menu[i].hide();menu.show(item);}
			}
			item.onmouseout=function()
			{
				time1=setTimeout("hideMeun()",200);	
				if(!menu.isShow)
				{	
					item.style.cssText="margin:0 3 0 3;padding:6 4 2 13;cursor:hand;text-align:center;height:18;background:transparent url(DesktopModules/Winstar.WebParts.Navigation/images/mainNav_line.gif) left center no-repeat;"
					item.style.width=item.innerHTML.length*21
				}
			}
			mb.item[mb.item.length]=item     //住层对象下添加菜单
			mb.menu[mb.menu.length]=menu
			menu.bar=item
			var tailitem=document.createElement("span")
			if(document.all)
			{
				mb.body.insertAdjacentElement("beforeEnd",tailitem)	
			}
			else
			{
				mb.body.appendChild("beforeEnd",tailitem)	
			}
			tailitem.style.cssText="text-align:center;width:2;height:20;"		
		}
		else
		{
			var item=document.createElement("span")
			
			mb.body.insertAdjacentElement("beforeEnd",item)
			if(exefunc.indexOf("'1'")>1)
			{
				item.style.cssText="margin:0 3 0 3; font-weight:bold; font-size:13px; cursor:hand; padding:6 4 2 4;text-align:center;height:18;BACKGROUND-COLOR: transparent;";
			}
			else
			{
				item.style.cssText="margin:0 3 0 3; font-weight:bold; font-size:13px; cursor:hand; padding:6 4 2 12;text-align:center;height:18;BACKGROUND-COLOR: transparent; background:transparent url(DesktopModules/Winstar.WebParts.Navigation/images/mainNav_line.gif) left center no-repeat; color:#000;"
			}
			item.innerText=Text
			item.style.width=Text.length*21
			item.onmouseover=function()
			{
				if(time1!=null)
				{
					clearTimeout(time1);
				}
				//this.style.filter="progid:DXImageTransform.Microsoft.gradient(startColorstr=#98b8da, endColorstr=#1861ad);"
				if(chkShow()){for(var i=0;i<col_menu.length;i++)col_menu[i].hide();}				
			}
			item.onmouseout=function()
			{				
				if(exefunc.indexOf("'1'")>1)
				{
					item.style.cssText="margin:0 3 0 3; font-weight:bold; font-size:13px; cursor:hand; padding:6 4 2 4;text-align:center;height:18;BACKGROUND-COLOR: transparent;";
				}
				else
				{
					item.style.cssText="margin:0 3 0 3; font-weight:bold; font-size:13px; cursor:hand; padding:6 4 2 12;text-align:center;height:18;BACKGROUND-COLOR: transparent; background:transparent url(DesktopModules/Winstar.WebParts.Navigation/images/mainNav_line.gif) left center no-repeat; color:#000;"
				}
				item.style.width=item.innerHTML.length*21
				time1=setTimeout("hideMeun()",200);	
			}	
			var tailitem=document.createElement("span")
			if(document.all)
			{
				mb.body.insertAdjacentElement("beforeEnd",tailitem)	
			}
			else
			{
				mb.body.appendChild("beforeEnd",tailitem)	
			}
			tailitem.style.cssText="text-align:center;width:2;height:20;background-position:top; cursor:hand; background-repeat:no-repeat;BACKGROUND-IMAGE: url(images/seperator.gif);"				
		}
		item.onclick=function(){if(exefunc!="")eval(exefunc)}
		return item
	}	
}

function hideAllItem(menu)
{
	for(var i=0;i<menu.item.length;i++)
	{		
		if(menu.item[i].subMenu!=null)
		{		
			menu.item[i].subMenu.hide();
			hideAllItem(menu.item[i].subMenu);
		}
	}
}
function eByID(tag)
{
	var target=document.getElementById(tag);
	if(target!=null){
	return target;}
}
function hideMeun(){for(var i=0;i<col_menu.length;i++)col_menu[i].hide();}
