<html>
<head>
<title>
Parent Window
</title>

</head>
<body>
<?php
include("connect.php");
$poNo = $_GET['po'];
$result2 = mysql_query("SELECT * FROM purchaseorder WHERE poNo = '$poNo'");

$row2 = mysql_fetch_array($result2);

$supID = $row2['supID'];
$result3 = mysql_query("SELECT * FROM supplier WHERE supID = '$supID'");

$row3 = mysql_fetch_array($result3);

echo "<fieldset style='width:100%'>";
echo "<legend>Purchase Order - $poNo</legend>";
echo "<br/>";
echo "<table width='100%' border='0'>";
echo "<tr>";
echo "<td width='15%'><b>Supplier: </b></td>";
echo "<td colspan='5'>$row3[supName]</td>";

echo "<td width='15%'><b>Purchase Order ID: </b></td>";
echo "<td width='25%'>$poNo</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Address: </b></td>";
echo "<td colspan='5'>$row3[supAddress]</td>";

echo "<td><b>Date: </b></td>";
echo "<td>".$row2["poDate"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Contact No: </b></td>";
echo "<td colspan='5'>".$row3["supPhone"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Email: </b></td>";
echo "<td colspan='5'>".$row3["supEmail"]."</td>";
echo "</tr>";

echo "</table>";
?>

<br/>
<p align="left">
<a href="JavaScript:void(0);" id=addrow name=addrow type=button value=Add onClick="add()";">
<img src="Picture/add.gif" width="35" height="35" alt="Add Row">Add Item</a>
 
<!--<button onClick="test()">test</button>!--> 
</p>

<div id="bookmenu">
<form method="post" name="form" action="updatestock2.php" onsubmit="getvalue(counter);" >
<table id="t1" border="1" width="100%">
<tr bgcolor='black' style='color:white'>
<th width='15%'>ISBN</th>
<th width='40%'>Description</th>
<th width='10%'>Unit Price</th>
<th width='10%'>Quantity</th>
<th width='10%'>Total</th>
<th width='5%'>Del</th>
</TR>


</table>
<table cellpadding="4" border="0" cellspacing="0" bordercolorlight="#006830" bordercolordark="#FFFFFF" width="100%"> 
<tr bgcolor='black' style='color:white'>
<th align="left" width="65%">Total</th>
<th width="10%"><input type='text' name='qtotal' size='9' value='0' readonly></th>
<th align='left' width="10%">RM 
<input type='text' name='total' size='6' value='0.00' readonly>
</th>
<th width="5%"><input type="hidden" id="counter" name="counter" value=""></th>
</tr>

<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" />
<script language="JavaScript"> 
var k=0;
function getvalue(cv){
	var e = cv;
	e.value = k + 1;
}

function add(){ 
k++; 
if(k<10){
var row = t1.insertRow(t1.rows.length); 
var col = row.insertCell(0); 
col.innerHTML = "<td width=15%><div id=ISBN"+k+"><input type=text size=18 readonly></div></td>"; 
col = row.insertCell(1); 
col.innerHTML = "<td width=40%><input type=text size=50 id=description"+k+" name=description"+k+" value='' onfocus='passvalue(this.value,"+k+")'>";
col = row.insertCell(2); 
col.innerHTML = "<td width=10%>RM <input type=text size=6  id=price"+k+" name=price"+k+" value=0 onchange='multiply(quantity"+k+".value, price"+k+".value, subtotal"+k+", total, subtotal"+k+".value, total.value, qtotal, qtotal.value, oldquantity"+k+", oldquantity"+k+".value);'>";
col = row.insertCell(3); 
col.innerHTML = "<td width=10%><input type=text size=10  id=quantity"+k+" name=quantity"+k+" value=0 onchange='multiply(quantity"+k+".value, price"+k+".value, subtotal"+k+", total, subtotal"+k+".value, total.value, qtotal, qtotal.value, oldquantity"+k+", oldquantity"+k+".value);'>"; 
col = row.insertCell(4); 
col.innerHTML = "<td width=10%>RM <input type=text size=6  type='text' id=subtotal"+k+" name=subtotal"+k+" value=0 readonly><input type='hidden' id=oldquantity"+k+" name=oldquantity"+k+" value=0>";
col = row.insertCell(5); 
col.innerHTML = "<td width=5%><a href='JavaScript:void(0)'; type=button value=Delete onclick='deleteRow(this, quantity"+k+".value, total, subtotal"+k+".value, total.value, qtotal, qtotal.value);'><img src=Picture/delete.gif width=25 height=25 border=0 alt=Delete Last Row></a></td>";

$().ready(function() {
	$("#description"+k+"").autocomplete("itemauto.php", {
		width: 260,
		matchContains: true,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
});

}
else{
alert("full");
} 
}
function del(){ 
var c = document.getElementsByName('tt'); 
for(var i=0; i<c.length; i++) 
if(c[i].checked) 
t1.deleteRow(i); 
} 
//onclick='deleteRow(this, quantity"+k+".value, total, subtotal"+k+".value, total.value, qtotal, qtotal.value)
function deleteRow(obj,q,t,l,v,y,h){
	var e = y;
	e.value = parseInt(h) - parseInt(q);
	
	var d = t;
	d.value = ((v-l).toFixed(2));
 
t1.deleteRow(obj.parentElement.parentElement.rowIndex); 
} 
function test(){ 
for(i=0;i<t1.rows.length;i++) alert(t1.rows[i].cells[1].innerHTML); 
}

function passvalue(str, z)
{
var p = z;
if (str=="")
  {
  document.getElementById("ISBN"+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("ISBN"+p+"").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
//onchange='multiply(quantity"+k+".value, price"+k+".value, subtotal"+k+", total, subtotal"+k+".value, total.value, qtotal, qtotal.value, oldquantity"+k+", oldquantity"+k+".value);'>
function multiply(q,p,s,t,l,v,y,a,h,x){
	
	var c = s;
	c.value=((q*p).toFixed(2));
	
	var d = t;
	d.value = ((v-l+(q*p)).toFixed(2));
	
	var e = y;
	e.value = parseInt(a)+parseInt(q)-parseInt(x);
	
	var f = h;
	f.value = q;
}
</SCRIPT> 

<tr>
<?php
echo "<td colspan='6'><center><input type='hidden' name='poNo' value='$poNo'><input type='submit' name='Submit' value='Submit'><input type='hidden' name='poNo' value='$poNo'><input type='submit' name='Cancel' value='Cancel'></center></td>";
?>
</tr>

</table>
</form>
</div>
</body>
</html>