﻿$(document).ready(function() {
    //$.formValidator.initConfig({onError:function(){alert("校验没有通过，具体错误请看错误提示")}});
    $.formValidator.initConfig({ onError: function(msg) { alert(msg) } });
    $("#txtAccount").formValidator({ onshow: "请输入用户名.", onfocus: "用户名至少3个字符,最多20个字符.", oncorrect: "该用户名可以注册." }).InputValidator({ min: 3, max: 20, onerror: "你输入的用户名非法,请确认." }).RegexValidator({ regexp: "username", datatype: "enum", onerror: "用户名格式不正确." })
	    .AjaxValidator({
	        type: "GET",
	        url: "AjaxHandler/Validate.ashx",
	        data: "do=checkaccount",
	        success: function(data) {
	            if (data == "true") {
	                return true;
	            }
	            else {
	                return false;
	            }
	        },
	        buttons: $("#btnRegister"),
	        error: function() { alert("服务器没有返回数据，可能服务器忙，请重试"); },
	        onerror: "该用户名不可用，请更换用户名",
	        onwait: "正在对用户名进行合法性校验，请稍候..."
	    });
    $("#txtPassword").formValidator({ onshow: "请输入密码.", onfocus: "密码不能为空.", oncorrect: "密码合法." }).InputValidator({ min: 6, onerror: "密码不能为空,且不能少于6个字符." });
    $("#txtPasswordConfirm").formValidator({ onshow: "请输入重复密码.", onfocus: "两次密码必须一致.", oncorrect: "密码一致." }).InputValidator({ min: 6, onerror: "重复密码不能为空,且不能少于6个字符." }).CompareValidator({ desID: "txtPassword", operateor: "=", onerror: "2次密码不一致,请确认." });
    $("#txtTrueName").formValidator({ empty: true, onshow: "请填写真实姓名,可以为空.", onfocus: "你要是输入了，必须输入正确.", oncorrect: "谢谢你的合作.", onempty: "你真的不想留真实姓名啊？" }).InputValidator();
    $("#txtTel_Country").formValidator({ tipid: "TelTip", empty: true, onshow: "请输入国家区号.", onfocus: "请输入国家区号.", oncorrect: "恭喜你,你输对了.", defaultvalue: "86" }).RegexValidator({ regexp: "^\\d{2,4}$", onerror: "国家区号不正确." });
    $("#txtTel_Number").formValidator({ tipid: "TelTip", empty: true, onshow: "请输入电话号码.", onfocus: "请输入电话号码.", oncorrect: "恭喜你,你输对了." }).RegexValidator({ regexp: "^\\d{5,20}$", onerror: "电话号码不正确." });
    $("#txtMobile").formValidator({ empty: true, onshow: "请输入你的手机号码,可以为空.", onfocus: "你要是输入了,必须输入正确.", oncorrect: "谢谢你的合作.", onempty: "你真的不想留手机号码啊？" }).InputValidator({ min: 11, max: 11, onerror: "手机号码必须是11位的,请确认." }).RegexValidator({ regexp: "mobile", datatype: "enum", onerror: "你输入的手机号码格式不正确." });
    $("#txtFax_Country").formValidator({ tipid: "FaxTip", empty: true, onshow: "请输入国家区号.", onfocus: "请输入国家区号.", oncorrect: "恭喜你,你输对了.", defaultvalue: "86" }).RegexValidator({ regexp: "^\\d{2,4}$", onerror: "国家区号不正确." });
    $("#txtFax_Number").formValidator({ tipid: "FaxTip", empty: true, onshow: "请输入传真号码.", onfocus: "请输入传真号码.", oncorrect: "恭喜你,你输对了." }).RegexValidator({ regexp: "^\\d{5,20}$", onerror: "传真号码不正确." });
    $("#txtEmail").formValidator({ empty: true, onshow: "请填写您的电子邮件.", onfocus: "邮箱至少6个字符,最多100个字符.", oncorrect: "恭喜你,你输对了.", onempty: "你真的不想留电子邮件啊？" }).InputValidator({ min: 6, max: 100, onerror: "你输入的邮箱长度非法,请确认." }).RegexValidator({ regexp: "^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$", onerror: "你输入的邮箱格式不正确." });
    $("#txtValidate").formValidator({ onshow: "请在文本框中输入图片上的文字.", onfocus: "请输入图片上的文字,不区分大小写.", oncorrect: "验证码输入正确.", onempty: "你真的不想留真实姓名啊？" }).InputValidator({ min: 5, max: 5, onerror: "验证码不能为空,且不能少于5个字符." }).RegexValidator({ regexp: "username", datatype: "enum", onerror: "验证码格式不正确." })
    .AjaxValidator({
        type: "GET",
        url: "AjaxHandler/Validate.ashx",
        data: "do=validatecode",
        success: function(data) {
            if (data == "true") {
                return true;
            }
            else {
                return false;
            }
        },
        buttons: $("#btnRegister"),
        error: function() { alert("服务器没有返回数据,可能服务器忙,请重试."); },
        onerror: "验证码输入错误,请重新输入.",
        onwait: "正在对验证码进行合法性校验,请稍候..."
    });
});

function doReset() {
    this.form.reset();
    return false;
}
