//***JavaScript 表单域读写函数集*******//
//*******编写：牛云飞 *****************//

function outcheck(check_value){
	if(check_value != ""){
		alert(check_value)
		return false; 
	}
	return true;
}

function checkvalue(obj, low, up, mode, lable){
/*
Mode = 1 检测是否为空   2是否是数字  4是否整数
8是否是为数字、字母和_.-
16 自定义字符检测
32 长度检测
64 数字大小检测
*/
    var temp,type;
    var length, i, base, str;
    
    str=getformvalue(obj);
    if(str==null){
		lenght=0;
		str="";
	}	
	else{	
		length = str.length
	}	
    temp=""
    if( mode % 2 >= 1 ){
        if( str == "" ){
            temp = temp + "“" + lable + "”" + "不能为空！" + "\n";
        }
    }
    
    if( mode % 4 >= 2 ){
        base = "0123456789."
        for(i = 0;i<=length-1;i++)
            if( base.indexOf(str.substring(i, i+1)) == -1  ){
				temp = temp + "“" + lable + "”" + "必需是数字！" + "\n";
				break;
            }    
    }
    
    if( mode % 8 >= 4 ){
        base = "0123456789"
        for(i = 0;i<=length-1;i++)
            if( base.indexOf(str.substring(i, i+1)) == -1  ){
                temp = temp + "“" + lable + "”" + "必需是整数！" + "\n";
                break;
            }    
    }
    
    if( mode % 16 >= 8 ){
        base = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789_-."
        for(i = 0;i<=length-1;i++)
            if( base.indexOf(str.substring(i, i+1)) == -1  ){
                temp = temp + "“" + lable + "”" + "包含非法字符！它只能是字母、数字和“- _ .”。" + "\n";
                break;
            }
    }
    
    if( mode % 32 >= 16 ){
        base = low.replace("[a-z]", "abcdefghijklmnopqrstuvwxyz")
        base = base.replace("[a-z]", "abcdefghijklmnopqrstuvwxyz")
        base = base.replace( "[0-9]", "0123456789")
        for(i = 0;i<=length-1;i++)
            if( base.indexOf(str.substring(i, i+1)) == -1 ){
                temp = temp + "“" + lable + "”" + "包含非法字符！它只能是" + up + "。" + "\n";
                break;
            }
    }
    
    if( mode % 64 >= 32 ){
        if( ! (length >= low && length <= up) ){
               temp = temp + "“" + lable + "”" + "的长度必需在" + low + "到" + up + "之间！" + "\n";
        }
    }
    
     if( mode % 128 >= 64 ){
        if( ! (parseInt(str) >= parseInt(low) && parseInt(str) <= parseInt(up)) ){
               temp = temp + "“" + lable + "”" + "必需在" + low + "到" + up + "之间！" + "\n";
        }

    }
    if(temp!=""){
    	alert(temp);
    	type=(getformtype(obj));
    	if(type!="radio" && type!="checkbox"){
    		obj.focus();
    	}
	return false; 
   }
   return true;
    
}

function getformtype(obj){
	var type;
	type=obj.type;
	if(typeof(type)=="undefined"){

		type=obj[0].type;
	}
	return type;		
}
function getformvalue(input){
//取表单域的值
	var type,temp;
	temp="";
	
	type=getformtype(input);	

	switch(type){
		case "radio":	//单选框
			n=input.length-1;

			if(isNaN(n)==true){
				if(input.checked == true){
					temp = input.value;
				}else{
					temp = "";
				}	
			}else{
				for(i=0;i<=n;i++){
					if(input[i].checked == true){
						return(input[i].value);
					}
				}
				break;
			}
			case "checkbox":	//复选框
			n=input.length-1;
			if(isNaN(n)==true){
				if(input.checked == true){
					temp = input.value;
				}else{
					temp = "";
				}	
			}else{
				for(i=0;i<=n;i++){
					if(input[i].checked == true){
						if(temp!=""){
							temp += ",";
						}
						temp += input[i].value;

					}	
				}
			}
			return(temp);
			break;
			
		case "select-one" :	//单选列表框
			n=input.length-1;	
			for(i=0;i<=n;i++){
				if(input.options[i].selected == true){
					temp = input.options[i].value;
					break;
				}			
			}
			return(temp);
			break;				
		case "select-multiple":	//多选列表框
			n=input.length-1;	
			for(i=0;i<=n;i++){
				if(input.options[i].selected == true){
					if(temp!=""){
						temp+=",";
					}					
					temp+=input.options[i].value;
				}			
			}
			return(temp);
			break;			
		default:				//其它
			return(input.value);
			break;
	
	}
	
	return(input.value);

}

function ischecked(group,value){
	var i,n;
	n=group.length-1;
	for(i=0;i<=n;i++){
		if(value==group[i]){
			return true;			
		}
	}
	return false;
}


function SetSelectedAndChecked(input,value){
//设置表单域的选择
	var type,temp,i,n;
	var split_value = new Array();
	temp="";
	
	type=input.type;
	
	if(typeof(type)=="undefined"){
		type=input[0].type;
	}
	

	switch(type){
		case "radio":	//单选框
			n=input.length-1;

			if(isNaN(n)==true){
				if(input.value = value){
					input.checked = true;
				}else{
					input.checked = false;
				}	
			}else{
				for(i=0;i<=n;i++){
					if(input[i].value == value){
						input[i].checked = true;
					}else{
						input[i].checked = false;					
					}
				}
			}
			break;

		case "checkbox":	//复选框
			n=input.length-1;
			split_value=value.split(",");
			if(isNaN(n)==true){
				if(ischecked(split_value,input.value)){
					input.checked = true;
				}else{
					input.checked = false;
				}	
			}else{
				for(i=0;i<=n;i++){
					if(ischecked(split_value,input[i].value)){
						input[i].checked = true;
					}else{
						input[i].checked = false;					
					}					
				}
				
			}
			break;
			
		case "select-one" :	//单选列表框
			n=input.options.length-1;	
			for(i=0;i<=n;i++){
				if(input.options[i].value == value){
					input.options[i].selected = true;
				}else{
					input.options[i].selected = false;				
				}
						
			}
			break;				
		case "select-multiple":	//多选列表框
			n=input.options.length-1;	
			split_value=value.split(",");
			for(i=0;i<=n;i++){
				if(ischecked(split_value,input.options[i].value)){
						input.options[i].selected = true;
				}else{
						input.options[i].selected = false;				
				}			
			}
			break;			
		default:				//其它
			return false;
			break;
	
	}
	
	return true;

}

function IsEmail(argValue)
{
	var emailStr=argValue.toLowerCase();
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var emailPat=/^(.+)@(.+)$/;
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
			return false;
		}
	}
	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			return false;
		}
	}
	if (user.match(userPat)==null)
	{
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				return false;
			}
		}
		return true;
	} 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
	{
		return false;
	}
	if (len<2)
	{
		return false;
	}
	return true;
}


/* 
 * 功能：表单内容格式检测
 * 参数 obj 　　　为表单名称（ID）
 *      chktype　 为类型，参照函数内释
 */
function chk(obj, chktype){
var temp=1;
 switch(chktype){
  case 1://判断是否为空
   if(obj.value == ""){
    alert("请输入必要的字符。");
    obj.focus();
    obj.select();
    temp=0;    
   }
   break;
  case 2://判断是否为数字
   var reg = /^\d+(\.\d+)?$/;
   if(obj.value != ""){
   if(!reg.test(obj.value)){
    alert("请输入数字。");
    obj.focus();
    obj.select();
    temp=0;
   }
   }
   break;
  case 3://判断是否为用户名格式
   var reg = /^[^\d\-_][\w\-]*[^\-_]$/;
   if(obj.value != ""){
   if(!reg.test(obj.value)){
    alert("请输入正确的格式。");
    obj.focus();
    obj.select();
    temp=0;
   }
   }
   break;
  case 4://判断是否为汉字
   var reg = /^[\u4E00-\u9FA5]*$/;
   if(obj.value != ""){
   if(!reg.test(obj.value)){
    alert("你输入的不全是汉字。");
    obj.focus();
    obj.select();
    temp=0;
   }
   }
   break;
  case 5://判断是否为邮箱格式
   var reg = /^[^\d\-_][\w\-]*[^\-_]@[^\-][a-zA-Z\d\-]*[^\-](\.[^\-][a-zA-Z\d\-]*[^\-])*\.[a-zA-Z]{3}(\.[a-zA-Z]{2})?$/;
   if(obj.value != ""){
   if(!reg.test(obj.value)){
    alert("你输入正确的邮箱格式。");
    obj.focus();
    obj.select();
    temp=0;
   }
   }
   break;
  case 6://判断是否为合法日期格式
   var reg = /^(19|20)\d\d\-(0|1)\d\-(0|1|2|3)\d$/;
   if(obj.value != ""){
   if(!reg.test(obj.value)){
    alert("你输入正确的日期格式。");
    obj.focus();
    obj.select();
    temp=0;
   }
   }
   break;
 }
 
 if(temp==1)
 {
    return true;
 }
 else
 {
    return false;
 }
 
}

function OpenNoteAdd(type,id)
{
newWindow = window.open ("/lyadd.aspx?id="+id+"&type="+type,"我要留言","toolbar=no,resizable=no,scrollbars=no,dependent,width=600,height=510,left=0,top=0");
newWindow.focus();
}



function chksearch()
{
return false;
/*
  if(searchjob.cboField.value == "tJob.dCreate")
  {
    if (!chk(searchjob.txtKeyWord,1)) return false;
    if (!chk(searchjob.txtKeyWord,6)) return false;
  }
  */
}

function OpenLogin()
{
   newWindow = window.open ("/login.aspx","登陆","toolbar=no,resizable=no,scrollbars=no,dependent,width=600,height=400,left=0,top=0");
   newWindow.focus();
}

/*
舜子制作
Made by PuterJam
*/
//--初始化变量--
var rT=true;//允许图像过渡
var bT=true;//允许图像淡入淡出
var tw=0;//提示框宽度
var endaction=true;//结束动画

var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 0;
offsetY = 20;
var toolTipSTYLE="";
function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg, fg, bg)
{
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) 
    {
    toolTipSTYLE.visibility = "hidden";
    }
    else 
    {
      //--图象过渡，淡出处理--
      if (!endaction) {toolTipSTYLE.display = "none";}
      if (rT) document.all("msg1").filters[1].Apply();
      if (bT) document.all("msg1").filters[2].Apply();
      document.all("msg1").filters[0].opacity=0;
      if (rT) document.all("msg1").filters[1].Play();
      if (bT) document.all("msg1").filters[2].Play();
      if (rT){ 
      if (document.all("msg1").filters[1].status==1 || document.all("msg1").filters[1].status==0){  
      toolTipSTYLE.display = "none";}
      }
      if (bT){
      if (document.all("msg1").filters[2].status==1 || document.all("msg1").filters[2].status==0){  
      toolTipSTYLE.display = "none";}
      }
      if (!rT && !bT) toolTipSTYLE.display = "none";
      //----------------------
    }
  }
  else // show
  {
    if(!fg) fg = "#777777";
    if(!bg) bg = "#eeeeee";
    var content =
    '<table id="msg1" name="msg1" border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '" class="trans_msg"><td>' +
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + 
    '"><td width=' + tw + '><span style="font-family:宋体;font-size: 12px;color:' + fg +'">' + msg +
    '</span></td></table></td></table>';

    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
      //--图象过渡，淡入处理--
      var cssopaction=document.all("msg1").filters[0].opacity
      document.all("msg1").filters[0].opacity=0;
      if (rT) document.all("msg1").filters[1].Apply();
      if (bT) document.all("msg1").filters[2].Apply();
      document.all("msg1").filters[0].opacity=cssopaction;
      if (rT) document.all("msg1").filters[1].Play();
      if (bT) document.all("msg1").filters[2].Play();
      //----------------------
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
    
  }
  
  toolTipSTYLE.left = x + offsetX;
  toolTipSTYLE.top = y + offsetY;
  return true;
}




