//读写cookie
var expdate=new Date();
expdate.setTime(expdate.getTime()+(24*60*60*1000*365));
function getCookieVal(offset)
{
var endstr=document.cookie.indexOf(";",offset);
if(endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset,endstr));}
function GetCookie(name)
{var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while(i<clen)
{var j=i+alen;
if(document.cookie.substring(i,j)==arg)
return getCookieVal(j);
i=document.cookie.indexOf(" ",i)+1;
if(i==0)
break;
}
return null;
}
function SetCookie(name,value)
{var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(2<argc)?argv[2]:null;
var path=(3<argc)?argv[3]:null;
var domain=(4<argc)?argv[4]:null;
var secure=(5<argc)?argv[5]:false;
document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}

//菜单程序体开始
var menus    = new Array();
var isShow   = new Boolean(); 
var theonly;
isShow=false;
var isdown   = new Boolean();
isdown=false;
var srcel; 
var fromel;  
var toel; 
var usestatus=false;
var thestatus="";
var popTimer = 0;
var theTitle="",titlebgcolor="";

menucolor='#f4f4f4';fontcolor='MenuText';menuoutcolor='#cccccc';menuincolor='#cccccc';menuoutbordercolor='#f4f4f4';menuinbordercolor='#000000';midoutcolor='#cccccc';midincolor='#cccccc';menuovercolor='#000000';menuunitwidth=140;menuitemwidth=200;menuheight=180;menuwidth='140';menuadjust=0;
menualign='left';leftchar='(无)';rightchar='(无)';fonts='font-family: 宋体; font-size: 9pt; color: MenuText; ';cursor='hand';
var fadeSteps = 5;
var fademsec = 20;
var fadeArray = new Array();
function fade(el, fadeIn, steps, msec) {
	if (steps == null) steps = fadeSteps;
	if (msec == null) msec = fademsec;
	if (el.fadeIndex == null)
		el.fadeIndex = fadeArray.length;
	fadeArray[el.fadeIndex] = el;
	if (el.fadeStepNumber == null) {
		if (el.style.visibility == "hidden")
			el.fadeStepNumber = 0;
		else
			el.fadeStepNumber = steps;
		if (fadeIn)
			el.style.filter = "Alpha(Opacity=0)";
		else
			el.style.filter = "Alpha(Opacity=100)";
	}
	window.setTimeout("repeatFade(" + fadeIn + "," + el.fadeIndex + "," + steps + "," + msec + ")", msec);
}
function repeatFade(fadeIn, index, steps, msec) {	
	el = fadeArray[index];
	
	c = el.fadeStepNumber;
	if (el.fadeTimer != null)
		window.clearTimeout(el.fadeTimer);
	if ((c == 0) && (!fadeIn)) {
		el.style.visibility = "hidden";
		return;
	}
	else if ((c==steps) && (fadeIn)) {
		el.style.filter = "";
		el.style.visibility = "visible";
		return;
	}
	else {
		(fadeIn) ? 	c++ : c--;
		el.style.visibility = "visible";
		el.style.filter = "Alpha(Opacity=" + 100*c/steps + ")";
		el.fadeStepNumber = c;
		el.fadeTimer = window.setTimeout("repeatFade(" + fadeIn + "," + index + "," + steps + "," + msec + ")", msec);
	}
}
function popOut() {
popTimer = setTimeout('allhide()', 1000);
}
function getReal(el, type, value) {
	temp = el;
	while ((temp != null) && (temp.tagName != "BODY")) {
		if (eval("temp." + type) == value) {
			el = temp;
			return el;
		}
		temp = temp.parentElement;
	}
	return el;
}


function MenuRegister(menu) 
{
  menus[menus.length] = menu
  return (menus.length - 1)
}
function MenuItem(caption,command,target,isline,statustxt){
	this.caption=caption;
	this.command=command;
	this.target=target;
	this.isline=isline;
	this.statustxt=statustxt;
}

function Menu(caption,command,target){
	this.items = new Array();
	this.caption=caption;
	this.command=command;
	this.target=target;
	this.id=MenuRegister(this);
}
function MenuAddItem(item)
{
  this.items[this.items.length] = item
  item.parent = this.id;
  this.children=true;
}

Menu.prototype.addItem = MenuAddItem;
function toout(src){
src.style.borderLeftColor=menuoutbordercolor;
src.style.borderRightColor=menuinbordercolor;
src.style.borderTopColor=menuoutbordercolor;
src.style.borderBottomColor=menuinbordercolor;
src.style.backgroundColor=menuoutcolor;
src.style.color=menuovercolor;
src.style.border="#999999 1px solid";
}
function toin(src){
src.style.borderLeftColor=menuinbordercolor;
src.style.borderRightColor=menuoutbordercolor;
src.style.borderTopColor=menuinbordercolor;
src.style.borderBottomColor=menuoutbordercolor;
src.style.backgroundColor=menuincolor;
src.style.color=menuovercolor;
src.style.border="#999999 1px solid";
}
function nochange(src){
src.style.borderLeftColor=menucolor;
src.style.borderRightColor=menucolor;
src.style.borderTopColor=menucolor;
src.style.borderBottomColor=menucolor;
src.style.backgroundColor=menucolor;
src.style.color=fontcolor;
}
function allhide(){
  
	for(var nummenu=0;nummenu<menus.length;nummenu++){
		
		var themenu=document.all['menu'+nummenu]
		var themenudiv=document.all['menudiv'+nummenu]
                nochange(themenu);
                menuhide(themenudiv);
               }
}
function menuhide(menuid){
fade(menuid,false,1);
isShow=false;
}
function menushow(menuid,pid){
menuid.style.left=menutable.offsetLeft+menuadjust+parseInt(menuwidth);menuid.style.top=menutable.offsetTop+pid.offsetTop;
fade(menuid,true,1);
isShow=true;
}
function menu_over(menuid,x){
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
if (toEl == fromEl) return;
srcel = window.event.srcElement;
if(menus[x].command==""){
  
  allhide();
  toin(srcel);
  menushow(menuid,eval("menu"+x));
}else{
  isShow = false;
  allhide();
  toout(srcel);
}

clearTimeout(popTimer);
}
function menu_out(menuid){
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
if (toEl == fromEl) return;	
srcel = window.event.srcElement;
if (isShow){
toin(srcel);
}else{

nochange(srcel);
}
popOut()
}
function menu_down(menuid,x){
srcel = getReal(window.event.srcElement, "className", "coolButton");
if(menus[x].command==""){
  if(isShow){
  menuhide(menuid);
  toout(srcel);
  }
  else{
  toin(srcel);
  menushow(menuid,eval("menu"+x));
  isdown=true;
  }
}else{
  toin(srcel);
  isdown=true;
}

}
function menu_up(){
  isdown=false;
}
function menuitem_over(menuid){
srcel = getReal(window.event.srcElement, "className", "coolButton");
if(isdown){
	toin(srcel);
}
else{
toout(srcel);
}
if(thestatus!=""){
	usestatus=true;
	window.status=thestatus;
}
clearTimeout(popTimer);
}
function menuitem_out(menuid){
srcel = getReal(window.event.srcElement, "className", "coolButton");
nochange(srcel);
if(usestatus)window.status="";
popOut()
}
function menuitem_down(menuid){
srcel = getReal(window.event.srcElement, "className", "coolButton");
toin(srcel)
isdown=true;
}
function menuitem_up(menuid){
srcel = getReal(window.event.srcElement, "className", "coolButton");
toout(srcel)
isdown=false;
}
function exec2(x){
var cmd;
if (menus[x].command!="Img"&&menus[x].command!="Img")
{
SetCookie("XPmenuid",x,expdate,"/",null,false);
if(menus[x].target=="blank"){
  cmd = "window.open('"+menus[x].command+"')";
}else{
  cmd = menus[x].target+".location='"+menus[x].command+"'";
}

eval(cmd);
}
}
function exec(x,i){
var cmd;
if (menus[x].items[i].command!="Img"&&menus[x].items[i].command!="Text")
 {   SetCookie("XPmenuid",x,expdate,"/",null,false);
if(menus[x].items[i].target=="blank"){
  cmd = "window.open('"+menus[x].items[i].command+"')";
}else{
  cmd = menus[x].items[i].target+".location='"+menus[x].items[i].command+"'";
}
eval(cmd);
}
}
//set Title
function setTitle(thetitle,Tbgcolor)
{
theTitle=thetitle;
titlebgcolor=Tbgcolor;
}
function body_click(){
if (isShow){
	srcel = getReal(window.event.srcElement, "className", "coolButton");
	for(var x=0;x<=menus.length;x++){
		if(srcel.id=="menu"+x)
		return;
	}
	allhide();
}
}
document.onclick=body_click;
var MenuBodyRef;
function writetodocument(){
      var wb=1;
      for(var i in document.all){
              if (document.all[i].tagName == 'BODY'){
                     MenuBodyRef = document.all[i]
                     var stringx='<table id=menutable border=0 cellpadding=0 cellspacing=2 width='+menuwidth+' height='+menuheight+' bgcolor='+menucolor+
                     ' onselectstart="event.returnValue=false"'+
                     ' style="position:relative;cursor:'+cursor+';'+fonts+
                     ' border-left: '+wb+'px solid '+menuoutbordercolor+';'+
                     ' border-right: '+wb+'px solid '+menuinbordercolor+'; '+
                     'border-top: '+wb+'px solid '+menuoutbordercolor+'; '+
                     'border-bottom: '+wb+'px solid '+menuinbordercolor+'; padding:2px"><tr>'
					 if (theTitle!="") stringx+='<td style="cursor:default" bgcolor="'+titlebgcolor+'">'+theTitle+'</td></tr><tr>';
                     if(leftchar!="(无)")stringx+='<td width="100%" align="center">'+leftchar+'</td></tr><tr>'
                      for(var x=0;x<menus.length;x++){
                     	var thismenu=menus[x];
                     	//控制显示图片和文字
                     	if (thismenu.command=="Img"||thismenu.command=="Text")
                     	{
                     	
                      	stringx += "<td class=coolButton id=menu"+x+" style='border: 1px solid "+menucolor+
                     	"' width="+menuunitwidth+"px ";
                     	
                     	
                     	}else
                     	{//正常的菜单
                       stringx += "<td class=coolButton id=menu"+x+" style='border: 1px solid "+menucolor+
                     	"' width="+menuunitwidth+"px onmouseover=menu_over(menudiv"+x+
                     	","+x+") onmouseout=menu_out(menudiv"+x+
                     	") onmousedown=menu_down(menudiv"+x+","+x+")";
                     	
                     if(thismenu.command!=""){
                     	          stringx += " onmouseup=exec2("+x+");menu_up();";
                     	      }else{
                     	      	  stringx += " onmouseup=menu_up()";
                     	      }
					 	}
                     	    
                     	      
				      
				       
				      //显示标记
					  if(thismenu.command!="")
                     	stringx += " align="+menualign+">"+thismenu.caption+"</td></tr><tr>"
						else
						stringx += " align="+menualign+">"+thismenu.caption+"<img style='position:absolute;left="+eval(menuwidth-20)+"px;'src='images/right.gif' border=0 align=absmiddle></td></tr><tr>"
                     }
                     if(rightchar!="(无)")stringx+='<td width="100%" align="center">'+rightchar+'</td>'
                     stringx+="</tr></table>";
                     
                     
                     for(var x=0;x<menus.length;x++){
                     	thismenu=menus[x];
                        if(1==0){
                        stringx+='<div id=menudiv'+x+' style="visiable:none"></div>';
                        }else{
                        stringx+='<div id=menudiv'+x+
                        ' style="cursor:'+cursor+';position:absolute;'+
                        'width:'+menuitemwidth+'px; z-index:'+(x+100)+
                        ';border-left: 1px solid '+midoutcolor+'; '+
                        'border-right: 1px solid '+menuinbordercolor+';'+
                        ' border-top: 1px solid '+midoutcolor+'; '+
                        'border-bottom: 1px solid '+menuinbordercolor+';visibility:hidden" onselectstart="event.returnValue=false">\n'+
                     	'<table width="100%" border="0" height="100%" align="center" cellpadding="0" cellspacing="2" '+
                     	'style="'+fonts+' border-left: 1px solid '+menuoutbordercolor+';'+
                     	' border-right: 1px solid '+midincolor+';'+
                     	' border-top: 1px solid '+menuoutbordercolor+'; '+
                     	'border-bottom: 1px solid '+midincolor+'; padding: 4px" bgcolor='+menucolor+'>\n'
                     	for(var i=0;i<thismenu.items.length;i++){
                     		var thismenuitem=thismenu.items[i];
                     		if(!thismenuitem.isline){
                     		stringx += "<tr><td class=coolButton style='border: 1px solid "+menucolor+
                     		"' width=100% height=15px onmouseover=\"thestatus='"+thismenuitem.statustxt+"';menuitem_over(menudiv"+x+
                     		");\" onmouseout=menuitem_out(menudiv"+x+
                     		") onmousedown=menuitem_down(menudiv"+x+") onmouseup=";
 				stringx += "exec("+x+","+i+");menuitem_up(menudiv"+x+")>"+ thismenuitem.caption +"</td></tr>\n";
                     	        }else{
                     		stringx+='<tr><td height="1"><hr size=1></td></tr>\n';
                     		}
								
                     	}
						stringx+='</table>\n</div>'
                     	}
                     //	stringx+='</table>\n</div>'
                }
                
                     document.write(stringx);
                     //document.write("<textarea rows=11 name=S1 cols=84>"+stringx+"</textarea>");
                     
      break
    }
  }
}

function toinonly(src){

src.style.backgroundColor=menuincolor;
src.style.border="#999999 1px solid";
}

function loadMenu(thenum){
   	writetodocument();
	
}
function setBottom(thestr)
{
rightchar=thestr;
}