<head>
<?php
		$table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
		$selected_query = "SELECT store_item_id, quantity, price FROM $table_name WHERE user =  '".$_SESSION['username']."' ORDER BY class, depth, width, length "; 
		$selected_result = mySQL_query($selected_query);
		$selected_num = mysql_num_rows($selected_result);
		$_SESSION['list_no_3'] = $selected_num;
		
		$table_name = $_SESSION['db_prefix']."_presets";
		$rate_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'Exchange rate'  ";
		$rate_result = mySQL_query($rate_query);
		$rate = mysql_result($rate_result, 0, "preset_value");
		
?>

<!--jscript-->
<script language="JavaScript" src="../jscript/go_to_URL.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
</head>
<?php include('../include/wait.php') ?>

<body onLoad="<?php $i=0; while ($i<$_SESSION['list_no_3']) {?> MM_callJS('priceCalculation<?php echo $i?>()');  <?php  $i++; }?>; MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<div class="page_middle_frame">
<form id="feedbackform" method="POST" action="receivingTimberWizbase.php?p=4&s=3" >
  <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" ><div class="wizard_frame">
          <?php if ($selected_num!=0) { ?>
          <table width="421" border="0">
            <tr>
              <td >&nbsp;</td>
              <td align="center">&nbsp;</td>
            </tr>
            <tr>
              <td ><label class="label_std">Item</label></td>
              <td width="173" align="center"><label class="label_std">Quantity <br />
                  (no)</label></td>
            </tr>
            <?php
$t=0;

while ($t<$_SESSION['list_no_3']  ) {
	?>
            <tr> 
              <script>
		function priceCalculation<?php echo $t?>()
		{
		//Assume form with id="theform"
    	var theForm = document.forms["feedbackform"];
   		 //Get a reference to the TextBox
    	var cub_price<?php echo $t?> = theForm.elements["cub_price_text<?php echo $t?>"];
		var volume<?php echo $t?> = theForm.elements["volume<?php echo $t?>"];
   		var unitPrice<?php echo $t?> = cub_price<?php echo $t?>.value  * volume<?php echo $t?>.value ;
    		//If the textbox is not blank
    	
        unit_price<?php echo $t?> =  parseFloat(unitPrice<?php echo $t?>);
      	
		rand_price<?php echo $t?> = ((unit_price<?php echo $t ?>).toFixed(4));
		
		pula_price<?php echo $t?> = ((unit_price<?php echo $t ?> / <?php echo $rate ?>).toFixed(4));
				
	    document.getElementById('rand_price_text<?php echo $t?>').value = rand_price<?php echo $t?>;
		document.getElementById('pula_price_text<?php echo $t?>').value = pula_price<?php echo $t?>;	
}
</script>
              <?php
	

	$a1 = mysql_result($selected_result, $t, "store_item_id"); 
	$table_name = $_SESSION['db_prefix']."_store_items";
	$name_query = "SELECT item_name,volume, bulk_price FROM $table_name WHERE store_item_id = '".$a1."' ";
	$name_result = mySQL_query($name_query);
	$a2 = mysql_result($name_result, 0, "item_name");
	$a4 = mysql_result($name_result, 0, "volume");
	$a3 = mysql_result($selected_result, $t, "quantity");
	$a5 = mysql_result($name_result, 0, "bulk_price");
?>
              <td width="238" height="30" ><label class="label_std"><?php echo $a2 ?>
                  <input type="hidden" name="<?php echo "store_item_id".$t ?>" id="<?php echo "store_item_id".$t ?>"  value="<?php echo $a1 ?>"/>
                  <input type="hidden" name="volume<?php echo $t?>" id="volume<?php echo $t?>" value="<?php echo $a4 ?>" />
                </label></td>
              <td align="center"><input type="text" name="<?php echo "qty_text".$t ?>" id="<?php echo "qty_text".$t ?>" onfocus = "this.select();" class="text60"  onkeypress="return numbersonly(this, event)" style="text-align:right" value="<?php echo $a3 ?> " autofocus tabindex=<?php echo $t+1+$_SESSION['list_no_3'] ?> /></td>
              <?php

  $t++;
}

?>
            </tr>
          </table>
          <?php }
else {
	echo "<label class='label_std'>No timber selected</label>";
}
?>
      </div></td>
    </tr>
    <tr>
      <td><table width="675" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117"><input type="button" name="prev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_goToURL('parent','receivingTimberWizbase.php?s=&p=2');return document.MM_returnValue" MM_showHideLayers('wait','','show');/></td>
            <td width="115">&nbsp;</td>
            <td width="99"><span class="wizard">
              <input name="s" type="hidden" id="s" value="3" />
              <input name="p" type="hidden" id="p" value="3" />
              </span></td>
            <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../store/store_main.php');" value="Cancel" /></td>
            <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" tabindex=<?php echo $t+1+$_SESSION['list_no_3'] ?>/></td>
          </tr>
        </table></td>
    </tr>
  </table>
  </table>
</form>
</div>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("feedbackform");
  frmvalidator.EnableMsgsTogether();
  <?php 
  $i=0;
  while ($i<$selected_num) {
  ?>
  frmvalidator.addValidation("qty_text<?php echo $i ?>","req","Not all quantities were entered.");
  <?php
  $i=100;
  }
  ?>
  
  
</script>
</body>
