<?php
?>
<html> 
<head> 
<title>Purchase Order</title> 
</head> 
<body bgcolor="lightyellow" text="000000" link="000000" vlink="000000" alink="000000"> 
<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"> 

function addrow() 
{


var row = Table1.insertRow(Table1.rows.length); 
var col = row.insertCell(0);
var k = row.rowIndex;
if(row.rowIndex<10){ 
col.innerHTML = ""+k+""; 
col = row.insertCell(1); 
col.innerHTML = "<div id=ISBN"+k+"></div>"; 
col = row.insertCell(2); 
col.innerHTML = "<input type=text size=70 id=description"+k+" name=description"+k+" value='' onfocus='passvalue(this.value,"+k+")'>";
col = row.insertCell(3); 
col.innerHTML = "<input type=text size=10  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(4); 
col.innerHTML = "<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(5); 
col.innerHTML = "<input type=text size=10  type='text' id=subtotal"+k+" name=subtotal"+k+" value=0><input type='hidden' id=oldquantity"+k+" name=oldquantity"+k+" value=0>";
col = row.insertCell(6); 
col.innerHTML = "<button onClick='delrow()'>Del</button>"; 

$().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 delrow () { 
var srcName = document.getElementsByTagName("button"); 
var rowIndex = 0; 
for ( k=0;k<srcName.length;k++){ 
if(srcName[k]==event.srcElement) 
rowIndex=k; 
} 
Table1.deleteRow(rowIndex + 1); 
} 

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();
}

//function passvalue(str){

//k.value = str;
//}



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> 

<CENTER> 
<form name='poform' id='Form1' method='post' action='updatestock.php'>

<input type="button" name="btn" value="Ìí¼ÓÒ»ÐÐ" onClick="addrow()"> 
<INPUT id=DelOneLine name=DelOneLine type=button value=Delete LANGUAGE=javascript onclick="return delrow()"> 
</P>

<div id="bookmenu">
<TABLE id=Table1 border="1" cellpadding="4" cellspacing="0" bordercolorlight="#006830" bordercolordark="#FFFFFF" width="70%"> 
<tr bgcolor='black' style='color:white'>
<th width='5%' nowrap>No</th>
<th width='15%' nowrap>ISBN</th>
<th width='40%' nowrap>Description</th>
<th width='10%' nowrap>Unit Price</th>
<th width='10%' nowrap>Quantity</th>
<th width='10%' nowrap>Total</th>
</TR>

<table>
</tr>
</FORM>
</table>
<table cellpadding="4" cellspacing="0" bordercolorlight="#006830" bordercolordark="#FFFFFF" width="70%"> 
<tr bgcolor='black' style='color:white'>
<th align="left" width="70%">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>
</tr>
</table>
</div>