function valid_user_id(u_id){//详细验证用户名是否正确
	if(!(/^[a-zA-Z0-9_]*$/.exec(u_id))){
		showMsg("登陆名只能是大小写字母、数字和下划线的组合！",1);
		return false ;
	}

	var chars = u_id.replace(/[a-zA-Z0-9_]/g,"").length;
	var alllength = u_id.length + chars;
	
	if(alllength < 4){
		showMsg("登陆名长度不能小于4位！",1);
		return false;
	}

	if(alllength > 20){
		showMsg("登陆名长度不能大于20位！",1);
		return false;
	}
	
	if(/^\d+$/.exec(u_id)){
		showMsg("登陆名不能全为数字！",1);
		return false;
	}
	
	if(/^.+_$/.exec(u_id)){
		showMsg("登陆名不能以下划线结束！",1);
		return false;
	}
	
	return true;
}

//检测用户名有效性
function check_id(){
	var u_id=xGetElementById("u_id").value;//获取登陆名的内容
	if(valid_user_id(u_id)){	//判断该登录名是否合法
		var	queryString='';
		queryString+='type=check_id';
		queryString+='&value='+u_id;
		var	url					=	'/register/register_check.php';
		new ajax.nero.Request(url, queryString, check_id_handler, "POST");
	}
}

//用户名检测 handler
function check_id_handler(request){
	if ( request.readyState == 4 ){
		if ( request.status == 200 )	{
			var	con	=	request.responseText.trim();
			if(con=='ok'){

				xShow('submit_button'); 
				showMsg("可以使用该用户名,并可使用该用户名注册社区论坛！");
			}else if(con=='dup'){
				showMsg("该用户名已被注册，不可以使用！",1);
				xHide('submit_button');
			}
		}
		request = null;
	}
}


function valid_user_nick(u_nick){//详细验证社区昵称是否正确
	if(xGetElementById("u_nick").value == ""){
		showMsg("昵称不能为空！",1);
		return false;
	}
	var chars = u_nick.replace(/[a-zA-Z0-9_]/g,"").length;
	var alllength = u_nick.length + chars;
	if(alllength < 4){
		showMsg("昵称长度字符最少为4位，汉字最少为2位！",1);
		return false;
	}
	if(alllength > 20){
		showMsg("昵称长度不能大于20位！汉字不能大于10位！",1);
		return false;
	}
	return true;
}

function check_nick(){
	var u_nick=xGetElementById("u_nick").value;//获取社区昵称的内容
	if(valid_user_nick(u_nick)){	//判断该社区昵称是否合法
		var	queryString='';
		queryString+='type=check_nick';
		queryString+='&value='+u_nick;		
		var	url					=	'/register/register_check.php';
		new ajax.nero.Request(url, queryString, check_nick_handler, "POST");
	}
}


//用户名检测 handler
function check_nick_handler(request){
	if ( request.readyState == 4 ){
		if ( request.status == 200 )	{
			var	con	=	request.responseText.trim();
			if(con=='ok'){
				xShow('submit_button'); 
				showMsg("可以使用该用昵称！");
			}else if(con=='dup'){
				showMsg("该昵称已被注册，不可以使用！",1);
				xHide('submit_button');
			}
		}
		request = null;
	}
}

function check(){
	var bool = true;

	if(!(valid_user_id(xGetElementById("u_id").value)))
		return false;
	
	if(xGetElementById("u_pass").value == ""){
		showMsg("密码不能为空！",1);
		return false;
	}
	if(xGetElementById("u_pass").value.length < 6){
		showMsg("密码长度不能少于6位！",1);
		return false;
	}
	if(xGetElementById("u_pass2").value == ""){
		showMsg("确认密码不能为空！",1);
		return false;
	}
	if(xGetElementById("u_pass").value != xGetElementById("u_pass2").value){
		showMsg("二次输入密码不一样！",1);
		return false;
	}
	
	if(!(valid_user_nick(xGetElementById("u_nick").value)))
		return false;
		
	if(xGetElementById("u_email").value == ""){
		showMsg("电子邮件地址不能为空！",1);
		return false;
	}

	var email=xGetElementById("u_email");
	var emailPat= /^(.+)@(.+)[.](.+)$/;
	if(!emailPat.exec(email.value)){
		email.focus();
		showMsg("电子邮件地址有误！",1);
		return false;
	}

	if(xGetElementById("u_tell1").value!="" || xGetElementById("u_tell2").value!=""){
		var pObj = xGetElementById("u_tell1");
		if(!(/^[\d]{3,4}$/.exec(pObj.value))){
			showMsg("区号填写错误！",1);
			pObj.focus();
			return false;
		}
		
		var pObj1 = xGetElementById("u_tell2");
		if(!(/^[\d]{7,8}$/.exec(pObj1.value))){
			showMsg("电话号码填写错误！",1);
			pObj1.focus();
			return false;
		}
		xGetElementById("u_tell").value	=	xGetElementById("u_tell1").value+"-"+xGetElementById("u_tell2").value+(xGetElementById("u_tell3").value ? ("-"+xGetElementById("u_tell3").value) : '');
	}

	
	
	if(xGetElementById("u_cell").value.length < 1){		
		showMsg("请填写手机号！",1);
		xGetElementById("u_cell").focus();
		return false
	}
	
	if(!/^1[\d]{10}$/.exec(xGetElementById("u_cell").value)){
		showMsg("手机号填写错误！",1);
		xGetElementById("u_cell").focus();
		return false;
	}



	if(!xGetElementById("agree").checked){
		if(!window.confirm("同意奥翔网协议吗?")){
			window.location = "/";
			return false;
		}else{
			bool = true;
		}
	}
	
	var mForm	=	xGetElementById('mForm');
	mForm.action	=	'/register/register_basic_process.php';
	//mForm.target	=	'inframe';

	return true;
}


function showMsg(msg,flag){
	if(!msg)	return false;
	if(flag)	alert(msg);
	xInnerHtml("check_msg",msg);
}
