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

<?php
$table_name = $_SESSION['db_prefix']."_special_orders";
if ($page=='') {
$special_query = "SELECT special_order_id, job_card_no, special_name, quantity_ordered FROM $table_name ORDER BY job_card_no DESC";
}
if ($page=='purchase') {
$special_query = "SELECT special_order_id, job_card_no, special_name, quantity_ordered FROM $table_name WHERE date_purchased IS NULL  ORDER BY job_card_no DESC";
}
if ($page=='receive') {
$special_query = "SELECT special_order_id, job_card_no, special_name, quantity_ordered FROM $table_name WHERE date_purchased IS NOT NULL AND date_received IS NULL ORDER BY job_card_no DESC";
}


	$special_result = execsql($special_query);
	$special_num = mysql_num_rows($special_result);
	$w = 0;
	$arrId200 = array ();
	$arrName200 = array ();
	while ($w < $special_num) {
		//$spec_name = mysql_result($special_result, $w, "job_card_no").' - '.mysql_result($special_result, $w, "special_name");
		$arrId200[$w] = mysql_result($special_result, $w, "special_order_id");
		$arrName200[$w] = mysql_result($special_result, $w, "job_card_no").' - '.mysql_result($special_result, $w, "special_name");
		$w++;
	}
?>

<script language="javascript">
function addRow2(dataTable2) {
            var table2 = document.getElementById(dataTable2);
            var rowCount = table2.rows.length;
            var row = table2.insertRow(rowCount);
			var line_no = rowCount-1;
 
            var cell1 = row.insertCell(0);
            var element21 = document.createElement("input");
            element21.type = "checkbox";
            element21.name="line_checkbox2"+line_no;
			element21.id="line_checkbox2"+line_no;
			element21.onchange = function() {document.getElementById("item_select2"+line_no).selectedIndex=-1};
			/*element21.checked="checked";*/
            cell1.appendChild(element21);
			
			var element25 = document.createElement("input");
			element25.type = "hidden";
			element25.name = "special_order_id2"+line_no;
			element25.id = "special_order_id2"+line_no;
			
			 
            var cell2 = row.insertCell(1);
            var element22 = document.createElement("select");
           	element22.name = "item_select2"+line_no;
			element22.id = "item_select2"+line_no;
			element22.className="select300"
			element22.onchange = function(){document.getElementById("line_checkbox2"+line_no).checked = "checked"; document.getElementById("special_order_id2"+line_no).value = document.getElementById("item_select2"+line_no).value; };
			cell2.appendChild(element22);
			cell2.appendChild(element25);
			
			var option0 = document.createElement("option");
   				 	option0.text = ".";
    				option0.value = ".";
				element22.add(option0);
				
			
			<?php
    			for ($i = 0; $i < count($arrId200); $i++) { ?>
				
				var option<?php echo $i?> = document.createElement("option");
   				 	option<?php echo $i?>.text = "<?php echo $arrName200[$i]?>";
    				option<?php echo $i?>.value = <?php echo $arrId200[$i]?>;
				element22.add(option<?php echo $i?>);
			<?php	
			}
			?>
			
						
 
            var cell4 = row.insertCell(2);
			cell4.align="right";
            var element23 = document.createElement("input");
            element23.type = "text";
            element23.name = "quantity_text2"+line_no;
			element23.className = "text60";
			element23.value = "";
			element23.style = "text-align:right";
			element23.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if ( charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element23.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";}
			cell4.appendChild(element23);
			
					
			var cell5 = row.insertCell(3);
			cell5.align="right";
			var element26 = document.createElement("input");
            element26.type = "text";
            element26.name = "amount_text2"+line_no;
			element26.className = "text60";
			element26.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;
       								}
									;
			element26.onkeyup = function() {this.value = this.value.replace (/(\...).*/, '$1')};
			element26.style = "text-align:right";		

            var element24 = document.createElement("input");
            element24.type = "hidden";
            element24.name = "line_num2";
			element24.value = rowCount;
            						
			cell5.appendChild(element26);
            cell5.appendChild(element24);
			
			var element28 = document.createElement("script");
			element28.setAttribute('type', 'text/javascript');
			element28.innerHTML="var frmvalidator  = new Validator('form1');frmvalidator.EnableMsgsTogether();for (i = 0; i < 10; i++) {frmvalidator.addValidation('quantity_text2'+i,'req','- quantity on special orders line '+(i+1)+'.');frmvalidator.addValidation('amount_text2'+i,'req','- price on special orders line '+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element28);
			
			
			element21.onmouseup = function() {
				 if (document.getElementById('line_checkbox2'+line_no).checked) {
                         element22.hidden =true;
						 element22.style.background = '#F0F0F0';
						 element23.style.background = '#F0F0F0';
						 element26.style.background = '#F0F0F0';
						 element22.value = '.';
						 element23.value = '.';
						 element26.value = '.';
						 element22.disabled = true;
						 element23.disabled = true;
						 element26.disabled = true;
						 
                } else {
						element22.hidden = false;
                        element22.style.background = '#FFF';
						element23.style.background = '#FFF';
						element26.style.background = '#FFF';
						element22.value = '';
						element23.value = '';
						element26.value = '';
						element22.disabled = false;
						element23.disabled = false;
						element26.disabled = false;
						 
                }
				};
			
}
</script> 