

<?php
   if($_SESSION['s']==1) {
		    $_SESSION['delNoteText'] = $_GET['delNoteText'];
			$_SESSION['complete'] = $_GET['complete_select'];
	
	}
	
	$query = "SELECT delNote FROM sales WHERE  delNote = '". $_SESSION['delNoteText']."' " ;
	$result = mySQL_query($query) or die ("Error in query:   $query . * ". mySQL_error());
	$num = mysql_num_rows($result);
	
	if ($num!=0) { 
	$_SESSION['error']=1;
	$_SESSION['p']=1;
	
	?>
    <script language="javascript" type="text/javascript">
        <!--
		needToConfirm = false;
	 window.location="outWizbase.php?s=0&p=1 ";
        -->
     </script>

<?php	
       }
    else{
    $_SESSION['error']=0;
    $order_no = $_SESSION['orderNo'];
   include ('../include/formValidations.php');
   require_once ('classes/tc_calendar.php');
$d = date("d" );
$m = date("m");
$y = date("Y");
?>


<?php
$orderQuery = "SELECT * FROM orders WHERE orderNo = '". $order_no."'" ;
	$orderResult = mySQL_query($orderQuery) or die ("Error in query:   $Query . * ". mySQL_error());
	$_SESSION['orderNum'] = mysql_num_rows($orderResult);	

?>

<script language="JavaScript" src="gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>  <!--form validation-->
<script type="text/javascript" src="../css/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<script language="javascript" type="text/javascript" >
<!--
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.";
  }
</script>

<script type="text/javascript">
<!-- 
function validate_required(input,alerttxt,maxvalue)
{
with (input)
  {
  if (value>maxvalue)
    {
    alert(alerttxt);
	input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}
//-->
</script>

<body >

<form id="feedbackform" method="GET" onSubmit="mysubmit();return false" action="outWizbase.php">
    <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
          <tr>
            <td width="525" valign="top" ><br />
              <?php
$i=0;
while ($i < $_SESSION['orderNum']) {
	    $d0 = mysql_result($orderResult, $i, "productId");
		   $productQuery = "SELECT productName,price FROM products WHERE productId = $d0 ";
		   $productResult = execsql($productQuery);
		   $d1 = mysql_result($productResult, 0, "productName");
		   $d5 = mysql_result($productResult, 0, "price");
		$d2 = mysql_result($orderResult, $i, "quantity");
	    $d3 = mysql_result($orderResult, $i, "reserved");
		$d4 = $d2-$d3;
		
		
		$_SESSION['ProductIdText'.$i] = $d0;
        $_SESSION['ProductNameText'.$i] = $d1; 
		if ($_SESSION['complete']=='complete') {
		      $_SESSION['QuantityText'.$i] = $d2;
		}
		
?>
              <?php 
if ($d3>0) { ?>
<table width="560" id="tableResume">
                <tr>
    <td width="221"><span class="wizard">
        <b><?php echo $_SESSION['ProductNameText'.$i]; ?></b>
        <input type="hidden" name="ProductIdText<?php echo $i ?>" id="ProductIdText<?php echo $i ?>"  value="<?php echo $d0 ?>" />
        <input type="hidden" name="ProductNameText<?php echo $i ?>" id="ProductNameText<?php echo $i ?>"  value="<?php echo $d1 ?>"  />
        <input type="hidden" name="PriceText<?php echo $i ?>" id="PriceText<?php echo $i ?>" value="<?php echo $d5 ?>"/>
    </span></td>
    <td width="84"><span class="wizard">ordered:&nbsp;</span></td>
    <td width="67" align="right"><span class="wizard"><?php echo $d2 ?></span></td>
    <td width="168">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><span class="wizard">delivered:</span></td>
    <td align="right"><span class="wizard"><?php echo $d4 ?></span></td>
    <td align="right"><?php if ($_SESSION['complete']!="complete") { ?>no delivery:
      <input type="checkbox" name="no_del_checkbox<?php echo $i ?>" id="no_del_checkbox<?php echo $i ?>" 
    onClick="document.getElementById('QuantityText<?php echo $i?>').value='';  document.getElementById('QuantityText<?php echo $i?>').disabled=this.checked;" <?php if ($_SESSION['DeliverCheck'.$i]=='on') { ?>checked="checked" <?php } ?> /><?php } ?></td>
  
 
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><span class="wizard">balance:&nbsp;</span></td>
    <td align="right"><span class="wizard"><?php echo $d3 ?></span></td>
    <td align="right"><span class="wizard">
      or deliver:
          <?php if ($_SESSION['complete']=="complete") { ?>
<input type="hidden" name="QuantityText<?php echo $i?>" id="QuantityText<?php echo $i?>" value="<?php echo $d3 ?>"/><?php echo $d3 ?>
      <?php } else { ?>
      <input name="QuantityText<?php echo $i?>" type="text" class="wizard2" id="QuantityText<?php echo $i?>" onFocus = "this.select();" onKeyPress="return numbersonly(this, event)"
   onBlur="validate_required(QuantityText<?php echo $i?>, 'The delivery amount exceeds the balance, the entry will be cleared. ' +'\n'+ 'Please enter a valid amount.', <?php echo $d3 ?>)" value="<?php echo $_SESSION['QuantityText'.$i] ?>" <?php if ($_SESSION['DeliverCheck'.$i]=='on') { ?> disabled="disabled"  <?php } ?> 
     />
      <?php } ?>
    </span></td>
  </tr>
  <?php 
   $type = "DOUBLE";
   $type2 = "SLATE";
   $pos = strpos($d1,$type);
   $pos2 = strpos($d1,$type2);
   if (($pos === false) AND ($pos2 === false) ) {?>
   
   <input type="hidden" name="BatchCode1Text<?php echo $i?>" id="BatchCode1Text<?php echo $i?>" value=""/>
   <input type="hidden" name="BatchCode2Text<?php echo $i?>" id="BatchCode2Text<?php echo $i?>" value=""/>
      
<?php      
   }
   else {
?>
   <tr>
    <td>Batch codes:</td>
    <td colspan="2"><input type="text" class="wizard2" name="BatchCode1Text<?php echo $i?>" id="BatchCode1Text<?php echo $i?>" onKeyUp="ToUpper(this)" value="<?php echo $_SESSION['BatchCode1Text'.$i] ?>" />      <input type="text" class="wizard2" name="BatchCode2Text<?php echo $i?>" id="BatchCode2Text<?php echo $i ?>" onKeyUp="ToUpper(this)" value="<?php echo $_SESSION['BatchCode2Text'.$i] ?>"/></td>
    <td align="right"></td>
    </tr>
       
  
<?php
}
?>
</table>
<?php } ?><br />


<?php
	$i++;
	}
?>
<table width="557" id="tableResume">
  <tr>
    <td width="221">pallets delivered:
&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="no_pallets_checkbox" id="no_pallets_checkbox" onClick="document.getElementById('pallets_text').value='';  document.getElementById('pallets_text').disabled=this.checked;"   <?php if ($_SESSION['no_pallets']=='on') { ?> checked="checked" <?php } ?> />
no pallets </td>
    <td width="84"><input type="text" class="wizard2" name="pallets_text" id="pallets_text" onKeyUp="ToUpper(this)" value="<?php echo $_SESSION['PalletsText'] ?>" <?php if ($_SESSION['no_pallets'] == 'on') { ?> disabled="disabled" <?php } ?> onKeyPress="return numbersonly(this, event)" /></td>
    <td width="236">&nbsp;</td>
  </tr>
</table>
<br /></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"><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="99">&nbsp;</td>
                  <td width="125"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="javascript:confirmRefresh(); needToConfirm = false;" value="Cancel" /></td>
                  <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; " /></td>
                </tr>
              </table></td>
          </tr>
        </table>
  </table>
  
</form>


<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("feedbackform");
  //var chktestValidator  = new Validator("feedbackform");
  frmvalidator.EnableMsgsTogether();
  <?php 
    if ($_SESSION['complete']!="complete") {
     $a=0;
     while ($a < $_SESSION['orderNum']) { ?>
	    frmvalidator.addValidation("QuantityText<?php echo $a ?>","req","Enter a number or select 'no tiles'.\n",
			"VWZ_NotChecked(document.forms['feedbackform'].elements['no_del_checkbox<?php echo $a ?>'],'no delivery')");					   
	<?php 
	
		$type = "DOUBLE";
        $type2 = "SLATE";
        $pos = strpos($_SESSION['ProductNameText'.$a],$type);
        $pos2 = strpos($_SESSION['ProductNameText'.$a],$type2);
        if (($pos === false) AND ($pos2 === false) ) { } else {?>
		frmvalidator.addValidation("BatchCode1Text<?php echo $a ?>","req","Enter at least one batch code.\n",						   
		   "VWZ_NotChecked(document.forms['feedbackform'].elements['no_del_checkbox<?php echo $a ?>'],'no delivery')");
	<?php 	}
      
    $a++;
    }
	}
    ?>  
 
 frmvalidator.addValidation("pallets_text","req","Enter number of pallets or select no pallets.\n",
        "VWZ_NotChecked(document.forms['feedbackform'].elements['no_pallets_checkbox'],'no pallets')");
  
 </script>

<?php 
	}
	?>
</body>