<?php
	$defaultid="U".strval(time()-strtotime("2005-01-01 01:01:01"));
	$defaultword="";
	for ($i=1;$i<=10;$i++) {				//生成10位随机密码字符串，密码全部是数字
		$defaultword=$defaultword.chr(rand(48,57));
	}
	$buylength="0";
	$money1="0";
?>
<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<script language="javascript">
function setmoney1()
{
    var str=document.form1.usertype.options(document.form1.usertype.selectedIndex).text;
    var n1=str.search("单价");
    var n2=str.search("元");
    var price=parseFloat(str.substring(n1+2,n2));
    str=document.form1.buylength.value;
    str=str.replace(" ","");
    var buylength=parseInt(str);
    if (isNaN(buylength)) buylength=0;
    var money1=Math.round(price*buylength*10)/10;
	document.all.money12.innerText=" "+money1.toString()+"元";
	document.form1.money1.value=money1.toString();
}

function checkdata()
{
    var str=document.form1.loginname.value;
    n=str.length;
    for (i=0;i<n;i++) str=str.replace(" ","");
    if (str.length<6) {
    	alert("用户ID长度不能小于6个字符！");
    	return false;
    }
    str=document.form1.password.value;
    n=str.length;
    for (i=0;i<n;i++) str=str.replace(" ","");
    if (str.length<6) {
    	alert("用户密码长度不能小于6个字符！");
    	return false;
    }
    str=document.form1.buylength.value;
    str=str.replace(" ","");
    var buylength=parseInt(str);
    if (isNaN(buylength)||buylength<1) {
    	alert("必须输入有效的购买数量！");
    	return false;
    }
	str=document.form1.usertype.options(document.form1.usertype.selectedIndex).text;
    n1=str.search("单价");
    n2=str.search("元");
    var price=parseFloat(str.substring(n1+2,n2));
    var money1=Math.round(price*buylength*10)/10;
	document.form1.money1.value=money1.toString();
	return true;
}
</script>
<title>自助注册用户</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>自助注册用户</b></font></p>
<hr color="#999966">
<div align="center">
<center>
<form method="POST" name="form1" action="register_result.php" onsubmit="return checkdata();">
<table border="1" width="626" bordercolor="#008080" cellspacing="0" cellpadding="0">
<tr>
   <td width="173" align="center" height="46">用户ID</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <input type="text" name="loginname" size="20" maxlength="20" value="<?php echo $defaultid; ?>">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">用户密码</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp; 
   <input type="text" name="password" size="20" maxlength="20" value="<?php echo $defaultword; ?>">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">用户类型</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <select size="1" name="usertype" onclick="setmoney1();">
<?php
		$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
		mysql_select_db(get_cfg_var("SIPDB"),$db);
		$rs = mysql_query("select typeid,name,price from types where typemode='1' order by typeid",$db);
		if ($row = mysql_fetch_array($rs)) {
           echo("<option selected value=".chr(34).$row["typeid"].chr(34).">".$row["name"]."，单价".strval($row["price"])."元</option>");	//缺省选择第一项
           while ($row = mysql_fetch_array($rs)) {
	           echo("<option value=".chr(34).$row["typeid"].chr(34).">".$row["name"]."，单价".strval($row["price"])."元</option>");	//缺省选择第一项
           }
		}
		mysql_free_result($rs);
		mysql_close($db);
?>
       </select> 
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">用户名称</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <input type="text" name="username" size="20" maxlength="50">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">联系方式</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <input type="text" name="usertel" size="20" maxlength="50"> </td>
</tr>
<tr>
   <td width="173" align="center" height="46">备注说明</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <input type="text" name="comment" size="20" maxlength="100">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">购买数量</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	<input type="text" name="buylength" size="4" maxlength="4" onkeyup="setmoney1();">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">合计费用</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <span id="money12"><?php echo $money1; ?>元</span>
       <input type="hidden" name="money1" value="0">
   </td>
</tr>
<tr>
   <td colspan="2" width="566" align="center" height="57">
       <input type="submit" value="提交" name="B1">
   </td>
</tr>
</table>
</form>
</center>
</div>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
