$(document).ready(function() {
	$.formValidator.initConfig({formid:"form1"});
	$("#txtName").formValidator({onshow:Required+"<br/>"+UserName,onfocus:Required+"<br/>"+UserName,oncorrect:UserNameRegister}).inputValidator({min:6,max:15,onerror:Required+"<br/>"+UserName}).regexValidator({regexp:"username",datatype:"enum",onerror:UserNameFormatIncorrect}).ajaxValidator({
		type : "get",
		url : "MemberRegister.aspx?nocopyright=1&userName=",
		datatype : "html",
		success : function(data){
            if($.trim(data)!='-1')
			{
                return false;  
            }
            else
            {
				return true;
            }
        },
        buttons: $("#btnRegister"),
        error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
        onerror : "该用户名已被使用，请更换用户名",
        onwait : "正在对用户名进行合法性校验，请稍候..."
	});
	$("#txtPassword").formValidator({onshow:Required+"<br/>"+PasswordLength,onfocus:Required+"<br/>"+PasswordLength,oncorrect:FillCorrect}).inputValidator({min:6,max:20,empty:{leftempty:false,rightempty:false,emptyerror:PasswordSymbols},onerror:Required+"<br/>"+PasswordLength});
	$("#txtPassword2").formValidator({onshow:Required+"<br/>"+ReqeatPasswordEntere,onfocus:Required+"<br/>"+ReqeatPasswordEntere,oncorrect:FillCorrect}).inputValidator({min:6,max:20,empty:{leftempty:false,rightempty:false,emptyerror:Required+"<br/>"+PasswordSymbols},onerror:Required+"<br/>"+ReqeatPasswordEntere}).compareValidator({desid:"txtPassword",operateor:"=",onerror:Required+"<br/>"+TwoPaddword});
	$("#txtEmail").formValidator({onshow:Required+"<br/>"+EmailLength1,onfocus:Required+"<br/>"+EmailLength1,oncorrect:FillCorrect,defaultvalue:"@"}).inputValidator({min:6,max:100,onerror:Required+"<br/>"+EmailLength}).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:Required+"<br/>"+EmailFormat});
	$("#txtQuestion").formValidator({onshow:Required+"<br/>"+PasswordProblems,onfocus:Required+"<br/>"+PasswordProblems,oncorrect:PasswordProblems1}).inputValidator({min:6,max:100,onerror:Required+"<br/>"+PasswordProblems2});
	$("#txtAnswer").formValidator({onshow:Required+"<br/>"+PasswordAnswers,onfocus:Required+"<br/>"+PasswordAnswers,oncorrect:PasswordAnswers1}).inputValidator({min:3,max:100,onerror:Required+"<br/>"+PasswordAnswers2}).compareValidator({desid:"txtQuestion",operateor:"!=",onerror:Required+"<br/>"+PasswordAnswers3});;
	$("#ddlTopAreas").formValidator({onshow:Optional+"<br/>"+Register8,onfocus:Optional+"<br/>"+Register8,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"地址不能为空"});
	$("#ddlSubAreas").formValidator({onshow:Optional+"<br/>"+Register1,onfocus:Optional+"<br/>"+Register1,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"地址不能为空"});
	$("#ddlThirdAreas").formValidator({onshow:Optional+"<br/>"+Register1,onfocus:Optional+"<br/>"+Register1,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"地址不能为空"});
	$("#txtZip").formValidator({onshow:Optional+"<br/>"+Register9,onfocus:Optional+"<br/>"+Register9,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"邮编不能为空"});
	$("#txtQQ").formValidator({onshow:Optional+"<br/>"+Register1,onfocus:Optional+"<br/>"+Register1,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"QQ不能为空"});
	$("#txtICQ").formValidator({onshow:Optional+"<br/>"+Register2,onfocus:Optional+"<br/>"+Register2,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"ICQ不能为空"});
	$("#txtMSN").formValidator({onshow:Optional+"<br/>"+Register3,onfocus:Optional+"<br/>"+Register3,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"MSN不能为空"});
	$("#txtNames").formValidator({onshow:Optional+"<br/>"+Register4,onfocus:Optional+"<br/>"+Register4,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"姓名不能为空"});
	$("#txtAddress").formValidator({onshow:Optional+"<br/>"+Register5,onfocus:Optional+"<br/>"+Register5,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"详细地址不能为空"});
	$("#txtPhone").formValidator({onshow:Optional+"<br/>"+Register6,onfocus:Optional+"<br/>"+Register6,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"电话号码不能为空"});
	$("#txtMobile").formValidator({onshow:Optional+"<br/>"+Register7,onfocus:Optional+"<br/>"+Register7,oncorrect:FillCorrect}).inputValidator({min:0,onerror:"手机号码不能为空"});
	
	//绑定地区
	function BindAreas(obj1,obj2)
    {
		var svalue = obj1.value; 
		var weburl = "ajax.aspx?NoCopyright=1&parent_id="+svalue + "&r=" + Math.random(); 
		$.get(weburl,function(data){
    		document.getElementById(obj2).length = 0; 
			document.getElementById(obj2).options.add(new Option(address,"0")); 
			if(data!="")
			{ 
				var allArray = data.split("<")[0].toString().split(","); 
				for(var i=1;i<allArray.length;i++) 
				{ 
					var thisArray = allArray[i].split("|"); 
					document.getElementById(obj2).options.add(new Option(thisArray[1].toString(),thisArray[0].toString())); 
				} 
			} 
		})
    
    }
     $('#cbFull').click(function(){if($(this).attr("checked")){$('#full_info').removeClass("hidden")}else{$('#full_info').addClass('hidden')}});
    //给地区下拉框绑定事件
    $('#ddlTopAreas').change(function(){$('#ddlSubAreas option:gt(0)').remove();$('#ddlThirdAreas option:gt(0)').remove();if($(this).val()!='0'){BindAreas(this,'ddlSubAreas')};});
    $('#ddlSubAreas').change(function(){$('#ddlThirdAreas option:gt(0)').remove();if($('option[selected]',this).val() != '0')(BindAreas(this,'ddlThirdAreas'));});
});
