$(function(){
$('.footer-banner').attr('style','display:none');
//添加自定义验证规则
//手机号验证
	jQuery.validator.addMethod("phone", function(value, element) { 
		var length = value.length; 
		var phone =  /^1[34578]\d{9}$/
		return this.optional(element) || (length == 11 && phone.test(value)); 
	}, "手机号码格式错误"); 
	//邮编验证
	jQuery.validator.addMethod("code", function(value, element) { 
		var code = /^[0-9][6]$/ 
		return this.optional(element) || (code.test(value)); 
	}, "邮政编码格式错误"); 
		
		
//公共参数配置	
$.validator.setDefaults({
		
 //重写showErrors
showErrors: function (errorMap, errorList) {
var msg = "";
$.each(errorList, function (i, v) {
	//msg += (v.message + "\r\n");
	//在此处用了layer的方法,显示效果更美观
	//layer.tip(v.message, v.element, {time: 2000 });
	layer.msg(v.message,{ icon:0,time: 2000 });
	$(".login-form-item").find("img").attr("src",yzm_url +'?'+Math.random());			
	return false;
});  
},
	 //空值检测开启，方便检测下拉框			
	ignore: "",	
	onkeyup : false,
		
});
//公共参数配置完成

//前台用户注册表单验证
$("#loginForm").validate({
submitHandler:function(form) {
$(form).ajaxSubmit({
				
beforeSubmit:function(formData, jqForm, options){
//点击后，防止多次点击，将表单先禁用
$('#loginSubmit').attr("disabled","disabled");
$('#loginSubmit').val("正在登陆中......");
layer.load();
},
				
success:function (msg, statusText) {

	if(msg){
	setTimeout(function(){
	layer.closeAll('loading');
	if(msg['type']=="1"){layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']},function(){location.href=login_url;});}
	$('#submitBtn').attr("disabled","disabled");
	$('#submitBtn').val("登陆成功正在跳转......");
	if(msg['type']=="0"){
	layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']});
	$(".login-form-item").find("img").attr("src",yzm_url +'?'+Math.random());
	$('#loginSubmit').removeAttr("disabled");
	$('#loginSubmit').val("登 陆");
	}
	
	},1000);
		
	}	

	
},
	
//当有错误的情况下，提示错误原因
error:function (event, errorText, errorType) {
layer.closeAll('loading');
layer.alert("操作失败，失败原因：<br>" + errorType, {icon: 0});
				
				
					
	},
	
	});
},
		
//开始验证

	rules:{
		username:{
		required:true,//必填
		minlength:3, //最少6个字符
		maxlength:32,//最多20个字符
		remote:chk_url,
		},
		password:{
		required:true,
		remote:{
		url : chk_url,
		type : 'get',
		dataType : 'json',
		data : {
		username : function () {
		return $('#username').val();
		},
		},
		},
				
		},
			
		yzm:{
		required:true,
		remote:chk_url,
		},
			
	},
	
	//错误信息提示
	messages:{
		username:{
			required:"填写登录帐号 /手机号 / 邮箱",
			minlength:"用户帐号至少为3个字符",
			maxlength:"用户帐至多为32个字符",
			remote: "该帐号不存在",
		},
		password:{
			required:"密码没有填写",
			remote: "帐号跟密码不匹配",
		},
		
		yzm:{
			required:"还没有填写验证码",
			remote:"验证码错误！",
		},
		
	},

	});
	
	
	
	
	
		
})
