function GE(a){return document.getElementById(a);}
function GetName(a){return document.getElementsByName(a);}
function Check(){
  var customerName=GetName("customerName")[0];
  //姓名
  if(customerName.value=='' || customerName.value=='姓名')
  {
    GE("messageId").innerHTML="请填写您的姓名!"; 
    customerName.focus();
    return false;
  }
  if(customerName.value.length>20)
  {
    GE("messageId").innerHTML="请填写您的真实姓名以方便我们与您联系!";
    customerName.focus();
    return false;
  }
  
  var customerTel=GetName("customerTel")[0];
  //联系电话
  if(customerTel.value=='' || customerTel.value=='电话')
  {
    GE("messageId").innerHTML="请填写您联系电话!";
    customerTel.focus();
    return false;
  }
  var checkPhone=/^(\d{3,4})-(\d{7,8})$/;
  var chekcMobile=/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/;
  if(!chekcMobile.exec(customerTel.value) && customerTel.value.length<11 )
  {
     GE("messageId").innerHTML="请填写正确的联系电话,如0755-88888888";
     customerTel.focus();
     return false;
  }
  if(!checkPhone.exec(customerTel.value) && customerTel.value.length>11)
  {
    GE("messageId").innerHTML="请填写正确联系电话，如0755-88888888";
    customerTel.focus();
    return false;
  }
  
   var customerEmail=GetName("customerEmail")[0];
   //联系邮箱
   if(customerEmail.value=='' || customerEmail.value=='电子邮件')
   {
     GE("messageId").innerHTML="请填写您联系邮箱!";
     customerEmail.focus();
     return false;
   }
   var checkEmail=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
   if(!checkEmail.exec(customerEmail.value))
   {
      GE("messageId").innerHTML="请填写您真实的联系邮箱!";
      customerEmail.focus();
      return false;
   }
   var customerContent=GetName("customerContent")[0];
   //留言内容
   if(customerContent.value=='' || customerContent.value=='留言')
   {
     GE("messageId").innerHTML="请填写您的留言内容!";
     customerContent.focus();
     return false;
   }
   if(customerContent.value.length>500)
   {
     GE("messageId").innerHTML="请填写您500字以内的留言内容!";
     customerContent.focus();
     return false;
   }

   
 var X=new ActiveXObject("Msxml2.XMLHTTP");
 if(X){
  GE('addMsgSubmit').disabled=true;
  X.onreadystatechange=function(){
   if(X.readyState==4){
    if(X.status==200){
     eval(X.responseText)
    }
    else{GE('messageId').innerHTML=X.statusText}
   }
   else{GE('messageId').innerHTML="正在提交数据..."}
  };
  X.open('POST','/mail.php',true);
  X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  var SendData = 'action=addmsg&Name='+GetName('customerName')[0].value+'&Tel='+GetName('customerTel')[0].value+'&Email='+GetName('customerEmail')[0].value+'&Content='+GetName('customerContent')[0].value;
  X.send(SendData);
 }
 else{
 GE('messageId').innerHTML='你的浏览器不支持XMLHttpRequest'
 }
}
