<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

							
$querysetup="select base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}


$QPurId     = $_POST['QPurId']; if ($QPurId == ""){$QPurId = $_GET["QPurId"];}
$QPurDtId   = $_POST['QPurDtId']; if ($QPurDtId == ""){$QPurDtId = $_GET["QPurDtId"];}
$QItemCode  = $_POST['QItemCode']; if ($QItemCode == ""){$QItemCode = $_GET["QItemCode"];}
$QItemQty   = $_POST['QItemQty']; if ($QItemQty == ""){$QItemQty = $_GET["QItemQty"];}
$QRemainQty = $_POST['QRemainQty']; if ($QRemainQty == ""){$QRemainQty = $_GET["QRemainQty"];}


print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Item Quantity</title>
<script type="text/javascript" language="javascript">

function ClearForm()
{
  x=document.purchaseqty;
  x.QItemQty.value='';
  x.action='Form_PurchaseEditQty.php';
  x.submit();

}


function SubmitForm() {
	x=document.purchaseqty;
	
	var ItemQty = x.QItemQty.value;
	var PurDtId = x.QPurDtId.value;
	var PurId   = x.QPurId.value;
	var PurDtRemQty = x.QRemainQty.value;
	
	ItemQty = parseInt(ItemQty);
	PurDtRemQty = parseInt(PurDtRemQty);

	if (ItemQty == '' || ItemQty*1 != ItemQty/1 || ItemQty <= 0){
		alert('Quantity should be a NUMERIC value and MORE THAN Zero');
		x.QItemQty.focus();
	}
	else if (PurDtRemQty != '' && ItemQty > PurDtRemQty ) {
		alert('Quantity entered not allowed. Qty must be <= Remaining Ordered Qty ['+PurDtRemQty+'].');
		x.QItemQty.focus();
	}
	else 
	{
		x.action="Form_Purchase_Actions.php?mode=editqty&SPurId="+PurId+"&SPurDtId="+PurDtId;
		x.submit();
		
		opener.document.purchase.txtPurId.value = PurId;
		//opener.document.purchase.mainaction.value='edit';
		//opener.document.purchase.actionmode.value='';
		opener.document.purchase.action='Form_Purchase.php';
		opener.document.purchase.submit();
		self.close();
	
	
	}

}






</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>

</head>
<body>
<form name='purchaseqty' method='post' action=''>
		    
HERE;




echo"<table border='0' style='table-layout:fixed' align='center'>
	  <col width=120>
	  <col width=200>
		     
	  <tr bgcolor='#F7F7F7'>
	    <td align='center' colspan='2'><span class='style16'>Item $QItemCode</span></td></tr>
	  <tr bgcolor='#F7F7F7'>
		<td height='15' align='center' colspan='2'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>		
	  <tr bgcolor='#F7F7F7'>
	    <td align='left' ><span class='style11'>Enter Quantity</span></td>
		<td align='left' ><span class='style11'>
			<input type='text' name='QItemQty' id='QItemQty' value='$QItemQty' size='20' maxlength='40'/>
			<input type='hidden' name='QItemCode' id='QItemCode' value='$QItemCode' size='20' maxlength='40'/>
			<input type='hidden' name='QPurId' id='QPurId' value='$QPurId' size='10' maxlength='40'/>
			<input type='hidden' name='QPurDtId' id='QPurDtId' value='$QPurDtId' size='10' maxlength='40'/>
			<input type='hidden' name='QRemainQty' value='$QRemainQty' >
			</span></td> 
			
	  </tr>
	  <tr bgcolor='#DDDDDD' height='35'>
		<td align='center' colspan='2'><span class='style11'><input type='button' name='btnSubmit' value='Submit' onclick='SubmitForm();' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
						  <input type='button' name='btnCancel' value='Cancel' onclick='ClearForm();' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></span></td> 
	  </tr>	
  
	</table>";
	


          

		  

print <<<HERE
</form>
</body>

HERE;



?>