﻿$("document").ready(function(){

    $("#btnsave").click(function(){
        
        var name=$("#name").val();
        var company=$("#company").val();
        var mobile=$("#mobile").val();
        var email=$("#email").val();
        var address=$("#address").val();
        var code=$("#code").val();
        var your_tel = /1[358]\d{9}/;
        var email_ = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*$/;
        var code_ = /^[1-9]\d{5}$/;
        
      
       var radio = $("input[name='radio']:checked").val();
       if($.trim(radio)=='')
       {
                $("#radio").focus();
            alert('请选择问题答案！');
            return; 
       }    
//        if($.trim(name)=='')
//        {
//         $("#name").focus();
//            alert('请填写姓名！');
//            return;
//        }
//        if($.trim(name).length<2 || $.trim(name).length>12)
//        {
//         $("#name").focus();
//            alert('姓名长度在2到12个字符之间！');
//            return;
//        }
//        if($.trim(company)=='')
//        {
//         $("#company").focus();
//              alert('请填写公司名称！');
//            return;
//        }
//         if($.trim(company).length<2)
//        {
//         $("#company").focus();
//            alert('公司名称格式填写有误！');
//            return;
//        }
//         if($.trim(mobile)=='')
//        {
//         $("#mobile").focus();
//              alert('请填写手机号码！');
//            return;
//        }
//        if (mobile != '填写手机号码') {
//        if (!mobile.match(your_tel)) {
//            $("#mobile").focus();
//            alert('手机号码格式填写有误');
//            $("#mobile").focus();
//            return;
//        }
//    }
//      if($.trim(email)=='')
//        {
//            $("#email").focus();
//            alert('请填写电子邮箱！');
//            return;
//        }
//         if (!email.match(email_)) {
//               $("#email").focus();
//               alert('电子邮箱格式填写有误！');
//               return false;
//            }
//     if($.trim(address)=='')
//        {
//            $("#address").focus();
//            alert('请填写联系地址！');
//            return;
//        }
//         if($.trim(address).length<2)
//        {
//         $("#address").focus();
//            alert('联系地址格式填写有误！');
//            return;
//        }
//        
//          if($.trim(code)=='')
//        {
//            $("#code").focus();
//            alert('请填写邮编！');
//            return;
//        }
//         if (!code.match(code_)) {
//        $("#code").focus();
//        alert('邮编格式填写有误');
//        return false;
//    }
    
      $.ajax({
        type: "POST",
        data: { answer:radio,name: name,company:company,mobile:mobile,email:email,address:address,code:code },
        url: "ajax/index.ashx",
        async: "false",
        cache: "false",
        success: function(msg) {
        if(msg==1)
        {
            alert('您填写的手机号码已经存在，请重新填写！');
        }
        else if(msg==2)
        {
         alert('您填写的电子邮箱已经存在，请重新填写！');
        }
        
          else if(msg==0)
          {
           alert('提交成功！');
           window.location='index.html';
          }
         else
         {
            alert('系统繁忙，请稍后在提交！');
         }
        }

    });
    })  
})
