var menus    = new Array();
var isShow   = new Boolean(); 
isShow=false;
var isdown   = new Boolean();
isdown=false;
var srcel; 
var fromel;  
var toel; 
var usestatus=false;
var space=" ";
menucolor='#000000';
fontcolor='#ffffff';
menuhighlighttext='highlighttext';
menuhightlight='#000000';
menuoutcolor='#000000';
menuincolor='#000000';
menuoutbordercolor='#000000';
menuinbordercolor='#000000';
midoutcolor='#000000';
midincolor='#000000';
menuovercolor='#000000';
menuunitwidth=60;
menuitemwidth=160;
menuheight='100%';
menuwidth='100%';
menuadjust=0; 
menualign='center';
leftchar='(无)';
rightchar='(无)';
fonts='font-family: 宋体; font-size: 9pt; color:#ffffff; ';
cursor='default';
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)?true:false;
 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='#000000';
src.style.borderRightColor='#000000';
src.style.borderTopColor='#000000';
src.style.borderBottomColor='#000000';
src.style.backgroundColor='#000000';
src.style.color='red';
}
function toin(src){
src.style.borderLeftColor='#000000';
src.style.borderRightColor='#000000';
src.style.borderTopColor='#000000';
src.style.borderBottomColor='#000000';
src.style.backgroundColor='#000000';
src.style.color='red';
}
function nochange(src){
src.style.borderLeftColor='#000000';
src.style.borderRightColor='#000000';
src.style.borderTopColor='#000000';
src.style.borderBottomColor='#000000';
src.style.backgroundColor='#000000';
src.style.color='#ffffff';
}
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){
menuid.style.visibility='hidden';
isShow=false;
}
function menushow(menuid,pid){
menuid.style.left=posflag.offsetLeft+pid.offsetLeft+menuadjust;menuid.style.top=menutable.offsetTop+menutable.offsetHeight;menuid.style.visibility='visible';
isShow=true;
//document.focus();
//document.activeElement=window.event.srcElement;
//window.document.all(menuid).focus();
}
function menu_over(menuid,thehref,pid){
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
if (toEl == fromEl) return;
srcel = window.event.srcElement;
if(thehref==""){
  allhide();
  toin(srcel);
  menushow(menuid,pid);
}else{
  isShow = false;
  allhide();
  toout(srcel);
}
}
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);
}
}
function menu_down(menuid,thehref,pid){
srcel = getReal(window.event.srcElement, "className", "coolButton");
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
if(thehref==""){
  if(isShow){
  menuhide(menuid);
  toout(srcel);
  }
  else{
  toin(srcel);
  menushow(menuid,pid);
  isdown=true;
  }
}else{
  toin(srcel);
  isdown=true;
}
}
function menu_up(){
  isdown=false;
}
function menuitem_over(menuid,x,i){
srcel = getReal(window.event.srcElement, "className", "coolButton");
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
if(isdown){
 toin(srcel);
}
else{
toout(srcel);
}
thestatus=menus[x].items[i].statustxt;
if(thestatus!=""){
 usestatus=true;
 window.status=thestatus;
}
}
function menuitem_out(menuid){
//var tempElementName=window.event.toElement.parentElement.parentElement.parentElement.parentElement.outerHTML;
srcel = getReal(window.event.srcElement, "className", "coolButton");
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
nochange(srcel);
if(usestatus)window.status="";
//if (tempElementName.indexOf(menuid.id)==0)
//{menuhide(menuid);}
}
function menuitem_down(menuid){
srcel = getReal(window.event.srcElement, "className", "coolButton");
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
toin(srcel)
isdown=true;
}
function menuitem_up(menuid,thehref){
srcel = getReal(window.event.srcElement, "className", "coolButton");
toEl = getReal(window.event.toElement, "className", "coolButton");
fromEl = getReal(window.event.fromElement, "className", "coolButton");
toout(srcel)
isdown=false;
}


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;
//document.onbeforedeactivate=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='<div id="posflag" style="position:absolute;"></div><table id=menutable border=0 cellpadding=0 cellspacing=0 width='+menuwidth+' height='+menuheight+' bgcolor='+menucolor+
                     ' onselectstart="event.returnValue=false"'+
                     ' style="cursor:'+cursor+';'+fonts+
                     ' border-left: '+wb+'px solid '+menuoutbordercolor+';'+
                     ' border-right: '+wb+'px solid '+menucolor+'; '+
                     'border-top: '+wb+'px solid '+menuoutbordercolor+'; '+
                     'border-bottom: '+wb+'px solid '+menucolor+'; padding:0px"><tr>'
                     if(leftchar!="(无)")stringx+='<td width=16 align="center" valign=bottom>'+leftchar+'</td>'      
                     for(var x=0;x<menus.length;x++){
                      var thismenu=menus[x];
                      stringx += "<td class=coolButton id=menu"+x+" style='border: 1px solid;"+menucolor+
                      ""+fonts+"' width="+menuunitwidth+"px onmouseover=menu_over(menudiv"+x+
                      ",'"+thismenu.command+"',menu"+x+") onmouseout=menu_out(menudiv"+x+
                      ") onmousedown=menu_down(menudiv"+x+",'"+thismenu.command+"',menu"+x+")";
                            if(thismenu.command!=""){
                                if(thismenu.target=="blank"){
                         stringx += " onmouseup=window.open('"+thismenu.command+"');menu_up();";
                         }else{
                         stringx += " onmouseup="+thismenu.target+".location='"+thismenu.command+"';menu_up();";
                         }
                            }else{
                               stringx += " onmouseup=menu_up()";
                            }
                      stringx += " align="+menualign+" valign=bottom>"+thismenu.caption+"</td>"
                     }
                     if(rightchar!="(无)")stringx+='<td width=16 align="center" valign=bottom>'+rightchar+'</td>'
                     stringx+="<td width=*> </td></tr></table>";
                     
                     
                     for(var x=0;x<menus.length;x++){
                      thismenu=menus[x];
                        if(x<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%" valign=bottom align="center" cellpadding="0" cellspacing="1" '+
                      'style="'+fonts+' border-left: 1px solid '+menuoutbordercolor+';'+
                      ' border-right: 1px solid '+midincolor+';'+
                      ' border-top: 1px solid '+menuoutbordercolor+'; '+
                      'border-bottom: 1px solid '+midincolor+'; padding: 0px" bgcolor='+menucolor+'>\n'
                      for(var i=0;i<thismenu.items.length;i++){
                       var thismenuitem=thismenu.items[i];
                       if(!thismenuitem.isline){
                       stringx += "<tr><td valign=bottom class=coolButton style='PADDING-TOP: 3px;border: 0px solid "+menucolor+
                       ""+fonts+"' width=100% height=15px onmouseover=menuitem_over(menudiv"+x+
                       ","+x+","+i+") onmouseout=menuitem_out(menudiv"+x+
                       ") onmousedown=menuitem_down(menudiv"+x+") onmouseup=";
                         if(thismenuitem.target=="blank"){
                         stringx += "window.open('"+thismenuitem.command+"');menuitem_up(menudiv"+x+")>"+"  "+thismenuitem.caption +"</td></tr>\n";
                         }else{
                         stringx += thismenuitem.target+".location='"+thismenuitem.command+"';menuitem_up(menudiv"+x+")>"+"  "+ thismenuitem.caption +"</td></tr>\n";
                         }
                              }else{
                       stringx+='<tr><td height="1" ><hr></td></tr>\n';
                       }
                      }
                      }
                      stringx+='</table>\n</div>'
                }
					//alert(stringx);
                     document.write(stringx);
      break
    }
  }
}

//http://www.microsoft.com/isapi/gomscom.asp?target=/china/product/?MSCOMTB=MS_产品
pmenu1=new Menu('产品&nbsp;&nbsp;|  ','','blank');
pmenu1.addItem(new MenuItem('免费下载','http://www.microsoft.com/isapi/gomscom.asp?target=/china/msdownload/?MSCOMTB=MS_Products|免费下载','self',false,'免费下载'));
pmenu1.addItem(new MenuItem('产品目录','http://www.microsoft.com/isapi/gomscom.asp?target=/catalog/Default3.asp?subid=2&MSCOMTB=MS_Products|产品目录','self',false,'产品目录'));
pmenu1.addItem(new MenuItem('辅助功能','http://www.microsoft.com/isapi/gomscom.asp?target=/china/enable/?MSCOMTB=MS_Products|辅助功能','self',false,'辅助功能'));
pmenu1.addItem(new MenuItem('选购指南','http://www.microsoft.com/isapi/gomscom.asp?target=/china/retail/?MSCOMTB=MS_Products|选购指南','self',false,'选购指南'));
pmenu1.addItem(new MenuItem('BackOffice产品系列','http://www.microsoft.com/isapi/gomscom.asp?target=/china/servers/?MSCOMTB=MS_Products|BackOffice产品系列','self',false,'BackOffice产品系列'));
pmenu1.addItem(new MenuItem('开发工具','http://www.microsoft.com/isapi/gomscom.asp?target=/china/MSDN/?MSCOMTB=MS_Products|开发工具','self',false,'开发工具'));
pmenu1.addItem(new MenuItem('Office产品系列','http://www.microsoft.com/isapi/gomscom.asp?target=/china/office/?MSCOMTB=MS_Products|Office产品系列','self',false,'Office产品系列'));
pmenu1.addItem(new MenuItem('Windows产品系列','http://www.microsoft.com/china/windows/?MSCOMTB=MS_Products|Windows产品系列','self',false,'Windows产品系列'));

//http://www.microsoft.com/isapi/gomscom.asp?target=/china/support/?MSCOMTB=MS_支持
pmenu2=new Menu('支持&nbsp;&nbsp;|  ','','self');
pmenu2.addItem(new MenuItem('技术支持','http://www.microsoft.com/isapi/gomscom.asp?target=/china/support/?MSCOMTB=MS_Support|技术支持','self',false,'技术支持'));
pmenu2.addItem(new MenuItem('企业顾问咨询服务','http://www.microsoft.com/isapi/gomscom.asp?target=/china/mcs/?MSCOMTB=MS_Support|企业顾问咨询服务','self',false,'企业顾问咨询服务'));
pmenu2.addItem(new MenuItem('市场活动与讲座','http://www.microsoft.com/isapi/gomscom.asp?target=/china/events/?MSCOMTB=MS_Support|市场活动与讲座','self',false,'市场活动与讲座'));
pmenu2.addItem(new MenuItem('认证与培训','http://www.microsoft.com/isapi/gomscom.asp?target=/china/training/?MSCOMTB=MS_Support|认证与培训','self',false,'认证与培训'));
pmenu2.addItem(new MenuItem('选购指南','http://www.microsoft.com/isapi/gomscom.asp?target=/china/retail/?MSCOMTB=MS_Support|选购指南','self',false,'选购指南'));
pmenu2.addItem(new MenuItem('微软出版社','http://www.microsoft.com/isapi/gomscom.asp?target=/china/mspress/?MSCOMTB=MS_Support|微软出版社','self',false,'微软出版社'));

//http://www.microsoft.com/isapi/gosearch.asp?target=/china/?MSCOMTB=MS_搜索
pmenu3=new Menu('搜索&nbsp;&nbsp;|  ','','self');
pmenu3.addItem(new MenuItem('搜索microsoft.com/china','http://www.microsoft.com/isapi/gosearch.asp?target=/china/?MSCOMTB=MS_Search|搜索%20microsoft.com/china','self',false,'搜索microsoft.com/china'));

//http://www.microsoft.com/isapi/gosearch.asp?target=/china/?MSCOMTB=MS_搜索
pmenu4=new Menu('<nobr>Microsoft 指南</nobr>','','self');

pmenu4.addItem(new MenuItem('微软(中国)主页','http://www.microsoft.com/isapi/gomscom.asp?target=/china/?MSCOMTB=MS_Microsoft|微软(中国)主页','self',false,'微软(中国)主页'));
pmenu4.addItem(new MenuItem('美国总部主页','http://www.microsoft.com/?MSCOMTB=MS_Microsoft|美国总部主页','self',false,'美国总部主页'));
pmenu4.addItem(new MenuItem('MSN主页','http://www.msn.com/?MSCOMTB=MS_Microsoft|MSN主页','self',false,'MSN主页'));
pmenu4.addItem(new MenuItem('站点地图','http://www.microsoft.com/isapi/gomscom.asp?target=/china/sitemap/?MSCOMTB=MS_Microsoft|站点地图','self',false,'站点地图'));
pmenu4.addItem(new MenuItem('与我们联系','http://register.microsoft.com/contactus30/contactus.asp?domain=generic&lcid=2052&MSCOMTB=MS_Microsoft|与我们联系','self',false,'与我们联系'));
pmenu4.addItem(new MenuItem('注册个人信息','http://register.microsoft.com/regsys/decisionpoint.asp?LCID=2052&MSCOMTB=MS_Microsoft|注册个人信息','self',false,'注册个人信息'));
pmenu4.addItem(new MenuItem('市场活动与讲座','http://www.microsoft.com/isapi/gomscom.asp?target=/china/events/?MSCOMTB=MS_Microsoft|市场活动与讲座','self',false,'市场活动与讲座'));
pmenu4.addItem(new MenuItem('认证与培训','http://www.microsoft.com/isapi/gomscom.asp?target=/china/training/?MSCOMTB=MS_Microsoft|认证与培训','self',false,'认证与培训'));
pmenu4.addItem(new MenuItem('微软出版社','http://www.microsoft.com/isapi/gomscom.asp?target=/china/mspress/?MSCOMTB=MS_Microsoft|微软出版社','self',false,'微软出版社'));

pmenu5=new Menu('&nbsp;&nbsp;&nbsp;&nbsp;','','blank');
//writetodocument是生成菜单的主函数
