//<!-- #include file="../include/common_Exception.inc" -->
if (document.all)    {n=0;ie=1;fShow="visible";fHide="hidden";}
if (document.layers) {n=1;ie=0;fShow="show";   fHide="hide";}

window.onerror=new Function("return true");

var pnArray_RightsID=new Array();
var pnRightsID_Count;
		
		pnRightsID_Count=0;
		pnArray_RightsID[0]=0;
		
		pnRightsID_Count=1;
		pnArray_RightsID[1]=1;
		
		pnRightsID_Count=2;
		pnArray_RightsID[2]=2;
		
		pnRightsID_Count=3;
		pnArray_RightsID[3]=3;
		
		pnRightsID_Count=4;
		pnArray_RightsID[4]=4;
		
		pnRightsID_Count=5;
		pnArray_RightsID[5]=5;
		
		pnRightsID_Count=6;
		pnArray_RightsID[6]=6;
		
		pnRightsID_Count=7;
		pnArray_RightsID[7]=7;
		
		pnRightsID_Count=8;
		pnArray_RightsID[8]=21;
		
		pnRightsID_Count=9;
		pnArray_RightsID[9]=22;
		
		pnRightsID_Count=10;
		pnArray_RightsID[10]=31;
		
		pnRightsID_Count=11;
		pnArray_RightsID[11]=32;
		
		pnRightsID_Count=12;
		pnArray_RightsID[12]=33;
		
		pnRightsID_Count=13;
		pnArray_RightsID[13]=34;
		
		pnRightsID_Count=14;
		pnArray_RightsID[14]=35;
		
		pnRightsID_Count=15;
		pnArray_RightsID[15]=61;
		
		pnRightsID_Count=16;
		pnArray_RightsID[16]=62;
		
		pnRightsID_Count=17;
		pnArray_RightsID[17]=63;
		
		pnRightsID_Count=18;
		pnArray_RightsID[18]=64;

		pnRightsID_Count=19;
		pnArray_RightsID[19]=65;

		pnRightsID_Count=20;
		pnArray_RightsID[20]=36;

		pnRightsID_Count=21;
		pnArray_RightsID[21]=37;
////////////////////////////////////////////////////////////////////////////
// Function Menu()                                                        //
////////////////////////////////////////////////////////////////////////////
var leftX;
var leftY;
var rightX;
var rightY;
var baseWidth;
var version;
var nWindowActual_Width;  //窗口的真实大小
var baseY;
var dotpic;
dotpic = "/common/menu/1.gif";
//*****************************************************************************颜色控制
//var Font_Color="AA0000"                  //字体颜色
//var Main_Color="#ffff00"                 //主菜单原始颜色
//var Main_onMouseOverColor="#CCCCCC"      //主菜单onMouseOver时Color 
//var Main_onMouseOutColor="#CCCCFF"       //主菜单onMouseOut时Color ,包括子菜单显示后的主菜单的颜色

//var List_Color="#FF33FF"                 //子菜单原始颜色
//var List_backgroundColor="#333333"       //子菜单背景色,显示为边框颜色
//var List_onMouseOverColor="#00FF00"      //子菜单onMouseOver时Color 
//var List_onMouseOutColor="#FF6699"       //子菜单onMouseOut时Color 

//var firstWidth;
//*****************************************************************************
//if (n)nWindowActual_Width = window.outerWidth;
//if (ie)nWindowActual_Width = document.body.offsetWidth;
baseY=160;
rightX = 0;
var lastMenu = null;
//if(n)
//{
//	//Main_onMouseOverColor=Main_Color;
//	//List_onMouseOverColor=List_Color;
//	alert(Main_Color);
//	alert(List_Color);
//	}
var pnTotalitemNumber;
function Menu(itemNumber,ver)
{
	pnTotalitemNumber = itemNumber;
	version = ver;	//版本说明 bs;bp;ss;sp
	if (ie)
       		nWindowActual_Width = parseInt(document.all("menu_X").style.pixelWidth);       	
       	if (n)
       		{//alert(Document.MainTable.id);
       		
       		//alert(Main_Color);
       		//alert(document.MainTable.clip.left);
       		//alert(document.MainTable.clip.right);
       		nWindowActual_Width =parseInt(document.MainTable.clip.right-document.MainTable.clip.left);
       		}
       		
       	//alert(nWindowActual_width);
	//if (n)   
	//	nWindowActual_Width=parseInt(document.all("menu_X").style.pixelWidth);       	  	
       	//alert(nWindowActual_Width);
	windowWidth=800;
	this.submenubgLightColor=Main_onMouseOverColor//onmouseover后的color
	this.submenubgDimColor="#DDDDDD"
	this.firstMenuPaneWidth = 2;//first item width
	//this.bgColor     = List_backgroundColor; //改List菜单背景色(显示为边框颜色)
	this.bgColor     = List_Color
	this.fontColor	=Font_Color;
	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.showMenu   = showMenu;
	this.mainPaneBorder = 0;
	this.subMenuPaneBorder = 0;
	this.menuFont='16px';
	this.submenuFont='14px';
	
	//if ((nWindowActual_Width-2*itemNumber)>(windowWidth-2*itemNumber))
		this.subMenuPaneWidth =(nWindowActual_Width-2*itemNumber)/(itemNumber);
		//alert(nWindowActual_Width);
	//else
	//	this.subMenuPaneWidth =(windowWidth-2*itemNumber)/(itemNumber);
	//alert(this.subMenuPaneWidth);
	baseWidth = this.subMenuPaneWidth;
	
	firstWidth = this.firstMenuPaneWidth;
	lastMenu = null;
	rightY = 0;
	leftY = 0;
	leftX = 0;
	HTMLstr = "";
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "\n";
	if (ie) HTMLstr += "<div id='MainTable'>\n";
	HTMLstr += "<table width='"+nWindowActual_Width+"'  border='"+this.mainPaneBorder+"' cellspacing='0' cellpadding='0'>\n";//去除table中bgcolor='"+this.bgColor+"'为主菜单透明
	HTMLstr += "<tr>";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	if (ie) HTMLstr+= "</div>\n";
	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}

function UserNorights(Menuid)
{
	var theId;
	var i;
	if (pnRightsID_Count==-1)
		return false;
	theId = parseInt(Menuid.substr(Menuid.indexOf("=")+1));
	for (i=0;i<=pnRightsID_Count;i++)
		if (theId==pnArray_RightsID[i]) 
			return false;
	return true;	
}
var firstItemAdd;
firstItemAdd = false;
var pnMenuCount;
pnMenuCount = 0;
function addItem(idItem, text, hint, altLocation,target,location)
{
	var relaWidth;
	var theWidth;
	pnMenuCount++;
	theWidth = baseWidth;
	if (UserNorights(altLocation)) return;
	//alert(theWidth);
	switch(version)
	{	
	case "bs":relaWidth = baseWidth/4;break;	
	default:relaWidth = 25
	}
	var Lookup = "<!-- ITEM "+idItem+" -->";
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (n)
	{
		Main_onMouseOverColor=Main_Color;
		//MENUitem += "<td class='main' height='20' bgcolor='"+Main_Color+"' width='"+theWidth+"'>";
		MENUitem += "<td class='main' height='20' width='"+theWidth+"'>";
		MENUitem += "<ilayer id="+idItem+" >"	
		MENUitem += "<layer width=100% height='20' id="+idItem+"  onMouseOver=\"displaySubMenu('"+idItem+"','"+relaWidth+"');\" onclick=\"return false;\">";
		MENUitem += "<center>";
		//MENUitem += "<img src='" + dotpic+"' width=10 hight=10>\n";
		//MENUitem += "<a href='"+altLocation+"' class=netscapeLink  target="+target+"><Font color='"+Font_Color+"'>";
		MENUitem += "<a href='"+altLocation+"' class=netscapeLink><Font color='"+Font_Color+"'>";
		MENUitem += text;
		MENUitem += "</font></a>";
		MENUitem += "</center>";
		MENUitem += "</layer>";
		MENUitem += "</ilayer>";
		MENUitem += "</td>";		
	}
	if (ie)
	
	{	
		if (firstItemAdd)
			MENUitem += "<td><font color="+Font_Color+" style='font-size:12px'>|</font></td>";
//			MENUitem += "<td><font color='#000000' style='font-size:12px'>|</font></td>";
		else
			firstItemAdd = true;
		MENUitem += "<td align='center' class='main' height='20' bgcolor='"+Main_Color+"' width='"+theWidth+"'";//第一次显示的mainmenu的color
		//MENUitem+=" onmouseover=\"this.style.backgroundColor='"+Main_onMouseOverColor+"';document.all('"+idItem+"1').style.color='"+Main_Color+"';displaySubMenu('"+idItem+"','"+relaWidth+"');keepmenu();\" onmouseout=\"this.style.backgroundColor='"+Main_onMouseOutColor+"';document.all('"+idItem+"1').style.color='"+Font_Color+"';\">\n";//onmouseover mainlist color		
		MENUitem+=" document.all('"+idItem+"1').style.color='"+Main_Color+"';displaySubMenu('"+idItem+"','"+relaWidth+"');keepmenu();\" onmouseout=\"this.style.backgroundColor='"+Main_onMouseOutColor+"';document.all('"+idItem+"1').style.color='"+Font_Color+"';\">\n";//onmouseover mainlist color		
		MENUitem += "<div id='"+idItem+"' style='position:relative;' >\n";
		//MENUitem += "<img id='"+idItem+"2' src='" + dotpic+"' border='0' width=10 hight=10>\n";
		MENUitem += "<a id='"+idItem+"1' style='text-decoration: none;color:"+Font_Color+";'";
		if (hint != null)
			MENUitem += "title='"+hint+"' ";
			if (altLocation != null)
			{	
				MENUitem += "href='"+altLocation+"' target="+target;//目标
				//if ((pnMenuCount)==pnTotalitemNumber)
				//	MENUitem += "href='"+altLocation+"' target="+target;//目标
				//else
				//	MENUitem += "href='#'"+pnMenuCount;//目标
			}
			else
				MENUitem += "href='.' ";
			MENUitem += " onmouseover=\"this.style.color='"+Mover_Font_Color+"';displaySubMenu('"+idItem+"','"+relaWidth+"');\" ";
			MENUitem +="onmouseout=\"this.style.color='"+Font_Color+"'\" ";
			
		
		MENUitem += ">";
		MENUitem += "\n";
			
		MENUitem += text;
		MENUitem += "</a>\n";
		MENUitem += "</div>\n";
		MENUitem += "</td>\n";		
		if (idItem!='lastmenu'){
			MENUitem +="<td width='2' bgcolor='"+Main_Color+"'><img src='0.gif' width='2' height='11'></td>\n";//mainlist 间距的color;
			}
		
	}
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";
	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
	//alert(MENUitem)
	//alert('dsdafgasdgas')
}


function addSubItem(idParent, text, hint,location,targetTo)
{
	var relaWidth;
	var theWidth;
	if (UserNorights(location)) return;
	
	if(idParent=="firstmenu")
	{
		theWidth = firstWidth;
		relaWidth = firstWidth/5+2;//firstWidth/5+2;
	}
	else
	{
		theWidth = baseWidth;  //zwf
		relaWidth = baseWidth/3;
	}
	//alert(theWidth);
	var MENUitem = "";
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		if (n)
		{
			MENUitem += "\n";
			MENUitem += "<layer id='"+idParent+"submenu' visibility='hide' bgcolor='"+this.bgColor+"' >\n";
			MENUitem += "<table border='"+this.subMenuPaneBorder+"' cellpadding=0 cellspacing=1 width="+theWidth+" class='main'>\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</layer>\n";
			MENUitem += "\n";
		}
		if (ie)
		{
			MENUitem += "\n";
            		MENUitem += "<div id='"+idParent+"submenu' style='z-index:1;position:absolute; visibility: hidden;width: "+theWidth+";top:300px;' onmouseover='keepMenu();' >\n";
			//MENUitem += "<table border='"+this.subMenuPaneBorder+"' cellpadding=0 cellspacing=1 bgcolor='"+this.bgColor+"' width="+theWidth+" height='20' style='margin-top:1px' >\n";
			MENUitem += "<table border='"+this.subMenuPaneBorder+"' cellpadding=0 cellspacing=1 bgcolor='"+this.bgColor+"' width="+theWidth+" height='20' style='margin-top:1px' >\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</div>\n";
			MENUitem += "\n";
		}
		MENUitem += "<!-- SUB_MENU -->\n";
		HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
	}

	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	if (n)  
	{
		
		//alert(List_backgroundColor);
		if (List_Color=='')
		{
			//alert('sadf');		
			List_Color=List_backgroundColor;
			//alert(List_backgroundColor);
			//alert(List_Color);
		}
//		elsef
//		{
//			List_onMouseOverColor=List_Color;
//		}
		
		//alert(List_Color);
		//alert(List_onMouseOverColor);
		MENUitem = "<tr>";
		MENUitem +="<td bgcolor='"+List_Color+"' align='center' width='" +theWidth+"' height='20' class='main'> ";
		MENUitem +="<iLayer>";
		MENUitem +="<Layer width=100% height='20'>";
		MENUitem +="<center>";
		MENUitem +="<a title='"+hint+"' class=netscapeLink href='"+location+"' target='"+targetTo+"'><Font color='"+Font_Color+"'>"+text+"</font></a>";
		MENUitem +="</center>";
		//MENUitem +="<br>";
		MENUitem +="</Layer>";
		MENUitem +="</iLayer>";
		MENUitem +="</td>";
		MENUitem +="</tr>\n";
	}	
	if (ie) 
	//MENUitem = "<tr><td align='center' valign='middle' width='" +theWidth+"' class='main' bgcolor='"+List_Color+"' onmouseover=\"this.style.backgroundColor='"+List_onMouseOverColor+"';document.all('"+location+"').style.color='"+Mover_Font_Color+"';\" onmouseout=\"this.style.backgroundColor='"+List_onMouseOutColor+"';document.all('"+location+"').style.color='"+Font_Color+"';\"><a id='"+location+"' title='"+hint+"' href='"+location+"' target="+targetTo+" style='text-decoration: none;position:relative;top:5;height:20px;color:"+Font_Color+"' onmouseover=\"this.style.color='"+Mover_Font_Color+"';\" onmouseout=\"this.style.color='"+Font_Color+"';\">"+text+"</a><br></td></tr>\n";//目标
	MENUitem = "<tr height=20><td align='center' valign='middle' width='" +theWidth+"' class='main' bgcolor='"+List_Color+"' onmouseover=\"this.style.backgroundColor='"+List_onMouseOverColor+"';document.all('"+location+"').style.color='"+Mover_Font_Color+"';\" onmouseout=\"this.style.backgroundColor='"+List_onMouseOutColor+"';document.all('"+location+"').style.color='"+Font_Color+"';\"><a  id='"+location+"' title='"+hint+"' href='"+location+"' target="+targetTo+" style='width:100%;text-decoration: none;color:"+Font_Color+"' onmouseover=\"this.style.color='"+Mover_Font_Color+"';\" onmouseout=\"this.style.color='"+Font_Color+"';\">"+text+"</a><br></td></tr>\n";//目标
	//MENUitem = "<tr> <td align='left' valign='middle' width='" +theWidth+"' class='main' bgcolor='"+List_Color+"' onmouseover=\"document.all('"+location+"').style.color='"+Mover_Font_Color+"';\" onmouseout=\"this.style.backgroundColor='"+List_onMouseOutColor+"';document.all('"+location+"').style.color='"+Font_Color+"';\" height=14><a style='position:relative;left:10px' id='"+location+"' title='"+hint+"' href='"+location+"' target="+targetTo+" style='text-decoration: none;position:relative;top:1;height:12px;color:"+Font_Color+"' onmouseover=\"this.style.color='"+Mover_Font_Color+"';\" onmouseout=\"this.style.color='"+Font_Color+"';\">"+text+"</a><br></td></tr>\n";//目标
	MENUitem  += Lookup;//*****************************************************************************下级菜单默认显示颜色********与上级菜单上的OnMouseOver时的color相同*****************************************************下拉单的OnMouseOver的Color属性；
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);
	//alert(HTMLstr);
	
	
}


function showMenu()
{
	if (n)
	{	
		//window.onLoad=nShowMenu();
	}
	if (ie)
	{
		
		document.writeln(HTMLstr);
	}	

}

////////////////////////////////////////////////////////////////////////////
// Private declaration
function displaySubMenu(idMainMenu,itemW)
{
	//alert(idMainMenu);
	var menu;
	var submenu;
	var useragent;
	var m_mainmenu;
	if (n)
	{
		submenu = document.layers['MainTable'].document.layers[idMainMenu+"submenu"];
		m_mainmenu = document.layers['MainTable'].document.layers[idMainMenu].document.layers[0];
		if (lastMenu != null && lastMenu != submenu) hideAll();
		submenu.left = document.layers['MainTable'].document.layers[idMainMenu].pageX-8;
		//submenu.top  = document.layers['MainTable'].document.layers[idMainMenu].pageY + 18;
		//submenu.top  = document.layers['MainTable'].top + 18;
		submenu.visibility = fShow;
		leftX  = document.layers['MainTable'].document.layers[idMainMenu+"submenu"].left;
		rightX = leftX + document.layers['MainTable'].document.layers[idMainMenu+"submenu"].clip.width;
		leftY  = document.layers['MainTable'].document.layers[idMainMenu+"submenu"].top;
		rightY = leftY+document.layers['MainTable'].document.layers[idMainMenu+"submenu"].clip.height;

		m_mainmenu.document.captureEvents(Event.MOUSEOUT|Event.MOUSEMOVE);
		m_mainmenu.document.onMouseOut=myIfhideall;
		m_mainmenu.document.onMouseMove=myIfhideall;
		//document.captureEvents(Event.MOUSEOUT);
		//document.onMouseOut=myIfhideall;
		//document.onMouseMove=myIfhideall;
	}
	else if (ie) 
	{
		useragent = navigator.userAgent;
		menu = eval(idMainMenu);
		if (document.all(idMainMenu+"submenu"))
		{
		}
		else
		{
			//alert(1);
			return;
		}	
		submenu = eval(idMainMenu+"submenu.style");
	        // 如果检测浏览器不是IE5.5以上版本left值减25；
	        if(window.event.srcElement.tagName == "IMG" )
	        {}
	        else
	        {
	        if (useragent.indexOf("MSIE 5.5")==-1) 
	        {
	         	submenu.left=document.body.scrollLeft+event.clientX-event.offsetX-2;
	        }
	        else
	        {
		         submenu.left=document.body.scrollLeft+event.clientX-event.offsetX-2;
	        }
	        }
		submenu.top  = calculateSumOffset(menu, 'offsetTop')+16+2;
		submenu.visibility = fShow;
		if (lastMenu != null && lastMenu != submenu) hideAll();
		leftX  = document.all[idMainMenu+"submenu"].style.posLeft;
		//alert(leftX);
		rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth; //zwf
		//alert(rightX);
		leftY = document.all[idMainMenu+"submenu"].style.posTop;
		//alert(leftY);
		rightY = leftY+23+document.all[idMainMenu+"submenu"].offsetHeight;
		//alert(document.all[idMainMenu+"submenu"].offsetHeight);
		//alert(rightY);
		var x = window.event.clientX;
		var y = window.event.clientY-baseY;
		
		//var x = document.body.scrollLeft;
		//var y = document.body.scrollTop;
		//leftY = document.all[idMainMenu+"submenu"].style.posTop;
		//rightY = leftY+23+document.all[idMainMenu+"submenu"].offsetHeight;
		//var thisbaby=window.event.clientX;
		//alert(thisbaby);	
		
	}
	lastMenu = submenu;
}

function myIfhideall(evt)
{
	if (n)
	{
		//alert(evt.pageX);
		if(!(evt.pageX>=leftX && evt.pageX <= rightX))
		{
			
			hideAll();
			//document.releaseEvents(Event.MOUSEMOVE);
		}	
	}	
	if (ie)		
		if(!(evt.pageX>=leftX && evt.pageX <= rightX && evt.pageY <= rightY && evt.pageY >= leftY - 21))
			hideAll();
}
function hideAll()
{
		if (ie)
			if (!(window.event.clientX >= leftX && window.event.clientX <= rightX && window.event.clientY <= leftY+2))//&& window.event.clientY >= leftY - 21去掉为在窗口变化时现实
			{
				if (lastMenu)
				{
					lastMenu.visibility = fHide;
					lastMenu.left = 0;
					lastMenu = null;
				}
			}
		if (n)
		{
			lastMenu.visibility = fHide;
			lastMenu.left = 0;
			lastMenu = null;
		}	
	
}


function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

function updateIt(e)
{
	if (ie)
	{
		var x = window.event.clientX;
		var y = window.event.clientY-baseY;

		if (x > rightX || x < leftX) 
			{
				 //hideAll();
			}
		else if (y > rightY || y<leftY) 
			{
				//alert('rightY'+rightY+'leftY'+leftY+'y'+y);
				//hideAll();
			}
	}
	else
	{
		if(!(evt.pageX>=leftX && evt.pageX <= rightX))
		{
			hideAll();
			//document.releaseEvents(Event.MOUSEMOVE);
		}	
	}
	
}

if (document.all)
{
	document.body.onclick=hideAll;
	document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;
}
if (document.layers)
{
	document.onmousedown=hideAll;
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=updateIt;
}

function keepMenu()
{
		window.event.cancelBubble = true;
}

document.onmouseover = hideAll; 
if (n)	window.onLoad=nShowMenu;
function nShowMenu()
{
	document.layers['MainTable'].document.write(HTMLstr);
	document.layers['MainTable'].document.close();
}	
