﻿
    
    //打开模式对话框
 
    function OpenModalDialog(url, dialogWidth, dialogHeight)
    {
        if (null == dialogWidth)
            dialogWidth = 600;
        if (null == dialogHeight)
            dialogHeight = 310;
        dialogHeight += 20;
        var features = "dialogHeight:" + dialogHeight + "px;dialogWidth:" + dialogWidth + "px;center:yes;help:no;resizable:no;status:no;scroll:auto";
        return window.showModalDialog(url, window, features);
    }
    
        //打开模式对话框--针对用户类别（有参数的url）
 
    function openModalDialog1(url, dialogWidth, dialogHeight,checkVaule)
    {
        if (null == dialogWidth)
            dialogWidth = 800;
        if (null == dialogHeight)
            dialogHeight = 410;
        dialogHeight += 20;
        var features = "dialogHeight:" + dialogHeight + "px;dialogWidth:" + dialogWidth + "px;center:yes;help:no;resizable:no;status:yes;scroll:no";
        var TempVaule;
        //为了防止ie缓存，加一个随机的参数
        var now = new Date(); 
        var number = now.toString();
        TempVaule = window.showModalDialog(url+"&other="+number, checkVaule, features);
         if(TempVaule=="True")   
         {   
          window.location.href=window.location.href;   
          window.location.reload;   
         } 
         return TempVaule;
    }
    
            //打开模式对话框--针对没有参数的url
    function openModalDialog2(url, dialogWidth, dialogHeight,checkVaule)
    {
        if (null == dialogWidth)
            dialogWidth = 800;
        if (null == dialogHeight)
            dialogHeight = 410;
        dialogHeight += 20;
        var features = "dialogHeight:" + dialogHeight + "px;dialogWidth:" + dialogWidth + "px;center:yes;help:no;resizable:no;status:yes;scroll:no";
        var TempVaule;
        //为了防止ie缓存，加一个随机的参数
        var now = new Date(); 
        var number = now.toString();
        TempVaule = window.showModalDialog(url+"?other="+number, checkVaule, features);
         if(TempVaule=="True")   
         {   
          window.location.href=window.location.href;   
          window.location.reload;   
         } 
         return TempVaule;
    }
    
    
    ///用window.open打开
    function openWindow(url, width, height)
    {
        if (null == width)
            width = 800;
        if (null == height)
            height =600;
        var features ="width="+width+",height="+height+",top=50,left=100,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes";
        window.open(url, null, features);

    }

    
    ///------------------------------------------------------------------------------------------------------------------------------------
    ///以模式对话框的方式打开
    function OpenWithArgs(url,dialogWidth, dialogHeight)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedID();
       if(id==null) return false; 
       OpenModalDialog(url+id,dialogWidth, dialogHeight);
       return false;
    }
     ///以模式对话框的方式打开(方法2)
    function OpenWithArgsModal(url,dialogWidth, dialogHeight)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedID();
       if(id==null) return false; 
       top.Tant_Modal.Open(url+id,dialogWidth, dialogHeight);
       return false;
    }
///以模式对话框的方式打开(方法3)更新部门
    function OpenWithArgsModal(url,dialogWidth, dialogHeight)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedID();
       if(id==null) return false; 
    //   top.Tant_Modal.Open(url+id,dialogWidth, dialogHeight);
    ModalUpdateDeparment(url+id,"");
       return false;
    }
    ///以模式对话框的方式打开(方法3)更新部门

    ///以模式对话框的方式打开(方法4)更新部门
    function OpenWithArgsModal11(url)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedJobID();
       if(id==null) return false; 
    //   top.Tant_Modal.Open(url+id,dialogWidth, dialogHeight);
    CommonModalNew(url+id,"编辑部门");
       return false;
    }
     ///以模式对话框的方式打开(方法4)更新部门
    function OpenWithArgsModal12(url)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedJobID();
       if(id==null) return false; 
    //   top.Tant_Modal.Open(url+id,dialogWidth, dialogHeight);
    CommonModalNew(url+id,"批量移动职位");
       return false;
    }
    ///以模式对话框的方式打开(方法4)更新部门
    function OpenWithArgsModal11Set(url,dialogWidth, dialogHeight)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedID();
       if(id==null) return false; 
    //   top.Tant_Modal.Open(url+id,dialogWidth, dialogHeight);
    CommonModalNewSet(url+id,"");
       return false;
    }
        ///以模式对话框的方式打开(方法4)更新部门
    function OpenWithArgsModallast(url,dialogWidth, dialogHeight)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedID();
       if(id==null) return false; 
    //   top.Tant_Modal.Open(url+id,dialogWidth, dialogHeight);
    CommonModalLast(url+id,"",dialogWidth, dialogHeight);
       return false;
    }
    
        ///以模式对话框的方式打开(方法5)更新部门
    function OpenWithArgsModal5(url)
    {
       if(!IsSelected(1)) return false;
       var id=GetSelectedJobID();
      
       if(id==null) return false;
        window.location.href=url+id;
       return false;
    }
    
    
    function openurl(url)
    {
      if(confirm("确定放入职位收藏夹吗?")) return true;
       window.location.href=url;
      return false;
    }
    function jobdelete()
    {
      if(confirm("确定删除该搜索器吗?")) return true;
      return false;
    }
    //全选
    function checkAll()
    {
    var objs = document.getElementsByTagName("input");
    for(var i=0; i<objs.length; i++) {
            if(objs[i].type.toLowerCase() == "checkbox" )
                 objs[i].checked = true;

      }        
    }
    //反选
    function unCheckAll()
   {
    var objs = document.getElementsByTagName("input");
    for(var i=0; i<objs.length; i++) {
            if(objs[i].type.toLowerCase() == "checkbox" )            
                    objs[i].checked = false;
                    

      }        
    }
     //获取选中记录的ID
    function GetSelectedJobID()
    {
      var id;
      var checkBoxNodes=document.getElementsByTagName("input");
      var chkNodeValue;
      for(var i=0;i<checkBoxNodes.length;i++)
      {
         var checkFlag=checkBoxNodes[i].type;
         if (checkFlag=="checkbox" )
         {
            if(checkBoxNodes[i].checked)
            {
               id=checkBoxNodes[i].getAttribute("title"); 
            }              
         }                 
       }
       return escape(id);
    }
    
    
    //判断用户是否选中checkbox
    //IsSingle：1为只能选择一条记录
    function IsSelected(IsSingle)
     {
          var id=0;
          var checkBoxNodes=document.getElementsByTagName("input");
          var chkNodeValue;
          var j=0;
          for(var i=0;i<checkBoxNodes.length;i++)
          {
             var checkFlag=checkBoxNodes[i].type;
             if (checkFlag=="checkbox" )
             {
                    if(checkBoxNodes[i].checked)
                    j++; 
             }                 
          }
           if(j==0)
           {
              alert("请选择一条记录");
              return false;
           }
           if(IsSingle==1)//是否控制只能选一条记录
           {
               if(j>1)
               {
                  alert("只能选择一条记录");
                  return false;
               }
           }     
           return true;
       }
    
     //判断用户是否选中checkbox
    //IsSingle：1为只能选择一条记录
    //TBName:容器ID
    //owen重载的方法
    function IsSelectedByCheckBoxName(TBName,IsSingle)
     {
      if(TBName==null)
        return false;
      var objTable = document.getElementById(TBName);
      var id;
      var checkBoxNodes=objTable.getElementsByTagName("input");
      var chkNodeValue;
      var j=0;
      for(var i=0;i<checkBoxNodes.length;i++)
      {
         var checkFlag=checkBoxNodes[i].type;
         if (checkFlag=="checkbox")
         {
            if(checkBoxNodes[i].id.indexOf("chkExport")!=-1)
            {
              if(checkBoxNodes[i].checked)
              j++; 
              }
         }                 
      }
       if(j==0)
       {
          alert("请选择一条记录");
          return false;
       }
       if(IsSignle==1)//是否控制只能选一条记录
       {
           if(j>1)
           {
              alert("只能选择一条记录");
              return false;
           }
       }     
       return true;
       }
    
    
    //获取选中记录的ID
    function GetSelectedID()
    {
      var id;
      var checkBoxNodes=document.getElementsByTagName("input");
      var chkNodeValue;
      for(var i=0;i<checkBoxNodes.length;i++)
      {
         var checkFlag=checkBoxNodes[i].type;
         if (checkFlag=="checkbox" )
         {
            if(checkBoxNodes[i].checked)
            {
               id=checkBoxNodes[i].parentNode.getAttribute("title"); 
            }              
         }                 
       }
       return escape(id);
    }
    
    function returndata()
    {
      if(!IsSelected()) return false;
      if(confirm("确定申请该职位吗?")) return true;
      return false;
    }
     
    
     ///删除数据
    function DeleteData()
    {
        ///如果没有选中记录
        if(!IsSelected())  return false;
        if(confirm("确定要删除吗？")) return true;
        return false;
    }
    
         ///删除数据
         //CheckBox的Name属性
    function DeleteDataByCheckBoxName(checkBoxName)
    {
        ///如果没有选中记录
        if(!IsSelectedByCheckBoxName(checkBoxName))  return false;
        if(confirm("确定要删除吗？")) return true;
        return false;
    }

    ///---------------------------------------------------------全选/反选----------------------------------------------------------------------
 
     function allSelect(TBName)
     { //全选
        if(TBName==null)
            return;
        var objTable = document.getElementById(TBName);
        var chks = objTable.getElementsByTagName("input");
        for(i=0;i<chks.length;i++)
        {
            if(chks[i].type == "checkbox" && chks[i].disabled == false)
            {
                chks[i].checked = true;
            }
        }
    }
    
    function antiSelect(TBName)
     { //反选
        if(TBName==null)
            return;
        var objTable = document.getElementById(TBName);
        var chks = objTable.getElementsByTagName("input");
        for(i=0;i<chks.length;i++)
        {
            if(chks[i].type == "checkbox" && chks[i].disabled == false)
            {
                
                if(chks[i].checked == true)
                    chks[i].checked = false;
                else
                    chks[i].checked = true;
            }
        }
    }
// iframe的自适应高度调整 
function iframeResize(pid)
{
	var dyniframe   = null;
	if (document.getElementById)
	{
		dyniframe= document.getElementById(pid);
		if(dyniframe.height<dyniframe.Document.body.scrollHeight)
		{
		    dyniframe.height = dyniframe.Document.body.scrollHeight;
		}
	}
}
// iframe的自适应高度调整 --owen
function iframeResizeByowen(pid)
{
	var dyniframe   = null;
	if (document.getElementById)
	{
		dyniframe= document.getElementById(pid);
        dyniframe.height = dyniframe.Document.body.scrollHeight;
	}
}


//  限制图片显示大小,图片宽或高中的最大值如果超过限制值，则将其取值设为限制值（图片将自动调整）
//  --Jim Li
function CheckImageSize(MaxInt,imgObj)
{
    if(imgObj.width>imgObj.height && imgObj.width>MaxInt)
    {
        imgObj.width=MaxInt;
    }
    else if(imgObj.width<imgObj.height && imgObj.height>MaxInt)
    {
        imgObj.height=MaxInt;
    }
    else
    {}
}


//Trim方法
function Trim(s)
{ 
   var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/); 
   return (m == null) ? "" : m[1]; 
} 
    

    //-------------------------------------------------------------------------------------------------------------------


