<?php
include('../include/formValidations.php');
require_once ('classes/tc_calendar.php');
$start = strtotime($_SESSION['supplyDate']);
$d = date("d", $start );
$m = date("m", $start );
$y = date("Y", $start );
$cat = $_SESSION['category'];
$subCat = $_SESSION['subCategory'];

	$productQuery = "SELECT productId, productName FROM nam_products WHERE category ='$cat'  AND isRemoved != '1' ORDER BY productName ASC";
	
	if($subCat != ""){
		$productQuery = "SELECT productId, productName FROM nam_products WHERE category ='$cat' AND subCategory = '$subCat' AND isRemoved != '1' ORDER BY productName ASC";
		
	}
	$arrId = array();
	$arrName = array();
	$productResult = execsql($productQuery);
	$productNum = mysql_num_rows($productResult);
	
	$a = 0;
	while($a < $productNum) {
		$arrId[$a] = mysql_result($productResult, $a, "productId");
		$arrName[$a] = mysql_result($productResult, $a, "productName");
		$a++;
	}
?>
<?php 
if ($_SESSION['category'] == "Direct Materials" ) { ?>
<script type="text/javascript">
    function toggle() {
         document.getElementById('directContainer').style.display = 'block';
	     document.getElementById('dieselContainer').style.display = 'none';       
           }
	 
</script> 
<?php  } ?>



<link rel="stylesheet" type="text/css" href="../css/jquery.autocomplete.css" />
<script type="text/javascript" src="../css/jquery.1.4.2.js"></script>
<script type="text/javascript" src="../css/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<script>
 $(document).ready(function(){
  $("#productName_text").autocomplete("store_autocomplete.php", {
        selectFirst: true
  });
 });
</script>
<script>
function confirmRefresh() {
var okToRefresh = confirm("Do you really want to cancel this entry?");
var url='showAllProducts.php?cat=Tiles and Accessories&productSelect=All&colorSelect=All'
if (okToRefresh)
	{
			window.location=url;
	}
}
</script>
<script language="JavaScript">
  var needToConfirm = true;
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    if (needToConfirm)
      return "You did not finish the wizard./nIf you leave now your data will not be saved.";
  }
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
</script>

<body   onload="toggle();"  >

<form id="form1" name="form1" method="get" action="issueWizbase.php">
  <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" >
      <div id="directContainer">
        <p class="wizard">
          <label class="std">Select what to issue: </label>
            
            <option value=""></option>
      &nbsp;&nbsp;
      <select name="productId" class="wizard3">
        <option value="<?php echo $_SESSION['productId'] ?>" selected="selected"><?php echo $_SESSION['productName'] ?></option>
        <?php
			for ($i = 0 ; $i < count($arrId) ; $i++) {
				echo "<option value=". "\"". $arrId[$i]. "\"" .">" . $arrName[$i] . "</option>";
			}

			?>
      </select>
      <label class="star">
              *</label>
            
        </p>
        </div>
        <p class="wizard"><label class="std">Quantity:&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; </label>
          <input type="text" name="quantityText" id="quantityText" class="wizard2" value="<?php echo $_SESSION['quantity'] ?> " onKeyPress="return numbersonly(this, event)"/>
        
          <label class="star">*</label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <label class="std">Order no:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <input type="text" name="orderText" id="orderText" class="wizard2" value="<?php echo $_SESSION['order'] ?> " onkeyup="ToUpper(this)"/>
        &nbsp;&nbsp;</p>
        <p class="wizard"><label class="std">Date: </label>
          <?php
		$myCalendar = new tc_calendar("supplyDate", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
		$myCalendar->writeScript();
?>
      </p></td>
    </tr>
    <tr>
      <td><table width="590" height="50" align="center" id="tableButtonBar">
          <tr>
            <td width="117"><input type="submit" name="prev_button" id="prev_button" class="imagebutton" value="Prev" onClick=" needToConfirm = false; " /></td>
            <td width="115">&nbsp;</td>
            <td width="99"><span class="wizard">
              <input name="p" type="hidden" id="p" value="2" />
              <input name="s" type="hidden" id="s" value="2" />
            </span></td>
            <td width="125" align="left"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; confirmRefresh();" value="Cancel" /></td>
            <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick=" validate(); needToConfirm = false; " /></td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>
<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  function validate() {
  <?php if ($_SESSION['category']=="Diesel" ) { ?>
	  frmvalidator.addValidation("quantityText","req","Please enter a quantity.");
  <?php } 
  else {  ?>
  frmvalidator.addValidation("productId","req","Please enter a product name.");
  frmvalidator.addValidation("quantityText","req","Please enter a quantity.");
  <?php ;} ?>
  }
  </script>

</body>