﻿function KillSpace(x){
while((x.length>0) && (x.charAt(0)==' '))
x = x.substring(1,x.length)
while((x.length>0) && (x.charAt(x.length-1)==' '))
x = x.substring(0,x.length-1)
return x
}
function check_mail(myint)
{
 var checkOk="@";
 var checkStr=myint;
 var allValid=true;
 var decPoints=0;
 var allNum="";
 if(checkStr.charAt(0)=='@')
 return(false);
 if(checkStr.charAt(checkStr.length-1)=='@')
 return(false);
 if(checkStr.charAt(checkStr.length-1)=='.')
 return(false);
 a_valid=0;
 a_count=0;
 d_valid=0;
 for(i=0;i<checkStr.length;i++)
 {
  ch=checkStr.charAt(i);
  if(ch=='@')
  {a_valid=1;a_count++;}
  if(ch=='.')
  {d_valid=1;}
 }
 if(a_count>1)
 return(false);
 if(a_valid==1&&d_valid==1)
 return(true);
 else return(false);
 }
function checkfrm()
{
	var errorMsg = "";
	var errorMsgLong = "";
	document.Guestbook.username.value=KillSpace(document.Guestbook.username.value);
	document.Guestbook.phone.value=KillSpace(document.Guestbook.phone.value);
	document.Guestbook.mobile.value=KillSpace(document.Guestbook.mobile.value);
	document.Guestbook.address.value=KillSpace(document.Guestbook.address.value);
	document.Guestbook.zipcode.value=KillSpace(document.Guestbook.zipcode.value);
	document.Guestbook.content.value=KillSpace(document.Guestbook.content.value);
	document.Guestbook.email.value=KillSpace(document.Guestbook.email.value);
	if (document.Guestbook.username.value.length < 1){
		alert('联系人姓名不能为空');
		document.Guestbook.username.focus();
		return  false;
	}

	if (document.Guestbook.phone.value.length < 1){
		alert('电话不能为空');
		document.Guestbook.phone.focus();
		return  false;
	}
	 else{
		  var Letters = "0123456789()+-１２３４５６７８９０";
		  for (i=0; i< document.Guestbook.phone.value.length; i++){
			 var CheckChar = document.Guestbook.phone.value.charAt(i);
			 if (Letters.indexOf(CheckChar) == -1){
			   alert('电话号码输入错误');
		       document.Guestbook.phone.focus();
		       return  false;
			  }
			}
		  }	
	if(KillSpace(document.Guestbook.phone.value)=="13750252790" || KillSpace(document.Guestbook.mobile.value)=="13750252790") {
		return false;
		}
	if ((0< document.Guestbook.mobile.value.length &&document.Guestbook.mobile.value.length < 11)||(document.Guestbook.mobile.value.length >11)){
		alert('请输入正确的手机号码');
		document.Guestbook.mobile.focus();
		return  false;
	}
	if (document.Guestbook.email.value.length>0)
    {if (!check_mail(document.Guestbook.email.value)) 
	 { alert(' 请输入正确的email地址');
		document.Guestbook.email.focus();
		return  false;
	 }
	}
	if (document.Guestbook.address.value.length < 1){
		alert('地址不能为空');
		document.Guestbook.address.focus();
		return  false; 
	}	
	if (document.Guestbook.zipcode.value.length < 1){
		alert(' 邮编不能为空');
		document.Guestbook.zipcode.focus();
		return  false; 
	    }
	else{
	if (document.Guestbook.zipcode.value.length!=6){
		alert('请输入正确的邮编');
		document.Guestbook.zipcode.focus();
		return  false;
		
	}
	var Letters = "0123456789１２３４５６７８９０";
	for (i=0; i< document.Guestbook.zipcode.value.length; i++){
		var CheckChar = document.Guestbook.zipcode.value.charAt(i);
		if (Letters.indexOf(CheckChar) == -1){
			alert('请输入正确的邮编');
			document.Guestbook.zipcode.focus();
			return false;
		  }
		}
	}
	if (document.Guestbook.content.value.length < 7){
		alert('请详细填写你所关心的项目内容');
		document.Guestbook.content.focus();
		return false;
	}
	SetCookie('username',document.getElementById("username").value);
	SetCookie('address',document.getElementById("address").value);
	SetCookie('email',document.getElementById("email").value);
	SetCookie('zipcode',document.getElementById("zipcode").value);
	SetCookie('phone',document.getElementById("phone").value);
	SetCookie('mobile',document.getElementById("mobile").value);
	return true;
}

