/*
**sample:
function checkSubmit(){
	if(chkEmpty(orderForm.userName,"姓名")){
		return false
	}
	if(chkEmpty(orderForm.userDetailAddr,"邮寄地址")){
		return false
	}
	if(chkPostCode(orderForm.userPostCode)){
		return false
	}
	if(chkTel(orderForm.userContectTel,"电话号码只能包含数字、-")){
		return false
	}
	if(chkEmail(orderForm.userEmail)){
		return false
	}
	if(chkNumber(orderForm.purPrice,"产品价格")){
		return false
	}
	return true
}
**/
function trim(str) {
	regExp1 = /^ */;
	regExp2 = / *$/;
	return str.replace(regExp1,'').replace(regExp2,'');
}
function chkEmpty(obj,altStr){
	if(obj.value==""){
		alert("请输入" + altStr)
		obj.focus()
		return true
	}
	return false
}
function chkObjNum(obj,Type){
  Str=obj.value
	elen=Str.length
	if (Type==0){
		if(elen!=6)
			return true
	}

	for (i=0;i<=elen-1;i++)
	{
	  alert(Type)
    if(Type==0){
		   if (Str.charCodeAt(i) > 57 || Str.charCodeAt(i) < 48 ){
         return true;
       }else{
         continue
       }
  	 }else if(Type==1){    //Type=1  电话   charCodeAt-----45:"-"   48:"0"   57:"9"
        if(Str.charCodeAt(i) == 45){
                continue
        }else{
                if (Str.charCodeAt(i) > 57 || Str.charCodeAt(i) < 48 ){
                  return true;
                }else{
                  continue
                }
        }
     }else if(Type==3){
		   if (Str.charCodeAt(i) > 57 || Str.charCodeAt(i) < 48 ){
         return true;
       }else{
         continue
       }
     }else if(Type==2){
        if(Str.charCodeAt(i) == 46 || Str.charCodeAt(i) == 44){
           continue
        }else{
          if (Str.charCodeAt(i) > 57 || Str.charCodeAt(i) < 48 ){
            return true;
          }else{
            continue
          }
        }
      }
      else{
            return true
      }

	}
	return false;
}

function chkTel(obj,str){
  Str=obj.value
	for (i=0;i<=elen-1;i++)
	{
     if (Str.charCodeAt(i) > 57 || Str.charCodeAt(i) < 48 ){
       return true;
     }else{
       continue
     }
  }
}

function chkNumber11(obj,val){
  Str=obj.value
  elen = Str.length
  if(elen==0)
  {
    alert(val + "只能输入数字")
		obj.focus();
		return true
  }
	for (i=0;i<=elen-1;i++)
	{
     if (Str.charCodeAt(i) > 57 || Str.charCodeAt(i) < 48 ){
        alert(val + "只能输入数字")
    		obj.focus();
    		return true
     }else{
        continue
     }
  }
	return false
}

function chkPostCode(obj){
	if(chkObjNum(obj,0)){
		alert("请输入正确的邮政编码")
		obj.focus();
		return true
	}
	return false
}

function chkEmail(obj){
  if (obj.value.length > 100)
  {
    window.alert("email地址长度不能超过100位!");
    obj.focus();
    return true;
  }
   var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
   var re = new RegExp(regu);
   if (obj.value.search(re) != -1) {
         return false;
   } else {
         window.alert ("请输入有效合法的E-mail地址 ！")
         obj.focus();
         return true;
   }
}

function chkNumber(obj,Type){
	Str=obj.value
	elen=Str.length-1
	for (var_i=0;var_i<=elen;var_i++)
	{
	   if (Str.charCodeAt(var_i) > 57 || Str.charCodeAt(var_i) < 48 ){
		 return true;
	   }
	}
	return false;
}

 //注释：判断一个表单元素值是否为合法的日期。传入参数为表单的一个元素对象，
//返回一个布尔值（ture为合法，false为非法）并给出提示
function checkDate(obj)
{
alert(obj.value);
	datestr=obj.value;
	alert(datestr);
	var lthdatestr=0;
//alert(datestr);
	if (datestr != "")
		lthdatestr= datestr.length ;
	else
		lthdatestr=0;
//alert(lthdatestr);
	var tmpy="";
	var tmpm="";
	var tmpd="";
	var status;
	status=0;
	if ( lthdatestr== 0){
		return (true);
	}
	var i;
	for (i=0;i<lthdatestr;i++)
	{
		if (datestr.charAt(i)== '-')
		{
			status++;
		}
		if (status>2)
		{
			alert("日期输入有误！");
			obj.select();
			return (false);
		}
		if ((status==0) && (datestr.charAt(i)!='-'))
		{
			tmpy=tmpy+datestr.charAt(i);
		}
		if ((status==1) && (datestr.charAt(i)!='-'))
		{
			tmpm=tmpm+datestr.charAt(i);
		}
		if ((status==2) && (datestr.charAt(i)!='-'))
		{
			tmpd=tmpd+datestr.charAt(i);
		}
	}
	year=new String (tmpy);
	month=new String (tmpm);
	day=new String (tmpd)
	tempdate= new String (year+month+day);
//alert(tempdate);
	if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
	{
		alert("输入日期的错误！");
		obj.select();
		return (false);
	}
	if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
	{
		alert ("输入的日期越界！");
		obj.select();
		return (false);
	}
	if (!((year % 4)==0) && (month==2) && (day==29))
	{
		alert ("输入的日期不是闰年");
		obj.select();
		return (false);
	}
	if ((month<=7) && ((month % 2)==0) && (day>=31))
	{
		alert ("输入的日期不是大月！");
		obj.select();
		return (false);

	}
	if ((month>=8) && ((month % 2)==1) && (day>=31))
	{
		alert ("输入的日期不是大月！");
		obj.select();
		return (false);
	}
	if ((month==2) && (day==30))
	{
		alert("二月没有三十号！");
		obj.select();
		return (false);
	}

	return(true);
}

function UserCode_OnKeyDown()
{
	if (event.keyCode < 48 && event.keyCode != 13 && event.keyCode != 8 && event.keyCode != 9)
	{
		event.returnValue = false
	}
	if ((event.keyCode > 57 && event.keyCode < 96) || event.keyCode > 105)
	{
		event.returnValue = false
	}
	return true
}

	function URLjump(obj){
		if(obj.selectedIndex > 0)
			window.open(obj.value,"")
	}

	function chkSelect(obj,str){
	  if(obj.selectedIndex==0){
      alert("请选择" + str)
  		obj.focus();
  		return true
	  }
	  return false
	}
