var oksubmit=false;
function ChkRepeatNick(m){
	ajaxurl("inc/ajaxproc.php?user="+m);
}

function ajaxurl(Urlx){
var ajax=new AJAXRequest({
		url: Urlx,
		method: "GET",
		oncomplete: ProcChecNick,
		charset: "GB2312"
	});
ajax.get();
}

function ProcChecNick(obj){
	if(obj.responseText){
		if(obj.responseText == "true"){
			$("sUserMail").innerHTML = '该邮箱已被注册，请重新输入！';
			$("sUserMail").className = "rf";
			Ofocu('tbUserMail');
			oksubmit=false;
		}else{
			$("sUserMail").innerHTML = '恭喜，该邮箱可以使用!';
			$("sUserMail").className = "font-green01";
			oksubmit=true;
		}
	}
}

function ChkReg(){
	var userMail= $("tbUserMail").value;
	var userNick = $("tbUserNick").value;
	var userPwd = $("tbUserPwd").value;
	var rePwd = $("tbRePwd").value;
	var userSecQues = $("tbUserSecQues").value;
	var userSecAns = $("tbUserSecAns").value;
	var safeCode = $("tbSafeCode").value;
	if(oksubmit==false){return false;}
	if(chkMail(userMail)==false){
		$("sUserMail").innerHTML = '对不起，您输入的邮件称式错误！';
		$("sUserMail").className = "rf";
		Ofocu('tbUserMail');
		return false;
	}
	if(ChkString(userNick,1,20)==false){
		$("sUserNick").innerHTML = '对不起，您输入的呢格称式错误！';
		$("sUserNick").className = "rf";
		Ofocu('tbUserNick');
		return false;
	}
	else{
		$("sUserNick").innerHTML = "&nbsp;";
		$("sUserNick").className = "";
	}
	if(userPwd.length < 5){
		$("sUserPwd").innerHTML = '对不起，您输入的密码格式错误！';
		$("sUserPwd").className = "rf";
		Ofocu('tbUserPwd');
		return false;
	}
	else{
		$("sUserPwd").innerHTML = "&nbsp;";
		$("sUserPwd").className = "";
	}
	if(userPwd != rePwd){
		$("sRePwd").innerHTML = "对不起，您输入的确认密码与新密码不一致！";
		$("sRePwd").className = "rf";
		Ofocu('tbRePwd');
		return false;
	}
	else{
		$("sRePwd").innerHTML = "&nbsp;";
		$("sRePwd").className = "";
	}
	if(userSecQues==""){
		$("sUserSecQues").innerHTML = '对不起，请选择安全提问！';
		$("sUserSecQues").className = "rf";
		Ofocu('tbUserSecQues');
		return false;
	}
	else{
		$("sUserSecQues").innerHTML = "&nbsp;";
		$("sUserSecQues").className = "";
	}
	if(ChkString(userSecAns,1,20) || userSecAns==""){
		$("sUserSecAns").innerHTML = '对不起，您输入的安全答案格式有误！';
		$("sUserSecAns").className = "rf";
		Ofocu('tbUserSecAns');
		return false;
	}
	else{
		$("sUserSecAns").innerHTML = "&nbsp;";
		$("sUserSecAns").className = "";
	}
	if(ChkSafeCode(safeCode)==false){
		$("sSafeCode").innerHTML = '对不起，您输入的验证码格式错误！';
		$("sSafeCode").className = "rf";
		Ofocu('tbSafeCode');
		return false;
	}
	else{
		$("sSafeCode").innerHTML = "&nbsp;";
		$("sSafeCode").className = "";
	}
	$("Submit2").disabled=true;
}

function Chkforpwd(){
	var userAccount= $("tbUserAccount").value;
	var userSecQues = $("tbUserSecQues").value;
	var userSecAns = $("tbUserSecAns").value;
	var safeCode = $("tbSafeCode").value;

	if(ChkString(userAccount,1,20)==false || userAccount==""){
		$("sUserAccount").innerHTML = '对不起，您输入的用户帐户格式错误！';
		$("sUserAccount").className = "rf";
		Ofocu('tbUserAccount');
		return false;
	}
	else{
		$("sUserAccount").innerHTML = "&nbsp;";
		$("sUserAccount").className = "";
	}
	
	if(userSecQues==""){
		$("sUserSecQues").innerHTML = '对不起，请选择安全提问！';
		$("sUserSecQues").className = "rf";
		Ofocu('tbUserSecQues');
		return false;
	}
	else{
		$("sUserSecQues").innerHTML = "&nbsp;";
		$("sUserSecQues").className = "";
	}
	if(ChkString(userSecAns,1,20) || userSecAns==""){
		$("sUserSecAns").innerHTML = '对不起，您输入的安全答案格式有误！';
		$("sUserSecAns").className = "rf";
		Ofocu('tbUserSecAns');
		return false;
	}
	else{
		$("sUserSecAns").innerHTML = "&nbsp;";
		$("sUserSecAns").className = "";
	}
	if(ChkSafeCode(safeCode)==false){
		$("sSafeCode").innerHTML = '对不起，您输入的验证码格式错误！';
		$("sSafeCode").className = "rf";
		Ofocu('tbSafeCode');
		return false;
	}
	else{
		$("sSafeCode").innerHTML = "&nbsp;";
		$("sSafeCode").className = "";
	}
	$("Submit2").disabled=true;
}

function $(obj){
	return typeof(obj) == "string" ? document.getElementById(obj) : obj;
}

function showCode(){
	$('regSafeCode').src='inc/code.php';
}

function Ofocu(obj){
	window.tmpObj = $(obj);
	window.setTimeout("window.tmpObj.focus()",100);
}

function ChkString(str,minLength,maxLength,pattern){
	pattern = typeof(pattern) == 'undefined' ? '^[^`%&()=;:/\'"]*$' : pattern;
	pattern = new RegExp(pattern);
	if(pattern.test(str)==false){
		return false;
	}
}

function ChkSafeCode(code){
	if((/[A-Za-z1-9]{4}/.test(code)) == false || code.length!=4){
		return false;
	}
}

function chkMail(mail,minLength,maxLength,pattern){
	pattern = typeof(pattern) == 'undefined' ? '^\\\w+((-\\\w+)|(\\\.\\\w+))*\\\@[A-Za-z0-9]+((\\\.|-)[A-Za-z0-9]+)*\\\.[A-Za-z0-9]+$' : pattern;
	pattern = new RegExp(pattern);
	if(pattern.test(mail)==false){
		return false;
	}
}

function checkedAll(id){
	var id = document.getElementsByName(id+"[]");
	for(i=0;i<id.length;i++){
		if(id[i].checked == true){
			id[i].checked = false;
		}
		else{
			id[i].checked = true;
		}
	}
}