<head>
<?php

		
		$table_name = $_SESSION['db_prefix']."_receive_store_lines_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_name.price, $table_name2.unit FROM $table_name, $table_name2 WHERE  user =  '".$_SESSION['username']."' AND ($table_name.store_item_id = $table_name2.store_item_id) ORDER BY item_name "; 
		
		$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/numbers_only.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  
</head>
<?php include('../include/wait.php') ?>
<body onLoad="MM_showHideLayers('wait','','hide'); <?php $i=0; while ($i<$_SESSION['list_no_3']) {?> MM_callJS('priceCalculation<?php echo $i?>()');  <?php  $i++; }?>;" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<div class="page_middle_frame">
<form id="feedbackform" method="post" action="receivingPlatesWizbase.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" height="272" valign="top" ><div class="wizard_frame">
          <?php if ($selected_num!=0) { ?>
          <table width="652" border="0">
            <tr>
              <td height="24">&nbsp;</td>
              <td align="center">&nbsp;</td>
              <td colspan="2" align="right"><span class="label_std">
                <label class="label_std">Exchange rate: <?php echo $rate ?></label>
                </span></td>
            </tr>
            <tr>
              <td height="24"><label class="label_std">Item</label></td>
              <td align="center"><label class="label_std">Price<br>
                  (SAR)</label></td>
              <td align="center">Quantity</td>
              <td align="center"><label class="label_std">Price<br>
                  (BWP)</label></td>
            </tr>
            <?php
$t=0;

while ($t<$selected_num  ) {
	?>
            <tr> 
              <script>
		function priceCalculation<?php echo $t?>()
		{
		
    	var SA_price<?php echo $t?> = document.getElementById('SA_price_text<?php echo $t?>').value;
		   	
        var rand_price<?php echo $t?> =  parseFloat(SA_price<?php echo $t?>);
      					
		var pula_price<?php echo $t?> = ((rand_price<?php echo $t ?> / <?php echo $rate ?>).toFixed(4));
				
	    document.getElementById('BW_price_text<?php echo $t?>').value = pula_price<?php echo $t?>;	
}
</script>
              <?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,volume, bulk_price, unit 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, "unit");
	$a3 = mysql_result($selected_result, $t, "quantity");
	$a5 = mysql_result($name_result, 0, "bulk_price");
}
else
{
	$a1='';
	$a2='';
	$a3='';
	$a4='';
	$a5='';
}

if ($a1!='') { ?>
              <td width="274"><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 ?>"/>
                </label></td>
              <td width="146" align="center"><input name="SA_price_text<?php echo $t?>" type="text" class="text60" id="SA_price_text<?php echo $t?>" onKeyUp="priceCalculation<?php echo $t?>(); "  value="<?php if($_SESSION['SA_price'.$t]=='') { echo $a5; } else { echo $_SESSION['SA_price'.$t];} ?>" onKeyPress="return isNumberKey(event);" onBlur=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();" tabindex=<?php echo  $t+1?>></td>
              <td width="116" 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 ?> " tabindex=<?php echo $t+1+$_SESSION['list_no_3'] ?> autofocus />
                &nbsp;<?php echo $a4 ?></td>
              <td width="98" align="center"><input type="text" name="<?php echo "BW_price_text".$t ?>" id="<?php echo "BW_price_text".$t ?>" onfocus = "this.select();" class="text60"  onkeypress="return numbersonly(this, event)" readonly style="text-align:right; border-style:none; background-color:inherit;" value="<?php echo $a5 ?>" /></td>
              <?php
}
else {
?>
              <?php
}
	   $v++;
	   $t++;
}
?>
            </tr>
            <?php
 
}

?>
          </table>
          <?php }
else {
	echo "<label class='label_std'>No items selected</label>";
}
?>
        </div></td>
    </tr>
    <tr>
      <td valign="bottom"><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" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','receivingPlatesWizbase.php?s=&amp;p=2');return document.MM_returnValue" /></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;  MM_showHideLayers('wait','','show'); 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']+1 ?> /></td>
          </tr>
        </table></td>
    </tr>
  </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>
