$(document).ready(function(){
	
	
//添加自定义验证规则

	//手机号验证
	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 });			
				return false;
			});  
		},
		//空值检测开启，方便检测下拉框			
		ignore: "",	
		onkeyup : false,
		
		
		
		//JAAX表单提交参数
		submitHandler:function(form) {
		$(form).ajaxSubmit({

		beforeSubmit:function(formData, jqForm, options){
		//点击后，防止多次点击，将表单先禁用
		$('#ew80_submit').attr("disabled","disabled");
		layer.load();
		},

		success:function (msg,statusText) {
		if(msg){
		setTimeout(function(){
		layer.closeAll('loading');
		//返回的是正确的提示时
		
		if(msg['type']=="1"){
		
			//如果参数中的url为空,则只刷新页面局部
			if(msg['url']==""){
			layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']});
			parent.$("#ew80_list_warp").load(window.parent.location.href+" #ew80_list_warp");
			$('#ew80_submit').removeAttr("disabled");
			}else{
			//如果存在URL，则跳转到url地址
			layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']},function(){location.href = msg['url'];});
			$('#ew80_submit').removeAttr("disabled");
			}
		
		}
		
		//返回的是错误信息时					
		if(msg['type']=="0"){
		layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']});
		$('#ew80_submit').removeAttr("disabled");
		}	
			
		},100);

		}	


		},

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

		});
		},	
	
		
			
	});
	
	//公共参数配置完成
	
		
	
});
