jQuery(document).ready(function() {
	$("#updatePasswordForm").validate({
		submitHandler : function(form) {
			$(form).ajaxSubmit({
				success : function(e) {
					console.log(e);
					if (e && e.success == true) {
						new $.zui.Messager('修改成功', {
							type : 'success',
							time : 1500
						}).show();
						$("#myModal-updatePassword").modal('hide');
					} else {
						new $.zui.Messager('修改失败:'+e.msg, {
							type : 'danger',
							time : 1500
						}).show();
					}
				}
			});
		},
		rules : {
			'oldPassword' : {
				required : true,
				minlength:6
			},
			'password' : {
				required : true,
				checkPassword : true,
				remote:{
					url:"/user/isAgreement",
					type:"get",
					dataType:'json',
					data:{
						oldPassword:function(){
							return $("#oldPassword").val();
						},
						password:function(){
							return $("#password").val();
						}
					}
				}
			},
			'password1' : {
				required : true,
				equalTo : '#password'
			}
		},
		messages : {
			'oldPassword' : {
				required : "旧密码不能为空",
				minlength:$.validator.format("密码不可少于{0}位")
			},
			'password' : {
				required : "请输入新密码",
				remote : "新密码不能和旧密码一致"
			},
			'password1' : {
				required : "请输入确认密码",
				equalTo : "两次密码输入不一致"
			}
		}
	});

	$.validator.addMethod("checkPassword", function(value, element, params) {
		var checkPassword = /^[0-9A-Za-z]{6,32}$/;
		return this.optional(element) || (checkPassword.test(value));
	}, "密码必须是6~32位数字和字母的组合");
});