
<!--jscript-->


<?php

$table_name = $_SESSION['db_prefix']."_job_return_lines_temp";
$delete_query = "DELETE FROM $table_name WHERE usr_name  = '".$_SESSION['username']."'   "; 
execsql($delete_query);

$table_name = $_SESSION['db_prefix']."_order_job_lines";
$store_item_query = "SELECT store_item_id, misc, store_reg_id, item_name FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."'  ";
$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) {
				$store_item_id = mysql_result($store_item_result, $w, "store_item_id");
				$misc = mysql_result($store_item_result, $w, "misc");
				
				if ($store_item_id!=0) {
				
				if ($store_item_id<10000) {
				$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, register FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
				$name_result = mySQL_query($name_query);
				$store_item_name = mysql_result($name_result, 0, "item_name");
				$register = mysql_result($name_result, 0, "register");
				$store_reg_id = '0';
				if ($register=='yes') {
					$store_reg_id = mysql_result($store_item_result, $w, "store_reg_id");
					
	if ($store_reg_id>0) {							
				$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number  FROM $table_name WHERE store_register_id = '".$store_reg_id."' ";
					$register_result = mySQL_query($register_query);
					$register_num = mysql_num_rows($register_result);
					$serial = mysql_result($register_result, 0, "serial_number");
					}
					else {
						$serial = '';
					}
	}
	else {
		$store_item_name = mysql_result($store_item_result, $w, "item_name");
	}
				} 
	else {
		$store_item_name = '--';
	}
				}
				
		$value = $store_reg_id.'|'.mysql_result($store_item_result, $w, "store_item_id");
		$arrId1[$w] = $value;
		if ($register=='yes') {
			   if ($serial=='returned') {
				     $arrName1[$w] = '';
			   }
			   else { 			    
				$arrName1[$w] = $store_item_name.' ('.$serial.')';
			   }
		}
		else {
			    $arrName1[$w] = $store_item_name;
				
		}
		
		
		$w++;
	}
	


$table_name = $_SESSION['db_prefix']."_job_return_lines_temp WHERE user_name = '".$_SESSION['username']."' AND store_item_id>0";
$line_query = "SELECT * FROM $table_name ";
$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<20 ) {

?>

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>


<!--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>  
<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";
			
			
			var element4 = document.createElement("input");
            element4.type = "hidden";
            element4.name = "line_num";
			element4.value = rowCount;
			
			cell2.appendChild(element2);
			cell2.appendChild(element4);
			
			var option0 = document.createElement("option");
   				 	option0.text = "";
    				option0.value = "";
				element2.add(option0);
			
			var option1 = document.createElement("option");
   				 	option1.text = ".";
    				option1.value = ".";
				element2.add(option1);	
				
			
			<?php
    			for ($i = 0; $i < count($arrId1); $i++) { ?>
				
				var option<?php echo $i?> = document.createElement("option");
   				 	option<?php echo $i?>.text = "<?php echo $arrName1[$i]?>";
    				option<?php echo $i?>.value ="<?php echo $arrId1[$i]?>";
				element2.add(option<?php echo $i?>);
			<?php	
			}
			?>
						 
            var cell4 = row.insertCell(2);
			cell4.align = "right";
            var element3 = document.createElement("input");
            element3.type = "text";
            element3.name = "quantity_text"+line_no;
			element3.autocomplete="off";
			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 = "center";
            var element4 = document.createElement("input");
            element4.type = "checkbox";
            element4.name="return_checkbox"+line_no;
			element4.id="return_checkbox"+line_no;
			/*element1.checked="checked";*/
            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('category'+i,'req','- item on line '+(i+1)+'.');frmvalidator.addValidation('quantity_text'+i,'req','- quantity on 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';
						 element2.selectedIndex=1;
						 element3.value = '.';
						 element4.checked = false;
						 element2.disabled = true;
						 element3.disabled = true;
						 element4.disabled = true;
						
                } else {
                        element2.style.background = '#FFF';
						element3.style.background = '#FFF';
						element2.selected_index=0;
						element3.value = '';
						element4.checked = false;
						element2.disabled = false;
						element3.disabled = false;
						element4.disabled = false;
						 
                }
				};
			
}
</script> 


<script language="javascript">
function initCS() {
<?php
$t=0;
while ($t<25) {
?>
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>

<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide'); initCS(); " onFocus="MM_showHideLayers('wait','','hide');" >

<form id="form1" name="form1" method="get" action="returnWizbase.php">
<div class="wizard_page_middle_frame">
<div class="wizard_frame" style="height:auto; min-height:240px;"><br>
  <table id="dataTable" width="564" border="1" style="border-collapse:collapse;">
    <?php
	
	   if ($line_num==0) {
	       $a1='';
		   $a1a='';
		   $a2='';
		   $a7='';
		  
	   }
	   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");
		   $a7 = mysql_result($line_result, 0, "to_return");
		   }
		?>
    <thead>
      <tr>
        <td>&nbsp;</td>
        <td width="348">Store item</td>
        <td>Quantity</td>
        <td align="center">Return to stock</td>
      </tr>
    </thead>
    <script>
			 function check_it() {
				 if (document.getElementById('line_checkbox0').checked) {
                         document.getElementById('category0').style.background = '#F0F0F0';
						 document.getElementById('quantity_text0').style.background = '#F0F0F0';
						 document.getElementById('category0').selectedIndex=0;
						 document.getElementById('quantity_text0').value = '.';
						 document.getElementById('return_checkbox0').checked = false;
						 document.getElementById('category0').disabled = true;
						 document.getElementById('quantity_text0').disabled = true;
						 document.getElementById('return_checkbox0').disabled = true;
						 
                } else {
                         document.getElementById('category0').style.background = '#FFF';
						 document.getElementById('quantity_text0').style.background = '#FFF';
						 document.getElementById('category0').selectedIndex=0;
						 document.getElementById('quantity_text0').value = '';
						 document.getElementById('return_checkbox0').checked = false;
						 document.getElementById('category0').disabled = false;
						 document.getElementById('quantity_text0').disabled = false;
						 document.getElementById('return_checkbox0').disabled = false;
				
                }
				}
		     </script>
    <tr>
      <td width="20"><input type="checkbox" name="line_checkbox0" id="line_checkbox0" onMouseUp="check_it()" <?php if ($a1!='') { ?> checked="checked" <?php } ?> /></td>
      <td><select name="category0" id="category0" style="width:160px;" onChange="document.getElementById('line_checkbox0').checked=true; ">
        <option value="" selected="selected"></option>
        <?php 
    	for ($w = 0; $w < count($arrId1); $w++) {
		echo "<option value=\"".$arrId1[$w] . "\"" . ">" . $arrName1[$w] ."</option>";	
	    }
     ?>
      </select>
        <input type="hidden" name="line_num" id="line_num" value="1"></td>
      <td width="84" align="right"><input  name="quantity_text0" type="text" class="text60" id="quantity_text0" style="text-align:right" onKeyPress="return numbersonly(this, event)" size="10" autocomplete="off"/></td>
      <td width="84" align="center"><input type="checkbox" name="return_checkbox0" id="return_checkbox0" <?php if ($a7=='yes') { ?> checked="checked" <?php } ?>></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");
		   $a7 = mysql_result($line_result, $i, "to_return");
		   
		?>
    
    <?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="wizard_frame">
  <table width="590" 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','returnWizbase.php?s=&amp;p=1'); return document.MM_returnValue; ;return document.MM_returnValue"/></td>
            <td width="115">&nbsp;</td>
            <td width="99"><span class="wizard">
              <input name="error" type="hidden" id="error" value="0" />
              <input name="p" type="hidden" id="p" value="2" />
              <input name="s" type="hidden" id="s" value="2" />
            </span></td>
            <td width="125" align="left"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false;  cancel_confirmation(1, '../store/store_main.php');;" value="Cancel" /></td>
            <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
          </tr>
      </table>
    </div>
  </div>
</form>
</div>

<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 20; i++) {
	frmvalidator.addValidation("store_item_text"+i,"req","- store item on store line 1-"+(i+1)+".");
	frmvalidator.addValidation("quantity_text"+i,"req","- quantity  on store line 1-"+(i+1)+".");
  	
  }

 for (j = 0; j < 20; j++) {
	frmvalidator.addValidation("item_text2"+j,"req","- store item on store line 2-"+(j+1)+".");
	frmvalidator.addValidation("order_text2"+j,"req","- order no on store line 2-"+(j+1)+".");
	frmvalidator.addValidation("quantity_text2"+j,"req","- quantity  on store line 2-"+(j+1)+".");
  	frmvalidator.addValidation("amount_text2"+j,"req","- price on store line 2-"+(j+1)+".");
}	
  </script>
</body>