<?php
session_start();
include ("connect.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<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 type="text/javascript">

</script>
</head>
<body style="background-color: #ffffff;background-image:url(rail.jpg);background-repeat: repeat-y">

<center><a href="stock.php" ><img src=back.jpg width=50 height=50></a></center>
<center><h1><u>Purchase Order Form</u><h1></center>


<?php
$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
mysql_selectDB("wauhaha_karaoke",$login);
$SupID = $_GET['SupID'];
$result6 = mysql_query("select * from supplier where SupID='$SupID'");	
$time = date('Y-m-d');
$row3=mysql_fetch_array($result6);
$ProID= $row3['ProID'];
echo "<form  method='post'  action=http://www.wauhaha.com/karaoke/addnewstockaction.php?SupID=$SupID onsubmit='getvalue(c);'>

<br>
<h2>Company Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:".$row3['SupName']."</h2>
<h2>Company Address :".$row3['SupAdd']."</h2>
<h2>Company Phone &nbsp;&nbsp;&nbsp;:".$row3['SupContact']."</h2>
<h2>Company HPhone :".$row3['SupHp']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date:&nbsp;&nbsp;&nbsp;$time<input type=hidden name=time value=".$time.">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h2>
<hr>";
echo "<input type=button name=btn value=Add&nbsp;Item onClick='addrow()'> 
<table id=activeTable style=border:#000000 solid 1px; cellspacing=0 width=100% cellpadding=0 > 

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

</tr>

<input type='hidden' id='c' name='c' value=''>
</table> 
<table>
<tr>
	<td width=300></td>
	<td width=300></td>
	<td  width=300 align=right><b>Total</b></td>
	<td width=300 align=left> RM<input type=text name=total size=5 readonly></td>
	<td width=300></td>
</tr></table>";
?>
<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=pr"+a+" id=pr"+a+" value=0  size=5 onchange='multiply(q"+a+".value,pr"+a+".value,t"+a+",total,t"+a+".value,total.value,oldquantity"+a+",oldquantity"+a+".value)'>"; 
col = row.insertCell(2); 
col.innerHTML = "<input type='text' name=q"+a+" id=q"+a+" size='5' value=0 onchange='multiply(q"+a+".value,pr"+a+".value,t"+a+",total,t"+a+".value,total.value,oldquantity"+a+",oldquantity"+a+".value)'>"; 
col = row.insertCell(3);
col.innerHTML = "RM<input type='text' name=t"+a+" id=t"+a+" size='5' value=0 readonly><input type='hidden' id=oldquantity"+a+" name=oldquantity"+a+" value=0>"; 
col = row.insertCell(4); 
//col.innerHTML = "<a href='#'; type=button value=Delete onclick='delrow(this, total, t"+a+".value, total.value);'>Delete</a>";
col.innerHTML = "<button href='#' onClick='delrow(this, total, t"+a+".value, total.value);'>Delete</button>"; 

$().ready(function() {
	$("#p"+a+"").autocomplete("find.php", {
		width: 260,
		matchContains: true,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
});
} 
}
function delrow (obj,formtotal,subtotal,totalvalue) { 
var srcName = document.getElementsByTagName("button"); 
var rowIndex = 0; 
for ( i=0;i<srcName.length;i++){ 
if(srcName[i]==event.srcElement) 
rowIndex=i; 
}
	var d = formtotal;
	d.value = ((totalvalue-subtotal).toFixed(2));
 
activeTable.deleteRow(obj.parentElement.parentElement.rowIndex); 

//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","getprice.php?q="+str,true);
xmlhttp.send();
}
</script>
<script language="javascript" type="text/javascript">
//multiply(q"+a+".value,pr"+a+".value,t"+a+",total,t"+a+".value,total.value,oldquantity"+a+",oldquantity"+a+".value)'>
	function multiply(q,p,s,t,l,v,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><input type=submit value=Submit style='width:60;height:60'></center>
 </form>