$(document).ready(function(){
    $.formValidator.initConfig({
        
    });
    $("#password1").formValidator({
        onshow:"请输入密码",
        onfocus:"密码不能为空",
        oncorrect:"密码合法"
    }).inputValidator({
        min:4,
        empty:{
            leftempty:false,
            rightempty:false,
            emptyerror:"密码两边不能有空符号"
        },
        onerror:"密码不能为空,请确认"
    });
    $("#password2").formValidator({
        onshow:"请输入重复密码",
        onfocus:"两次密码必须一致哦",
        oncorrect:"密码一致"
    }).inputValidator({
        min:4,
        empty:{
            leftempty:false,
            rightempty:false,
            emptyerror:"重复密码两边不能有空符号"
        },
        onerror:"重复密码不能为空,请确认"
    }).compareValidator({
        desid:"password1",
        operateor:"=",
        onerror:"2次密码不一致,请确认"
    });
    $("#email").formValidator({
        onshow:"请输入EMAIL",
        onfocus:'EMAIL 6-50个字符,没Email？注册：<a href="http://mail.google.com/mail/signup" target="_blank">Gmail</a> <a href="http://reg.163.com/reg/reg0.jsp?url=http://mscan3.163.com/activate163/QuickCreateMail.jsp" target="_blank">163</a> <a href="http://reg.126.com/regmail126/userRegist.do?action=start&from=" target="_blank">126</a>',
        oncorrect:"EMAIL 正确"
    }).inputValidator({
        min:6,
        max:50,
        onerror:"你输入的EMAIL长度非法,请确认"
    }).regexValidator({
        regexp:"email",
        datatype:"enum",
        onerror:"你输入的EMAIL格式不正确"
    }).ajaxValidator({
//        addidvalue:false,
        type : "get",
//        url : "",
//        data:"username="+$("#username").val(),
        data:"controller=AJAX&action=chkUserEmail",
        datatype : "html",
        success : function(data){
            if(data==''){
                return true;
            }
            else{
                return false;
            }
        },
        error: function(){
            alert("服务器没有返回数据，可能服务器忙，请重试");
        },
        onerror : "该Email地址已经被注册，请确认",
        onwait : "正在对Email进行合法性校验，请稍候..."
    });
    $("#username").formValidator({
        onshow:"请输入帐号",
        onfocus:"帐号不能含有特殊字符，如“, ~ >”等",
        oncorrect:"该帐号可以注册"
    }).inputValidator({
        min:4,
        max:20,
        onerror:"你输入的帐号非法,请确认"
    }).regexValidator({
        regexp:"^[a-z]\\w+$",
        onerror:"帐号格式不正确"
    }).ajaxValidator({
//        addidvalue:false,
        type : "get",
//        url : "",
//        data:"username="+$("#username").val(),
        data:"controller=AJAX&action=chkUserid",
        datatype : "html",
        success : function(data){
            if(data==''){
                return true;
            }
            else{
                return false;
            }
        },
        error: function(){
            alert("服务器没有返回数据，可能服务器忙，请重试");
        },
        onerror : "该帐号已经被注册，如果是您的帐号请登录",
        onwait : "正在对帐号进行合法性校验，请稍候..."
    });
    $("#name").formValidator({
        onshow:"请输入姓名或者称呼",
        onfocus:"真实姓名会提高求职成功率,至少1个字符,最多20个字符",
        oncorrect:"该姓名/称呼可以注册"
    }).inputValidator({
        min:1,
        max:20,
        onerror:"你输入的姓名/称呼非法,请确认"
    }).regexValidator({
        regexp:"chinese",
        datatype:"enum",
        onerror:"姓名/称呼格式不正确"
    });
    $("#telephone").formValidator({
        onshow:"请输入你的联系电话",
        onfocus:"格式例如：020-22271000 13800138000",
        oncorrect:"谢谢你的合作"
    }).functionValidator({
	    fun:function(val,elem){
            var partten = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
            var partten1 = /^(13|15|18)[0-9]{9}$/;
            if(partten.test(val)){
                return true;
            }
            else if(partten1.test(val)){
                return true;
            }
            else
                return false;
		}
	});
    //    $("input:radio[name='check_role']").formValidator({tipid:"checkroleTip",onshow:"请选择同意",onfocus:"不同意不能注册",oncorrect:"输入正确"}).inputValidator({min:0,max:1,onerror:"帐号协议忘记选了"});//.defaultPassed();
    $("#code").formValidator({
        onshow:"请输入验证码",
        onfocus:"不分大小写，点击图片更换",
        oncorrect:"验证码正确"
    }).regexValidator({
        regexp:"ascii",
        datatype:"enum",
        onerror:"你输入验证码不正确"
    }).ajaxValidator({
//        addidvalue:false,
        type : "get",
        datatype : "html",
//        data:'code='+$('#code').val(),
        data: 'controller=AJAX&action=ChkVcode',
        success: function(data) {
            if(data==1){
                return true;
            }
            else{
                return false;
            }
        },
        error: function(){
            alert("服务器没有返回数据，可能服务器忙，请重试");
        },
        onerror : "验证码错误，请重新输入",
        onwait : "正在检查验证码，请稍候..."
    });
    $("input:checkbox[name='check_role']").formValidator({
        tipid:"checkroleTip",
        onshow:"请选择",
        onfocus:"请选择同意，不同意不能注册",
        oncorrect:"您已经同意了帐号协议"
    }).inputValidator({
        min:1,
        max:1,
        onerror:"帐号协议忘记选了,请确认"
    }).functionValidator({
        fun:function(val,elem){
            if(val=="1"){
                return true;
            }else{
                return "必须同意后才能注册";
            }
        }
    });
    $('#register_form .input_button').click(function(){
        return jQuery.formValidator.pageIsValid('1');
    });
});
