var d=new Date()
var formID='#contact-form';
jQuery(function($){
	 $(formID).bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
		
			 user_name: {
				group: '.input-item',
                validators: {
                    notEmpty: {
                        message: '您的姓名不能为空.'
                    } 
                }
            },

           
			
		
		email: {
				 group:'.input-item',
                validators: {
					 notEmpty: {
                        message: '您的邮箱不能为空.'
                    },
					regexp: {
                        regexp: /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,
                        message: '请输入有效的邮箱地址.'
                    }
				}
			},
		
         validcode: {
			    group: '.input-item',
                validators: {
					 notEmpty: {
                        message: '验证码不能为空.'
                    },
                  //  callback: {
//                        message: '验证码输入错误',
//						callback: chk_code
//                    }
                }
            }
			,
			
			
            telephone: {
               
				group: '.input-item',
                validators: {
                    notEmpty: {
                        message: '您的手机不能为空.'
                    },
                  /*  stringLength: {
                        min: 11,
                        max: 11,
                        message: '手机号必须是11位.'
                    },
                    regexp: {
                        regexp: /^1[3|4|5|7|8][0-9]{9}$/,
                        message: '请输入有效的手机号.'
                    }*/
                  
                }
            },
		
		body: {
				group: '.input-item',
                validators: {
                    notEmpty: {
                        message: '留言内容不能为空.'
                    }
                }
            }
		
        }
    }).on('success.form.bv', function(e) {//提交验证成功后执行
			//表单无法提提交需要再次触发一次表单的提交 必需要写
		 /*
			setTimeout(function(e){
				$(formID).removeAttr("novalidate");
				$('#Submit').removeAttr("disabled");
				$('#Submit').click();
			},300)*/
			
        });

    // Validate the form manually
    $('#Submit').click(function() {
        //$(formID).bootstrapValidator('validate');

    });

    $('#Reset').click(function() {
        $(formID).data('bootstrapValidator').resetForm(true);
		
    });
	
	
	  $("#gender input[type='radio']").change(function(e){
			   $("#gender label").removeClass("sel");
			   $("#gender label").removeAttr("checked");
			   $(this).attr("checked","checked");
			   $(this).parent("label").addClass("sel");
	})
		  
		  
	
	 $("#validcode").change(function(e){
		  var value=$(this).val();
		  if(value=='')return;
			  $.get(www_url+"/index.php",
			{
				m: "inquiry",
				a : "chk_code",
				code: value,
				temp:Math.random()
			}
			,function(data){
				if(data=='yes'){
					 $(".btn-brand").removeAttr("disabled");
					 set_status($("#validcode"),"div.input-item","success",'your enter code is right.');
					 return true;
				}else{
					 set_status($("#validcode"),"div.input-item","error",'your enter is error');
					 $(".btn-brand").attr("disabled","disabled");
					 return false;
				}
				
			 }
		)
	 })
});