<head>

<?php

		
		$table_name = $_SESSION['db_prefix']."_plates_temp";
		$table_name2 = $_SESSION['db_prefix']."_store_items";
		$selected_query = "SELECT $table_name.store_item_id, $table_name2.store_item_id, $table_name.quantity,  $table_name2.unit FROM $table_name, $table_name2 WHERE  user =  '".$_SESSION['username']."' AND ($table_name.store_item_id = $table_name2.store_item_id)  AND user =  '".$_SESSION['username']."' ORDER BY item_name "; 
		
		$selected_result = mySQL_query($selected_query);
		$selected_num = mysql_num_rows($selected_result);
		$_SESSION['list_no_9'] = $selected_num;
		
		$table_name = $_SESSION['db_prefix']."_captured_jobs";
		$length_query = "SELECT plate_area  FROM $table_name WHERE job_no  = '".$_SESSION['job_no']."' ";
		$length_result = mySQL_query($length_query);
		$plate_area = mysql_result($length_result, 0, "plate_area");
		
		
?>

<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>   
<script>
$(document).ready(function(){
        //iterate through each textboxes and add keyup
        //handler to trigger sum event
        $(".text60").each(function() {
             $(this).keyup(function(){
                calculateSum();
            });
        });

    });
 
    function calculateSum() {
         var sum = 0;
        //iterate through each textboxes and add the values
        $(".text60").each(function() {
             //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                sum += parseFloat(this.value);
            }
         });
        //.toFixed() method will roundoff the final sum to 2 decimal places
        $("#sum").html(sum.toFixed(8));
		
		issued_total1 = (sum.toFixed(8));
		document.getElementById('issued_total1').value =issued_total1;
    }
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>

</head>
<?php include('../include/wait.php') ?>
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<body onLoad="MM_showHideLayers('wait','','hide'); <?php if ($_SESSION['error6']=='yes') {?> alertMessage(1, 'trussesJobWizbase?s=&p=6', 'The issued area and the required area do not match. Please adjust the quantity.');<?php } ?>" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<?php $_SESSION['error6']='no'?>
<div class="page_middle_frame">
<form id="form1" method="get"  >
<table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
        <td width="525" height="264" valign="top" ><div class="wizard_frame">
        <?php if ($selected_num!=0) { ?>
          <table width="663" id="table_resume_wizard3">
          <tr>
          <td height="24"><label class="label_std">Item</label></td>
          <td><label class="label_std">Quantity (no)</label></td>
          <td width="112" align="center"><label class="label_std">Area (m<sup>2</sup>)</label></td>
          <td colspan="2">&nbsp;</td>
          </tr>
  
<?php
$t=0;

while ($t<$selected_num  ) {
	?>
    <tr>
    <?php
	$v=0;
while ($v<1) {
if ($t<$selected_num) {
	$a1 = mysql_result($selected_result, $t, "store_item_id"); 
	$table_name = $_SESSION['db_prefix']."_store_items";
	$name_query = "SELECT item_name, area FROM $table_name WHERE store_item_id = '".$a1."' ";
	$name_result = mySQL_query($name_query);
	$a2 = mysql_result($name_result, 0, "item_name");
	$a3 = mysql_result($selected_result, $t, "quantity");
	$a5 = mysql_result($selected_result, $t, "unit");
	$a4 = mysql_result($name_result, 0, "area");
}
else
{
	$a1='';
	$a2='';
	$a3='';
	$a4='';
	$a5='';
}

if ($a1!='') { ?>

    <td width="170"><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="<?php echo "area".$t ?>" id="<?php echo "area".$t ?>"  value="<?php echo $a4 ?>" />
    </label></td>
    <td width="79">&nbsp;
      <input name="<?php echo "qty_text".$t ?>" type="text" class="text40" id="<?php echo "qty_text".$t ?>" style="text-align:right"  onfocus = "this.select(); " autocomplete="off" tabindex="<?php echo $t+1?>" autofocus
onkeyup=" 
   var textValue1 = document.getElementById('<?php echo "area".$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text".$t ?>').value;
   var textValue3 = ((textValue1 * textValue2).toFixed(8));
   
   document.getElementById('<?php echo 'sub'.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text'.$t ?>').value = textValue3;
   calculateSum(); 
" 
onblur=" 
   var textValue1 = document.getElementById('<?php echo "area".$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text".$t ?>').value;
   var textValue3 = ((textValue1 * textValue2).toFixed(8));
   document.getElementById('<?php echo 'sub'.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text'.$t ?>').value = textValue3;
   calculateSum();
    
" 
onkeypress="return numbersonly(this, event)" value="<?php echo $a3 ?> "/>      &nbsp;</td>
    <td align="right"><label id=<?php echo 'sub'.$t ?> ></label></td>
    <td colspan="2"><input type="text" name="<?php echo 'text'.$t ?>" id="<?php echo 'text'.$t ?>" class='text60' hidden="hidden"/></td>
    <?php
}
else {
?>
<?php
}
	   $v++;
	   $t++;
}
?>
    </tr>
   
  
 <?php
 
}

?>
 <tr>
      <td valign="middle">&nbsp;</td>
      <td valign="middle">&nbsp;</td>
      <td align="right" valign="middle"><label class="txt3"><b><span id="sum"></span></b></label>
        </td>
      <td width="51" valign="middle"><b>&nbsp;m<sup>2</sup></b>&nbsp;&nbsp;</td>
      <td width="229" align="right" valign="middle"><label class="label_std">required area: <?php echo number_format($_SESSION['plate_area'], 8, '.', ',') ?> m<sup>2</sup></label>
        <sup><br>
          <br>
        </sup></td>
    </tr>
 <tr>
   <td valign="bottom">&nbsp;</td>
   <td valign="bottom">&nbsp;</td>
   <td align="right" valign="bottom">&nbsp;</td>
   <td colspan="2" align="right" valign="bottom"><sup>
     <input name="issued_total1"  id="issued_total1" type="text" size="10" readonly  style="border-style:hidden; font-size:9px;" onFocus="document.getElementById('next_button').focus();" tabindex="-1">
   </sup></td>
 </tr>
  
          </table>
          
            <?php }
else {
	echo "<label class='label_std'>No plates 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="lastprev_button" class="imagebutton" value="Prev" tabindex="<?php echo $t+3?>" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','trussesJobWizbase.php?s=&amp;p=5');return document.MM_returnValue" /></td>
                  <td width="115">&nbsp;</td>
                  <td width="99"><span class="wizard">
                    <input name="s" type="hidden" id="s" value="6" />
                    <input name="p" type="hidden" id="p" value="6" />
                  </span></td>
                  <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../production/production_main.php')" value="Cancel" tabindex="<?php echo $t+4?>"/></td>
                  <td width="110" align="right" ><input type="submit" name="next_button" onFocus="check();" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" tabindex="<?php echo $t+2?>"/></td>
                </tr>
              </table></td>
          </tr>
  </table>
  
</form>
</div>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
 
  <?php 
  $i=0;
  while ($i<$_SESSION['list_no_9']) {
  ?>
  frmvalidator.addValidation("qty_text<?php echo $i ?>","req","Not all quantities were entered.");
  <?php
  $i++;
  }
  ?>
  
  
</script>

<?php
   $i=0;
   while ($i<$_SESSION['list_no_9']) { 	   ?>
   <script>
   var textValue1 = document.getElementById('<?php echo "area".$i ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text".$i ?>').value;
   var textValue3 = ((textValue1 * textValue2).toFixed(8));
   document.getElementById('<?php echo 'sub'.$i ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text'.$i ?>').value = textValue3;
   calculateSum();  
   </script>
   <?php
   $i++;
   }
   ?>

</body>