<? require "header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<html>
<head>
<title><?=$bbs_config_row['bbs_name']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<?=$T_BBS_Style_CSS?>" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<?=$BBSFolder?>/js/check.js"></script>
<script type="text/javascript" src="<?=$BBSFolder?>/js/ajax.js"></script>
</head>
 <script language="javascript">
			function send_request_get_reg(url) {
				create_request();
				http_request.onreadystatechange = processCheckUsername;
				http_request.open("GET", url, true);
				http_request.send(null);
			}
			
			function send_request_post_reg(url,querystring,func) {
				create_request();
				if(func=='reg') http_request.onreadystatechange = processReg;
				
				http_request.open("POST", url, true);
				http_request.setRequestHeader("Content-Type"," application/x-www-form-urlencoded"); 
				http_request.send(querystring);
			}
			
		
			function processReg() {
					var form=document.getElementById("form1");
					if (http_request.readyState == 4) { 
						if (http_request.status == 200) { 
							if(http_request.responseText==1)
							{
								
								location='<?=$BBSFolder?>/message.php?flag=reg';
								
							}
							if(http_request.responseText==2)
							{
								alert('用户名已经存在! ');
							}
							if(http_request.responseText==3)
							{
								alert('您的验证码输入错误! ');
							}
							
						   
						} else { //页面不正常
							alert("error");
						}
					}
				}
			
			function checkReg() {
				var form=document.getElementById("form1");
				if(form.validate_code.value.length!=4)
				{
					alert("验证码必须4位 !");
					form.validate_code.focus();
					return;
				}
			  if(!isCharVar(form.reg_username.value)||form.reg_username.value.length<3||form.reg_username.value.length>15)
				{
					alert("您的用户名 3 - 15 字符 !");
					form.reg_username.focus();
					return;
				}
				if(form.reg_psw.value.length<6||form.reg_psw.value.length>15)
				{
					alert("您的密码必须 6 - 15 字符和数字 !");
					form.reg_psw.focus();
					return;
				}
				if(form.reg_psw.value!=form.reg_psw1.value)
				{
					alert("两次输入密码不正确 !");
					form.reg_psw1.focus();
					return;
				}
				if(!isEmail(form.EmailName.value))
				{
					alert("请输入正确的邮箱地址 !");
					form.EmailName.focus();
					return;
				}
				
				var sex=1;
				if(form.sex[1].checked) sex=2;
				querystring="username="+form.reg_username.value+"&psw="+form.reg_psw.value+"&EmailName="+form.EmailName.value+"&sex="+sex+"&validate_code="+form.validate_code.value;
				 send_request_post_reg('ajax/reg.php',querystring,"reg");
			}
			
			function checkUsername() {
				var form=document.getElementById("form1");
			   if(form.reg_username.value=="")
				{
					alert("请输入用户名!");
					form.reg_username.focus();
					return;
				}
				send_request_get_reg('ajax/checkusername.php?username='+form.reg_username.value);
			}
			
			 function processCheckUsername() {
					if (http_request.readyState == 4) { 
						if (http_request.status == 200) { 
						   if(http_request.responseText==2)
							{
								alert("此用户名已经存在! ");
							}
							if(http_request.responseText==1)
							{
								alert('此用户可用 !');
							}
						   
						} else {
							alert("page error!");
						}
					}
				}
		
			
		</script>
<body>

<form name="form1" id="form1"  method="post" >
  <table border="0" cellpadding="0"  cellspacing="0" class="firsttable">
    <tr>
      <td align="center" valign="top">
	  	<table  cellpadding="0" cellspacing="0"  class="centertable">
      		<tr> 
            	<td align="center"><? include "top.php"?> 
            	</td>
       		</tr>
        	<tr>
        	  <td align="center">&nbsp;</td>
      	  </tr>
        	<tr>
        	  <td align="center"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="bg2">
                <tr>
                  <td height="26" style="padding-left:10px; "><img src="<?=$BBSFolder?>/images/rightarrow.gif" width="11" height="10"> <font class="font1"><a href="<?=$BBSFolder?>/index.php" style="text-decoration:none ">
                    首页
                  </a>
                   → 注册</font></td>
                </tr>
              </table></td>
      	  </tr>
        	<tr>
        	  <td align="center">&nbsp;</td>
        	</tr>
            <tr>
              <td id="an" align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="bg1" style="font-size:12px;">
                <tr align="center" class="bar" style="font-size:12px; font-weight:bold;color:#FFF2B1; ">
                  <td height="28" colspan="2" > 新成员注册</td>
                </tr>
              <tr>
				  <td height="30" class="lefttd" style="padding-left:10px; ">验证码 :</td>
				  <td class="righttd" style="padding-left:10px; padding-right:10px; "><input class="register_box"  style="float:left;" name="validate_code" type="text" id="validate_code" size="4" maxlength="4" />
                     <img src='include/validateCode.php'></td>
			    </tr>
                <tr>
					<td width="290" height="30" class="lefttd" style="padding-left:10px; "> 您的用户名 :</td>
                  <td class="righttd" style="padding-left:10px; "><input name="reg_username" type="text" id="reg_username" style="width:125px; ">
                    <span class="register_td_box">
                    <input type="button" class="button"  onclick="checkUsername()" value="检查用户名" />
                  </span>				  </td>
                </tr>
				<!--<tr>
				  <td height="30" class="lefttd" style="padding-left:10px; ">请输入您的验证码 </td>
				  <td class="righttd" style="padding-left:10px; padding-right:10px; "><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="60"><input name="identify" type="text" id="identify" style="width:45px; " ></td>
                      <td><?  $_SESSION['identify'] = mt_rand(1000, 9999);?>
                          <img src="include/antispam/index.php" ></td>
                      <td>&nbsp;</td>
                    </tr>
                  </table></td>
			    </tr>-->
				<tr>
				  <td height="30" class="lefttd" style="padding-left:10px; ">您的密码 :</td>
				  <td class="righttd" style="padding-left:10px; padding-right:10px; "><input name="reg_psw" type="password" id="reg_psw" style="width:125px; "></td>
			    </tr>
				<tr>
					<td height="30" class="lefttd" style="padding-left:10px; "> 重新输入密码 :</td>
                    <td class="righttd" style="padding-left:10px; padding-right:10px; "><input name="reg_psw1" type="password" id="reg_psw1" style="width:125px; "></td>
				</tr>
				<tr>
					<td height="30" class="lefttd" style="padding-left:10px; ">您的电子邮箱</td>
                    <td class="righttd" style="padding-left:10px; "><input name="EmailName" type="text" id="EmailName" style="width:125px; ">                    </td>
				</tr>
                 <tr>
					<td width="290" height="30" class="lefttd" style="padding-left:10px; "> 性别 :</td>
                  <td class="righttd" style="padding-left:10px; "><span class="register_td_box">
                    <?
					for($i=1;$i<=count($T_Gender);$i++)
					{
						if((int)$sex==$i||(empty($sex)&&$i==1))
							echo "<input name='sex' type='radio' checked  value='".$i."'>".$T_Gender[$i];
						else
							echo "<input name='sex' type='radio'   value='".$i."'>".$T_Gender[$i];
					}
				?>
                  </span></td>
                </tr>
				<tr>
                  <td align="center" valign="top" class="righttd" colspan="2"><input name="Submit2" type="button" class="button" value="提交" onClick="checkReg()">
                    &nbsp;&nbsp;&nbsp;&nbsp;<input name="Submit22" type="reset" class="button" value="清空" >
                  </td>
                </tr>
               
              </table></td>
            </tr>
          <tr>
               <td align="center">&nbsp;</td>
          </tr>
		   <tr>
               <td align="center"><span class="link2">
                 <? include "bottom.php"?>
               </span></td>
          </tr>
        </table>
	  </td>
    </tr>
</table>
	<input type="hidden" name="regstatus" >
</form>
</body>
</html>

<? $db->close_db();?>
