<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="javascript" src="../jscript/chainedselects.js"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 


<?php
include('../include/session.php');
require_once ('../include/tc_calendar.php');


$job_card_no=$_GET['job_card_no'];
$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$job_result = mySQL_query($job_query);
//$job_card_no = mysql_result($job_result, 0, "job_card_no");
$cust_id = mysql_result($job_result, 0, "cust_id");
$quote_note = mysql_result($job_result, 0, "quote_note");
$value = mysql_result($job_result, 0, "value");
$order_date = strtotime(mysql_result($job_result, 0, "date"));
$d = date("d", $order_date );
$m = date("m", $order_date );
$y = date("Y", $order_date );
$del_date = mysql_result($job_result, 0, "del_date");
$end_date = mysql_result($job_result, 0, "end_date");
$project_description = mysql_result($job_result, 0, "project_description");
$project = mysql_result($job_result, 0, "project");
$project_no = mysql_result($job_result, 0, "project_no");
$project_place = mysql_result($job_result, 0, "project_place");
$project_area = mysql_result($job_result, 0, "project_area");
$deliver_date = mysql_result($job_result, 0, "del_date");
$forman = mysql_result($job_result, 0, "forman");
if ($forman!='') {
	$table_name2 = $_SESSION['db_prefix']."_employee";
	$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$forman."' ";
	$employee_result = mySQL_query($employee_query);
	$employee_num = mysql_num_rows($employee_result);	
	$forman_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
}
else {
    $forman_name='';
	}


$captured = mysql_result($job_result, 0, "captured");
$compiled = mysql_result($job_result, 0, "compiled");
$invoiced = mysql_result($job_result, 0, "invoiced");
$completed = mysql_result($job_result, 0, "completed");

$table_name = $_SESSION['db_prefix']."_list_names_foreman";
$select_query = "SELECT emp_id, item_name FROM $table_name";
	$arrId17 = array ();
	$arrName17 = array ();
	$select_result = execsql($select_query);
	$select_num = mysql_num_rows($select_result);
	$a = 0;
	while ($a < $select_num) {
		$arrId17[$a] = mysql_result($select_result, $a, "emp_id");
		$arrName17[$a] = mysql_result($select_result, $a, "item_name");
		$a++;
	}	

$table_name = $_SESSION['db_prefix']."_list_area";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId18 = array ();
	$arrName18 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId18[$b] = mysql_result($position_result, $b, "item_name");
		$arrName18[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}
	
$table_name = $_SESSION['db_prefix']."_list_places";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId19 = array ();
	$arrName19 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId19[$b] = mysql_result($position_result, $b, "item_name");
		$arrName19[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}	

?>
<!--jscript-->
<script language="javascript" src="../jscript/chainedselects.js"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>

<?php

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Electric fencing' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $store_item_num) {
		$arrId2[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName2[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Fencing' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId3 = array ();
	$arrName3 = array ();
	while ($w < $store_item_num) {
		$arrId3[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName3[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Palisade' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $store_item_num) {
		$arrId4[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName4[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'M-works' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId5 = array ();
	$arrName5 = array ();
	while ($w < $store_item_num) {
		$arrId5[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName5[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Cleaning materials' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId6 = array ();
	$arrName6 = array ();
	while ($w < $store_item_num) {
		$arrId6[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName6[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Consumables' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId7 = array ();
	$arrName7 = array ();
	while ($w < $store_item_num) {
		$arrId7[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName7[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}	
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Fuel' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId8 = array ();
	$arrName8 = array ();
	while ($w < $store_item_num) {
		$arrId8[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName8[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}	
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Lubricants' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId9 = array ();
	$arrName9 = array ();
	while ($w < $store_item_num) {
		$arrId9[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName9[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}	

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Machine spares' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId10 = array ();
	$arrName10 = array ();
	while ($w < $store_item_num) {
		$arrId10[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName10[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'PPE' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId11 = array ();
	$arrName11 = array ();
	while ($w < $store_item_num) {
		$arrId11[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName11[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Tools' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId12 = array ();
	$arrName12 = array ();
	while ($w < $store_item_num) {
		$arrId12[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName12[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Welding & Engineering' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId13 = array ();
	$arrName13 = array ();
	while ($w < $store_item_num) {
		$arrId13[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName13[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_special_orders";
$special_query = "SELECT job_card_no, special_name, quantity_ordered FROM $table_name WHERE quantity_received IS NULL ORDER BY special_name ASC";
	$special_result = execsql($special_query);
	$special_num = mysql_num_rows($special_result);
	$w = 0;
	$arrId14 = array ();
	$arrName14 = array ();
	while ($w < $special_num) {
		$arrId14[$w] = '"'.mysql_result($special_result, $w, "job_card_no").'-'.mysql_result($special_result, $w, "special_name").'"';
		$arrName14[$w] = mysql_result($special_result, $w, "job_card_no").'-'.mysql_result($special_result, $w, "special_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'EF-spares' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId15 = array ();
	$arrName15 = array ();
	while ($w < $store_item_num) {
		$arrId15[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName15[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory = 'Signage' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId16 = array ();
	$arrName16 = array ();
	while ($w < $store_item_num) {
		$arrId16[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName16[$w] = mysql_result($store_item_result, $w, "item_name");
		$w++;
	}
		

$table_name = $_SESSION['db_prefix']."_order_job_lines";
$line_query = "SELECT * FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

?>




<script>


//var disable_empty_list=true; //uncomment this line to disable empty selection lists
<?php 
$i=0;
while ( $i<10 ) {

?>

addListGroup("Direct materials", "category<?php echo $i ?>", "store_item_id_select<?php echo $i ?>", "items");
//addOption("category0", "", "", "", 1); //Empty starter option
addList("category<?php echo $i ?>", "<?php echo $_SESSION['category'.$i]?>", "<?php echo $_SESSION['category'.$i]?>", "");
addList("category<?php echo $i ?>", "Electric fencing", "Electric fencing", "Electric fencing");
addList("category<?php echo $i ?>", "Fencing", "Fencing", "Fencing");
addList("category<?php echo $i ?>", "Palisade", "Palisade", "Palisade");
addList("category<?php echo $i ?>", "M-works", "M-works", "M-works");
addList("category<?php echo $i ?>", "Cleaning materials", "Cleaning materials", "Cleaning materials");
addList("category<?php echo $i ?>", "Consumables", "Consumables", "Consumables");
addList("category<?php echo $i ?>", "EF-spares", "EF-spares", "EF-spares");
addList("category<?php echo $i ?>", "Fuel", "Fuel", "Fuel");
addList("category<?php echo $i ?>", "Lubricants", "Lubricants", "Lubricants");
addList("category<?php echo $i ?>", "Machine spares", "Machine spares", "Machine spares");
addList("category<?php echo $i ?>", "PPE", "PPE", "PPE");
addList("category<?php echo $i ?>", "Signage", "Signage", "Signage");
addList("category<?php echo $i ?>", "Tools", "Tools", "Tools");
addList("category<?php echo $i ?>", "Welding & Engineering", "Welding & Engineering", "Welding & Engineering");

<?php
$i++;
}
?>

		addList("Electric fencing", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
    	for ($w = 0; $w < count($arrId2); $w++) { ?>
			addList("Electric fencing", "<?php echo $arrName2[$w]?> ", "<?php echo $arrId2[$w]?> ", "");
		<?php
	    }
     ?>
		addList("Fencing", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId3); $w++) { ?>
			addList("Fencing", "<?php echo $arrName3[$w]?> ", "<?php echo $arrId3[$w]?> ", "");
		<?php
	    }
	?>
      addList("Palisade", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId4); $w++) { ?>
			addList("Palisade", "<?php echo $arrName4[$w]?> ", "<?php echo $arrId4[$w]?> ", "");
		<?php
	    }
	?>
	   addList("M-works", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId5); $w++) { ?>
			addList("M-works", "<?php echo $arrName5[$w]?> ", "<?php echo $arrId5[$w]?> ", "");
		<?php
	    }
	?>
	addList("Cleaning materials", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId6); $w++) { ?>
			addList("Cleaning materials", "<?php echo $arrName6[$w]?> ", "<?php echo $arrId6[$w]?> ", "");
		<?php
	    }
	?>
	addList("Consumables", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId7); $w++) { ?>
			addList("Consumables", "<?php echo $arrName7[$w]?> ", "<?php echo $arrId7[$w]?> ", "");
		<?php
	    }
	?>
	addList("EF-spares", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId15); $w++) { ?>
			addList("EF-spares", "<?php echo $arrName15[$w]?> ", "<?php echo $arrId15[$w]?> ", "");
		<?php
	    }
	?>
	addList("Fuel", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId8); $w++) { ?>
			addList("Fuel", "<?php echo $arrName8[$w]?> ", "<?php echo $arrId8[$w]?> ", "");
		<?php
	    }
	?>
	addList("Lubricants", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId9); $w++) { ?>
			addList("Lubricants", "<?php echo $arrName9[$w]?> ", "<?php echo $arrId9[$w]?> ", "");
		<?php
	    }
	?>
	addList("Machine spares", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId10); $w++) { ?>
			addList("Machine spares", "<?php echo $arrName10[$w]?> ", "<?php echo $arrId10[$w]?> ", "");
		<?php
	    }
	?>
	addList("PPE", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId11); $w++) { ?>
			addList("PPE", "<?php echo $arrName11[$w]?> ", "<?php echo $arrId11[$w]?> ", "");
		<?php
	    }
	?>
	addList("Signage", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId16); $w++) { ?>
			addList("Signage", "<?php echo $arrName16[$w]?> ", "<?php echo $arrId16[$w]?> ", "");
		<?php
	    }
	?>
	addList("Tools", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId12); $w++) { ?>
			addList("Tools", "<?php echo $arrName12[$w]?> ", "<?php echo $arrId12[$w]?> ", "");
		<?php
	    }
	?>
	addList("Welding & Engineering", "<?php echo $_SESSION['store_item_name']?>", "<?php echo $_SESSION['store_item_id']?>", "");
		<?php 
        for ($w = 0; $w < count($arrId13); $w++) { ?>
			addList("Welding & Engineering", "<?php echo $arrName13[$w]?> ", "<?php echo $arrId13[$w]?> ", "");
		<?php
	    }
	?>


</script>
  
<script language="javascript">
function addRow(dataTable) {
 
            var table = document.getElementById(dataTable);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
			var line_no = rowCount-1;
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            element1.name="line_checkbox"+line_no;
			element1.id="line_checkbox"+line_no;
			/*element1.checked="checked";*/
            cell1.appendChild(element1);
			
            var cell2 = row.insertCell(1);
            var element2 = document.createElement("select");
            element2.name = "category"+line_no;
			element2.id = "category"+line_no;
			element2.className = "select160";
			element2.onchange = function() {document.getElementById("index"+line_no).value = document.getElementById("category"+line_no).selectedIndex; }
						
			var element9 = document.createElement("input");
            element9.type = "hidden";
            element9.name = "index"+line_no;
			element9.id = "index"+line_no;
			
			var element10 = document.createElement("input");
            element10.type = "hidden";
            element10.name = "store_item_id"+line_no;
			element10.id = "store_item_id"+line_no;
											
            var element7 = document.createElement("select");
            element7.name = "store_item_id_select"+line_no;
			element7.id = "store_item_id_select"+line_no;
			element7.className = "select160";
			element7.selectedIndex= -1;
			element7.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";  document.getElementById("store_item_id"+line_no).value = document.getElementById("store_item_id_select"+line_no).value;}
			
			cell2.appendChild(element2);
			cell2.appendChild(element9);
			cell2.appendChild(element10);
			cell2.appendChild(element7);
			
			<?php
			$t=0;
			while ($t<25) {
			?>
			if (line_no==<?php echo $t ?>) {
			initListGroup("Direct materials", form1.category<?php echo $t ?>, form1.store_item_id_select<?php echo $t ?>);
			function initLists() { 
  			form1.category<?php echo $t ?>.selectedIndex = -1;
  			form1.category<?php echo $t ?>.onchange();
			}
			}
			<?php 
			$t++;
			}
			?>
		
			
 
            var cell4 = row.insertCell(2);
			cell4.align = "right";
            var element3 = document.createElement("input");
            element3.type = "text";
            element3.name = "quantity_text"+line_no;
			element3.className = "text60";
			element3.value = "";
			element3.style = "text-align:right";
			element3.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if ( charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element3.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";}
			
			var element4 = document.createElement("input");
            element4.type = "hidden";
            element4.name = "line_num";
			element4.value = rowCount;
			
			
			cell4.appendChild(element3);
			cell4.appendChild(element4);
			
			var element8 = document.createElement("script");
			element8.setAttribute('type', 'text/javascript');
			element8.innerHTML="var frmvalidator  = new Validator('form1');frmvalidator.EnableMsgsTogether();for (i = 0; i < 10; i++) {frmvalidator.addValidation('quantity_text'+i,'req','- quantity on store line '+(i+1)+'.');frmvalidator.addValidation('amount_text'+i,'req','- price on store line '+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element8);



		
element1.onmouseup = function() {
				 if (document.getElementById('line_checkbox'+line_no).checked) {
                         element2.style.background = '#F0F0F0';
						 element3.style.background = '#F0F0F0';
						 element6.style.background = '#F0F0F0';
						 element2.selectedIndex=1;
						 element3.value = '-----';
						 element6.value = '0';
						 element2.disabled = true;
						 element3.disabled = true;
						 element6.disabled = true;
						 
                } else {
                        element2.style.background = '#FFF';
						element3.style.background = '#FFF';
						element6.style.background = '#FFF';
						element2.selected_index=0;
						element3.value = '';
						element6.value = '';
						element2.disabled = false;
						element3.disabled = false;
						element6.disabled = false;
						 
                }
				};

}
</script> 

<script language="javascript">
function initCS() {
<?php
$t=0;
while ($t<50) {
?>
initListGroup("Direct materials", form1.category<?php echo $t ?>, form1.store_item_id_select<?php echo $t ?>); 

function initLists() {
  form1.category<?php echo $t ?>.onchange();
  category<?php echo $t ?>.fireEvent("onchange");
}

function initLists2() {
  form1.store_item_id_select<?php echo $t ?>.selectedIndex = -1;
  form1.store_item_id_select<?php echo $t ?>.onchange();
}
<?php 
$t++;
}
?>
}

</script>

</head>


<body onLoad="initCS();" >

<form id="form1" name="form1" method="POST" action="edit_job_card_save.php">
<?php
include ("../navigation/header.php");
$page_name = "Orders-edit job card";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/orders_sidebar.php");
?>
<div class="main_frame">
<div class="page_head_frame">
          <table width="650" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="553"><label class="label_page_head">Job card</label></td>
              <td width="97"><label class="label_quote_no"><?php echo $job_card_no;  ?></label>
              <?php if (($captured=='yes') AND ($compiled=='') AND ($completed=='') ) { ?> <img src="../images/round_red.png" width="12" height="12"><?php } ?>
              <?php if (($captured=='yes') AND ($compiled=='yes') AND ($completed=='') ) { ?> <img src="../images/round_orange.png" width="12" height="12"><?php } ?>
              <?php if (($captured=='yes') AND ($compiled=='yes') AND ($completed=='yes') ) { ?> <img src="../images/round_green.png" width="12" height="12"><?php } ?></td>
            </tr>
          </table>
  </div>
<div class="page_middle_frame">          
<div class="page_inside_frame">
<?php 
include('../include/customer_block.php');
?>
</div>


<div class="page_inside_frame">
<table width="650" id="table_details_display">
    <tr>
      <td width="107" align="left" valign="middle">Project:</td>
      <td colspan="4" align="left" valign="middle"><select name="project_select" id="project_select" class="select160" tabindex="3">
        <option value="<?php echo $project?>"><?php echo $project?></option>
          <option value="Manase 358">Manase 358</option>
          <option value="Diamond mesh">Diamond mesh</option>
          <option value="Electric fencing">Electric fencing</option>
          <option value="Farm fence">Farm fence</option>
          <option value="Free standing electric fence">Free standing electric fence</option>
          <option value="Gate">Gate</option>
          <option value="Gate motor">Gate motor</option>
          <option value="Miscelaneous">Miscelaneous</option>
          <option value="Palisade standard">Palisade standard</option>
          <option value="Palisade fencing">Palisade fencing</option>
          <option value="Pool fence">Pool fence</option>
          <option value="Razor wire">Razor wire</option>
          <option value="Wall spikes">Wall spikes</option>
      </select></td>
      <td align="left" valign="middle"><?php echo 'Job card no:'; ?><?php echo $job_card_no;  ?></td>
    </tr>
    <tr>
      <td align="left" valign="middle">Foreman:</td>
      <td colspan="5" align="left" valign="middle">
        <select name="forman_select" class="select200"  id="forman_select" >
          <option value="<?php echo $forman ?>" selected><?php echo $forman_name ?></option>
          <?php
        	for ($j = 0; $j < count($arrId17); $j++) {
    		echo "<option value=" . "\"" . $arrId17[$j] . "\"" . ">" . $arrName17[$j] . "</option>";
	}
?>
        </select></td>
      </tr>
    <tr>
      <td align="left" valign="middle">Order date:</td>
      <td colspan="3" align="left" valign="middle"><?php

		$myCalendar = new tc_calendar("order_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2012, 2020);
		//$myCalendar->dateAllow('2009-02-20', "", false);
		$myCalendar->writeScript();
?></td>
      <td width="46" align="left" valign="middle">Job value</td>
      <td width="160" align="left" valign="middle"><input name="value_text" type="text" class="text80" value="<?php echo $value ?>"  onfocus = "this.select();" style="text-align:right" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')"></td>
    </tr>
    <tr>
      <td align="left" valign="middle">Project period:</td>
      <td colspan="5" align="left" valign="middle"><?php if ($deliver_date!='') {?>from: <?php echo date("d-m-Y", strtotime($deliver_date));  ?> to: <?php echo date("d-m-Y", strtotime($end_date));  ?><?php } ?> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src="../images/info_green.png" width="16" height="16">
        <label class="label_info">Edit period dates in Edit planner.</label>
        </td>
    </tr>
    <tr>
      <td valign="middle" >Project no:</td>
      <td width="144" valign="middle"><input name="project_no_text" type="text" class="text80" id="project_no_text" onKeyUp="ToLower(this)" onBlur="capitalize(this)" value="<?php echo $project_no?>" ></td>
      <td width="69" align="right" valign="middle">Area:</td>
      <td width="96" valign="middle"><select name="project_area_select" class="select120" tabindex="5" >
        <option value="<?php echo $project_area?>" selected><?php echo $project_area?></option>
        <?php
        	for ($j = 0; $j < count($arrId18); $j++) {
    		echo "<option value=" . "\"" . $arrId18[$j] . "\"" . ">" . $arrName18[$j] . "</option>";
	}
?>
      </select></td>
      <td align="right" valign="middle"><label class="label_std">Place:</label></td>
      <td valign="middle"><select name="project_place_select" class="select120" tabindex="6" >
        <option value="<?php echo $project_place?>" selected><?php echo $project_place?></option>
        <?php
        	for ($j = 0; $j < count($arrId19); $j++) {
    		echo "<option value=" . "\"" . $arrId19[$j] . "\"" . ">" . $arrName19[$j] . "</option>";
	}
?>
      </select></td>
    </tr>
    <tr>
      <td align="left" valign="top">Notes:</td>
      <td colspan="5" align="left" valign="top">
        <textarea name="notes_text" cols="80" rows="3" class="text_box" id="notes_text"><?php echo $quote_note ?></textarea></td>
    </tr>
  </table>
</div>




 
<div class="page_inside_frame">
    <table id="dataTable" width="564" border="1" style="border-collapse:collapse;">
    <?php
	
	   if ($line_num==0) {
	       
		   $a1='-';
		   $a1a='-';
		   $a2='-';
		   $a3='-';
	   }
	   else {
		   
		   $a1 = mysql_result($line_result, 0, "store_item_id");
		   		$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$a1."'  ";
				$name_result = mySQL_query($name_query);
				$a1a = mysql_result($name_result, 0, "item_name");
				
		   $a2 = mysql_result($line_result, 0, "quantity");
		   $a3 = mysql_result($line_result, 0, "price");
		   }
		?>
    <thead> 
        <tr>
          <td>&nbsp;</td>
          <td width="453">Store item</td>
          <td>Quantity</td>
          </tr>
        </thead>
        <script>
			 function check_it() {
				 if (document.getElementById('line_checkbox0').checked) {
                         document.getElementById('store_item_id_select0').style.background = '#F0F0F0';
						 document.getElementById('store_item_text0').style.background = '#F0F0F0';
						 document.getElementById('quantity_text0').style.background = '#F0F0F0';
						 document.getElementById('amount_text0').style.background = '#F0F0F0';
						 document.getElementById('store_item_id_select0').selectedIndex=1;
						 document.getElementById('store_item_text0').value = '.';
						 document.getElementById('quantity_text0').value = '.';
						 document.getElementById('amount_text0').value = '.';
						 document.getElementById('store_item_id_select0').disabled = true;
						 document.getElementById('store_item_text0').disabled = true;
						 document.getElementById('quantity_text0').disabled = true;
						 document.getElementById('amount_text0').disabled = true;
						 document.getElementById('add_icon0').hidden = true;
						 
                } else {
                         document.getElementById('store_item_id_select0').style.background = '#FFF';
						 document.getElementById('quantity_text0').style.background = '#FFF';
						 document.getElementById('amount_text0').style.background = '#FFF';
						 document.getElementById('store_item_id_select0').selectedIndex=0;
						 document.getElementById('store_item_text0').value = '';
						 document.getElementById('quantity_text0').value = '';
						 document.getElementById('amount_text0').value = '';
						 document.getElementById('store_item_id_select0').disabled = false;
						 document.getElementById('quantity_text0').disabled = false;
						 document.getElementById('amount_text0').disabled = false;
						 document.getElementById('add_icon0').hidden = false;
                }
				}
		     </script>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox0" id="line_checkbox0" onMouseUp="check_it()" <?php if ($a1!='-') { ?> checked="checked" <?php } ?> onClick="
				 {
                    document.getElementById('quantity_text0').value=0;
                    document.getElementById('store_item_divA0').hidden=true;
                    document.getElementById('quantity_text0').hidden=true;
                    document.getElementById('line_checkbox0').hidden=true;
				}
                "/></td>
          <td>
          
          
          <div id=store_item_divA0>
            <input name="store_item_text0" id="store_item_text0" type="text" class="text300" value="<?php echo $a1a ?>" readonly style="border:hidden; background-color:inherit; "> <input name="store_item_id0" id="store_item_id0" type="hidden" value="<?php echo $a1 ?>">
          </div>
            
            <div id=store_item_divB0 hidden="hidden">
              <select name="category0" id="category0" style="width:160px;"  onChange="document.getElementById('store_item_divA0').hidden=true; document.getElementById('store_item_divB0').hidden=false; document.getElementById('store_item_id_select0').selectedIndex=-1; document.getElementById('index0').value = document.getElementById('category0').selectedIndex; ">
              </select>
              <input type="hidden" name="index0" id="index0">
              <select name="store_item_id_select0" id="store_item_id_select0" style="width:160px;" onChange="document.getElementById('line_checkbox0').checked=true; document.getElementById('store_item_id0').value=document.getElementById('store_item_id_select0').value; document.getElementById('store_item_text0').value = document.getElementById('store_item_id_select0').value; document.getElementById('quantity_text0').disabled = false; document.getElementById('amount_text0').disabled = false;">
               
              </select>
            </div> 
            
          </td>
          <td width="69" align="right"><input  name="quantity_text0" type="text" class="text60" id="quantity_text0" style="text-align:right" onKeyPress="return numbersonly(this, event)" value="<?php echo $a2 ?>" <?php if ($a2=='-') { ?> disabled="true" <?php } ?> size="10" autocomplete="off"/>
            <input type="hidden" name="line_num2" id="line_num2" value="1" >  
          </td>
            <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
        </tr>
        <?php
		$i=1;
		while ($i<$line_num) {
		   $a1 = mysql_result($line_result, $i, "store_item_id");
		        $table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$a1."'  ";
				$name_result = mySQL_query($name_query);
				$a1a = mysql_result($name_result, 0, "item_name");
		   $a2 = mysql_result($line_result, $i, "quantity");
		   $a3 = mysql_result($line_result, $i, "price");
		?>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox<?php echo $i ?>" id="line_checkbox<?php echo $i ?>"  <?php if ($a1!='') { ?> checked="checked" <?php } ?> onClick="
				 {
                    document.getElementById('quantity_text<?php echo $i ?>').value=0;
                    document.getElementById('store_item_divA<?php echo $i ?>').hidden=true;
                    document.getElementById('quantity_text<?php echo $i ?>').hidden=true;
                    document.getElementById('line_checkbox<?php echo $i ?>').hidden=true;
				}
                "/></td>
          <td>
          
          
          <div id=store_item_divA<?php echo $i ?>>
            <input name="store_item_text<?php echo $i ?>" id="store_item_text<?php echo $i ?>" type="text" class="text300" value="<?php echo $a1a ?>" readonly style="border:hidden; background-color:inherit"> <input name="store_item_id<?php echo $i ?>" id="store_item_id<?php echo $i ?>" type="hidden" value="<?php echo $a1 ?>">
          </div>
            
            <div id=store_item_divB<?php echo $i ?> hidden="hidden">
              <select name="category<?php echo $i ?>" id="category<?php echo $i ?>" style="width:160px;"  onChange="document.getElementById('store_item_divA<?php echo $i ?>').hidden=true; document.getElementById('store_item_divB<?php echo $i ?>').hidden=false; document.getElementById('store_item_id_select<?php echo $i ?>').selectedIndex=-1; document.getElementById('index<?php echo $i ?>').value = document.getElementById('category<?php echo $i ?>').selectedIndex; ">
              </select>
              <input type="hidden" name="index<?php echo $i ?>" id="index<?php echo $i ?>">
              <select name="store_item_id_select<?php echo $i ?>" id="store_item_id_select<?php echo $i ?>" style="width:160px;" onChange="document.getElementById('line_checkbox<?php echo $i ?>').checked=true; document.getElementById('store_item_id<?php echo $i ?>').value=document.getElementById('store_item_id_select<?php echo $i ?>').value; document.getElementById('store_item_text<?php echo $i ?>').value = document.getElementById('store_item_id_select<?php echo $i ?>').value; ">
               
              </select>
            </div> 
            
          </td>
          <td width="69" align="right"><input  name="quantity_text<?php echo $i ?>" type="text" class="text60" id="quantity_text<?php echo $i ?>" style="text-align:right" onKeyPress="return numbersonly(this, event)" value="<?php echo $a2 ?>" size="10" autocomplete="off"/>
            <input type="hidden" name="line_num" id="line_num" value="<?php echo $line_num?>"></td>
          </tr>
        <?php
		$i++;
		}
		?>
        
  </table>
  
    <input type="button" class="imagebutton" onClick="addRow('dataTable')" value="Add line" />
    <div align="right"><label class="label_small">To delete a line: uncheck line box</label></div>
  </div>
  
<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="job_card_no" id="job_card_no" value="<?php echo $job_card_no ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../orders/orders_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>  
  
  
</div>
</div>  
</form>
<?php include ('../navigation/side_bar.php'); ?>


<?php } else {
$_SESSION['denied_return'] = "orders/orders_main.php";	
include ("../navigation/orders_sidebar.php");?>
<body onLoad="accessdenied(); return false">
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php }
?>
</body>
</html>