<?php
session_start();
session_register('member');


if(isset($_POST["submit"]))
{
	$memLname = $_POST["memLname"];
	$memPassword = $_POST["memPassword"];
	
	include ("connect.php");
	
	if($memLname!= "" && $memPassword != "")
	{
		$result = mysql_query("SELECT memLname, memPassword FROM member WHERE memLname = '$memLname' AND memPassword = '$memPassword'"); 
		if(mysql_fetch_array($result) == 1)
		{
			$validate = $result->fetch_assoc();
			$_SESSION['membership'] = $validate['memLname'];

			echo "<script language='javascript'>window.location='index.php'</script>"; 
		}
		else
		{
			echo "<script>alert('Please Check Your Login ID And Password!')</script>";
		}
	}else{
	echo "<script>alert('Please Enter Your Login ID And Password!')</script>";
	}
}
?>
<html>
<head>
<title>Online Bookshop - Welcome</title>
<link href="bookstore.css" rel="stylesheet" type="text/css"/>

<style> 
a{text-decoration:none}
a img{border:0}
.mainbox{ width:700px; position:relative}
.flashNews{height:339px;}
.flashNews .bg {position:absolute;left:0;bottom:0;width:700px;height:50px;
	background:orange}
.flashNews h3 {position:absolute;left:10px;top:265px;width:640px;height:35px;
	line-height:35px;z-index:2;}
.flashNews h3 a {font-size:30px;font-family:"Times";font-weight:bold;color:#FFFFFF;}
.flashNews h3 a:hover {color:#F20000;}
.flashNews p {position:absolute;left:10px;top:305px;width:284px;height:20px;
	line-height:20px;;z-index:2;}
.flashNews p a {color:brown;}
.flashNews p a:hover {color:#F20000;}
.flashNews ul {position:absolute;right:0;bottom:0;padding-left:47px;_padding-left:46px;
	background:url(../img/flashPage_bg.png) 0 0 no-repeat;z-index:2;
	_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/flashPage_bg.png',sizingMethod='crop')}
.flashNews ul li {float:left;width:15px;height:18px;line-height:18px;
	text-align:center;margin-left:1px;background:#000000;}
.flashNews ul li a {display:block;width:15px;height:18px;font-size:10px;
	font-family:Tahoma;font-weight:bold;color:#FFFFFF;}
.flashNews ul li a:hover, .flashNews ul li a.sel {color:#F20000;}
</style>


<script type="text/javascript"> 
function getDownloadUrl(productName) {
	var random = parseInt(Math.random()*100);
	var temp = 0;
	
		for(var i = 0; i < productName.length && random > temp; i++) {
				temp += parseInt(productName[i].percent);
			}
			i = (random == 0 ? 0 : i - 1);
			return "<a href=\"" + productName[i].url + "\">" + productName[i].name + "</a>";
}

function switchTab(identify,index,count) {
	for(i=0;i<count;i++) {
		var CurTabObj = document.getElementById("Tab_"+identify+"_"+i) ;
		var CurListObj = document.getElementById("List_"+identify+"_"+i) ;
		if (i != index) {
			fRemoveClass(CurTabObj , "upH3") ;
			fRemoveClass(CurListObj , "upBox") ;
		} 

	}
	fAddClass(document.getElementById("Tab_"+identify+"_"+index),"upH3") ;
	fAddClass(document.getElementById("List_"+identify+"_"+index),"upBox") ;
}
 
function switchSideTab(identify,index,count) {
	for(i=0;i<count;i++) {
		var CurTabObj = document.getElementById("Tab_"+identify+"_"+i) ;
		var CurListObj = document.getElementById("List_"+identify+"_"+i) ;
		if (i != index) {
			fRemoveClass(CurTabObj , "upH3") ;
			fRemoveClass(CurListObj , "upUL") ;
		}
	}
	fAddClass(document.getElementById("Tab_"+identify+"_"+index),"upH3") ;
	fAddClass(document.getElementById("List_"+identify+"_"+index),"upUL") ;
}
 
function fAddClass(XEle, XClass)
{/* shawl.qiu code, void return */
  if(!XClass) throw new Error("XClass 不能为空!");
  if(XEle.className!="") 
  {
    var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
    XEle.className = XEle.className.replace(Re, "");
	var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"") ;
	if (OldClassName == "" ) {
		 XEle.className = XClass;
	}
	else {
		XEle.className = OldClassName + " " + XClass;
	}
   
  }
  else XEle.className = XClass;
}/* end function fAddClass(XEle, XClass) */
 
function fRemoveClass(XEle, XClass)
{/* shawl.qiu code, void return */
  if(!XClass) throw new Error("XClass 不能为空!");
  var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"") ;
  if(OldClassName!="") 
  {
	
    var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
    XEle.className = OldClassName.replace(Re, "");
  }
}/* function fRemoveClass(XEle, XClass) */
 
function switchPic(screen) {
	if (screen > MaxScreen) {
		screen = 1 ;
	}
	
	for (i=1;i<=MaxScreen;i++) {
		document.getElementById("Switch_"+i).style.display = "none" ;
	}
	document.getElementById("Switch_"+screen).style.display = "block" ;
	showSwitchNav(screen);
	showSwitchTitle(screen);
	//Effect.Appear("Switch_"+screen);
			
	//switchLittlePic(screen);
	//showSwitchTitles(screen);
	CurScreen = screen  ;
}
 
function showSwitchNav(screen) {
	var NavStr = "" ;
	for (i=1;i<=MaxScreen;i++) {
		if (i == screen) {
			NavStr += '<li onmouseover="pauseSwitch();" onmouseout="goonSwitch();"><a href="javascript://" target="_self" class="sel">'+i+'</a></li>' ;
		}
		else {
			NavStr += '<li onmouseover="pauseSwitch();" onmouseout="goonSwitch();" onclick="goManSwitch('+i+');"><a href="javascript://" target="_self">'+i+'</a></li>' ;
		}
		
	}
	document.getElementById("SwitchNav").innerHTML = NavStr ;
}
 
function showSwitchTitle(screen) {
	var titlestr = "" ;
	titlestr = '<h3><a href="'+Switcher[screen]['link']+'" target="_blank">'+Switcher[screen]['title']+'</a></h3><p><a href="'+Switcher[screen]['link']+'" target="_blank">'+Switcher[screen]['stitle']+'</a></p>' ;
	document.getElementById("SwitchTitle").innerHTML = titlestr ;
}
 
function reSwitchPic() {
	refreshSwitchTimer = null;
	switchPic(CurScreen+1);
	refreshSwitchTimer = setTimeout('reSwitchPic();', 3000);
}
 
function pauseSwitch() {
	clearTimeout(refreshSwitchTimer);
}
 
function goonSwitch() {
	clearTimeout(refreshSwitchTimer);
	refreshSwitchTimer = setTimeout('reSwitchPic();', 3000);
}
 
function goManSwitch(index) {
	clearTimeout(refreshSwitchTimer);
	
	CurScreen = index - 1 ;
	reSwitchPic();
}
 
function floatAdMove() {
	try{BigAd = document.getElementById("BigAd")}catch(e){}
	if (BigAd.style.display != "none") {
		if (document.ns) {
			BigAd.style.top=bdy.scrollTop+bdy.clientHeight-imgheight_close -360;
			BigAd.style.left=bdy.offsetWidth/2-bdy.scrollLeft-300;
		}
		else {
			BigAd_style_left=bdy.offsetWidth/2-bdy.scrollLeft-300;
			BigAd_style_top = 200 ;
			BigAd.style.top=BigAd_style_top + "px";
			BigAd.style.left=BigAd_style_left + "px";
		}
	}
	setTimeout("floatAdMove();",50) ;
}
 
function FloatCtrlMove() {
	try{FloatCtrl = document.getElementById("FloatCtrl")}catch(e){}
	if (FloatCtrl.style.display != "none") {
		if (document.ns) {
			FloatCtrl.style.top=bdy.scrollTop+bdy.clientHeight-imgheight_close;
			FloatCtrl.style.left=bdy.scrollLeft+bdy.offsetWidth-150;
		}
		else {
			FloatCtrl_style_left=bdy.scrollLeft+bdy.offsetWidth-150;
			FloatCtrl_style_top = 500 ;
			FloatCtrl.style.top=FloatCtrl_style_top + "px";
			FloatCtrl.style.left=FloatCtrl_style_left + "px";
		}
	}
	setTimeout("FloatCtrlMove();",50) ;
}
 
function showFloatAd() {
	cleanTimer();
	try{floatbig = document.getElementById("floatbig")}catch(e){}
	if (floatbig.innerHTML != "") {
		BigAdStartTimer = setTimeout("Effect.Appear('BigAd');",500);
		BigAdEndTimer = setTimeout("hiddenFloatAd();",6000);
		hiddenFloatCtrl();
	}
}

 
function cleanTimer() {
	clearTimeout(BigAdStartTimer) ;
	clearTimeout(BigAdEndTimer);
}
	var MaxScreen = 3 ;
	var CurScreen = 1 ;
</script>

<script type="text/javascript">
function goEvent() {
window.location.href('companyevent.php');
}
</script>

<script type="text/javascript">
function goMain() {
window.location.href('index.php');
}
</script>

<script type="text/javascript">
function goMem() {
window.location.href('Addmem.php');
}
</script>
</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">
<center>
<h2>Welcome To Daily Bookstore</h2>
</center>

<table width="90%" align="center" border="0">
<tr>
<td align="center">
<div class="mainbox">
<div class="flashNews">

<div id="Switch_1"><font face="fantasy"><a href="#" onclick="goMain();" blockid="1121">
	<img src="Picture/p1.jpg" width="700" height="350" alt="Picture1" onmouseover="pauseSwitch();"  onmouseout="goonSwitch();"/></a></font></div>

<div id="Switch_2" style="display:none;"><font face="fantasy"><a href="#" onclick="goEvent();" blockid="1121">
	<img src="Picture/p2.jpg" width="700" height="350" alt="Picture2" onmouseover="pauseSwitch();"  onmouseout="goonSwitch();"/></a></font></div>

<div id="Switch_3" style="display:none;"><font face="fantasy"><a href="#" onclick="goMem();" blockid="1121">
	<img src="Picture/p3.jpg" width="700" height="350" alt="Picture3" onmouseover="pauseSwitch();"  onmouseout="goonSwitch();"/></a></font></div>

<div id="SwitchTitle" onmouseover="pauseSwitch();" onmouseout="goonSwitch();"></div>
			<ul id="SwitchNav"></ul>
			<div class="bg" onmouseover="pauseSwitch();"  onmouseout="goonSwitch();"></div>
	</div>	
</div><font face="Times New Roman">
</td>

<script type="text/javascript"> 
var Switcher = new Array();
	Switcher[1] = Array() ;
	Switcher[1]['title'] = "" ;
	Switcher[1]['stitle'] = "Welcome To Daily Bookshop!" ;
	Switcher[1]['link'] = "" ;
	
	Switcher[2] = Array() ;
	Switcher[2]['title'] = "" ;
	Switcher[2]['stitle'] = "Discount 15%" ;
	Switcher[2]['link'] = "" ;
	
	Switcher[3] = Array() ;
	Switcher[3]['title'] = "" ;
	Switcher[3]['stitle'] = "Join Our Member Now!" ;
	Switcher[3]['link'] = "" ;
	
var refreshSwitchTimer = null;
	switchPic(CurScreen);
		refreshSwitchTimer = setTimeout('reSwitchPic();', 3000);
</script>
</td>
</tr>

<?php
echo "<tr>";
echo "<td colspan='2'>";
echo "<div id='indexbook'>";
echo "<table width='100%'>";
echo "<tr>";
echo "<td colspan='4'><br/></td>";
echo "</tr>";


echo "<tr>";
echo "<th colspan='4' align='left'>Daily Preorder</th>";
echo "<th><div id='commonlink2'><a href='bookmenu.php?sort=itemDate DESC'>";
echo "View More...</a>";
echo "</div>";
echo "</th>";
echo "</tr>";

include ("connect.php");

$result3 = mysql_query("SELECT * FROM item WHERE itemDate>curdate() ORDER BY itemDate DESC");   

echo "<tr>";
for($i=0; $i<5; $i++)
{
$row3 = mysql_fetch_array($result3);
echo "<td width='20%'>";
echo "<table width='100%' border='0'>";
echo "<form name='qform' method='GET' action='indexaddcart.php'>";
echo "<tr>";
echo "<td align='center' height='100pt'>";
echo "<a href='bookviewpage.php?ISBN=".$row3["ISBN"]."'><img src=/bookstore/bookstaff/".$row3["itemImage"]." border='0' width='120' height='160'></a>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td height='70pt' valign='top' align='center'>";
echo "<input type='hidden' name='itemName' value='".$row3["itemName"]."'><a href='bookviewpage.php?ISBN=".$row3["ISBN"]."'>".$row3["itemName"]."</a><br/>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'>Price: RM ";
printf("%10.2f",$row3["itemPrice"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'><br/>";
	echo "<name='temQuantity'>";
	echo "<select name='temQuantity'>";
	$temQuantityArray = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
	for($j = 0; $j < 9 ; $j++)
	{echo "<option>".$temQuantityArray[$j];
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row3[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row3[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
echo "</td>";
echo "</tr>";
echo "</form>";
echo "</table>";	
echo "</td>";
}
echo "</tr>";



echo "<tr>";
echo "<th colspan='4' align='left'>Daily New Books</th>";
echo "<th><div id='commonlink2'><a href='bookmenu.php?sort=itemDate DESC'>";
echo "View More...</a>";
echo "</div>";
echo "</th>";
echo "</tr>";

include ("connect.php");

$result = mysql_query("SELECT * FROM item WHERE itemDate<curdate() ORDER BY itemDate DESC");   

echo "<tr>";
for($i=0; $i<5; $i++)
{
$row = mysql_fetch_array($result);
echo "<td width='20%'>";
echo "<table width='100%' border='0'>";
echo "<form name='qform' method='GET' action='indexaddcart.php'>";
echo "<tr>";
echo "<td align='center' height='100pt'>";
echo "<a href='bookviewpage.php?ISBN=".$row["ISBN"]."'><img src=/bookstore/bookstaff/".$row["itemImage"]." border='0' width='120' height='160'></a>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td height='70pt' valign='top' align='center'>";
echo "<input type='hidden' name='itemName' value='".$row["itemName"]."'><a href='bookviewpage.php?ISBN=".$row["ISBN"]."'>".$row["itemName"]."</a><br/>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'>Price: RM ";
printf("%10.2f",$row["itemPrice"]);
echo "</td>";
echo "</tr>";

echo "<tr>";

echo "<td align='center'><br/>";
	$tem = $row[itemQuantity];
	echo "<name='temQuantity'>";
	echo "<select name='temQuantity'>";
	for($j=1; $j<=$tem; $j++)
	{
	echo "<option value='$j'>".$j;
	echo "</option>";
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
echo "</td>";
echo "</tr>";
echo "</form>";
echo "</table>";	
echo "</td>";
}
echo "</tr>";
echo "</table>";

echo "<table width='100%'>";
echo "<tr>";
echo "<th colspan='4' align='left'>Top Sales</th>";
echo "<th><div id='commonlink2'><a href='bookmenu.php?sort=itemSales DESC'>";
echo "View More...</a>";
echo "</div>";
echo "</th>";
echo "</tr>";

$result1 = mysql_query("SELECT * FROM item WHERE itemDate<curdate() ORDER BY itemSales DESC");   

echo "<tr>";
for($k=0; $k<5; $k++)
{
$row1 = mysql_fetch_array($result1);
echo "<td width='20%'>";
echo "<table width='100%' border='0'>";
echo "<form name='qform' method='GET' action='indexaddcart.php'>";
echo "<tr>";
echo "<td align='center' height='100pt'>";
echo "<a href='bookviewpage.php?ISBN=".$row1["ISBN"]."'><img src=/bookstore/bookstaff/".$row1["itemImage"]." border='0' width='120' height='160'></a>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td height='70pt' valign='top' align='center'>";
echo "<input type='hidden' name='itemName' value='".$row1["itemName"]."'><a href='bookviewpage.php?ISBN=".$row1["ISBN"]."'>".$row1["itemName"]."</a><br/>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'>Price: RM ";
printf("%10.2f",$row1["itemPrice"]);
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'><br/>";
	$tem = $row1[itemQuantity];
	echo "<name='temQuantity'>";
	echo "<select name='temQuantity'>";
	for($j=1; $j<=$tem; $j++)
	{
	echo "<option value='$j'>".$j;
	echo "</option>";
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row1[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row1[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
	
echo "</td>";
echo "</tr>";
echo "</form>";
echo "</table>";	
echo "</td>";
}
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "</table>"
?>
</div>
<hr/>
<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>

</div>
</center>
</body>
</html>