$(document).ready(function(){
    $(document).keydown(function (event){
        if(event.keyCode==13) {
            event.keyCode=0;
            return false;
        }
    });
	$("#codeimg").click(function(){
        updatecode("codeimg");
    });
	$.formValidator.initConfig({formid:"reg_form",onerror:function(msg){alert(msg);}});
    $("#username").formValidator({onshow:"请输入用户名(数字、字母或“_“组成)",onfocus:"用户名至少2个字符,最多12个字符",oncorrect:"该用户名可以注册"}).inputValidator({min:2,max:12,onerror:"你输入的用户名长度非法"}).regexValidator({regexp:"username",datatype:"enum",onerror:"用户名格式不正确"}).ajaxValidator({
	    type : "get",
		url : "checkusername.do",
		datatype : "json",
		success : function(data){	
            if( data == "1" )
			{
                return true;
			}else{
                return false;
			}
		},
		buttons: $("#button"),
		error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
		onerror : "该用户名不可用，请更换用户名",
		onwait : "正在对用户名进行合法性校验，请稍候..."
	});
	
	$("#email").formValidator({onshow:"请输入邮箱",onfocus:"邮箱至少6个字符,最多50个字符",oncorrect:"邮箱可以注册"}).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:"你输入的邮箱格式不正确"}).ajaxValidator({
	    type : "get",
		url : "checkemail.do",
		datatype : "json",
		success : function(data){	
            if( data == "1" )
			{
                return true;
			}else{
                return false;
			}
		},
		buttons: $("#button"),
		error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
		onerror : "该邮箱不可用，请更换邮箱",
		onwait : "正在对邮箱进行合法性校验，请稍候..."
	});

	$("#password").formValidator({onshow:"请输入密码",onfocus:"密码不能为空",oncorrect:"密码合法"}).inputValidator({min:1,onerror:"密码不能为空,请确认"});
	$("#confirmpassword").formValidator({onshow:"请输入重复密码",onfocus:"两次密码必须一致哦",oncorrect:"密码一致"}).inputValidator({min:1,onerror:"重复密码不能为空,请确认"}).compareValidator({desid:"password",operateor:"=",onerror:"两次密码不一致,请确认"});
    $("#imgcode").formValidator({onshow:"",onfocus:"",oncorrect:""}).inputValidator({min:1,onerror:"验证码不能为空"});/*.ajaxValidator({
	    type : "get",
		url : "checkcode.do",
		datatype : "json",
		success : function(data){	
            if( data == "1" )
			{
                return true;
			}
            else
			{
			    
                return false;
			}
		},
		buttons: $("#button"),
		error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
		onerror : "验证码错误",
		onwait : "正在对用户名进行合法性校验，请稍候..."
	});*/
	$("#accept").formValidator({onshow:"",onfocus:"",oncorrect:""}).inputValidator({min:1,onerror:"你没有选择同意遵守条款"});
});








