<!--{template 'default/head'}-->
<div class="memeber_path cbody"></div>
<script language=javascript>
function changeVerifyImage(){
	if($('verify_code_img') != null) $('verify_code_img').src = 'code.php?height=30&bgcolor=ffffff&d='+(new Date()).toString();
	return false;
}
var regVerify = parseInt('{$_SET['reg_code']}');
regVerify = isNaN(regVerify) ? 0 : regVerify;
function checkUsername(){
	var obj = $('username');
	var old = obj.getAttribute('rel');
	if( obj.value.trim() == ''){
		$('msg').innerHTML = '<font color=green>请输入用户名</font>';
		return false;
	}
	if(old && obj.value.trim() == old) return;
	obj.setAttribute('rel', obj.value.trim());
	$('reg_submit').disabled = true;
	AJAX.request( 'user.php?ac=reg',{
		method	: 'post',
		parameters 	: 'check=1&username='+encodeURIComponent($('username').value.trim()),
		onComplete	: function(resp){
			$('reg_submit').disabled = false;
			var json = evaljson(resp);
			if( parseInt(json.status) == 200){
				$('msg').innerHTML = "<font color=green>您可以使用该用户名</font>";
			}else{
				$('msg').innerHTML   = "<font color=red>"+json.message+"</font>";
			}
		}
	});
}

function CharMode(iN){
	if (iN>=48 && iN <=57) return 1; 
	if (iN>=65 && iN <=90) return 2;
	if (iN>=97 && iN <=122) return 4;
	else return 8;
}
function bitTotal(num){
	modes=0;
	for (i=0;i<4;i++){
		if (num & 1) modes++;
		num>>>=1;
	}
	return modes;
}
function checkStrong(sPW){
	if (sPW.length<=4) return 0;
	Modes=0;
	for (i=0;i<sPW.length;i++){
		Modes|=CharMode(sPW.charCodeAt(i));
	}
	return bitTotal(Modes);
} 
function pwStrength(pwd){
	O_color="#cccccc";
	L_color="#FF0000";
	M_color="#FF9900";
	H_color="#33CC00";
	if (pwd==null||pwd==''){
		Lcolor=Mcolor=Hcolor=O_color;
	} else{
		S_level=checkStrong(pwd);
		switch(S_level) {
			case 0:
				Lcolor=Mcolor=Hcolor=O_color; 
			case 1:
				Lcolor=L_color;
				Mcolor=Hcolor=O_color;
				break;
			case 2:	
				Lcolor=Mcolor=M_color;
				Hcolor=O_color;
				break;
			default:
				Lcolor=Mcolor=Hcolor=H_color;
		}
	}
	$("strength_L").style.background=Lcolor;
	$("strength_M").style.background=Mcolor;
	$("strength_H").style.background=Hcolor;
	return;
}
function CheckForm(){
	var xp = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var url = "{$forward_encode}";
	if($('username').value.trim()==""){
		alert("请输入用户名！");
		$('username').focus();
		return false;
	}
	if($('password').value.trim() == "" || $('pwdconfirm').value.trim() == ''){
		alert("请输入密码和确认密码");
		return false;
	}
	if($('email').value.trim() == '' || !xp.test($('email').value.trim())){
		alert("请输入正确的邮件地址");
		return false;
	}
	if($('verify_code') != null && $('verify_code').value.trim().length == 0){
		alert("请输入验证码");
		return false;
	}
	$('reg_submit').disabled = true;
	removeClassName($('_loading'), 'hidden');
	Form.send('ajaxForm', function(resp){
		var json = evaljson(resp);
		if(json == null || typeof json.status == 'undefined') return alert("服务器异常，请按F5刷新浏览器");
		if(json.status == 200){
			$('_loading').innerHTML = "已注册成功，正在登录中....";
			setTimeout(function(){
				window.location.replace(url || "user.php");
			},1000);
		}else if(json.status == 302){
			$('_loading').innerHTML = "已注册成功，需要通过相应的验证后才能登录...";
			setTimeout(function(){
				window.location.replace(json.message);
			},1500);
		}else{
			changeVerifyImage();
			if($('verify_code') != null) $('verify_code').value = '';
			alert(json.message);
			addClassName($('_loading'), 'hidden');
			$('reg_submit').disabled = false;
		}
	});
	return false;
}
</script>
<div class="cbody">
	 <form class="label login" name="ajaxForm" id="ajaxForm" method="post" action="user.php?ac=reg" onsubmit="return CheckForm();">
      <p>
        <label class="f-label">登录账号</label><input name="username" type="text" class="f-text" id="username" size="25" onBlur="checkUsername()"  autocomplete="off"><span id=msg style="margin-left:5px;">&nbsp;长度为2到20个英文字符或中文（不能含有特殊字符）</span>
      </p>
      <p>
        <label class='f-label'>密码</label>
        <input name="password" type="password" id="password" class="f-text" size="25" onKeyUp=pwStrength(this.value) onBlur=pwStrength(this.value)> <span id="strength_L" style="padding:4px;background-color:#cccccc">弱</span> <span id="strength_M" style="padding:4px;background-color:#cccccc">中</span> <span id="strength_H" style="padding:4px;background-color:#cccccc">强</span> 不得少于6个字符和大于32个英文字符
      </p>
	  <p>
        <label class='f-label'>确认密码</label>
        <input name="pwdconfirm" type="password" id="pwdconfirm" size="25" class="f-text">
      </p>
      <p>
        <label class='f-label'>邮箱</label>
        <input name="email" type="text" class="f-text" id="email" size="25" maxlength="64"  autocomplete="off"> 
      </p>
	   <!--{if $_SET['reg_code']}-->
      <p>
        <label class='f-label'>验证码</label>
        <input name="verify_code" type="text" class="f-text" id="verify_code" size="25" maxlength="4" style="width:50px"  autocomplete="off" /> &nbsp;把下面的数字再输入一遍，<a href="###" onclick="return changeVerifyImage()">看不清楚？换一张</a>
      </p>	  
      <p>
        <label class='f-label'>　</label>
        <img title="点击更换图片" src="code.php?height=30&bgcolor=ffffff" onclick="return changeVerifyImage()" id="verify_code_img" />
      </p>		 
	  <!--{/if}-->
	  <p class='note'>
		<input type="hidden" name="myFormAc" value="update">
		<input type="submit" id="reg_submit" value=" 注册 "  class="f-button"><span id="_loading" class="loading hidden">提交中，请等待...</span>
	    </p>
		<p class='note'>已经注册？<a href="user.php?ac=login&forward={$forward}">点击登录</a></p>
		</form>
</div>

<!--{template 'default/foot'}-->
