//获取页面指定ID公用函数
function GE(a) {
	return document.getElementById(a);
}

// 新增&修改字典时的父字典选择
function getParentMenuValue(){
    var rs = chooseParentMenu(document.MenuForm.parentId.value);// 返回用户选择定节点的父级业务功能对象????参数用意：表示当前已选择的字典
    if(rs!=null){
        document.MenuForm.parentId.value   = rs.parentId;
        document.MenuForm.parentName.value = rs.parentName;
    }
}

/**
     * 业务菜单管理方法: 调用入口
     * 参数: 
     *     path -------- 上下文路径[ request.getContextPath() ]
     *     oldDictId --- 原字典ID(可选项)
     *     dWidth ------ 窗口宽度(可选项)
     *     dHeight ----- 窗口高度(可选项)
     */
    function chooseParentMenu(oldParentId, dWidth, dHeight){

        if(dWidth==null){
            dWidth = 400;
        }
        if(dHeight==null){
            dHeight = 400;
        }
        if(oldParentId==null){
            oldParentId = "";
        }
        var styles = "dialogHeight:"+dHeight+"px;dialogWidth:"+dWidth+"px;center:yes; help:no; resizable:no; status:no";
        var objReturn = window.showModalDialog("/menu.do?formAction=chooseParentMenu&parentId="+oldParentId,"父级业务选择",styles);
        return objReturn;
    }

  // 根据选择返回值对象
  function choiceParentMenu(){
      with(document.choiceParentMenuForm){
          if(parentId.value.length>0){
              var vParentMenu = new ParentMenu(parentId.value, parentName.value);
              window.returnValue = vParentMenu;
          }
      }
      clickCancel();
  }
  
  // 关闭窗口
  function clickCancel(){
      parent.window.close();
  }
  
// 设置值 到父窗口的树显示页中
function setParentMenuValue(choiceId, choiceName){
     with(self.parent.choiceParentMenuForm){
         parentId.value   = choiceId;
         parentName.value = choiceName;
     }
 }

//清空操作
  function clickClear(){
      window.returnValue = new ParentMenu("","");
      window.close();
  }

  // 定义返回值对象
  function ParentMenu(parentId, parentName){
      this.parentId   = parentId;
      this.parentName = parentName;
  }
// 功能按纽样式
//--2
function fTableBarBtnMouseDown(obj) {
	obj.style.borderRight = "1px #F3F8FC solid";
	obj.style.borderBottom = "1px #F3F8FC solid";
	obj.style.borderTop = "1px #cccccc solid";
	obj.style.borderLeft = "1px #cccccc solid";
}
function fTableBarBtnMouseUp(obj) {
	obj.style.borderRight = "1px solid #aaa";
	obj.style.borderBottom = "1px solid #aaa";
	obj.style.borderTop = "1px solid #fff";
	obj.style.borderLeft = "1px solid #fff";
}
function fTableBarBtnMouseOver(obj) {
	obj.style.borderRight = "1px solid #aaa";
	obj.style.borderBottom = "1px solid #aaa";
	obj.style.borderTop = "1px solid #fff";
	obj.style.borderLeft = "1px solid #fff";
	obj.className = "grid_bar_hov";
}
function fTableBarBtnMouseOut(obj) {
	obj.style.border = "none";
	obj.className = "grid_bar_nohov";
}
function fTableBarBtnMouseDown(obj) {
	obj.style.borderRight = "1px #F3F8FC solid";
	obj.style.borderBottom = "1px #F3F8FC solid";
	obj.style.borderTop = "1px #cccccc solid";
	obj.style.borderLeft = "1px #cccccc solid";
}
			//3
function fTableBarImgMouseDown(obj) {
	obj.style.borderRight = "1px #F3F8FC solid";
	obj.style.borderBottom = "1px #F3F8FC solid";
	obj.style.borderTop = "1px #cccccc solid";
	obj.style.borderLeft = "1px #cccccc solid";
}
function fTableBarImgMouseUp(obj) {
	obj.style.borderRight = "1px solid #aaa";
	obj.style.borderBottom = "1px solid #aaa";
	obj.style.borderTop = "1px solid #fff";
	obj.style.borderLeft = "1px solid #fff";
}
function fTableBarImgMouseOver(obj) {
	obj.style.borderRight = "1px solid #aaa";
	obj.style.borderBottom = "1px solid #aaa";
	obj.style.borderTop = "1px solid #fff";
	obj.style.borderLeft = "1px solid #fff";
	obj.style.cursor = "pointer";
}
function fTableBarImgMouseOut(obj) {
	obj.style.border = "none";
}
function fTableBarImgMouseDown(obj) {
	obj.style.borderRight = "1px #F3F8FC solid";
	obj.style.borderBottom = "1px #F3F8FC solid";
	obj.style.borderTop = "1px #cccccc solid";
	obj.style.borderLeft = "1px #cccccc solid";
}

function selectAll(){
     with(document.forms[0]){
         if(radioId){
             var radioIdLen = radioId.length;
             if(radioIdLen){
                 for(var i=0; i<radioIdLen; i++){
                 	if(radioId[i].disabled == false){
                     	radioId[i].checked = event.srcElement.checked;
                    }
                 }
             }else{
             	if(radioId.disabled == false){
                 radioId.checked = event.srcElement.checked;
                }
             }
         }
     }
}

function OpenDialog(url,str_dialogWidth,str_dialogHeight){
     if(document.all) //IE   
       {
          feature="dialogWidth:" + str_dialogWidth + "px;dialogHeight:" + str_dialogHeight + "px;help:no;status:no;";
          return window.showModalDialog(url,window,feature);
       }else{   
          //modelessDialog可以将modal换成dialog=yes
          feature ="width=" + str_dialogWidth + ",height=" + str_dialogHeight + ",menubar=no,toolbar=no,location=no,";
          feature+="scrollbars=no,status=no,modal=yes,dialog=yes";
          return window.open(url,"mcePopup",feature);
       }
}

function GetRetVal(url,dialogWidth,dialogHeight){
   var win=OpenDialog(url,dialogWidth,dialogHeight);
   if (win=="" || win==undefined){		       
       return;
   }
   return win;
}		

String.prototype.trim= function(){  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}

function leftMenuThisPage(tag,content,count){
	for(i=1; i <count; i++){
		if ("tag"+i==tag){
			document.getElementById(tag).getElementsByTagName("a")[0].className="selectli"+i;
			document.getElementById(tag).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="selectspan"+i;
		}else{
			document.getElementById("tag"+i).getElementsByTagName("a")[0].className="";
			document.getElementById("tag"+i).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="";
		}
		if ("content"+i==content){
			document.getElementById(content).className="";
		}else{
			document.getElementById("content"+i).className="hidecontent";
		}
		document.getElementById("content").className=content;
	}
}

function query(url){
  	document.forms[0].action = url;
    document.forms[0].submit();
}

var oldRowIndex = -1;//保存上一次的行索引
var rowIndex = 0;//记录当前行索引
function selectRow(tableName){
	try{
		var table = document.all.item(tableName);
      	rowIndex = event.srcElement.parentElement.rowIndex;
		if (oldRowIndex != rowIndex){
            //表格中原有高亮显示的行  
	        if (oldRowIndex != -1){
	             //将原高亮行按奇偶行恢复为原色
	             var iRemainder = oldRowIndex % 2;
	             if (iRemainder == 0){	        
	   	           	table.rows[oldRowIndex].style.backgroundColor= "#FFFFFF";
	   	         }else{
	       	       	table.rows[oldRowIndex].style.backgroundColor= "#F9F9F9";
	   	         }    
	        }
	        //鼠标选中当前行以高亮色显示即黄色
	        table.rows[rowIndex].style.backgroundColor="#f3f3f3"; 
	        //将二者同值，以便下次鼠标选行时判断是否选中不同行
	        oldRowIndex = rowIndex;
	      }
		  }catch(err){} //点击操作列屏蔽错误信息
}

//页面加载时选中前次选中的行
function selectInit(){
   var iOldRowIndex=0;
}

function checkOneId(){
	var ches = document.getElementsByName("radioId");
	var len = ches.length;
	var y = 0;
	var ckIds="";
	for(var i=0;i<len;i++){
		if(ches[i].checked==true){
			if(""!=ches[i].value){
				ckIds+=ches[i].value;
				y+=1;
			}			
		}
	}
	if(y==0){
		alert("请至少选择一条记录!");
		return "";
	}else if(y>1){
		alert("只能选择一条记录进行操作!");
		return "";
	}else{
		return ckIds;
	}
}
function checkOddId(){
	var ches = document.getElementsByName("radioId");
	var len = ches.length;
	var y = 0;
	var ckIds="";
	for(var i=0;i<len;i++){
		if(ches[i].checked==true){
			if(""!=ches[i].value){
				ckIds+=ches[i].value+",";
				y+=1;
			}			
		}
	}
	if(y==0){
		alert("请至少选择一条记录!");
		return "";
	}else if(y>1){
		alert("只能选择一条记录进行操作!");
		return "";
	}else{
		return ckIds;
	}
}
function initAjax(url){
	ajax = new FyAjax(callFun);//回调方法
	ajax.open("GET",url);
}
function callFun(){
	if(ajax.readyState() == 4){
		if(ajax.status() == 200){
			document.forms[0].submit();
			alert("共"+ajax.responseText()+"条记录操作成功！");
		}else{
			alert('网络错误');
		}
	}
}
function better_time(strDateStart,strDateEnd){
   var strSeparator = "-"; //日期分隔符
   var strDateArrayStart;
   var strDateArrayEnd;
   var intDay;
   strDateArrayStart = strDateStart.split(strSeparator);
   strDateArrayEnd = strDateEnd.split(strSeparator);
   var strDateS = new Date(strDateArrayStart[0] + "/" + strDateArrayStart[1] + "/" + strDateArrayStart[2]);
   var strDateE = new Date(strDateArrayEnd[0] + "/" + strDateArrayEnd[1] + "/" + strDateArrayEnd[2]);
   intDay = (strDateE-strDateS)/(1000*3600*24);
   return intDay;
}
// 同步控制复选框的选中状态，并设置默认单元格的颜色
function synMRstatus(tdobj){
	if(tdobj.hasChildNodes()){
        var oli=tdobj.childNodes;
        for(var i=0;i<oli.length;i++){
			if(oli[i].nodeType == 1){
				if (oli[i].tagName.toUpperCase() == "INPUT") {
					if(!oli[i].checked){
						oli[i].checked = true;
					}else{
						oli[i].checked = false;
					}
				}
				if(oli[i].checked){
					tdobj.className="hskuang";
				}else{
					tdobj.className=tdobj.char;
				}
			}
        }
    }
}
// 同步控制复选框的选中状态，并设置指定单元格的颜色
function synTSstatus(tdobj,dyval,lenval){
	if(tdobj.hasChildNodes()){
        var oli=tdobj.childNodes;
        for(var i=0;i<oli.length;i++){
			if(oli[i].nodeType == 1){
				if (oli[i].tagName.toUpperCase() == "INPUT") {
					if(!oli[i].checked){
						oli[i].checked = true;
					}else{
						oli[i].checked = false;
					}
					var tdtemp,tdli;
					if(oli[i].checked){
						for(var j=1;j<=lenval;j++){
							tdtemp = document.getElementById(dyval+""+j);
							if(null != tdtemp && "" != tdtemp && "undefined" != tdtemp){
								tdli=tdtemp.childNodes;
						        for(var k=0;k<tdli.length;k++){
									if(tdli[k].nodeType == 1){
										if (tdli[k].tagName.toUpperCase() == "INPUT") {
											tdli[k].checked = true;
										}
									}
								}
								tdtemp.className="hskuang";
							}
						}
					}else{
						for(var j=1;j<=lenval;j++){
							tdtemp = document.getElementById(dyval+""+j);
							if(null != tdtemp && "" != tdtemp && "undefined" != tdtemp){
								tdli=tdtemp.childNodes;    
						        for(var k=0;k<tdli.length;k++){
									if(tdli[k].nodeType == 1){
										if (tdli[k].tagName.toUpperCase() == "INPUT") {
											tdli[k].checked = false;
										}
									}
								}
								tdtemp.className=tdtemp.char;
							}
						}
					}
				}
			}
        }
    }
}

/**HashMap结构体实现**/
function HashMap(){
     var ItemCollection=new Array();
     //private
     this.getMapCollection=function (){
          return ItemCollection;
     }

     var MapItem=function (key,value){    
         this.key=(key==null?"":key);        
         this.value=(value==null?"":value);
         this.getKey=function (){
             return this.key;            
        }
        this.getValue=function (){
            return this.value;            
         }
        this.setKey=function (key){
             this.key=key;            
         }
        this.setValue=function (value){
            this.value=value;            
         }
     }

     this.put=function (key,value){
        var item=new MapItem();        
        if(isItemExist(key)==false)
        {
             item.setKey(key);            
             item.setValue(value);            
             ItemCollection[ItemCollection.length]=item;            
         }else {
             item=getItem(key);            
             item.setValue(value);            
        }
     }

     this.putAll=function (itemCollection){
        if (HashMap.prototype.isPrototypeOf(itemCollection))
         {
             connectMap(itemCollection.getMapCollection());
             return true;
        } else {
            if (Array.prototype.isPrototypeOf(itemCollection))
             {
                for (var j=0;j<itemCollection.length ;j++ )
                {
                    if (MapItem.prototype.isPrototypeOf(itemCollection[j])==false)
                     {
                         return false;
                    }
                }

                connectMap(itemCollection);
                 
                 return true;
             }
         }
    }
 
    var connectMap=function (itemsArray){
       if (ItemCollection.length==0)
        {
            for (var i=0;i<itemsArray.length;i++)
            {
                ItemCollection[i]=itemsArray[i];
            }
        } else {
            var j= (parseInt(itemsArray.length)+parseInt(ItemCollection.length));
           var orginalLength=parseInt(ItemCollection.length);                //save the length of ItemCollection before putting
            
           for (var i=parseInt(ItemCollection.length) ; i<j; i++ )
            {
                ItemCollection[i]=itemsArray[i-orginalLength];
            }
        }
   }

    var getItem=function (key){
        var item=new MapItem();        
        
       for(var i=0;i<ItemCollection.length;i++)
        {
            if(ItemCollection[i].getKey()==key)
            {
                item=ItemCollection[i];                
                break;                
            }
        }
        return item;        
    }
    
    this.get=function (key){
        var value="";
        for(var i=0;i<ItemCollection.length;i++)
        {
           if(ItemCollection[i].getKey()==key)
            {
                value=ItemCollection[i].getValue();                
                break;                
            }
        }
        return value;
    }
    
    var isItemExist=function (key){
        var item=new MapItem();        
        item.setKey("");        
        item.setValue("");        
       var flag=false;
        for(var i=0;i<ItemCollection.length;i++)
        {
            if(ItemCollection[i].getKey()==key)
            {
               flag=true;                
                break;    
           }
        }
        return flag;
    }    

    this.remove=function (key){
        for (var i=0;i<ItemCollection.length;i++)
        {
            if (ItemCollection[i].getKey()==key)
            {
                var mid=ItemCollection.length/2;

                if (i<mid)
                {
                    for (var j=i;j>0 ;j-- )
                    {
                        ItemCollection[j]=ItemCollection[j-1];
                    }
                } else {
                   for (var j=i;j<ItemCollection.length ;j++ )
                   {
                        ItemCollection[j]=ItemCollection[j+1];
                    }
                }                
               ItemCollection.length=ItemCollection.length-1;
            }
        }
    }

    this.removeAll=function (){
       ItemCollection.length=0;
    }

    this.getSize=function (){
        return ItemCollection.length;        
    }

    this.contain=function (key){
        for (var i=0;i<ItemCollection.length ;i++ )
       {
            if (ItemCollection[i].getKey()==key)
            {
                return true;
            }
        }

        return false;
    }
}

/**冒泡排序**/
function sort(values) {
	var temp;
	for (var i = 0; i < values.length; ++i) {
		for (var j = 0; j < values.length - i - 1; ++j) {
			if (parseInt(values[j].split("-")[0]) > parseInt(values[j + 1].split("-")[0])) {
				temp = values[j];
				values[j] = values[j + 1];
				values[j + 1] = temp;
			}
		}
	}
}

// 取指定串中的连续子串，并分组 array
// param1 待处理的串  param2 分隔符
// return Array
function ksdyarr(str,reg){
	var arr = str.split(reg);
	var lstarr = new Array();
	sort(arr);
	var tempstr = arr[0];
	for(var i=0;(i<arr.length&&i+1<arr.length);i++){
		if((parseInt(arr[i].split("-")[0])+1) == parseInt(arr[i+1].split("-")[0])){
			tempstr += ","+arr[i+1];
		}else{
			lstarr.push(tempstr);
			tempstr = arr[i+1];
		}
	}
	lstarr.push(tempstr);
	return lstarr;
}

// 分离串 获取指定串分组 例 "1-aaa,2-bbb,3-ccc";
function boxOffStr(str){
	var arr = new Array();
	var temparr = str.split(",");
	var str1="",str2="";
	for(var i=0;i<temparr.length;i++){
		if(i==0){
			str1+=temparr[i].split("-")[0];
			str2+=temparr[i].split("-")[1];
		}else{
			str1+=","+temparr[i].split("-")[0];
			str2+=","+temparr[i].split("-")[1];
		}
	}
	arr.push(str1);
	arr.push(str2);
	return arr;
}

function doExpand(obj){
	var row = obj.parentNode.parentNode;
	var tbl = this.obj;
	var disp = "";
	// 获取当前节点所有子节点ID
	if(obj.src.indexOf("plus")!=-1){
		// 如果当前是隐藏的，则展开
		this.expandKids(row);
	}else{
		// 如果当前是展开的，则隐藏
		this.collapseKids(row);
	}
}
  
  // 展开方法
function expandKids(curRow){
  	var start = curRow.rowIndex; // 当前行的索引
  	var trStep = curRow.title;   // 当前行的等级
  	// 当前节点不隐藏
  	if(curRow.className.indexOf("even")!=-1){
  		curRow.className = "even nohidden";
  	} else if(curRow.className.indexOf("odd")!=-1){
  		curRow.className = "odd nohidden";
  	}
  	treeCell = curRow.childNodes[0];// 当前节点图标改成展开
	treeCell.innerHTML = treeCell.innerHTML.replace(/\/plus\.gif/,"/minus.gif");
	
	//循环隐藏当前节点下所有子节点
	var table = document.all.item("ec_table");
	var row;
	for(var i=start+1;i<table.rows.length;i++){
	 row = table.rows[i];
	 if(parseInt(trStep)>=parseInt(row.title)){
	 	break;
	 }
	 if((parseInt(trStep)+1) == parseInt(row.title)){
		 if(row.className.indexOf("even")!=-1){
	    	row.className = "even nohidden";
	     } else if(row.className.indexOf("odd")!=-1){
	    	row.className = "odd nohidden";
	     }
     }else{
     	if(row.className.indexOf("even")!=-1){
	    	row.className = "even hidden";
	     } else if(row.className.indexOf("odd")!=-1){
	    	row.className = "odd hidden";
	     }
     }
     treeCell = row.childNodes[0];// 图标改成隐藏
     treeCell.innerHTML = treeCell.innerHTML.replace(/\/minus\.gif/,"/plus.gif");
	}
}
   
// 隐藏方法
function collapseKids(curRow){
  	var start = curRow.rowIndex; // 当前行的索引
  	var trStep = curRow.title;   // 当前行的等级
  	// 当前节点不隐藏
  	if(curRow.className.indexOf("even")!=-1){
  		curRow.className = "even nohidden";
  	} else if(curRow.className.indexOf("odd")!=-1){
  		curRow.className = "odd nohidden";
  	}
  	treeCell = curRow.childNodes[0];// 当前节点图标改成隐藏
	treeCell.innerHTML = treeCell.innerHTML.replace(/\/minus\.gif/,"/plus.gif");
	
	//循环隐藏当前节点下所有子节点
	var table = document.all.item("ec_table");
	var row;
	for(var i=start+1;i<table.rows.length;i++){
	 row = table.rows[i];
	 if(parseInt(trStep)>=parseInt(row.title)){
	 	break;
	 }
	 if(row.className.indexOf("even")!=-1){
    	row.className = "even hidden";
     } else if(row.className.indexOf("odd")!=-1){
    	row.className = "odd hidden";
     }
     treeCell = row.childNodes[0];// 图标改成隐藏
     treeCell.innerHTML = treeCell.innerHTML.replace(/\/minus\.gif/,"/plus.gif");
	}
}
		
// 所有权限
function chkFun_Click(groupId,thischk){
    if(thischk.checked){
        chkall(true,groupId);
    }else{
    	chkall(false,groupId);
    }
}
// 所有权限
function chkall(flag,groupId){
	var chk=document.getElementsByName(groupId);
    for(i=0;i<chk.length;i++){
       chk[i].checked=flag;
    }
}

// 指定权限
function chk_Click(groupId,thischk){
	if(thischk.checked){
		var flag = true;
        var chk=document.getElementsByName(groupId);
	    for(i=0;i<chk.length;i++){
	       if(!chk[i].checked){
	       	  	flag = false;
    			break;
	       }
	    }
	    if(flag){
	    	document.getElementById("fun"+groupId).checked=true;
	    }else{
	    	document.getElementById("fun"+groupId).checked=false;
	    }
    }else{
    	document.getElementById("fun"+groupId).checked=false;
    }
}

function MouseDownToResize(obj){ 
	obj.mouseDownX=event.clientX; 
	obj.pareneTdW=obj.parentElement.offsetWidth; 
	obj.pareneTableW=ec_table.offsetWidth; 
	obj.setCapture(); 
}

function MouseMoveToResize(obj){
    if(!obj.mouseDownX) return false; 
	    var newWidth=obj.pareneTdW*1+event.clientX*1-obj.mouseDownX; 
	    if(newWidth>0){ 
			obj.parentElement.style.width = newWidth; 
		}
}

function MouseUpToResize(obj){ 
	obj.releaseCapture(); 
	obj.mouseDownX=0; 
}

function setPageNum(pageNums){ //设置页码
  var lenOfObjIds = objIds && objIds.length ? objIds.length : 0;
  for(var i=0;i<lenOfObjIds;i++){
    var objId = objIds[i];
    var objEditor = document.frames[objId + "Editor"];
    if(objEditor && objEditor.setPageNum){
      objEditor.setPageNum(pageNums[i]);
    }
  }		  
}

//多个编辑框的取值  	objIds 是表单textarea编号  确保表单textarea下的iframe的name和id 是objId + "Editor"			
function getMulEditContent(objIds){ //取值
  var lenOfObjIds = objIds && objIds.length ? objIds.length : 0; 
  for(var i=0;i<lenOfObjIds;i++){
    var objId = objIds[i];
    var obj = document.getElementById(objId);
    var objEditor = document.frames[objId + "Editor"];
    if(objEditor && objEditor.getEditContent){
      obj.value = objEditor.getEditContent();
    }
  }
 	return true;
}

//多个编辑框的设值  	objIds 是表单textarea编号  确保表单textarea下的iframe的name和id 是objId + "Editor"
function setMulEditContent(objIds){ //设值
  var lenOfObjIds = objIds && objIds.length ? objIds.length : 0;
  for(var i=0;i<lenOfObjIds;i++){
    var objId = objIds[i];
    var obj = document.getElementById(objId);
    var objEditor = document.frames[objId + "Editor"];
    if(objEditor && objEditor.setEditContent){
      objEditor.setEditContent(obj);
    }
  }	  
}

//多个编辑框的清空  	objIds 是表单textarea编号  确保表单textarea下的iframe的name和id 是objId + "Editor"
function clearMulEditContent(){ //清空
  var lenOfObjIds = objIds && objIds.length ? objIds.length : 0;
  for(var i=0;i<lenOfObjIds;i++){
    var objId = objIds[i];
    var objEditor = document.frames[objId + "Editor"];
    if(objEditor && objEditor.clearEditContent){
      objEditor.clearEditContent();
    }
  }		  
}
