<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<link rel="stylesheet" href="../css/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../css/modal.css" type="text/css" />
<link href="../css/wait.css" rel="stylesheet" type="text/css">

<!--jscript-->
<script type="text/javascript" src="../css/modal.js"></script>
<script type="text/javascript" src="../css/dhtmlwindow.js"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></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>

<?php
include ("../navigation/header.php");
$page_name = "Production-edit quote";
include ("../navigation/access.php");

$save_message=$_GET['save_message'];

if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");

$job_no = $_GET['job_no'];
$_SESSION['edit_start'] = $_GET['edit'];
$screen= $_GET['screen'];
$sub_category=$_GET['sub_category'];
$quote='no';

if ($_SESSION['edit_start']==0) {
		$table_name = $_SESSION['db_prefix']."_captured_mitek_edit_temp";
		$delete_query = "DELETE FROM $table_name WHERE cap_job='".$job_no."' "; 
		execsql($delete_query);
		
		$table_name = $_SESSION['db_prefix']."_captured_timber_edit_temp";
		$delete_query = "DELETE FROM $table_name WHERE cap_job='".$job_no."' "; 
		execsql($delete_query);

		$table_name = $_SESSION['db_prefix']."_captured_sundries_edit_temp";
		$delete_query = "DELETE FROM $table_name WHERE cap_job='".$job_no."' "; 
		execsql($delete_query);
}

$table_name = $_SESSION['db_prefix']."_captured_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_no = '".$job_no."' ";
$job_result = mySQL_query($job_query);
$cust_id = mysql_result($job_result, 0, "cust_id");	

if ($sub_category=='Timber') {
	$file_open = '../edit_windows/captured_edit_add_timber.php?job_no='.$job_no;
}


if (($sub_category=='Mitek') OR ($sub_category=='Sundries')) {
	$file_open = '../edit_windows/captured_edit_add.php?category=Direct materials&sub_category='.$sub_category.'&job_no='.$job_no;
}

if ($sub_category=='Bracing')  {
	$file_open = '../edit_windows/captured_edit_add_bracing.php?cat=Bracing&show=0&bracing_select=&job_no='.$job_no;
}

if ($sub_category=='Sundries2')  {
	$file_open = '../edit_windows/captured_edit_add_bracing.php?cat=Sundries&show=0&bracing_select=&job_no='.$job_no;
}
?>




<?php
$table_name = $_SESSION['db_prefix']."_captured_jobs";
$cust_id_query = "SELECT cust_id, designer, press_points, plate_area FROM $table_name WHERE job_no = '".$job_no."' ";
$cust_id_result = mySQL_query($cust_id_query);
$cust_id = mysql_result($cust_id_result, 0, "cust_id");
$designer = mysql_result($cust_id_result, 0, "designer");
$press_points = mysql_result($cust_id_result, 0, "press_points");
$plate_area = mysql_result($cust_id_result, 0, "plate_area");

$table_name = $_SESSION['db_prefix']."_customer";
$name_query = "SELECT comp_name FROM $table_name WHERE cust_id = '".$cust_id."' ";
$name_result = mySQL_query($name_query);
$name = mysql_result($name_result, 0, "comp_name");

$table_name = $_SESSION['db_prefix']."_captured_timber";
$timber5_check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_class = 'S5'  ";
$timber5_check_result = mySQL_query($timber5_check_query);
$timber5_check_num = mysql_num_rows($timber5_check_result);
		
if ($timber5_check_num>0) {
		$table_nameS5 = $_SESSION['db_prefix']."_captured_timber";
	}
else {
	$table_nameS5 = $_SESSION['db_prefix']."_captured_timber_done";
}
$timber_query = "SELECT cap_timber_id, cap_timber_name, cap_timber_length FROM $table_nameS5 WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_class = 'S5'  ";
$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);


$table_name = $_SESSION['db_prefix']."_captured_timber";
$timber7_check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_class = 'S7'  ";
$timber7_check_result = mySQL_query($timber7_check_query);
$timber7_check_num = mysql_num_rows($timber7_check_result);
		
if ($timber7_check_num>0) {
		$table_nameS7 = $_SESSION['db_prefix']."_captured_timber";
	}
else {
	$table_nameS7 = $_SESSION['db_prefix']."_captured_timber_done";
}
$timber2_query = "SELECT cap_timber_id, cap_timber_name, cap_timber_length FROM $table_nameS7 WHERE cap_timber_group = 'Trusses' and cap_job = '".$job_no."' AND cap_class = 'S7' ";
$timber2_result = mySQL_query($timber2_query);
$timber2_num = mysql_num_rows($timber2_result);

$table_name = $_SESSION['db_prefix']."_captured_mitek";
$mitek_check_query = "SELECT cap_mitek_id FROM $table_name WHERE cap_job = '".$job_no."'  ";
$mitek_check_result = mySQL_query($mitek_check_query);
$mitek_check_num = mysql_num_rows($mitek_check_result);

if ($mitek_check_num>0) {
$table_name = $_SESSION['db_prefix']."_captured_mitek";
}
else {
$table_name = $_SESSION['db_prefix']."_captured_mitek_done";
}
$table_name2 = $_SESSION['db_prefix']."_captured_mitek_edit_temp";
$mitek_query = "SELECT cap_mitek_id, cap_item_id,cap_quantity, auth_quantity FROM $table_name WHERE cap_job = '".$job_no."' UNION ALL SELECT cap_mitek_id, cap_item_id,cap_quantity, auth_quantity FROM $table_name2 WHERE cap_job = '".$job_no."' ";
$mitek_result = mySQL_query($mitek_query);
$mitek_num = mysql_num_rows($mitek_result);

$table_name = $_SESSION['db_prefix']."_captured_timber";
$bracing_check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_job = '".$job_no."' AND cap_timber_group = 'Bracing' ";
$bracing_check_result = mySQL_query($bracing_check_query);
$bracing_check_num = mysql_num_rows($bracing_check_result);
		
if ($bracing_check_num>0) {
		$table_name = $_SESSION['db_prefix']."_captured_timber";
	}
else {
	$table_name = $_SESSION['db_prefix']."_captured_timber_done";
}
$table_name2 = $_SESSION['db_prefix']."_captured_timber_edit_temp";
$bracing_query = "SELECT cap_timber_id, cap_timber_name, cap_timber_length FROM $table_name WHERE cap_timber_group = 'Bracing' AND cap_job = '".$job_no."' GROUP BY cap_timber_name UNION SELECT cap_timber_id, cap_timber_name, cap_timber_length FROM $table_name2 WHERE cap_timber_group = 'Bracing' AND cap_job = '".$job_no."'  GROUP BY cap_timber_name";
$bracing_result = mySQL_query($bracing_query);
$bracing_num = mysql_num_rows($bracing_result);

$table_name = $_SESSION['db_prefix']."_captured_timber";
$sundries_check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_job = '".$job_no."' AND cap_timber_group = 'Sundries' ";
$sundries_check_result = mySQL_query($sundries_check_query);
$sundries_check_num = mysql_num_rows($sundries_check_result);
		
if ($sundries_check_num>0) {
		$table_name = $_SESSION['db_prefix']."_captured_timber";
	}
else {
	$table_name = $_SESSION['db_prefix']."_captured_timber_done";
}
$table_name2 = $_SESSION['db_prefix']."_captured_timber_edit_temp";
$sundries_query = "SELECT cap_timber_id, cap_timber_name, cap_timber_length FROM $table_name WHERE cap_timber_group = 'Sundries' AND cap_job = '".$job_no."' GROUP BY cap_timber_name UNION SELECT cap_timber_id, cap_timber_name, cap_timber_length FROM $table_name2 WHERE cap_timber_group = 'Sundries' AND cap_job = '".$job_no."'  GROUP BY cap_timber_name";
$sundries_result = mySQL_query($sundries_query);
$sundries_num = mysql_num_rows($sundries_result);


$table_name = $_SESSION['db_prefix']."_captured_sundries";
$additional_check_query = "SELECT cap_sundries_id FROM $table_name WHERE cap_job = '".$job_no."'  ";
$additional_check_result = mySQL_query($additional_check_query);
$additional_check_num = mysql_num_rows($additional_check_result);
		
if ($additional_check_num>0) {
		$table_name = $_SESSION['db_prefix']."_captured_sundries";
	}
else {
	$table_name = $_SESSION['db_prefix']."_captured_sundries_done";
}
$table_name2 = $_SESSION['db_prefix']."_captured_sundries_edit_temp";
$additional_query = "SELECT * FROM $table_name WHERE cap_job = '".$job_no."' UNION ALL SELECT * FROM $table_name2 WHERE cap_job = '".$job_no."' ";
$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_result);


if ($sub_category=='Timber') {
	  $height='350px';
	  $width='400px';
}
else {
	  $height='220px';
	  $width='500px';
}
?>
<?php include ('../include/wait.php'); ?>

</head>


<body onload="<?php if ($screen==1) { ?> editwindow=dhtmlmodal.open('editBox', 'iframe', '<?php echo $file_open ?>', 'Add item', 'width=<?php echo $width ?>,height=<?php echo $height ?>,center=1,resize=0,scrolling=0')
needToConfirm = false; editwindow.onclose=function(){return window}; return false;<?php } ?>; MM_showHideLayers('wait','','hide') " >

<?php if ($save_message==1) { ?>
    <script>alertMessage(1, '', 'Item added to the list, you still need to save the list.');</script>
    <?php
	$save_message=0; } ?>


<div class="main_frame" style="height:auto;">
  <table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="62" valign="top" ><div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="472"><label class="label_page_head">Edit Job Capturing:</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $name ?></label></td>
            <td width="208"><label style="font-size:24px; color:#FB6808;"><?php echo "J".$job_no ?></label></td>
            </tr>
        </table>
      </div>
        <br />

<br /></td> <!--center of tableMain-->
</tr>
<tr>
<td height="93"> <!--center of tableMain-->
<div class="page_middle_frame">
<?php 
		include ('../include/customer_block.php');
		echo '<br>';
		include ('../include/job_block.php')
		?>
</div><br />
<br />
<br />
<br />
<br />
<br />
<form name="form1" id="form1" action="captured_edit_save.php" method="POST">
<div class="page_middle_frame">
<div style="float:left">
<table width="666" align="left" id="table_details_display" cellpadding="0"> 
				<tr  style="background-color:#FFF;">
				  <th height="22" colspan="5" align="left"><label class="label_std">Trusses:</label></th>
			  </tr>
				<tr  style="background-color:#FFF;">
      			<th height="22" align="left">Timber Class</th>
      			<th width="103" align="left">&nbsp;</th>
      			<th width="149" align="left">&nbsp;&nbsp;&nbsp;Timber</th>
      			<th width="77" align="center">Length</th>
      			<th width="59" align="center">Unit</th>
     			</tr>
              <tr>
                <?php
				$tot_5=0;
				
				$class5_query = "SELECT cap_timber_id, cap_timber, cap_timber_length FROM $table_nameS5 WHERE cap_class='S5' AND cap_job = '".$job_no."' AND cap_timber_name='Trusses'  ORDER BY cap_depth, cap_width ";
				$class5_result = mySQL_query($class5_query);
				$class5_num = mysql_num_rows($class5_result);
				
				
				$class5_tot_query = "SELECT SUM(cap_timber_length) AS tot_5 FROM $table_nameS5 WHERE cap_class='S5' AND cap_job = '".$job_no."' AND cap_timber_name='Trusses'";
				$class5_tot_result = mySQL_query($class5_tot_query);
				$tot_5 = mysql_result($class5_tot_result, 0, "tot_5"); 
				
                $i=0;
				
				?>
                <td width="96" align="left" valign="top"><label class="label_std">Class 5  </label></td>
                <td colspan="4" align="right" valign="top"><table width="527" align="left" id="table_details_display" style="border-top:hidden; border-bottom:hidden;">
                  <?php
				
				while ($i<$class5_num) {
					
				   $_SESSION['s5_cap_timber'.$i] = mysql_result($class5_result, $i, "cap_timber");
				   $_SESSION['edit_class5_quantity_'.$i] = mysql_result($class5_result, $i, "cap_timber_length");	 
				   											
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_class5_quantity_'.$i] =  mysql_result($class5_result, $i, "cap_timber_length");						
						}
												
				   	
				?>
                  <tr>
                    <td width="350" style="border-left:hidden;"><?php echo $_SESSION['s5_cap_timber'.$i] ?>&nbsp;</td>
                    <td width="132" align="right"><input name="class5_edit<?php echo $i?>" type="text" class="text60" id="class5_edit<?php echo $i?>" value="<?php echo $_SESSION['edit_class5_quantity_'.$i] ?>" onfocus = "this.select();" style="text-align:right;" onKeyPress="return isNumberKey(event)"; onchange=" this.value = this.value.replace (/(\...).*/, '$1')" autocomplete="off"/>                      &nbsp;</td>
                    <td width="29" style="border-right:hidden;">&nbsp;m</td>
                    </tr>
                  <?php
				  $i++;
				}
				  ?>
                 <input name="class5_num" type="hidden" value="<?php echo $class5_num ?>" /> 
                </table>                </td>
              </tr>
              
              <tr>
                <?php
				
				$class7_query = "SELECT cap_timber, cap_timber_length FROM $table_nameS7 WHERE cap_class='S7' AND cap_job = '".$job_no."' AND cap_timber_name='Trusses'  ORDER BY cap_depth, cap_width ";
				$class7_result = mySQL_query($class7_query);
				$class7_num = mysql_num_rows($class7_result);
				
				
				$class7_tot_query = "SELECT SUM(cap_timber_length) AS tot_7 FROM $table_nameS7 WHERE cap_class='S7' AND cap_job = '".$job_no."' AND cap_timber_name='Trusses'";
				$class7_tot_result = mySQL_query($class7_tot_query);
				$tot_7 = mysql_result($class7_tot_result, 0, "tot_7"); 
				?>
                <td align="left" valign="top"><label class="label_std">Class 7</label></td>
                <td colspan="4" align="left" valign="top"><table width="530" id="table_details_display" style="border-top:hidden; border-bottom:hidden;">
                  <?php
								
                $i=0;
				while ($i<$class7_num) {
				   $_SESSION['s7_cap_timber'.$i] = mysql_result($class7_result, $i, "cap_timber");
				   $_SESSION['edit_class7_quantity_'.$i] = mysql_result($class7_result, $i, "cap_timber_length");	 
				  						
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_class7_quantity_'.$i] =  mysql_result($class7_result, $i, "cap_timber_length");						
						}
						
						
				?>
                  <tr>
                    <td width="350" style="border-left:hidden;"><?php echo $_SESSION['s7_cap_timber'.$i] ?>&nbsp;</td>
                    <td width="132" align="right"><input name="class7_edit<?php echo $i?>" type="text" class="text60" id="class7_edit<?php echo $i?>" value="<?php echo $_SESSION['edit_class7_quantity_'.$i] ?>" onfocus = "this.select();" style="text-align:right; " onKeyPress="return isNumberKey(event)" onchange=" this.value = this.value.replace (/(\...).*/, '$1')" autocomplete="off"/>                      &nbsp;</td>
                    <td width="32" style="border-right:hidden;">&nbsp;m</td>
                    </tr>
                  <?php
				  $i++;
				}
				  ?>
                  <input name="class7_num" type="hidden" value="<?php echo $class7_num ?>" /> 
                </table>                </td>
              </tr>
                </table><br />
                <input name="timber_button" type="submit" class="imagebutton" id="timber_button" value="Add timber" onclick=" needToConfirm = false; this.form.action='captured_edit_temp_save.php';MM_showHideLayers('wait','','show')"/>
</div>


<div style="float:left"><br />

<?php

if ($_SESSION['edit_start']==0) {
						$_SESSION['press_points'] =  $press_points;	
						$_SESSION['plate_area'] =  $plate_area;						
						}
						
						?>

  <table width="669" id="table_details_display" > 
              <tr>
                <td width="462" align="left" valign="top"><label class="label_std">FT and plate area:</label></td>
                <td colspan="2" align="left" valign="top"><label class="label_std">Edit quoted </label></td>
              </tr>
              <tr>
                <td align="left" valign="top">Number of FT:</td>
                <td width="131" align="right" valign="top"><input name="press_points_edit" type="text" class="text60" id="press_points_edit" value="<?php echo $_SESSION['press_points'] ?>" onfocus = "this.select();" style="text-align:right; " onkeypress="return numbersonly(this, event)" autocomplete="off"/></td>
                <td width="60" align="center" valign="top">no</td>
              </tr>
              <tr>
                <td align="left" valign="top">Estimated plate area:</td>
                <td align="right" valign="top"><input name="plate_area_edit" type="text" class="text60" id="plate_area_edit" value="<?php echo number_format($_SESSION['plate_area'], 3, '.', ',')?>" onfocus = "this.select();" style="text-align:right; " onKeyPress="return isNumberKey(event)" onchange=" this.value = this.value.replace (/(\....).*/, '$1')" autocomplete="off"/></td>
                <td align="center" valign="top">m<sup>2</sup></td>
              </tr>
              
             <input name="mitek_num" type="hidden" value="<?php echo $i;?>" />
            </table>              
</div>
</div>

   <div class="page_middle_frame">
 <table width="669" id="table_details_display" > 
              <tr>
                <td align="left" valign="top"><label class="label_std">Mitek products:<a name="mitek" id="mitek"></a></label></td>
                <td colspan="2" align="left" valign="top"><label class="label_std">Edit quoted </label>
                                  <input name="edit_job_no" type="hidden" value="<?php echo $job_no?>" /></td>
              </tr>
              <?php 
				  $i=0;
				   while ($i<$mitek_num) { 
					    $_SESSION['edit_mitek_line'.$i] = mysql_result($mitek_result, $i, "cap_mitek_id");
					    $_SESSION['edit_mitek_item_id'.$i] = mysql_result($mitek_result, $i, "cap_item_id");
												
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_mitek_quantity_'.$i] =  mysql_result($mitek_result, $i, "cap_quantity");						
						}
						
						if ($_SESSION['edit_mitek_line'.$i]=='0') {
							     $_SESSION['edit_mitek_quantity_'.$i] = mysql_result($mitek_result, $i, "cap_quantity");
						}
												
						$quantity = mysql_result($mitek_result, $i, "cap_quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$_SESSION['edit_mitek_item_id'.$i]."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
	
				 ?>
             <tr>
               <td width="465"><?php echo $item_name ?><input name="cap_item_id<?php echo $i?>" id="cap_item_id<?php echo $i?>" type="hidden" value="<?php echo $_SESSION['edit_mitek_item_id'.$i] ?>" /></td>
               <td width="130" align="right"><input name="mitek_edit<?php echo $i?>" type="text" class="text60" id="mitek_edit<?php echo $i?>" value="<?php echo $_SESSION['edit_mitek_quantity_'.$i] ?>" onfocus = "this.select();" style="text-align:right; " onkeypress="return numbersonly(this, event)" autocomplete="off"/></td>
               <td width="58" align="center"><?php echo $unit?></td>
             </tr>
              <?php
						
			  $i++;
             }
			 ?>
             <input name="mitek_num" type="hidden" value="<?php echo $i;?>" />
            </table>

   <input name="mitek_button" type="submit" class="imagebutton" id="mitek_button" value="Add Mitek product" onclick=" needToConfirm = false; this.form.action='captured_edit_temp_save.php'; MM_showHideLayers('wait','','show');"/>
 <input name="mitek_num" id="mitek_num" type="hidden" value="<?php echo $mitek_num?>" />
          </div>
   <div class="page_middle_frame">
     <table width="669" id="table_details_display" >
       <tr>
         <td align="left" valign="top"><label class="label_std">Bracing:<a name="bracing" id="bracing"></a></label></td>
         <td colspan="2" align="left" valign="top"><label class="label_std">Edit quoted </label>
           <input name="edit_job_no2" type="hidden" value="<?php echo $job_no?>" /></td>
       </tr>
       <?php 
				  $i=0;
				   while ($i<$bracing_num) { 
					    $_SESSION['edit_bracing_line'.$i] = mysql_result($bracing_result, $i, "cap_timber_id");
					    //$_SESSION['edit_bracing_item_id'.$i] = mysql_result($mitek_result, $i, "cap_item_id");
						$_SESSION['edit_bracing_name'.$i] = mysql_result($bracing_result, $i, "cap_timber_name");						
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_bracing_quantity_'.$i] =  mysql_result($bracing_result, $i, "cap_timber_length");	
//						if ($_SESSION['edit_mitek_quantity_'.$i]=='') {
//						       $_SESSION['edit_mitek_quantity_'.$i] = mysql_result($mitek_result, $i, "cap_quantity");
//						}
//						if ($_SESSION['edit_mitek_quantity_'.$i]=='0') {
//						       $_SESSION['edit_mitek_quantity_'.$i] = mysql_result($mitek_result, $i, "auth_quantity");
//						}
						}
						
						if ($_SESSION['edit_bracing_line'.$i]=='0') {
							  
							     $_SESSION['edit_bracing_quantity_'.$i] = mysql_result($bracing_result, $i, "cap_timber_length");
						}
												
						//$quantity = mysql_result($mitek_result, $i, "cap_quantity");
						//$table_name = $_SESSION['db_prefix']."_store_items";
//						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$_SESSION['edit_mitek_item_id'.$i]."' ";
//						$item_name_result = mySQL_query($item_name_query);
//						$item_name = mysql_result($item_name_result, 0, "item_name"); 
//						$unit = mysql_result($item_name_result, 0, "unit"); 
	
				 ?>
       <tr>
         <td width="464"><?php echo $_SESSION['edit_bracing_name'.$i] ?>
           <input type="hidden" name="bracing_name<?php echo $i?>" id="bracing_name<?php echo $i?>" value="<?php echo $_SESSION['edit_bracing_name'.$i]?>"/>
           </td>
         <td width="131" align="right"><input name="bracing_edit<?php echo $i?>" type="text" class="text60" id="bracing_edit<?php echo $i?>" value="<?php echo $_SESSION['edit_bracing_quantity_'.$i] ?>" onfocus = "this.select();" style="text-align:right; " onKeyPress="return isNumberKey(event)" onchange=" this.value = this.value.replace (/(\...).*/, '$1')" autocomplete="off"/></td>
         <td width="58" align="center">m</td>
       </tr>
       <?php
						
			  $i++;
             }
			 ?>
       <input name="bracing_num" type="hidden" value="<?php echo $i;?>" />
     </table>
     <input name="bracing_button" type="submit" class="imagebutton" id="bracing_button" value="Add bracing timber" onclick=" needToConfirm = false; this.form.action='captured_edit_temp_save.php';MM_showHideLayers('wait','','show')"/>
     <input name="bracing_num" id="bracing_num" type="hidden" value="<?php echo $bracing_num?>" />
   </div>
   
   
   <div class="page_middle_frame">
     <table width="669" id="table_details_display" >
       <tr>
         <td align="left" valign="top"><label class="label_std">Sundries:<a name="sundries" id="sundries"></a></label></td>
         <td colspan="2" align="left" valign="top"><label class="label_std">Edit quoted </label>
           <input name="edit_job_no3" type="hidden" value="<?php echo $job_no?>" /></td>
       </tr>
       <?php 
				  $i=0;
				   while ($i<$sundries_num) { 
					    $_SESSION['edit_sundries_line'.$i] = mysql_result($sundries_result, $i, "cap_timber_id");
					    $_SESSION['edit_sundries_name'.$i] = mysql_result($sundries_result, $i, "cap_timber_name");						
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_sundries_quantity_'.$i] =  mysql_result($sundries_result, $i, "cap_timber_length");	
						}
						
						if ($_SESSION['edit_sundries_line'.$i]=='0') {
							     $_SESSION['edit_sundries_quantity_'.$i] = mysql_result($sundries_result, $i, "cap_timber_length");
						}
							
				 ?>
       <tr>
         <td width="466"><?php echo $_SESSION['edit_sundries_name'.$i] ?><input name="sundries_name<?php echo $i?>" type="hidden" value="<?php echo $_SESSION['edit_sundries_name'.$i] ?>" /></td>
         <td width="127" align="right"><input name="sundries_edit<?php echo $i?>" type="text" class="text60" id="sundries_edit<?php echo $i?>" value="<?php echo $_SESSION['edit_sundries_quantity_'.$i] ?>" onfocus = "this.select();" style="text-align:right; " onKeyPress="return isNumberKey(event)" onchange=" this.value = this.value.replace (/(\...).*/, '$1')" autocomplete="off"/></td>
         <td width="60" align="center">m</td>
       </tr>
       <?php
						
			  $i++;
             }
			 ?>
       <input name="sundries_num" type="hidden" value="<?php echo $i;?>" />
     </table>
     <input name="sundries_button" type="submit" class="imagebutton" id="sundries_button" value="Add sundries timber" onclick=" needToConfirm = false; this.form.action='captured_edit_temp_save.php';MM_showHideLayers('wait','','show')"/>
     <input name="sundries_num" id="sundries_num" type="hidden" value="<?php echo $sundries_num?>" />
   </div>
   <div class="page_middle_frame">

 <table width="675" id="table_details_display" >
   <tr>
     <td align="left" valign="top"><label class="label_std">Additional Sundries<a name="additional" id="additional"></a></label></td>
     <td colspan="3" align="left" valign="top"><label class="label_std">Edit quoted</label></td>
   </tr> 
             <?php 
				  $m=0;
				  while ($m<$additional_num) { 
					    
						$_SESSION['edit_additional_line'.$m] = mysql_result($additional_result, $m, "cap_sundries_id");
					    $_SESSION['edit_additional_item_id'.$m] = mysql_result($additional_result, $m, "cap_item_id");
												
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_additional_quantity_'.$m] =  mysql_result($additional_result, $m, "cap_quantity");	
						//if ($_SESSION['edit_additional_quantity_'.$m]=='') {
//						       $_SESSION['edit_additional_quantity_'.$m] = mysql_result($additional_result, $m, "cap_quantity");
//						}
//						if ($_SESSION['edit_additional_quantity_'.$m]=='0') {
//						       $_SESSION['edit_additional_quantity_'.$m] = mysql_result($additional_result, $m, "auth_quantity");
//						}
						}
						
						if ($_SESSION['edit_additional_line'.$m]=='0') {
							  
							     $_SESSION['edit_additional_quantity_'.$m] = mysql_result($additional_result, $m, "cap_quantity");
						}
						
						
						
						$_additional_quantity = mysql_result($additional_result, $m, "cap_quantity");
						//$_additional_auth_quantity = mysql_result($additional_result, $m, "auth_quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$_SESSION['edit_additional_item_id'.$m]. "' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name_num = mysql_num_rows($item_name_result);
						if ($item_name_num!=0) {
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						}
				 ?>
             <tr>
               <td width="465"><?php echo $item_name ?>
                <input name="additional_item<?php echo $m?>" id="additional_item<?php echo $m?>" type="hidden" value="<?php echo $_SESSION['edit_additional_item_id'.$m]?>" /></td>
               <td width="127" align="right"><input name="additional_edit<?php echo $m?>" type="text" class="text60" id="additional_edit<?php echo $m?>" value="<?php echo $_SESSION['edit_additional_quantity_'.$m] ?>" onfocus = "this.select();"  style="text-align:right;" onkeypress="return numbersonly(this, event)" autocomplete="off"/></td>
               <td width="31" align="center"></td>
               <td width="67" align="center"><?php echo $unit ?></td>
             </tr>
              <?php
					
			  $m++;
             }
			?>
            <input name="additional_num" type="hidden" value="<?php echo $m;?>" />
    </table>
 
   <input name="additional_button" type="submit" class="imagebutton" id="additional_button" value="Add sundries" onclick=" needToConfirm = false; this.form.action='captured_edit_temp_save.php'; MM_showHideLayers('wait','','show');" />

    
  </div>
  <div class="page_middle_frame">
    <table width="645" border="0">
      <tr>
      <td width="20">
	  <?php 
	  //if ($result<10) { ?>
      <!--<script>alertMessage(1, '', 'The result on this job is less than 10%. Check used quantities again.');</script>-->
      <?php //} ?>
    </td>
      <td width="615" align="right"><input type="hidden" name="job_no" id="job_no" value="<?php echo $job_no ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../production/production_main.php');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onclick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onclick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
</table>
  </div>
  </form>
  </td>
</tr>

</table>  <!--end of tableMain-->
  
</div>


<?php include ('../navigation/side_bar.php'); ?>




</body>
<?php } else {
$_SESSION['denied_return'] = "production/production_main.php";	
include ("../navigation/production_sidebar.php");?>
	<body onload="accessdenied(); return false">
    <?php include ('../navigation/side_bar.php'); ?>
	</body>
<?php }
?>
</html>