<?php
include("classes/cporder.php");

if (isset($_POST["Create"]))
{
	$po = new CPorder();
	$po->setFromForm();
	$po->updateDB();
	unset($po);
}
?>
<html>
<head>
<script language="javascript">
function calcTotal(rownum)
{
	var total = document.getElementById('po_qty'+rownum).value * document.getElementById('po_buy'+rownum).value;
	document.getElementById('po_total'+rownum).innerHTML = "&pound;"+total.toFixed(2);
}
function calcITotal(rownum)
{
	var total = document.getElementById('po_qty'+rownum).value * document.getElementById('po_sell'+rownum).value;
	document.getElementById('po_itotal'+rownum).innerHTML = "&pound;"+total.toFixed(2);
}
function calcMarkup(rownum)
{
	var total = (document.getElementById('po_sell'+rownum).value - document.getElementById('po_buy'+rownum).value)/(document.getElementById('po_buy'+rownum).value)*100.0;
	if (!(isNaN(total)))
	{
		document.getElementById('po_markup'+rownum).innerHTML = total.toFixed(0)+"%";
	}
}
function calcItUp(max)
{
	for (var x=1;x<max+1;x++)
	{
		calcTotal(x); calcITotal(x); calcMarkup(x);
	}
}
</script>

<link rel="stylesheet" type="text/css" href="styles/posystem.css" />
</head>
<body>

<form action="editpo.php" method="POST" name="createform" onsubmit="CheckForm();">
<p><h1>Edit / View Purchase Order</h1></p>
<?php

$po = new CPorder();

?>

<?php
	if (isset($_POST["addrow"]))
	{
		$po->displayHead();
		$po->displayRows($_POST["rowplus"]);
	} elseif (isset($_POST["removerow"])) {
		$po->displayHead();
		$po->displayRows($_POST["rowminus"]);
	} elseif (isset($_POST["quickadd"])) {
		$po->displayHead();
		$po->displayRows($_POST["makerows"]);
	} else {
		$po->setFromDB($_POST["ID"]);
	}
?>

<br><br>

<input type="submit" value="Update" name="Create" />

<script language="javascript">calcItUp(<?php echo $po->rows; ?>);</script>

<input type="submit" value="+" name="addrow" />
<input type="hidden" value="<?php echo $po->rows + 1; ?>" name="rowplus" />

<input type="submit" value="-" name="removerow" />
<input type="hidden" value="<?php echo $po->rows - 1; ?>" name="rowminus" /> 
<input type="text" value="10" name="makerows" size="4">
<input type="submit" value="Quick Rows" name="quickadd">
</form>

<?php unset($po); ?>

<?php include("footer.php");?>

<script language="javascript">
function CheckForm()
{
	if (document.getElementById("po_number").value.length != 0)
	{
		createform.submit();
	}
}
</script>

</body>
</html>

syntax highlighted by Code2HTML, v. 0.9.1