
<!--
 * this file is to be used in combination with store_item_select_table.php
 *
-->


<!--jscript-->
<script language="javascript" src="../jscript/chainedselects.js"></script>

<?php

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Packaging' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $store_item_num) {
		$arrId1[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName1[$w] = mysql_result($store_item_result, $w, "item_name")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Aggregates' 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}	
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Pigment' 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Cement' 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Oils' 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}	
	
				

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}	
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}	
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}	

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Tiles' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId14 = array ();
	$arrName14 = array ();
	while ($w < $store_item_num) {
		$arrId14[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName14[$w] = mysql_result($store_item_result, $w, "item_name")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}

$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit 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")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}


	
$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Motor spares' ORDER BY item_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId17 = array ();
	$arrName17 = array ();
	while ($w < $store_item_num) {
		$arrId17[$w] = mysql_result($store_item_result, $w, "store_item_id");
		$arrName17[$w] = mysql_result($store_item_result, $w, "item_name")." - -~".mysql_result($store_item_result, $w, "unit");
		$w++;
	}
	
?>
<script>
//var disable_empty_list=true; //uncomment this line to disable empty selection lists

<?php 
$k=0;
while ( $k<17 ) {
	$_SESSION['category'.$k]='';
$k++;
}
?>


<?php 
$k=0;
while ( $k<17 ) {
?>

addListGroup("Direct materials", "category<?php echo $k ?>", "store_item_id_select<?php echo $k ?>", "items");
//addOption("category0", "", "", "", 1); //Empty starter option
addList("category<?php echo $k ?>", "<?php echo $_SESSION['category'.$k]?>", "<?php echo $_SESSION['category'.$k]?>", "");
addList("category<?php echo $k ?>", "Motor spares", "Motor spares", "Motor spares");
addList("category<?php echo $k ?>", "Aggregates", "Aggregates", "Aggregates");
addList("category<?php echo $k ?>", "Cement", "Cement", "Cement");
addList("category<?php echo $k ?>", "Cleaning materials", "Cleaning materials", "Cleaning materials");
addList("category<?php echo $k ?>", "Consumables", "Consumables", "Consumables");
addList("category<?php echo $k ?>", "Fuel", "Fuel", "Fuel");
addList("category<?php echo $k ?>", "Lubricants", "Lubricants", "Lubricants");
addList("category<?php echo $k ?>", "Machine spares", "Machine spares", "Machine spares");
addList("category<?php echo $k ?>", "Oils", "Oils", "Oils");
addList("category<?php echo $k ?>", "Packaging", "Packaging", "Packaging");
addList("category<?php echo $k ?>", "Pigment", "Pigment", "Pigment");
addList("category<?php echo $k ?>", "PPE", "PPE", "PPE");
addList("category<?php echo $k ?>", "Tools", "Tools", "Tools");
addList("category<?php echo $k ?>", "Tiles", "Tiles", "Tiles");
addList("category<?php echo $k ?>", "Welding & Engineering", "Welding & Engineering", "Welding & Engineering");

<?php
$k++;
}
?>
		
	
addList("Aggregates", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId2); $w++) { ?>
			addList("Aggregates", "<?php echo $arrName2[$w]?>", "<?php echo $arrId2[$w]?>", "");
		<?php
	    }
	?>
	addList("Cement", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId4); $w++) { ?>
			addList("Cement", "<?php echo $arrName4[$w]?>", "<?php echo $arrId4[$w]?>", "");
		<?php
	    }
	?>
	addList("Cleaning materials", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId6); $w++) { ?>
			addList("Cleaning materials", "<?php echo $arrName6[$w]?>", "<?php echo $arrId6[$w]?>", "");
		<?php
	    }
	?>
	addList("Consumables", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId7); $w++) { ?>
			addList("Consumables", "<?php echo $arrName7[$w]?>", "<?php echo $arrId7[$w]?>", "");
		<?php
	    }
	?>
	addList("Fuel", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId8); $w++) { ?>
			addList("Fuel", "<?php echo $arrName8[$w]?>", "<?php echo $arrId8[$w]?>", "");
		<?php
	    }
	?>
	addList("Lubricants", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId9); $w++) { ?>
			addList("Lubricants", "<?php echo $arrName9[$w]?>", "<?php echo $arrId9[$w]?>", "");
		<?php
	    }
	?>
	addList("Machine spares", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId10); $w++) { ?>
			addList("Machine spares", "<?php echo $arrName10[$w]?>", "<?php echo $arrId10[$w]?>", "");
		<?php
	    }
	?>
	addList("Motor spares", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId17); $w++) { ?>
			addList("Motor spares", "<?php echo $arrName17[$w]?>", "<?php echo $arrId17[$w]?>", "");
		<?php
	    }
	?>
	addList("Oils", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId5); $w++) { ?>
			addList("Oils", "<?php echo $arrName5[$w]?>", "<?php echo $arrId5[$w]?>", "");
		<?php
	    }
	?>
	addList("Packaging", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId1); $w++) { ?>
			addList("Packaging", "<?php echo $arrName1[$w]?>", "<?php echo $arrId1[$w]?>", "");
		<?php
	    }
	?>
	addList("Pigment", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId3); $w++) { ?>
			addList("Pigment", "<?php echo $arrName3[$w]?>", "<?php echo $arrId3[$w]?>", "");
		<?php
	    }
	?>
	addList("PPE", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId11); $w++) { ?>
			addList("PPE", "<?php echo $arrName11[$w]?>", "<?php echo $arrId11[$w]?>", "");
		<?php
	    }
	?>
	addList("Tools", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId12); $w++) { ?>
			addList("Tools", "<?php echo $arrName12[$w]?>", "<?php echo $arrId12[$w]?>", "");
		<?php
	    }
	?>
	addList("Tiles", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId14); $w++) { ?>
			addList("Tools", "<?php echo $arrName14[$w]?>", "<?php echo $arrId14[$w]?>", "");
		<?php
	    }
	?>
	addList("Welding & Engineering", "", "", "");
		<?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 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> 


<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; 
				units=document.getElementById("store_item_id_select"+line_no).options[document.getElementById("store_item_id_select"+line_no).selectedIndex].text;
				units2 = units.split("~"); 
				units3 = units2[1]; 
				if (units3=="no") {
					document.getElementById("quantity_text"+line_no).value = ""; 
					document.getElementById("quantity_text"+line_no).onkeypress = function num(event) { return numbersonly(this, event);}
					
					}
					else {
						document.getElementById("quantity_text"+line_no).value = ""; 
						document.getElementById("quantity_text"+line_no).onkeypress = function num(event) { return isNumberKey(event);}
						}
						document.getElementById("store_item_id"+line_no).value=document.getElementById("store_item_id_select0"+line_no).value; 
						document.getElementById("store_item_text"+line_no).value = document.getElementById("store_item_id_select0"+line_no).value; 
						};
			cell2.appendChild(element2);
			cell2.appendChild(element9);
			cell2.appendChild(element10);
			cell2.appendChild(element7);
			
			<?php
			$t=0;
			while ($t<50) {
			?>
			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";}
			cell4.appendChild(element3);
			
					
			var cell5 = row.insertCell(3);
			cell5.align = "right";
			var element6 = document.createElement("input");
            element6.type = "text";
            element6.name = "amount_text"+line_no;
			element6.className = "text60";
			element6.style = "text-align:right";
			element6.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if (charCode != 46 && charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element6.onkeyup = function() {this.value = this.value.replace (/(\...).*/, '$1')};
			element6.style = "text-align:right";		

            var element4 = document.createElement("input");
            element4.type = "hidden";
            element4.name = "line_num";
			element4.value = rowCount;
            						
			cell5.appendChild(element6);
            cell5.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('store_item_id'+i,'req','- store item on line '+(i+1)+'.');frmvalidator.addValidation('quantity_text'+i,'req','- quantity on line '+(i+1)+'.');frmvalidator.addValidation('amount_text'+i,'req','- price on line '+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element8);



		
element1.onmouseup = function() {
				 if (document.getElementById('line_checkbox'+line_no).checked) {
                         element2.hidden = true;
						 element7.hidden = true;
						 element2.style.background = '#F0F0F0';
						 element3.style.background = '#F0F0F0';
						 element6.style.background = '#F0F0F0';
						 element2.selectedIndex=1;
						 element3.value = '.';
						 element6.value = '.';
						 element2.disabled = true;
						 element3.disabled = true;
						 element6.disabled = true;
						 
                } else {
					    element2.hidden = false;
						element7.hidden = false;
                        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>