<?
require_once "configure.php";

if($_POST["btnSubmit"]){
	$sql = "SELECT * from user WHERE ic='$ic' or email='$email'";
	$result =mysql_query($sql)or die(mysql_error());
	if(mysql_num_rows($result) > 0)print("<script type='text/javascript'>alert('Email or NRIC is taken.')</script>");	
	else{

		$sql="
		INSERT INTO `user` (`email`, `name`, `pwd`, `ic`, `mobile`) VALUES (\"$email\",\"$name\",'".md5($pwd)."','$ic',\"$mobile\")";
		@mysql_query($sql) or die(mysql_error());
	
		print("<script type='text/javascript'>location.href='register_success.php'</script>");
	}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=TITLE;?></title>
<link rel="stylesheet" type="text/css" href="style.css" >
<script>
function ValidateForm(theform)
{
	var msg="";

	if(!theform.email.value)msg+="Email required. \n";
	if(!theform.pwd.value)msg+="Password required. \n";		
	if(!theform.name.value)msg+="Full Name required. \n";			
	if(!theform.ic.value)msg+="NRIC required. \n";			
	if(!theform.mobile.value)msg+="Mobile required. \n";				
		
	if(msg){
		alert(msg)
		return false;
	}else return true;	
	
}
</script>
</head>

<body class="TextBox">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="46" bgcolor="#38abe3">
  <? require_once "header.php"; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><form name="form" method="post" action="<?=$PHP_SELF;?>" ONSUBMIT="return ValidateForm(this)"><table width="60%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="35" class="signin">Create Account</td>
          </tr>
          <tr>
            <td height="30" bgcolor="#cfecff" class="text">Email </td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="email" type="text" class="inputBox" id="email" value="<?=$email;?>" size="50" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text">Password</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="pwd" type="text" class="inputBox" id="pwd" value="<?=$pwd?>" size="50" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text">Full Name as NRIC</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="name" type="text" class="inputBox" id="pwd4" value="<?=$name?>" size="50" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text">NRIC NO.</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="ic" type="text" class="inputBox" id="pwd5" value="<?=$ic?>" size="50" maxlength="20" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text">Mobile No.</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="mobile" type="text" class="inputBox" id="pwd6" value="<?=$mobile?>" size="50" maxlength="20" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input type="submit" name="btnSubmit" id="btnSubmit" value="Apply" />
              <input type="button" name="button2" id="button2" value="Already Have Account" onclick="javascript:location.href='signin.php'"/></td>
          </tr>
        </table>
        </form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><a href="http://egenos.com" target="_blank">Powered by eGen online solution</a></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>