﻿//共用客户端JScript脚本 JScript
//Create by:  xie.lianghui
//Create on: 2008-07-18
//Update by:
//Update on:  
 
    //去掉 str 字符串前后的空格
    //add by  xie,lianghui
    String.prototype.trim=function()
	 { return this.replace(/(^\s*)|(\s*$)/g,"");}
	 
	//用于IFrame中显示页面

	//add by xie,lianghui
	function ToPage(PageName)
    {   
       window.document.getElementById("rightfrm").src=PageName;
    }
	
	//用于在IFrame页面中转换页面

	function ToPageFromIFrame(PageName)
	{
	    parent.document.getElementById("rightfrm").src=PageName;
	}  
	//设置IFrame的高度

	//把如下代码加到页面中就可调用到此函数
    //<script type="text/jscript">
    //window.onload= function ()
    //{ 
    //ResizeIFrame(800)  
    //}
    //</script>
	function ResizeIFrame(IFHeight) 
    { 
        try 
        { 
       

            if (parent.document.getElementById("rightfrm").src=="MainPage.aspx")
            {
            parent.document.getElementById("rightfrm").style.height="465"
            }
            else
            {           
            parent.document.all["rightfrm"].style.height=IFHeight            
            }
        } 
        catch(e){} 
    }   

	//計算 obj 的字節長度（漢字兩字節）	   
    //add by xie,lianghui
    String.prototype.VLength=function()
    {
    
      	var len = 0 
        for (var i = 0 ; i < this.length; i ++ )
        {
            if (this.charCodeAt(i)<= 255)
           	    len += 1
            else
           	    len += 2 
        }
        return len
    }  
	    

  
  //打开新增/维护画面的方法

  //url:要打开画面的url以及queryString
  //iWidth:打开画面的额宽度
  //iHeight:打开画面的高度

  //iSob:是否要滚动条，yes表示是，no表示否

  //如： <input id="btnAdd" type="button" value="新增"  onclick="ShowDialog('UserCFGU.aspx',550,200,'yes')" />
  //add by xie,lianghui
 function ShowDialog(url,iWidth,iHeight,iScb) 
{
  var  iTop=(window.screen.height-iHeight)/2;//屏幕中央上邊
  var  iLeft=(window.screen.width-iWidth)/2;//屏幕中央左邊
  window.open(url,"_blank", "Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft+",toolbar=no,menubar=no,status=no,scrollbars="+iScb +",resizable=yes")
 if(window.event)
 {
 window.event.returnValue=false;
 }
 

} 
 function ShowDialog2(url,iWidth,iHeight,iScb) 
{
  var  iTop=(window.screen.height-iHeight)/2;//屏幕中央上邊
  var  iLeft=(window.screen.width-iWidth)/2;//屏幕中央左邊
  window.open(url,"_blank", "Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft+",toolbar=no,menubar=no,status=yes,scrollbars="+iScb +",resizable=yes")
 if(window.event)
 {
 window.event.returnValue=false;
 }
 

} 
 function ShowDialogValue(url,DKey,iWidth,iHeight,iScb) 
{
  DValue=document.getElementById(DKey).value.trim();
  DValue=escape(DValue);
  var  iTop=(window.screen.height-iHeight)/2;//屏幕中央上邊
  var  iLeft=(window.screen.width-iWidth)/2;//屏幕中央左邊
  window.open(url+"?name="+DValue,"_blank", "Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft+",toolbar=no,menubar=no,status=no,scrollbars="+iScb +",resizable=yes")
 if(window.event)
 {
 window.event.returnValue=false;
 }
 

} 

//删除提示信息
//如：
//add by xie,lianghui

function DelConfirm()
{
    return confirm('确定要删除吗?');
}
function switchCell(n,totle) {
     for(i=0;i<totle;i++){
     document.getElementById("navcell" + i).className="tab-off";
     document.getElementById("tb" + i).style.display="none";
               }
     document.getElementById("navcell" + n).className="tab-on";
     document.getElementById("tb" + n).style.display="";
}

//新增和修改画面点，点击保存和修改后的关闭窗体的代码

function window_Close()
{
window.close();
window.event.returnValue=false;
}
//子画面刷新父画面的方法

//add by xie,lianghui
function RefreshPage(PageObj)
{
location.href=PageObj
}
//使用这个检查mail，含"-"的mail可以通过检测
function validate_email3(companyemail)
{
	if (companyemail != "") {
        var reg =/^[\w.-]+@([0-9a-z][\w-]+\.)+[a-z]{2,3}$/i; 
        // /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        flag = reg.test(companyemail);
        if (flag) {
            return true;
    	 }
    	 return false;
      }	
     return true;
}
//使用这个检查mail，含"@u.aa.edu"的mail可以通过检测
function validate_email2(companyemail)
{

	if(companyemail.length!=0)
　　 {
　　         if (companyemail.charAt(0)=="." || 
　　         companyemail.charAt(0)=="@"|| 
　　         companyemail.indexOf('@', 0) == -1 || 
　　         companyemail.indexOf('.', 0) == -1 || 
　　         companyemail.lastIndexOf("@")==companyemail.length-1 || 
　　         companyemail.lastIndexOf(".")==companyemail.length-1)
　　         {　　 
　　         return false;
　　         }
　　 }　　   
　　return true;
}
//使用这个检查mail，含"@u.aa.edu"\含"-"的mail可以通过检测
function validate_email(companyemail)
{

        if(companyemail.indexOf(',')>0 )
        {
     
                var ea= companyemail.split(",")
                var i=0
                var checkRe
                for( i ;i<ea.length;i++)
                {        
                     if(ea[i].trim()!="")
                     {
                         checkRe=validate_email(ea[i])
                         if(!checkRe)
                         {
                            return false;
                         }
                     }
                     else
                     {
                         return false;
                     }
                }
                return true;
        }
        else
        {
	        if (companyemail != "") {
                var reg =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; 
                flag = reg.test(companyemail);
                if (flag) {
                    return true;
    	         }
    	         return false;
              }	
                return true;
        }   
   
}
function validate_SendEmail(companyemail,i)
{
//var bb=4000
//if(i>bb)
//                {             
//                alert(companyemail+"--"+i);                
//                }
var flag=false;
try
{
  if (companyemail != "") {
                var reg =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; 
                flag = reg.test(companyemail);
                if (flag) {                  
                    return true;
    	         }            	         
    	         return false;
              }	                               
                return true;
                
 }
 catch(e)
 {
   return false;
 }
                
}
function validate_date(date){
    if(date != ""){
        var reg = /^(((1[6-9]|[2-9]\d)\d{2})|(((1[6-9]|[2-9]\d)\d{2})\.([1-9]|1[0-2]))|(((1[6-9]|[2-9]\d)\d{2})\.([13578]|1[02])\.([1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})\.([13456789]|1[012])\.([1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})\.2\.([1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))\.2\.29))$/;
        flag = reg.test(date);
        if(flag){
            return true;
        }
        return false;
    }
    return true;
}

//checkBox全选和全不选
//add by xie,lianghui
//页面有：全选和全部选2个checkbox
  function  SelectData2(objBt)
    {
         for(var i=0;i<document.forms[0].elements.length;i++)//遍历页面中的所有控件         {
            var obj=document.forms[0].elements[i];//获取当前控件    
            if (obj.type=="checkbox")
           {
            objBt.id=="radAll"?obj.checked=true:obj.checked=false   
           }
        }   
    }  
    //excel导入客户端检测
    //add by xie,lianghui on 2008-09-12 
     function  IsSelect()
    {
         for(var i=0;i<document.forms[0].elements.length;i++)//遍历页面中的所有控件         {
            var obj=document.forms[0].elements[i];//获取当前控件   
            if(obj.id!= "SelData")
            {
           
                    if (obj.type=="checkbox" )
                   {                 
                         if(obj.checked)
                         {
                         return true
                         }
                   }
           }
        } 
        alert("请选择需要导出的数据！")
        return false;  
    }   
 // checkBox全选和全不选  
 //add by xie,lianghui
 //页面只有一个全选checkbox
 function  SelectData(objBt)                                                                         
   {
                                                                                                 
        for(var i=0;i<document.forms[0].elements.length;i++)//遍历页面中的所有控件       {
                                                                                            
           var obj=document.forms[0].elements[i];//获取当前控件    
                                        
           if (obj.type=="checkbox")
                                                                 
          {
                        if(obj.id.indexOf("sr_code_")>=0)   
                        {
                        continue;
                        }     
                        if(obj.id.indexOf("cbExcelAll")>=0)   
                        {
                        continue;
                        }                                                             
                        objBt.checked?obj.checked=true:obj.checked=false   
                                       
          }
                                                                                          
       }   
                                                                                          
   }    
   
function addattchment()
{
	var objectitem = document.getElementById('numfiles');
	if(objectitem)
	{
		var fileitem = objectitem.value;
		var table_content = document.getElementById('filesupload');
		var tr = document.createElement('tr');		
		var obj_file_td = document.createElement('td');
		obj_file_td.align="left";
		obj_file_td.appendChild(createFile('personalresume'+fileitem, '', 'personalresume'+fileitem,80));
		tr.appendChild(obj_file_td);	
		
		var removeTd = document.createElement("td");
	    removeTd.appendChild(CreatImage());
		tr.appendChild(removeTd);  
		
		table_content.getElementsByTagName('tbody')[0].appendChild(tr);
		fileitem++;
		objectitem.value = fileitem;
	}
}

function createFile(name, value, id,size) {
  var input = document.createElement("input");
  input.type = "file";
  input.runat = "server";
  if (name) input.name = name;
  if (value) input.value = value;
  if (id) input.id = id;
  input.size = 30;
  if (size) input.size = size;
  return input;
}

function CreatImage()
{
	var m = new Image();
	m.src = "../Images/remove.png";
	m.onclick = function(){
	removeOneItem(this);
	};
	return m;
}  
function removeOneItem(img)		
{
   var tr = getAncestorByTagName(img, "tr");
   tr.parentNode.removeChild(tr);
}  
function getAncestorByTagName(e, tagName) {
  tagName = tagName.toLowerCase();
  do {
    e = e.parentNode;
  } while ((e.nodeType == 1) && (e.tagName.toLowerCase() != tagName));
  return (e.nodeType == 1) ? e : null;
}                                                                                          
 function addprojectinfo()
{
//debugger;
	var objectitem = document.getElementById('projectnum');
	if(objectitem)
	{
		var fileitem = objectitem.value;
		var table_content = document.getElementById('projectinfo');
		var tbody =  document.createElement('tbody');	
		var tr = document.createElement('tr');		
		var ti1 = document.createElement('td');
		ti1.appendChild(createLabel('项目名称'));
		tr.appendChild(ti1);	
		var place = document.createElement('td');
		place.appendChild(createInputText('projectname'+fileitem, '', 'projectname'+fileitem, 52));
		tr.appendChild(place);
			var removetbody = document.createElement("td");
	    removetbody.appendChild(CreatRemovetbody());
		tr.appendChild(removetbody); 
		
		
		tbody.appendChild(tr);
		var tr = document.createElement('tr');			
		var ti2 = document.createElement('td');
		ti2.appendChild(createLabel('项目简介（2000字以内）'));
		tr.appendChild(ti2);	
		var con2 = document.createElement('td');
		con2.appendChild(createTextArea('projectdesc'+fileitem, 'projectdesc'+fileitem, 5, 50));
		tr.appendChild(con2);	
		var removeTd = document.createElement("td");
	    //removeTd.appendChild(CreatImage());
		tr.appendChild(removeTd); 		
		
		tbody.appendChild(tr);
		table_content.appendChild(tbody);
		fileitem++;
		objectitem.value = fileitem;
	}
ChildResizeIFrame()

}
var imageurl = "/Images";

	function ChildResizeIFrame() 
    {
      //  var iframe = parent.document.getElementById("MainFrame");   
       // iframe.contentWindow.document.body.scrollHeight<=465 ?   iframe.height=475:  iframe.height= iframe.contentWindow.document.body.scrollHeight ;        
      
    }
    function createLabel(text, htmlFor) {
      var label = document.createElement("label");
      if (text) label.appendChild(document.createTextNode(text));
      if (htmlFor) label.htmlFor = htmlFor;      
      return label;
 }


 // Convenience function for creating an <input type="text">
function createInputText(name, value, id,size,maxlength) {
  var input = document.createElement("input");
  input.type = "text";
 
  if (name) input.name =  name;
  if (value) input.value = value;
  if (id) input.id = id;
  if (size)input.size=size;
  if (maxlength)input.maxlength=maxlength;
  return input;
}
 // Convenience function for creating an <input type="text">
function createTextArea(name, id, rows, cols) {
  var input = document.createElement("textarea");
  
  if (name) input.name =name;
  if (id) input.id =id;
  if (rows)input.rows=rows;
  if (cols)input.cols=cols;
  return input;
}

function CreatRemovetbody()
{
	var m = new Image();
	if(imageurl){
	m.src = imageurl+"/remove.png";
	}				
	m.onclick = function(){
		var tbody = getAncestorByTagName(this, "tbody");
	   tbody.parentNode.removeChild(tbody);
	// var objectitem = document.getElementById('projectnum');
	// objectitem.value=objectitem.value-1;//add by xie,lianghui
	 ChildResizeIFrame();//add by xie,lianghui
	 
	};
	return m;
}
