 var Register=new function(){

	/** 注册第一步  start */

	this.init = function(){
		$("#reg_username").blur(function(){
			Register.check_loginName();
		});

		$("#reg_password").blur(function(){
			Register.check_password();
		});

		$("#reg_passwordr").blur(function(){
			Register.check_passwordr();
		});

	};

	this.check_loginName = function(){
		return Register.loginNameCheck("reg_username");
	};

	this.check_password = function(){
		return Register.passwordCheck("reg_password");
	};

	this.check_passwordr = function(){
		return Register.passwordrCheck("reg_password");
	};


	this.loginNameCheck = function(name){
		var _name = $("#"+name).val();
		
		if($.trim(_name) == '' ||_name.indexOf(" ")>0 || _name.replace(/[ ]/g,"")==''){
			$("#usernametips").addClass("error");
			$("#usernametips").html("请输入4-16位用户名");
			return false;
		}else if(_name.replace(/[^\x00-\xff]/g, 'xx').length<4){

			$("#usernametips").addClass("error");
			$("#usernametips").html("用户名不能少于4位！");
			return false;
		}else if(_name.replace(/[^\x00-\xff]/g, 'xx').length>16){
			$("#usernametips").addClass("error");
			$("#usernametips").html("用户名不能超过16位！");
			return false;
		}else{
			var url = "checkusername.htm?username="+_name;
		    type = "json";
			var param = {};
			param.name=_name;
			param.uri = encodeURI(window.location);
			return $.post(url, param, function(obj){
			   if(obj=="true"){
				   $("#usernametips").addClass("error");
				   $("#usernametips").html("该用户名已经被注册！");
				   return false;
			   }else{
				   $("#usernametips").removeClass("error");
				   return true;
			   }
			}, type);

		}

		return true;
	};


	this.passwordCheck = function(name){
		var _name = $("#"+name).val();
		
		var cat = /^[\x20-\x7f]+$/;
		
		if($.trim(_name) == '' || _name.length<6 || _name.length>15 || _name.replace(/[ ]/g,"")==''){
			$("#passwordtips").addClass("error");
			$("#passwordtips").html("请输入6-15位密码");
			return false;
		}else{
			$("#passwordtips").removeClass("error");
		}

		return true;
	};
	this.passwordrCheck = function(name){
		if(!$("#"+name).val()){return false;}
		var _name = $("#"+name).val();
		var _newname = $("#"+name+"r").val();
		if(!($.trim(_name)==$.trim(_newname))){
			$("#passwordrtips").addClass("与创建的密码不一致");
			return false;
		}else{
			$("#passwordrtips").removeClass("error");
		}

		return true;
	};

	
	

	this.checkAndSub = function(){
		
		if(!Register.check_loginName()){
			return false;
		}
		if(!Register.check_password()){
			return false;
		}
		if(!Register.check_passwordr()){
			return false;
		}
		
		return true;
		
	};

	/** 注册第一步  end */
	
};



