<?php
session_start();
$username = $_SESSION['membership'];

if($_SESSION['membership']!= null)
{
	echo "<script language='javascript'>alert ('U already is a member,click OK to return to home page !')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
else{
	include ("connect.php");

	$memLname = $_POST["memLname"];
	$memName = $_POST["memName"];
	$memPassword = $_POST["memPassword"];
	$ICDate = $_POST["ICDate"];
	$ICState = $_POST["ICState"];
	$ICNo = $_POST["ICNo"];
	$memBdate= $_POST["memBdate"];
	$memSex = $_POST["memSex"];
	$memRace = $_POST["memRace"];
	$memAddress = $_POST["memAddress"];
	$memPcode = $_POST["memPcode"];
	$memCity = $_POST["memCity"];
	$memState = $_POST["memState"];
	$memHnum1 = $_POST["memHnum1"];
	$memHnum2 = $_POST["memHnum2"];
	$memHpnum1 = $_POST["memHpnum1"];
	$memHpnum2 = $_POST["memHpnum2"];
	$memEmail = $_POST["memEmail"];
	
	
	if($_POST["Submit"] == "Submit")
	{
	if(($memLname == "")||($memName == "")||($memPassword == "")||($ICDate == "")||($ICState == "")||($ICNo == "")
	||($memBdate == "")||($memSex == "")||($memRace == "")||($memAddress == "")||($memPcode == "")||($memCity == "")||($memState == "")
	||($memHnum1 == "")||($memHnum2 == "")||($memHnum2 == "")||($memHpnum1 == "")||($memHpnum2 == "")||($memEmail == ""))
	{
	echo "<script>alert('Please fill in your details! Please field up all the information?')</script>";
	echo "<script language='javascript'>window.location='Addmem.php'</script>";
	}
else{
	$query = "INSERT INTO member(memLname, memName, memPassword, ICDate, ICState, ICNo, memBdate, memSex, memRace, memAddress, memPcode, memCity, memState, memHnum1, memHnum2, memHpnum1, memHpnum2, memEmail)
	VALUES
	('$memLname', '$memName', '$memPassword', '$ICDate', '$ICState', '$ICNo', '$memBdate', '$memSex', '$memRace', '$memAddress', '$memPcode', '$memCity', '$memState', '$memHnum1', '$memHnum2', '$memHpnum1', '$memHpnum2', '$memEmail')";
	$result = $db->query($query);
	$db->close();
	echo "<script language='javascript'>alert('Register success. Your account is under validation.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
	}
}	
}
?>

<html>
<head>
<title>Online Bookshop - Welcome</title>
<link href="bookstore.css" rel="stylesheet" type="text/css"/>
</head>
<body style="background:lightyellow">
<center>
<div id="whole">
<div id="title">
<table width="100%" border="0">
<tr>
<td width="60%"><img src="Picture/Logo.gif" width="450" height="100"></td>
<td>
<form method="GET" action="http://www.google.com/search">
<input type="hidden" name="ie" value="UTF-8" >
<input type="hidden" name="oe" value="UTF-8" target="_blank">
<a href="http://www.google.com">
<img src="Picture/GoogleLogo.png" border="0" alt="Google" align="absmiddle" title="Google" >
</a>
<input type="text" name="q" size="20" maxlength="255" value="">
<input type="submit" name="btnG" value="Google Search">
</form>
</td>
</tr>
</table>
</div>
<div id="top">
<table border="0" width="100%">
<tr>

<?php
session_start();
$username = $_SESSION['membership'];
if($_SESSION['membership']!= null)
{
echo "<td align='left' width='75%'>";
echo "<a href='index.php'>Home Page</a>&nbsp;|&nbsp;<a href='bookmenu.php'>Our Book</a>&nbsp;|&nbsp;<a href='companyevent.php'>Event</a>&nbsp;|&nbsp;<a href='companyprofile.php'>About Us</a>&nbsp;|&nbsp;<a href='sitemap.php'>Site Map</a>&nbsp;|&nbsp;<a href='subtemcart.php'>Cart</a>&nbsp;|&nbsp;<a href='history.php'>Order History</a>&nbsp;|";
echo "</td>";

echo "<td align='right' width='25%'>";

echo "<b>You login as: </b><a href='profile.php'>".$username."</a>";
echo "&nbsp;<a href='logout.php'>(Logout)</a>";
echo "</td>";

}else{

echo "<td align='left' width='75%'>";
echo "<a href='index.php'>Home Page</a>&nbsp;|&nbsp;<a href='bookmenu.php'>Our Book</a>&nbsp;|&nbsp;<a href='companyevent.php'>Event</a>&nbsp;|&nbsp;<a href='companyprofile.php'>About Us</a>&nbsp;|&nbsp;<a href='sitemap.php'>Site Map</a>&nbsp;|&nbsp;<a href='Addmem.php'>Join Us</a>&nbsp;|&nbsp;<a href='login.php'>Member Login</a>&nbsp;|";
echo "</td>";

echo "<td align='right' width='25%'>";
echo "<b>You haven't login.</b>";
echo "&nbsp;<a href='login.php'>(Login)</a>";
echo "</td>";
}
?>
</tr>
</table>
</div>

<br/>
<div id="search">
<form action="bookmenu.php" name="searchform" method="GET">
<fieldset style="width:100%">
<legend>Find Your Books Here!</legend>
Search:<input type="text" size="100" name="keyword" value=""/>

<select name="searchBy" value="">
	<option value="itemName">Book Name</option>
	<option value="itemAuthor">Author</option>
	<option value="itemPublisher">Publisher</option>
	<option value="itemCategory">Category</option>
	</select>

<input type="submit" name="search" value="Search"/>
</fieldset>
</form>
</div>

<div id="links">
<h2>Category</h2>
<a href="bookmenu.php?keyword=Humanities&searchBy=itemCategory&search=Search">Humanities</a>
<a href="bookmenu.php?keyword=Business&searchBy=itemCategory&search=Search">Business & Management</a>
<a href="bookmenu.php?keyword=Engineering&searchBy=itemCategory&search=Search">Engineering</a>
<a href="bookmenu.php?keyword=Finance&searchBy=itemCategory&search=Search">Finance</a>
<a href="bookmenu.php?keyword=Sport&searchBy=itemCategory&search=Search">Sport</a>
<a href="bookmenu.php?keyword=Language&searchBy=itemCategory&search=Search">Language</a>
<a href="bookmenu.php?keyword=School&searchBy=itemCategory&search=Search">School Reference</a>
<a href="bookmenu.php?keyword=General&searchBy=itemCategory&search=Search">General</a>
<a href="bookmenu.php?keyword=Magazine&searchBy=itemCategory&search=Search">Magazine</a>
<a href="bookmenu.php?keyword=Children&searchBy=itemCategory&search=Search">Children</a>
<a href="bookmenu.php?keyword=Mandarin&searchBy=itemCategory&search=Search">Mandarin</a>
<a href="bookmenu.php?keyword=Malay&searchBy=itemCategory&search=Search">Malay</a>
<br/>
<a href='bookmenu.php?sort=itemSales DESC'>Top Sales</a>
<a href='bookmenu.php?sort=itemDate DESC'>New Item</a>

<br/><br/>
<hr/>
<div id="main">
<table>
<tr>
<td><center><h2>HOT Title</h2></center></td>
</tr>
<?php
include("leftbanner.php");
?>
</div>
</div>

<br/>

<div id="main">
<?php
include ("connect.php");
if($_GET["search"] == "Search")
{	
	$searchBy = $_GET["searchBy"];
	$keyword = $_GET["keyword"];
	if(($keyword=="")||($searchBy=="")){
	echo "<script language='javascript'>alert('Please insert your keyword and search category.')</script>";
	echo "<script language='javascript'>window.location='bookmenu.php'</script>"; 
	}else{
	$query = "SELECT * FROM item WHERE ".$searchBy." LIKE '%".$keyword."%' ORDER BY num";
	$result = $db->query($query);
}
}
else if($_GET["reset"] == "Reset Result")
{
	$query = "SELECT * FROM item ORDER BY num";
	$result = $db->query($query);
}
else
{
	$query = "SELECT * FROM item ORDER BY num";   
	$result = $db->query($query);
}
?>
<script language="JavaScript" src="gen_validatorv4.js"
    type="text/javascript" xml:space="preserve"></script>
<div id="main">

<form name="myform" id="myform" method="post">
<fieldset style="width:80%"> 
<legend>New Member Registration Form</legend>

<!--registration form--> 
<table width="80%" cellspacing="0" cellpadding="5" border="0">
		<tr> 
			<td colspan="3" class="contents">Please field up all the information</td> 
		</tr> 
			
		<tr> 
			<td valign="top"></td> 
			<td valign="top">Login Name</td> 
			<td><input type="text" name="memLname" size="55"/>
			<div id='myform_memLname_errorloc' class="error_strings"></div></td> 
		</tr>
		
		<tr> 
			<td valign="top"></td>
			<td valign="top">Name</td> 
			<td><input type="text" name="memName" size="55"s/>
			<div id='myform_memName_errorloc' class="error_strings"></div></td> 
		</tr>
        <tr> 
			<td valign="top"></td> 
			<td valign="top">Password</td> 
			<td><input type="password" name="memPassword" size="55"/> 
			<div id='myform_memPassword_errorloc' class="error_strings"></div></td> 
		</tr>
		<tr>
			<td valign="top"></td> 
			<td valign="top">Confrim Password</td> 
			<td><input type="password" name="Cpassword">
			<div id='myform_Cpassword_errorloc' class="error_strings"></div></td>
			</tr>
				
		<tr>
			<td valign="top"></td>
			<td valign="top">NRIC</td>
			<td><input type="text" name="ICDate" size="6" maxlength="6"/>-
			<input type="text" name="ICState" size="2" maxlength="2"/>-
			<input type="text" name="ICNo" size="4" maxlength="4"/>
			<div id='myform_ICDate_errorloc' class="error_strings"></div>
			<div id='myform_ICState_errorloc' class="error_strings"></div>
			<div id='myform_ICNo_errorloc' class="error_strings"></div></td>
		</tr>
		
		<tr>
			<td></td>
			<td valign="top">Date of Birth<br/>(DD/MM/YYYY):	</td>
			<td> 
			<input type="text" size="12" name="memBdate" id="memBdate" />
			<div id='myform_memBdate_errorloc' class="error_strings"></div></td>
        </tr>
		
		<tr>
			<td ></td>
			<td>Gender:</td>
			<td><table border="0">
			<tr><td><input type="radio" name="memSex" value="Male"/>Male</td></tr>
			<tr><td><input type="radio" name="memSex" value="Female"/>Female</td></tr>
			</td></table><div id='myform_memSex_errorloc' class="error_strings"></div>
		</tr>
		
		<tr>
			<td valign="top"></td>
			<td valign="top">Race:</td>
			<td><select name="memRace"><option value="0">Choose One</option>
						<option value="1">Chinese</option>
						<option value="2">Malay</option>
						<option value="3">Indian</option>
						<option value="4">Others</option>
						</select>
			<div id='myform_memRace_errorloc' class="error_strings"></div>
			</td>
		</tr>
		
		<tr>
			<td valign="top"></td>
			<td valign="top">Address :</td>
			<td valign="top"><textarea name="memAddress"rows="5" cols="34"></textarea>
			<div id='myform_memAddress_errorloc' class="error_strings"></div></td>
		</tr>
		
		<tr>
			<td valign="top"></td>
			<td valign="top">Post Code :</td>
			<td><input name="memPcode" type="text" maxlength="6" size="6"/>
			<div id='myform_memPcode_errorloc' class="error_strings"></div></td>
		</tr>
		
		<tr>
			<td valign="top"></td>
			<td valign="top">City :</td>
			<td><input name="memCity" type="text" maxlength="50" size="20"/>
			<div id='myform_memCity_errorloc' class="error_strings"></div></td>
		</tr>
		
		<tr>
			<td valign="top"></td>
			<td valign="top">State :</td>
			<td><select name="memState"><option value="0">Select</option>
									 <option value="Johor">Johor</option>
									 <option value="Kedah">Kedah</option>
									 <option value="Kelantan">Kelantan</option>
									 <option value="Kuala Lumpur">Kuala Lumpur</option>
									 <option value="Melaka">Melaka</option>
									 <option value="Negeri Sembilan">Negeri Sembilan</option>
									 <option value="Pahang">Pahang</option>
									 <option value="Penang">Penang</option>
									 <option value="Perak">Perak</option>
									 <option value="Perlis">Perlis</option>
									 <option value="Sabah">Sabah</option>
									 <option value="Sarawak">Sarawak</option>
									 <option value="Selangor">Selangor</option>
									 <option value="Terengganu">Terengganu</option>
									 </select>
			<div id='myform_memState_errorloc' class="error_strings"></div></td>
		</tr>
		
		<tr>
			<td valign="top"></td>
			<td valign="top">Contact :</td>
			<td><table>
		<tr><td>Home :</td>
			<td><input name="memHnum1" type="text" maxlength="3" size="3"/>&nbsp;-&nbsp;
				<input name="memHnum2" type="text" maxlength="10" size="10"/>
				<div id='myform_memHnum1_errorloc' class="error_strings"></div>
				<div id='myform_memHnum2_errorloc' class="error_strings"></div></td>
		</tr>
		<tr>
			<td>Handphone :</td>
			<td><select name="memHpnum1">
								<option value="0"></option>
								<option value="010">010</option>
								<option value="012">012</option>
								<option value="013">013</option>
								<option value="014">014</option>
								<option value="016">016</option>
								<option value="017">017</option>
								<option value="019">019</option>
								</select>&nbsp;-&nbsp;
								<input name="memHpnum2" type="text" maxlength="10" size="10"/>
			<div id='myform_memHpnum1_errorloc' class="error_strings"></div>
			<div id='myform_memHpnum2_errorloc' class="error_strings"></div>
			</td>
			</table></td>
		</tr>
		</tr>
		
		<tr>
			<td></td>
			<td valign="top">Email :</td>
			<td><input name="memEmail" type="text" maxlength="50" size="50"/>
			<div id='myform_memEmail_errorloc' class="error_strings"></div>
			</td>
		</tr>
		
        <tr>
			<td></td>
			<td></td>
			<td><br>
			<input type="submit" name="Submit" value="Submit"/>
			<input type="reset" value="Reset"/>
			</td>
		</tr>	
      </table>
	  </fieldset>
    </form><script language="JavaScript" type="text/javascript"
    xml:space="preserve">//<![CDATA[
//You should create the validator only after the definition of the HTML form
  var frmvalidator  = new Validator("myform");
 frmvalidator.EnableOnPageErrorDisplay();
 frmvalidator.EnableMsgsTogether();
 
  frmvalidator.addValidation("memLname","req","Please enter your Login Name");
  frmvalidator.addValidation("memLname","maxlen=20","Max length for Login Name is 20");
  frmvalidator.addValidation("memLname","alpha_s","Login Name can contain alphabetic chars only");
  
  frmvalidator.addValidation("memName","req","Please enter your Name");
  frmvalidator.addValidation("memName","maxlen=20","Max length for Name is 20");
  frmvalidator.addValidation("memName","alpha_s","Name can contain alphabetic chars only");
  
  frmvalidator.addValidation("memPassword","req","Please enter your Password");
  frmvalidator.addValidation("memPassword","maxlen=10","Max length for Password is 10");
  frmvalidator.addValidation("memPassword","minlen=6","Min length for Password is 6");
  
    frmvalidator.addValidation("Cpassword","eqelmnt=memPassword","The confirmed password is not same as password");

  frmvalidator.addValidation("ICDate","minlen=6","IC number's date invalid");
  frmvalidator.addValidation("ICDate","maxlen=6");
  frmvalidator.addValidation("ICDate","numeric","IC number must be a number");

  frmvalidator.addValidation("ICState","minlen=2","IC number's state invalid");
  frmvalidator.addValidation("ICState","maxlen=2");
  frmvalidator.addValidation("ICState","numeric","IC number must be a number");
  
  frmvalidator.addValidation("ICNo","minlen=4","IC number invalid");
  frmvalidator.addValidation("ICNo","maxlen=4");
  frmvalidator.addValidation("ICNo","numeric","IC number must be a number");
  
  frmvalidator.addValidation("memBdate","req","Please enter your Birthday");
	
  frmvalidator.addValidation("memSex","selone","Please select an option from 'Gender'");
  
  frmvalidator.addValidation("memRace","dontselect=0","Please select an option from 'Race'");
  
  frmvalidator.addValidation("memAddress","req","Please enter your Address");
  frmvalidator.addValidation("memAddress","maxlen=100");
  
  frmvalidator.addValidation("memPcode","maxlen=5");
  frmvalidator.addValidation("memPcode","minlen=5","Invalid post code");
  frmvalidator.addValidation("memPcode","numeric","Post code must be a number");
  
  frmvalidator.addValidation("memCity","maxlen=30","Max length for Login Name is 30");
  frmvalidator.addValidation("memCity","req","Please enter your City");
	
  frmvalidator.addValidation("memState","dontselect=0","Please select an option from 'State'");
  
  frmvalidator.addValidation("memHnum1","numeric","Home contact must be a number");
  frmvalidator.addValidation("memHnum2","numeric","Home contact must be a number");
  
  frmvalidator.addValidation("memHpnum1","dontselect=0","Please select an option from 'Handphone'");
  frmvalidator.addValidation("memHpnum2","req","Please enter your handphone");
  frmvalidator.addValidation("memHpnum2","numeric","Handphone contact must be a number");
  
  frmvalidator.addValidation("memEmail","maxlen=50");
  frmvalidator.addValidation("memEmail","req","Please enter your Email");
  frmvalidator.addValidation("memEmail","email","The email is no valid");
  

//]]></script>
</div>
</center>
<div id="bottomlink">
<br/>
<a href="index.php">Home Page</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="bookmenu.php">Our Book</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="Addmem.php"> Membership</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="companyevent.php">Event</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="companyprofile.php">About Us</a><br/><a href="sitemap.php">Site Map</a>
</div>

<div id="bottom">
<br/>
Copyright &#169; with Tian Tian Bookstore 2011. All Rights Reserved. 
</div>
</body>
</html>

