<?php
include("session.php");
include("connect.php");
$id=$_GET['id'];
$client=$_SESSION['client'];

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="facebox/facebox.css" />
<script language="javascript" src="jquery.js"></script>
<script language="javascript" src="facebox/facebox.js"></script>
<script language="javascript">
$(document).ready(function() {
    $('a[rel*=facebox]').facebox();
})
</script>


<style type="text/css">
body{
	font-family: myriad, Sans-Serif, Verdana, Tahoma, Arial;
}
a.address{
	color:blue;
	text-decoration:none;
	cursor:pointer;
}
a.address:hover{
	color:blue;
	text-decoration:none;
	cursor:pointer;
	border:0;
}
a img.logo{
border:0;
}
td.detail{
font: 12px/18px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
color: #333;
}
td.detail2{
font: 12px/18px  "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
color: #333;
font-size: 14px;
font-weight: normal;
font-style: normal;
line-height: 1.25em;

}
table.box1{
	border-radius: 4px;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	-o-border-radius: 4px;
	-khtml-border-radius: 4px;
	
	border: 1px solid;
	-webkit-box-shadow: rgba(0,0,0,0.3) 0 1px 3px;
	-moz-box-shadow: rgba(0,0,0,0.3) 0 1px 3px;
	box-shadow: rgba(0,0,0,0.3) 0 1px 3px;
	border-color: #E5E5E5 #DBDBDB #D2
	
}
td.productname{
font: 12px/18px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
color: #333;
font-size: 24px;
line-height: 36px;
}
td.promotion{
font: 12px/18px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
color: #333;
line-height: 36px;
font-size: 36px;
}
td img.image{

margin-left: auto;
margin-right: auto;
padding: 3px;
border: solid;
background-color: white;
border-color: #DDD #AAA #AAA #DDD;
border-width: 1px 2px 2px 1px;
}

div a.ratebutton:hover{
color: #333;
text-decoration:none;
cursor:pointer;
border:none;
font-size: 14px;
}
div a.ratebutton{
color: #333;
text-decoration:none;
cursor:pointer;
border:none;
font-size: 14px;
}
.ratebutton2:hover{
border:none;
}
.ratebutton2{
border:none;
}
</style>
<script type="text/javascript">
function checkaccount(){
	var asd = document.getElementById("clientid").value;
	if(asd == ""){
		alert("Please login first");
		return false;
	}
	else{
		return true;
	}
}
</script>
</head>
<body>
<?php
$queryB=mysql_query("select * from product where id='$id'");
$queryB2=mysql_query("select * from promotion where pID='$id'");
$result=mysql_fetch_array($queryB);
$result2=mysql_fetch_array($queryB2);
$companyid=$result['companyID'];
$queryB3=mysql_query("select * from company where id='$companyid'");
$result3=mysql_fetch_array($queryB3);

$productid=$id;
$productname=$result['pName'];
$producttype=$result['type'];
$productprice=$result['price'];
$productdollar=$result['dollar'];
if(($result['detail'])==""){
$productdetail="No detail";
}else{
$productdetail=$result['detail'];
}

$companyname=$result3['cName'];
$companyaddress = $result3['address'].",".$result3['postcode'].",".$result3['country'];
$companyphone = $result3['countryCode']."".$result3['telNo'];
$companyemail = $result3['email'];
$companyperson = $result3['cPerson'];
$promotionstart=$result2['startdate'];
$promotionend=$result2['enddate'];
$promotionprice=$result2['promotionprice']." ".$result2['dollar'];
if(($result['pcondition'])==""){
$promotioncondition="No condition";
}else{
$promotioncondition= $result2['pcondition'];
}

echo"<table border='0' class='box1'>";
echo"<tr><td colspan='4' align='left' valign='bottom' class='productname'>&nbsp;<b>$productname</b></td></tr>";
echo"<tr>";
echo"<td rowspan='14' width='250px' height='300px' align='center'>";
$checkpic = $id.".";
if ($result['productPic'] == $checkpic){
	echo"<img src='../company/album/NoImage.jpg' width = '230px' height = '280px' border='0' class='image'/>";
	echo"<br/>";
}else{
	echo"<img src='../company/album/$result[productPic]' width = '230px' height = '280px' border='0' class='image'/>";
	echo"<br/>";
}
echo"</td>";
echo"<td rowspan='14' width='60px' height='300px'>&nbsp</td>";
echo"</tr>";
echo"<tr><td width='210px' valign='top' align='left' class='detail2'>Product type :</td><td width='600px' valign='top' align='left' class='detail'>".$producttype."</td></tr>";
echo"<tr><td valign='top' align='left' class='detail2'>Price :</td><td valign='top' align='left' class='detail'>";printf("%10.2f",$productprice);echo" ".$productdollar."</td></tr>";
echo"<tr><td valign='top' align='left' height='38px' class='detail2'>More detail :</td><td valign='top' align='left' height='38px' class='detail'>".$productdetail."</td></tr>";
if($result2['status'] == 'on'){
echo"<tr><td valign='top' align='left' class='detail2'>Promotion Price :</td><td valign='top' align='left' class='detail'>";printf("%10.2f",$promotionprice);echo" ".$productdollar."</td></tr>";
echo"<tr><td valign='top' align='left' class='detail2'>Promotion start to :</td><td valign='top' align='left' class='detail'>".$promotionstart."</td></tr>";
echo"<tr><td valign='top' align='left' class='detail2'>Promotion end to :</td><td valign='top' align='left' class='detail'>".$promotionend."</td></tr>";
//echo"<tr><td valign='top' align='left' class='detail2'>Condition of promotion :</td><td valign='top' align='left' class='detail'>".$promotioncondition."</td></tr>";
}
else if($result2['status'] == 'off'){
echo"<tr><td height='50px' align='left' colspan='2' class='promotion'>No promotion now</td></tr>";
//echo"<tr><td colspan='2' height='100px'></td></tr>";
}
echo"<tr><td align='left' colspan='2'><hr></td></tr>";
echo"<tr><td valign='top' align='left' class='detail2'>Company name :</td><td valign='top' align='left' class='detail'>".$companyname."</td></tr>";
echo"<tr><td valign='top' align='left' class='detail2'>Contact number :</td><td valign='top' align='left' class='detail'>".$companyphone."</td></tr>";
echo"<tr><td valign='top' align='left' class='detail2'>Company Email :</td><td valign='top' align='left' class='detail'>".$companyemail."</td></tr>";
echo"<tr><td valign='top' align='left' class='detail2'>Contact Person :</td><td valign='top' align='left' class='detail'>".$companyperson."</td></tr>";

?>
<tr><td valign='top' align='left' class='detail2'>
<address>
<font>Location :</font></td><td valign='top' align='left' class='detail'><a href="http://maps.google.com?q=<?php echo $companyaddress?>" target="_blank" class='address'>
<img src="icon/Search-icon.png" alt="google maps" width="13" height="13" class='logo'/>&nbsp;<?php echo $companyaddress?>&nbsp;<img src="icon/Search-icon.png" alt="google maps" width="13" height="13" class='logo'/>
</a>
</address>
</td></tr>
</table>

<br/>
<?php
if($client != ""){
	echo "<div><a href='rating.php?id=$id' class='ratebutton' rel='facebox' />Rating: <img src='icon/rate.png' width='80' height='14px' valign='bottom'></a></div>";
	$checkNo = mysql_query("select * from customer where userID='$client'");
	$displayNo=mysql_fetch_array($checkNo);
	$no = $displayNo['no'];
	
	$check=mysql_query("select * from memberaddcart where customerID='$no' and productID='$productid' and status='incart'");
	if(mysql_num_rows($check)==0){
	
	echo "<div>
	<form action='addcart.php?id=$id' method='POST'>
	<select name='quantity'>
		<option value='1'>1</option>
		<option value='2'>2</option>
		<option value='3'>3</option>
		<option value='4'>4</option>
	</select>
	<input type='hidden' name='productID' value='$productid' />
	<input type='hidden' name='price' value='$productprice' />
	<input type='hidden' name='companyID' value='$companyid' />
	<input type='submit' value='Submit' />
	</form>
	</div>";
	}else{
		echo "Add cart already";
	}
}
else{

}
?>
<?php
echo"</br>";
include("viewcomment.php");
?>




</body>
</html>
<?php
include("closeconnection.php");
?>