<body style="background-color: #ffffff;background-image:url(rail.jpg);background-repeat: repeat-y">	
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<h2 align=center><i>Staff Sell Food</i></h2>
<?php 
	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
	
	$result=mysql_query("SELECT * from kstock");
	date_default_timezone_set('Asia/Brunei');

include('link3.php');
$date = date('Y-m-d');
$time = date('H:i:s');
echo "
<form method=post action='http://www.wauhaha.com/karaoke/buyaction.php' onsubmit='getvalue(c);'>
<table width=1300 >
<tr>
<td>
<table border='1' cellspacing='0' cellpadding='5' bordercolorlight='tan' align=center width=200 >
<tr>
	<th align=center bgcolor=lightblue height=30>Food</th>
	<th align=center bgcolor=lightblue height=30>Price</th>
	<th align=center bgcolor=lightblue height=30>Remain</th>
</tr>";
while($row=mysql_fetch_array($result)){

echo "<tr >
	<td align=center height=30>".$row['ProName']."</td>
	<td align=center height=30>RM".$row['ProPrice']."</td>
	<td align=center height=30>".$row['RQuan']."</td>
</tr>";
}
echo "

</table>
</td>

<td align=center>
	<table align=center >
		<tr>
			<td align=right >Date :</td>
			<td>$date <input type=hidden name=d value=".$date."></td>
		</tr>
		<tr>
			<td align=right >Time :</td>
			<td>$time <input type=hidden name=t value=".$time."></td>
		</tr>
		<tr>
			<td colspan=2 align=center><hr width=300></td>
		</tr>
		<tr>
			<td colspan=2><input type=button name=btn value=Add&nbsp;Item onClick='addrow()'><input type='hidden' id='c' name='c' value=''></td>
		</tr>
		<tr>
			<td colspan=2><table id=activeTable style=border:#000000 solid 1px; cellspacing=0 width=100% cellpadding=0 > 

<tr> 
<td width=100>Product Name</td> 
<td width=100>Quantity</td> 
<td width=100>Unit Price</td> 
<td width=100>Delete</td> 


</tr>

	";
?>
<script language="JavaScript"> 


var a=0;
function getvalue(cv){
	var e = cv;
	e.value = a + 1;
}


function addrow() { 
a++;
if(a<20){
var row = activeTable.insertRow(activeTable.rows.length); 
var col = row.insertCell(0); 
var i = row.rowIndex; 

col.innerHTML = "<input type='text' name=p"+a+" id=p"+a+" size='5' value='' onfocus='passvalue(this.value,"+a+")'>"; 
col = row.insertCell(1); 
col.innerHTML = "<input type='text' name=q"+a+" size='5' value=0>"; 
col = row.insertCell(2); 
col.innerHTML = "<div id=pr"+a+"></div>"; 
col = row.insertCell(3); 

col.innerHTML = '<button onClick="delrow()">Delete</button>'; 

$().ready(function() {
	$("#p"+a+"").autocomplete("find1.php", {
		width: 260,
		matchContains: true,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
});
} 
}
function delrow () { 
var srcName = document.getElementsByTagName("button"); 
var rowIndex = 0; 
for ( i=0;i<srcName.length;i++){ 
if(srcName[i]==event.srcElement) 
rowIndex=i; 
} 
activeTable.deleteRow(rowIndex + 1); 
}

function passvalue(str, z)
{
var p = z;
if (str=="")
  {
  document.getElementById("pr"+p+"").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("pr"+p+"").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getprice1.php?q="+str,true);
xmlhttp.send();
}
</script>
</table>
<tr>
	<td colspan=4 align=center><input type=submit value=Add ></td>
</tr>
</td>
</tr>
</form>
</table>