<?php
if ($_SESSION['job_no']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="store_no_return.php";
</script>
<?php
}
else {	
$table_name = $_SESSION['db_prefix']."_list_bracing";
$dropDownQuery = "SELECT item_id, item_name, width, depth, class FROM $table_name ORDER BY item_name ASC";
$dropDownResult = execsql($dropDownQuery);
	$num = mysql_num_rows($dropDownResult);
	$a = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($a < $num) {
		$arrId2[$a] = $a; // mysql_result($dropDownResult, $a, "item_id");
		$arrName2[$a] = mysql_result($dropDownResult, $a, "item_name");
		$arrWidth2[$a] = mysql_result($dropDownResult, $a, "width");
		$arrDepth2[$a] = mysql_result($dropDownResult, $a, "depth");
		$arrClass2[$a] = mysql_result($dropDownResult, $a, "class");
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$bracing_length_query = "SELECT store_item_id, length FROM $table_name WHERE width = '".$arrWidth2[$a]."' AND depth =  '".$arrDepth2[$a]."' AND class =  '".$arrClass2[$a]."' ORDER BY length ";
		$bracing_length_num = 0;
		$bracing_length_result = mySQL_query($bracing_length_query);
		$bracing_length_num = mysql_num_rows($bracing_length_result);
		
		
		$i=0;
		while ($i<$bracing_length_num) {
		$bracing_list_num = 'bracing_list_num'.$a;	
		${$bracing_list_num} = $i;
		$bracing_list = 'bracing_list'.$a.'_';
		${$bracing_list.$i} = mysql_result($bracing_length_result, $i, "length");
		$bracing_list_item = 'bracing_list'.$i;
		$bracing_list_id = 'bracing_list_id'.$a.'_';
		${$bracing_list_id.$i} = mysql_result($bracing_length_result, $i, "store_item_id");
		$bracing_list_item_id = 'bracing_list_id'.$i;
				
		$i++;
		}
		$a++;
		
		
	}
?>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">

<!--jscript-->
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></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>

<script type="text/javascript">
function validate_required(input,alerttxt,maxvalue)
{
	
with (input)
  {
  if (value>maxvalue)
    {
    alertMessage(1, 'deliverJobWizbase.php?p=3&s=', 'The delivery amount exceeds the balance, the entry will be cleared.<br><br>Please enter a valid amount.');
	input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script>

<script>
function del_all() {
	i=0;
	while (i < 20) {
		j=0;
		while (j < 20) {
		/*alert('supply_text'+i+j);*/ 
		
		if( $('#bracing_supply_text'+i+j).length ) {
		/*alert('supply_text'+i+j); */	
		document.getElementById('bracing_quantity'+i+j ).value=document.getElementById('bracing_balance_text'+i+j).value;
		}
		
		j++;
		
		}
	i++;
	}
}
</script>

<script>
function bracing_populate_length_2(box_no) {
	
	var box_no;
	
   if (box_no==1) {	
var bracing_product_select1_List = document.form1.bracing_product_select1;
ClearOptions(document.form1.bracing_length_select1);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select1[bracing_product_select1.selectedIndex].value == "<?php echo $j ?>") {
	  AddToOptionList(document.form1.bracing_length_select1, ".", ".");  
	  AddToOptionList(document.form1.bracing_length_select1, "", ""); 
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select1, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}

if (box_no==2) {	
var bracing_product_select2_List = document.form1.bracing_product_select2;
ClearOptions(document.form1.bracing_length_select2);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select2[bracing_product_select2.selectedIndex].value == "<?php echo $j ?>") {
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select2, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
if (box_no==3) {	
var bracing_product_select3_List = document.form1.bracing_product_select3;
ClearOptions(document.form1.bracing_length_select3);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select3[bracing_product_select3.selectedIndex].value == "<?php echo $j ?>") {
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select3, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
if (box_no==4) {	
var bracing_product_select4_List = document.form1.bracing_product_select4;
ClearOptions(document.form1.bracing_length_select4);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select4[bracing_product_select4.selectedIndex].value == "<?php echo $j ?>") {
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select4, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
if (box_no==5) {	
var bracing_product_select5_List = document.form1.bracing_product_select5;
ClearOptions(document.form1.bracing_length_select5);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select5[bracing_product_select5.selectedIndex].value == "<?php echo $j ?>") {
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select5, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
if (box_no==6) {	
var bracing_product_select6_List = document.form1.bracing_product_select6;
ClearOptions(document.form1.bracing_length_select6);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select6[bracing_product_select6.selectedIndex].value == "<?php echo $j ?>") {
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select6, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
if (box_no==7) {	
var bracing_product_select71_List = document.form1.bracing_product_select7;
ClearOptions(document.form1.bracing_length_select7);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select7[bracing_product_select7.selectedIndex].value == "<?php echo $j ?>") {
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select7, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
if (box_no==8) {	
var bracing_product_select8_List = document.form1.bracing_product_select8;
ClearOptions(document.form1.bracing_length_select8);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select8[bracing_product_select8.selectedIndex].value == "<?php echo $j ?>") {
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select8, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
</script>

<script language="javascript">
        function addRow(dataTable) {
 
            var table = document.getElementById(dataTable);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
			var bracing_line_no = rowCount-1;
			
			
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            element1.name="bracing_line_checkbox"+bracing_line_no;
			element1.id="bracing_line_checkbox"+bracing_line_no;
			
			var element7 = document.createElement("input");
            element7.type = "hidden";
            element7.name = "length_list_number"+bracing_line_no;
			element7.id = "length_list_number"+bracing_line_no;
			element7.value = '0';
			cell1.appendChild(element7);
			
			var element8 = document.createElement("input");
            element8.type = "hidden";
            element8.name = "length_list_number_index"+bracing_line_no;
			element8.id = "length_list_number_index"+bracing_line_no;
			element8.value = '2';
			cell1.appendChild(element8);
			
			var element10 = document.createElement("input");
            element10.type = "hidden";
            element10.name = "bracing_product_name"+bracing_line_no;
			element10.id = "bracing_product_name"+bracing_line_no;
			element10.value = '';
			cell1.appendChild(element10);
			
							
			cell1.appendChild(element1);
 
            var cell2 = row.insertCell(1);
            var element5 = document.createElement("select");
            element5.name = "bracing_product_select"+bracing_line_no;
			element5.id = "bracing_product_select"+bracing_line_no;
			element5.className = "select200";
			element5.style = "width:250px";
			element5.onblur = function() {document.getElementById("length_list_number"+bracing_line_no).value="bracing_product_select"+bracing_line_no;	document.getElementById("bracing_product_name"+bracing_line_no).value =document.getElementById("bracing_product_select"+bracing_line_no).options[document.getElementById("bracing_product_select"+bracing_line_no).selectedIndex].text; };
			element5.onchange = function () { document.getElementById("bracing_line_checkbox"+bracing_line_no).checked = "checked";
			document.getElementById("length_list_number"+bracing_line_no).value="bracing_product_select"+bracing_line_no;	
			document.getElementById("bracing_reason_text"+bracing_line_no).value="";
			document.getElementById("bracing_additional_text"+bracing_line_no).value="";
	
if (bracing_line_no==1) {	
var bracing_product_select1_List = document.form1.bracing_product_select1;
ClearOptions(document.form1.bracing_length_select1);

 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select1[bracing_product_select1.selectedIndex].value == "<?php echo $j ?>") {
	  	AddToOptionList(document.form1.bracing_length_select1, ".", ".");  
		AddToOptionList(document.form1.bracing_length_select1, "", ""); 
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select1, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}

if (bracing_line_no==2) {	
var bracing_product_select2_List = document.form1.bracing_product_select2;
ClearOptions(document.form1.bracing_length_select2);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select2[bracing_product_select2.selectedIndex].value == "<?php echo $j ?>") {
	   AddToOptionList(document.form1.bracing_length_select2, ".", ".");  
	   AddToOptionList(document.form1.bracing_length_select2, "", ""); 
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select2, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}

if (bracing_line_no==3) {	
var bracing_product_select3_List = document.form1.bracing_product_select3;
ClearOptions(document.form1.bracing_length_select3);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select3[bracing_product_select3.selectedIndex].value == "<?php echo $j ?>") {
	    AddToOptionList(document.form1.bracing_length_select3, ".", ".");  
		AddToOptionList(document.form1.bracing_length_select3, "", ""); 
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select3, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}
   
if (bracing_line_no==4) {	
var bracing_product_select4_List = document.form1.bracing_product_select4;
ClearOptions(document.form1.bracing_length_select4);
 <?php 
   $j=0;
   while ($j<15)  { ?>

   if (bracing_product_select4[bracing_product_select4.selectedIndex].value == "<?php echo $j ?>") {
	     AddToOptionList(document.form1.bracing_length_select4, ".", ".");  
		 AddToOptionList(document.form1.bracing_length_select4, "", ""); 
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select4, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}

if (bracing_line_no==5) {	
var bracing_product_select5_List = document.form1.bracing_product_select5;
ClearOptions(document.form1.bracing_length_select5);
 <?php 
   $j=0;
   while ($j<16)  { ?>

   if (bracing_product_select5[bracing_product_select5.selectedIndex].value == "<?php echo $j ?>") {
	     AddToOptionList(document.form1.bracing_length_select5, ".", ".");  
		 AddToOptionList(document.form1.bracing_length_select5, "", ""); 
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select5, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
}

document.getElementById("bracing_length_select"+bracing_line_no).options.selectedIndex = 1;
}
cell2.appendChild(element5);
			
			var option0 = document.createElement("option");
   				 	option0.text = ".";
    				option0.value = ".";
					element5.add(option0);
				
			/*var option1 = document.createElement("option");
   				 	option1.text = ".";
    				option1.value = ".";
				element5.add(option1);*/

			
			<?php
    			for ($i = 0; $i < count($arrId2); $i++) { ?>
				
				var option<?php echo $i?> = document.createElement("option");
   				 	option<?php echo $i?>.text = "<?php echo $arrName2[$i]?>";
    				option<?php echo $i?>.value = "<?php echo $arrId2[$i]?>";
				element5.add(option<?php echo $i?>);
			<?php	
			}
     ?>	



		 
            var cell3 = row.insertCell(2);
            var element2 = document.createElement("select");
            element2.name = "bracing_length_select"+bracing_line_no;
			element2.id = "bracing_length_select"+bracing_line_no;
			element2.className = "text200";
			
			
			cell3.appendChild(element2);
			
			element2.onchange = function() {document.getElementById("length_list_number_index"+bracing_line_no).value=document.getElementById("bracing_length_select"+bracing_line_no).selectedIndex;};
			
			var cell4 = row.insertCell(3);
            var element12 = document.createElement("input");
            element12.type = "text";
            element12.name = "bracing_reason_text"+bracing_line_no;
			element12.id = "bracing_reason_text"+bracing_line_no;
			element12.className = "text200";
			element12.value = ".";
			cell4.appendChild(element12);
			
			var cell5 = row.insertCell(4);
			var element6 = document.createElement("input");
            element6.type = "text";
            element6.name = "bracing_additional_text"+bracing_line_no;
			element6.id = "bracing_additional_text"+bracing_line_no;
			element6.className = "text60";
			element6.value = ".";
			element6.onkeypress= function() {return numbersonly(this, event)};
				

            var element4 = document.createElement("input");
            element4.type = "hidden";
            element4.name = "bracing_add_line_num";
			element4.id = "bracing_add_line_num";
			element4.value = rowCount;
			
						
            cell5.align = "right";						
			cell5.appendChild(element6);
            cell5.appendChild(element4);
			
			
			
						
var element9 = document.createElement("script");
			element9.setAttribute('type', 'text/javascript');
			element9.innerHTML="var frmvalidator  = new Validator('form1');frmvalidator.EnableMsgsTogether();for (i = 0; i < 10; i++) {frmvalidator.addValidation('bracing_product_select'+i,'req','Please select item on line '+(i+1)+'.');frmvalidator.addValidation('bracing_length_select'+i,'req','Please select length on line '+(i+1)+'.');frmvalidator.addValidation('bracing_reason_text'+i,'req','Please enter reason on line '+(i+1)+'.');frmvalidator.addValidation('bracing_additional_text'+i,'req','Please enter quantity on line '+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element9);
			
			element1.onmouseup = function() {
				if (document.getElementById('bracing_line_checkbox'+bracing_line_no).checked) {
                         element5.style.background = '#E1E1E1';
						 element6.style.background = '#E1E1E1';
						 element12.style.background = '#E1E1E1';
						 element5.options.selectedIndex = 0;
						 element6.value = '0';
						 element12.value = '.';
						 element5.disabled = true;
						 element6.disabled = true;
						 element2.selectedIndex=-1; 
						 element2.disabled=true;
						 element2.style.background = '#E1E1E1';
						 element2.options.selectedIndex = 0;
						 element8.value='';
						 element10.value=''; 
						 
                } else {
                        element5.style.background = '#FFF';
						element6.style.background = '#FFF';
						element12.style.background = '#FFF';
						element5.options.selectedIndex = 0;
						element6.value = '';
						element12.value = '';
						element5.disabled = false;
						element6.disabled = false;
						element12.disabled = false;
						element2.disabled=false;
						element2.style.background = '#FFF';
						 
                }
			}			
			
}

</script>


<script language="Javascript">
<!--
function bracing_populate_length(line_no) {
var line_no;	
        
   if (line_no==0) {
   var bracing_product_select0_List = document.form1.bracing_product_select0;
   // Clear out the list of teams
   ClearOptions(document.form1.bracing_length_select0);
   AddToOptionList(document.form1.bracing_length_select0, ".", ".");  
   AddToOptionList(document.form1.bracing_length_select0, "", ""); 
    
   
   
   <?php 
   $j=0;
   while ($j<15)  { ?>
      
   if (bracing_product_select0[bracing_product_select0.selectedIndex].value == "<?php echo $j?>") {
	  
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select0, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
   }
   
  if (line_no==1) {
   var bracing_product_select1_List = document.form1.bracing_product_select1;
   // Clear out the list of teams
   ClearOptions(document.form1.bracing_length_select1);
   AddToOptionList(document.form1.bracing_length_select1, "", "");  
   AddToOptionList(document.form1.bracing_length_select1, "", ""); 
   
   <?php 
   $j=0;
   while ($j<15)  { ?>
      
   if (bracing_product_select1[bracing_product_select1.selectedIndex].value == "<?php echo $j?>") {
	  
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select1, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
   }
   
   if (line_no==2) {
   var bracing_product_select1_List = document.form1.bracing_product_select2;
   // Clear out the list of teams
   ClearOptions(document.form1.bracing_length_select2);
   AddToOptionList(document.form1.bracing_length_select2, ".", ".");  
   AddToOptionList(document.form1.bracing_length_select2, "", ""); 
   
   <?php 
   $j=0;
   while ($j<15)  { ?>
      
   if (bracing_product_select2[bracing_product_select2.selectedIndex].value == "<?php echo $j?>") {
	   
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select2, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
   }
   
   if (line_no==3) {
   var bracing_product_select1_List = document.form1.bracing_product_select3;
   // Clear out the list of teams
   ClearOptions(document.form1.bracing_length_select3);
   AddToOptionList(document.form1.bracing_length_select3, ".", ".");  
   AddToOptionList(document.form1.bracing_length_select3, "", ""); 
   
   <?php 
   $j=0;
   while ($j<15)  { ?>
      
   if (bracing_product_select3[bracing_product_select3.selectedIndex].value == "<?php echo $j?>") {
	   
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select3, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
   }
   
   if (line_no==4) {
   var bracing_product_select1_List = document.form1.bracing_product_select4;
   // Clear out the list of teams
   ClearOptions(document.form1.bracing_length_select4);
   AddToOptionList(document.form1.bracing_length_select4, ".", ".");  
   AddToOptionList(document.form1.bracing_length_select4, "", ""); 
   
   <?php 
   $j=0;
   while ($j<15)  { ?>
      
   if (bracing_product_select4[bracing_product_select4.selectedIndex].value == "<?php echo $j?>") {
	   
	  <?php
	  $bracing_list_num = 'bracing_list_num'.$j; 
	  $bracing_teller = ${$bracing_list_num}+1;
	  $t=0;
	  while ($t< $bracing_teller) { 
	  $bracing_list = 'bracing_list'.$j.'_';
	  $bracing_list_id = 'bracing_list_id'.$j.'_';
	  ?>
	  AddToOptionList(document.form1.bracing_length_select4, "<?php echo ${$bracing_list_id.$t} ?>", "<?php echo ${$bracing_list.$t} ?> ");
	  <?php
	  $t++;
	  } ?>
   }
   <?php
   $j++;   
   }
  ?>
   }
   
}


function ClearOptions(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x = x - 1) {
      OptionList[x] = null;
   }
}


function AddToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}



//-->
</script>


<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />
<link href="../css/main.css" rel="stylesheet" type="text/css">

<!--jscript-->
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>

<?php
$table_name = $_SESSION['db_prefix']."_authorised_timber";
$table_name1 = $_SESSION['db_prefix']."_store_items";


$bracing_query = "SELECT $table_name.auth_timber_group, $table_name.auth_timber_name, $table_name.store_item_id, $table_name.reserved, $table_name.delivered, $table_name1.store_item_id, SUM($table_name.reserved) AS tot_reserved FROM $table_name, $table_name1 WHERE $table_name.job_no = '".$_SESSION['job_no']."' AND $table_name.store_item_id=$table_name1.store_item_id AND $table_name.store_item_id>0 AND $table_name.reserved>0 AND  $table_name.auth_timber_group='bracing' GROUP BY $table_name.auth_timber_name ORDER BY $table_name.auth_timber_name ";
$bracing_result = mySQL_query($bracing_query);
$bracing_num = mysql_num_rows($bracing_result);
//echo '<br>'.$bracing_query;



$all=$_GET['all'];
//echo 'all='.$all;
$tab=0;

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


<body onLoad="MM_showHideLayers('wait','','hide');<?php if ($_SESSION['error3']=='yes') {?> alertMessage(2, '', 'The quantity in the orange coloured boxes exceeded the maximum available stock quantity.<br><br>The quantity is now replaced by the maximum available stock quantity.')<?php } ?>;
<?php
$i=0;
while ($i<$_SESSION['line_no3c']+1) { ?>

document.getElementById('bracing_product_select<?php echo $i ?>').options.selectedIndex = <?php echo $_SESSION['bracing_timber_type_select'.$i]?>;
bracing_populate_length(<?php echo $i ?>);
document.getElementById('bracing_length_select<?php echo $i ?>').selectedIndex = <?php echo $_SESSION['bracing_length_select_index'.$i]?>;
document.getElementById('bracing_reason_text<?php echo $i ?>').value='<?php echo $_SESSION['bracing_reason_text'.$i]?>';
document.getElementById('length_list_number<?php echo $i ?>').value='bracing_product_select<?php echo $i ?>';
document.getElementById('length_list_number_index<?php echo $i ?>').value=document.getElementById('bracing_length_select<?php echo $i ?>').selectedIndex;
<?php
$i++;
}
?>
;" 
onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');"
>
<?php 
$i=0;
//echo '<br>line numbers:'.$_SESSION['line_no3a'];
while ($i<$_SESSION['line_no3a']) {
	//echo '<br>'. $_SESSION['bracing_timber_type_select'.$i].'  '.$_SESSION['bracing_length_select_index'.$i];
	$i++;
}?>
<?php $_SESSION['error3']='no'?>
<div class="page_middle_frame">
<form action="deliverJobWizbase.php?p=4&s=3" method="POST" name="form1" id="form1"> 
<div class="wizard_frame">
  <table width="640" border="0">
    <tr>
      <td width="596"><?php if ($_SESSION['variations_permission']=='yes') { ?><label class="label_red_bold"><font size="-1">Make variations on the authorised quantity here.</font></label> <img src="../images/red_arrow_down_2.png" width="16" height="16">        <?php } ?></td>
      <td width="84"><input name="button" type="button" class="imagebutton" id="button" onClick="del_all();" value="Deliver all" checked="checked" ></td>
    </tr>
  </table>
</div>
        <br>
<br>
<br><br>
<br>
   <div class="page_inside_frame">

            <table width="645" align="left" id="table_details_display" >
              <tr style="border-bottom:double">
                <td><label class="label_std">Bracing</label></td>
                <td>Length</td>
                <td>Stock</td>
                <td align="center">Authorised</td>
                <td align="center">Delivered</td>
                <td align="center">Balance</td>
                <td align="center">deliver</td>
              </tr>
              <?php 
			 $j=0;
			 $temp_name = '';
			 $tot_length=0;
			 while ($j<$bracing_num) {
				 $tab=1;
				 $bracing_name = mysql_result($bracing_result, $j, "auth_timber_name");
				 
				 
				 	$table_name = $_SESSION['db_prefix']."_authorised_timber";
					$bracing_sub_query = "SELECT * FROM $table_name WHERE  auth_timber_name = '".$bracing_name."' AND job_no = '".$_SESSION['job_no']."' AND reserved>0";
					$bracing_sub_result = mySQL_query($bracing_sub_query);
					$bracing_sub_num = mysql_num_rows($bracing_sub_result);
					$k=0;
					$temp_name = '';
					$tot_length=0;
					while ($k<$bracing_sub_num) {
					$store_item_id = mysql_result($bracing_sub_result, $k, "store_item_id");
					
$table_name = $_SESSION['db_prefix']."_variations_temp";
		$variations_query = "SELECT de_auth_quantity FROM $table_name WHERE job_no = '".$_SESSION['job_no']."' AND store_item_id = '".$store_item_id."' AND timber_name = '".$bracing_name."' AND user =  '".$_SESSION['username']."'  ";
		
		$variations_result = mySQL_query($variations_query);
		$variations_num = mysql_num_rows($variations_result);
		if ($variations_num>0){
		$a2b = mysql_result($variations_result, 0, "de_auth_quantity");	
		}
		else {
			$a2b=0;
		}					
					
					
				 	$a4 = mysql_result($bracing_sub_result, $k, "reserved")-mysql_result($bracing_sub_result, $k, "de_authorised")-$a2b;
					//$a5 = mysql_result($bracing_sub_result, $k, "delivered");
					
					$table_name = $_SESSION['db_prefix']."_authorised_timber";
					$delivered_query = "SELECT SUM(delivered) AS tot_delivered FROM $table_name WHERE auth_timber_name = '".$bracing_name."' AND job_no = '".$_SESSION['job_no']."' AND store_item_id = '".$store_item_id."' ";
					$delivered_result = mySQL_query($delivered_query);
					$delivered_num = mysql_num_rows($delivered_result);
					if ($delivered_num!=0) {
					$a5 = mysql_result($delivered_result, 0, "tot_delivered");
					}
					else {
						$a5='';
					}
					
					$table_name = $_SESSION['db_prefix']."_supply_customer_temp";
					$supply_query = "SELECT quantity, extra FROM $table_name WHERE store_item_id = '".$store_item_id."' AND timber_type = '".$bracing_name."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' AND NOT (extra='yes' )";
					//echo '<br>'.$supply_query;
					$supply_result = mySQL_query($supply_query);
					$supply_num = mysql_num_rows($supply_result);
					if ($supply_num!=0) {
					$a7 = mysql_result($supply_result, 0, "quantity");
					$extra = mysql_result($supply_result, 0, "extra");
					}
					else {
						$a7='';
						$extra='';
					}
					if ($a7<0) {$a7=0;}
					
					//echo '<br>'.$a5;
				 	if ($store_item_id!='0') {
					$table_name = $_SESSION['db_prefix']."_store_items";
					$item_query = "SELECT item_name, length, quantity FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
					$item_result = mySQL_query($item_query);
					$item_name = mysql_result($item_result, 0, "item_name");
					$length = mysql_result($item_result, 0, "length");
					$stock_quantity = mysql_result($item_result, 0, "quantity");
					$a6=$a4-$a5;
					
					}
					
					else {
						$item_name='';
					
					$a4='';
					$a5='';
					$a6='';
					}
	
			 ?>
              <tr <?php if ( $k+1==$bracing_sub_num) {?>style="border-bottom:double;"<?php } ?>>
                <td width="158"><?php if ($temp_name!=$bracing_name) echo $bracing_name; ?>
                  <?php $temp_name=$bracing_name;?><?php $_SESSION['truss_type'.$j] = $bracing_name; $_SESSION['bracing_timber_type'.$j]=$bracing_name?></td>
                <td width="75" align="left" ><?php  echo $length;?>
                <input type="hidden" name="bracing_item_id<?php echo $j.$k ?>" id="bracing_item_id<?php echo $j.$k ?>" value="<?php echo $store_item_id?>"></td>
                <td width="43" align="left" ><?php echo $stock_quantity ?></td>
                <td width="112" align="left" >
                
                <input name="bracing_supply_text<?php echo  $j.$k ?>" type="text" class="text50" id="bracing_supply_text<?php echo  $j.$k ?>"  value="<?php echo $a4 ?> " 
                
                onChange="
                waarde = document.getElementById('bracing_supply_text<?php echo  $j.$k ?>').value - document.getElementById('bracing_delivered_text<?php echo  $j.$k ?>').value;
                if (waarde<0) {
                  waarde2 = 0;
                  }
                  else {
                  waarde2 = waarde;
                  }
                document.getElementById('bracing_quantity<?php echo  $j.$k ?>').value= waarde2;
                
                document.getElementById('bracing_supply_text<?php echo  $j.$k ?>').style.background = '#FFE7CE'; 
                document.getElementById('bracing_quantity<?php echo  $j.$k ?>').style.background = '#FFE7CE'; 
                document.getElementById('bracing_authorised_text<?php echo  $j.$k ?>').value= 'var';
                " 
                
                 onfocus = "this.select();" <?php if ($_SESSION['variations_permission']!='yes') {?> readonly  <?php } ?>  >
                 &nbsp;&nbsp;&nbsp;<?php echo $a4 ?>
                  <input type="hidden" name="bracing_authorised_text<?php echo $j.$k ?>" id="bracing_authorised_text<?php echo $j.$k ?>" value="<?php echo $extra?>">
                <?php if ($extra=='var'){ echo '**'; } ?></td>
                <td width="77" align="center"><?php if ($a4>0) {echo $a5;}?>
                <input name="bracing_delivered_text<?php echo $j.$k ?>" id="bracing_delivered_text<?php echo $j.$k ?>" type="hidden" value="<?php echo $a5 ?>"></td>
                <td width="62" align="center"><?php if ($a4>0) {echo $a6;}?><input name="bracing_balance_text<?php echo $j.$k ?>" id="bracing_balance_text<?php echo $j.$k ?>" type="hidden" value="<?php echo $a6 ?>"></td>
                <td width="86" align="center"><input name="bracing_quantity<?php echo  $j.$k ?>" type="text" class="text60" id="bracing_quantity<?php echo  $j.$k ?>"  <?php if ($_SESSION['timber3_error'.$j.$k]=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['timber_error'.$_SESSION['timber3_error'.$j.$k]]='no' ?>
 onkeypress="return numbersonly(this, event)" onKeyUp="validate_required(bracing_quantity<?php echo $j.$k?>, 'The delivery amount exceeds the balance, the entry will be cleared. ' +'\n'+ 'Please enter a valid amount.', <?php echo $a6 ?>)"  autocomplete="off" autofocus onfocus = "this.select();" tabindex="<?php echo $j+1?>"  value="<?php echo $a7?>">                  
 <input name="bracing_length<?php echo $j.$k ?>" type="hidden" value="<?php echo $length?>"></td>
              </tr>
              <?php
			 $k++;
			 $_SESSION['line_no3b'.$j]=$k;
					}
			 $j++;
			 }
			 $_SESSION['line_no3a']=$j;
			 //echo $_SESSION['line_no3a'];
			 
			  $table_name = $_SESSION['db_prefix']."_supply_customer_temp";
	$extra_query = "SELECT store_item_id, quantity, timber_type FROM $table_name WHERE job_no = '".$_SESSION['job_no']."' AND user = '".$_SESSION['username']."' AND extra='yes' AND truss_type='Bracing' ";
	$extra_result = mySQL_query($extra_query);
	$extra_num = mysql_num_rows($extra_result);
	$j=0;
	while ($j<$extra_num) {
		$b1a = mysql_result($extra_result, $j, "timber_type");
		$b1 = mysql_result($extra_result, $j, "store_item_id");
		  	$table_name = $_SESSION['db_prefix']."_store_items";
			$item_query = "SELECT item_name, quantity, length FROM $table_name WHERE store_item_id = '".$b1."'  ";
			$item_result = mySQL_query($item_query);
			$item_num = mysql_num_rows($item_result);
			
			if ($item_num!=0) {
			      $b1b = number_format(mysql_result($item_result, 0, "quantity"), 0, '.', ',');
				  $b3 = mysql_result($item_result, 0, "length");
			}
        $b2 = mysql_result($extra_result, $j, "quantity");
		if ($b2>$b1b) { 
				$b2a = $b1b;
				$over = 'yes'; }
		else {
			$b2a = $b2;
			$over='';
		}
			
         ?>     
              <?php
		 
	$j++;
	}
	?>    
             
             
            </table>
            
    <?php
	 $table_name = $_SESSION['db_prefix']."_supply_customer_temp";
	 $bracing_additional_query = "SELECT store_item_id, quantity  FROM $table_name WHERE truss_type = 'bracing' AND job_no = '".$_SESSION['job_no']."' AND user = '".$_SESSION['username']."' AND extra = 'yes' ";
	 $bracing_additional_result = mySQL_query($bracing_additional_query);
	 $bracing_additional_num = mysql_num_rows($bracing_additional_result);
	 	if ($bracing_additional_num==0) {
			$b1='';
			$b1a='';
			$b2='.';	
		}
		else {
			    $b1 = mysql_result($bracing_additional_result, 0, "store_item_id");
				$b2 = mysql_result($bracing_additional_result, 0, "quantity");
				$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$b1."'  ";
				$name_result = mySQL_query($name_query);
				$b1a = mysql_result($name_result, 0, "item_name");
		}      
           
      ?>             


<div class="wizard_spacer_frame" style="height:5px;"></div>      
            
    
     <?php if ($_SESSION['variations_permission']=='yes') { ?>    
           <table id="dataTable" width="645">
           <thead>
               <tr>
                 <td colspan="5">Not authorised, extra deliveries:</td>
               </tr>
             </thead>
             <tr>
               <td>&nbsp;</td>
               <td>Timber type</td>
               <td>Length</td>
               <td>Reason for extra delivery</td>
               <td align="left">Qty               
             </tr>
             <tr>
             <script>
			 function bracing_check_it() {
				 if (document.getElementById('bracing_line_checkbox0').checked) {
                         document.getElementById('bracing_additional_text0').style.background = '#E1E1E1';
						 document.getElementById('bracing_product_select0').style.background = '#E1E1E1';
						 document.getElementById('bracing_product_select0').options.selectedIndex = 0;
						 document.getElementById('bracing_additional_text0').value = '0';
						 document.getElementById('bracing_product_select0').disabled = true;
						 document.getElementById('bracing_additional_text0').disabled = true;
						 document.getElementById('bracing_reason_text0').value = '.';
						 document.getElementById('bracing_reason_text0').style.background = '#E1E1E1';
						 document.getElementById('bracing_length_select0').style.background = '#E1E1E1';
						 document.getElementById('bracing_length_select0').options.selectedIndex = 0;
						 document.getElementById('length_list_number0').value='';
						 document.getElementById('length_list_number_index0').value='';
						 
                } else {
                        document.getElementById('bracing_additional_text0').style.background = '#FFF';
						document.getElementById('bracing_product_select0').style.background = '#FFF';
						document.getElementById('bracing_product_select0').options.selectedIndex = 1;
						document.getElementById('bracing_additional_text0').value = '';
						document.getElementById('bracing_product_select0').disabled = false;
						document.getElementById('bracing_additional_text0').disabled = false;
						document.getElementById('bracing_reason_text0').value = '';
						document.getElementById('bracing_reason_text0').style.background = '#FFF';
						document.getElementById('bracing_length_select0').style.background = '#FFF';
						document.getElementById('bracing_length_select0').options.selectedIndex = -1;
						
						
                }
				}
		     </script>
               <td width="27"><input type="checkbox" name="bracing_line_checkbox0" id="bracing_line_checkbox0"  onMouseUp="bracing_check_it();" <?php if ($b1!='') { ?> checked="checked" <?php } ?>/></td>
               
               <td width="257"><label id="closeOnSelect">
                 <!--<input type="checkbox" /> Close on selection-->
                 </label>
                 <select name="bracing_product_select0" class="select200" id="bracing_product_select0" style="width:250px;"  onChange="document.getElementById('bracing_line_checkbox0').checked = 'checked'; bracing_populate_length(0); document.getElementById('bracing_length_select0').options.selectedIndex = 1;  document.getElementById('length_list_number0').value='bracing_product_select0'; document.getElementById('bracing_additional_text0').value=''; document.getElementById('bracing_reason_text0').value='';" onBlur="document.getElementById('bracing_product_name0').value =document.getElementById('bracing_product_select0').options[document.getElementById('bracing_product_select0').selectedIndex].text;" >
         <option value="." selected="selected">.</option>
         <option> </option>          
                   <?php
    	for ($k = 0; $k < count($arrId2); $k++) {
		echo "<option value=" . "\"" . $arrId2[$k] . "\"" . ">" . $arrName2[$k] . "</option>";
		
		}
		
     ?>
     
               </select></td>
               <td width="52"><select name="bracing_length_select0" id="bracing_length_select0"  onChange="document.getElementById('length_list_number_index0').value=document.getElementById('bracing_length_select0').selectedIndex;">
                 <option value=".">.</option>
              </select> 
                <input type="hidden" name="length_list_number0" id="length_list_number0" value=""><input type="hidden" name="length_list_number_index0" id="length_list_number_index0" value="">
                <input type="hidden" name="bracing_product_name0" id="bracing_product_name0" value="<?php echo $_SESSION['bracing_productName0'] ?>"></td>
               <td width="191"><input name="bracing_reason_text0" type="text" class="text200" id="bracing_reason_text0" value="<?php echo $_SESSION['bracing_reason_text0'] ?>"></td>
               <td width="94" align="right"><input  name="bracing_additional_text0" type="text" class="text60" id="bracing_additional_text0" value="<?php echo $b2?>"  <?php if ($_SESSION['bracing_error0']=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['bracing_error0']='no' ?> onKeyPress="return numbersonly(this, event)"/>
                 <input type="hidden" name="bracing_add_line_num" id="bracing_add_line_num" value="1" >
                 
             </tr>
             <?php
		$i=1;
		while ($i<$bracing_additional_num) {
		$b1 = mysql_result($bracing_additional_result, $i, "store_item_id");
		$b2 = mysql_result($bracing_additional_result, $i, "quantity");
		$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$b1."'  ";
				$name_result = mySQL_query($name_query);
				$b1a = mysql_result($name_result, 0, "item_name");
		?>
             <tr>
             
               <td><input type="checkbox" name="bracing_line_checkbox<?php echo $i ?>" id="bracing_line_checkbox<?php echo $i ?>" checked="checked" onClick="{ if (document.getElementById('bracing_line_checkbox<?php echo $i ?>').checked) {
                        document.getElementById('bracing_additional_text<?php echo $i ?>').style.background = '#FFF';
						document.getElementById('bracing_product_select<?php echo $i ?>').style.background = '#FFF'; 
                        document.getElementById('bracing_product_select<?php echo $i ?>').options.selectedIndex = 1;
						document.getElementById('bracing_additional_text<?php echo $i ?>').value = '';
                        document.getElementById('bracing_product_select<?php echo $i ?>').disabled = false;
						document.getElementById('bracing_additional_text<?php echo $i ?>').disabled = false;
                        document.getElementById('bracing_length_select<?php echo $i ?>').disabled = false;
                        document.getElementById('bracing_length_select<?php echo $i ?>').style.background = '#FFF';
                        document.getElementById('bracing_reason_text<?php echo $i ?>').disabled = false;
                        document.getElementById('bracing_reason_text<?php echo $i ?>').style.background = '#FFF';
                        
                                             
                } else {
                        document.getElementById('bracing_additional_text<?php echo $i ?>').style.background = '#E1E1E1';
						document.getElementById('bracing_product_select<?php echo $i ?>').style.background = '#E1E1E1';
                        
                        document.getElementById('bracing_product_select<?php echo $i ?>').options.selectedIndex = 0;
						document.getElementById('bracing_additional_text<?php echo $i ?>').value = '0';
                        document.getElementById('bracing_product_select<?php echo $i ?>').disabled = true;
						document.getElementById('bracing_additional_text<?php echo $i ?>').disabled = true;
                        document.getElementById('bracing_reason_text<?php echo $i ?>').disabled = true;
                        document.getElementById('bracing_reason_text<?php echo $i ?>').style.background = '#E1E1E1';
                        
                        
                        
                        document.getElementById('bracing_length_select<?php echo $i ?>').disabled = true;
                        
                        document.getElementById('bracing_length_select<?php echo $i ?>').options.selectedIndex = 0;
                        document.getElementById('bracing_length_select<?php echo $i ?>').style.background = '#E1E1E1';
                        document.getElementById('length_list_number<?php echo $i ?>').value='';
						document.getElementById('length_list_number_index<?php echo $i ?>').value='';
                        
                }
				}
                "/></td>
               <td><select name="bracing_product_select<?php echo $i ?>" class="select200" id="bracing_product_select<?php echo $i ?>" style="width:250px;" onChange="document.getElementById('bracing_line_checkbox<?php echo $i ?>').checked = 'checked'; document.getElementById('length_list_number<?php echo $i ?>').value='bracing_product_select<?php echo $i ?>';" onBlur="document.getElementById('bracing_product_name<?php echo $i ?>').value =document.getElementById('bracing_product_select<?php echo $i ?>').options[document.getElementById('bracing_product_select<?php echo $i ?>').selectedIndex].text;">
             <option value="." selected="selected">.</option>
         <option> </option>  
                 <?php
    	for ($k = 0; $k < count($arrId2); $k++) {
		echo "<option value=" . "\"" . $arrId2[$k] . "\"" . ">" . $arrName2[$k] . "</option>";
		$_SESSION['bracing_productName'.$j] = $arrName2[$k];
		 }
     ?>
               </select></td>
               <td><select name="bracing_length_select<?php echo $i ?>" id="bracing_length_select<?php echo $i ?>"  onChange="document.getElementById('length_list_number_index<?php echo $i ?>').value=document.getElementById('bracing_length_select<?php echo $i ?>').selectedIndex;">
                <option value="x">x</option>
                
               </select>
                 <input type="hidden" name="length_list_number<?php echo $i ?>" id="length_list_number<?php echo $i ?>" value="">
               <input type="hidden" name="length_list_number_index<?php echo $i ?>" id="length_list_number_index<?php echo $i ?>" value="">
               <input type="hidden" name="bracing_product_name<?php echo $i ?>" id="bracing_product_name<?php echo $i ?>" value="<?php echo $_SESSION['bracing_productName'.$i] ?>"></td>
               <td><input name="bracing_reason_text<?php echo $i ?>" type="text" class="text200" id="bracing_reason_text<?php echo $i ?>" value="<?php echo $_SESSION['bracing_reason_text'.$i] ?>"></td>
              
               <td align="right"><input  name="bracing_additional_text<?php echo $i ?>" type="text" class="text60" id="bracing_additional_text<?php echo $i ?>" value="<?php echo $b2?>" onKeyPress="return numbersonly(this, event)" <?php if ($_SESSION['bracing_error'.$i]=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['bracing_error'.$i]='no' ?>/>
                 <input type="hidden" name="bracing_add_line_num" id="bracing_add_line_num" value="<?php echo $bracing_additional_num?>" >               
             </tr>
             <?php
			  $i++;
		}
		?>
           </table>
           <input type="button" class="imagebutton" onClick="addRow('dataTable')" value="Add line" /><div align="right"><label class="label_small">Not to save a line uncheck the line box.</label></div>
           <br>
        <?php } ?>
      <?php
	 $table_name = $_SESSION['db_prefix']."_supply_customer_temp";
	 $bracing_additional_query = "SELECT store_item_id, quantity, timber_type  FROM $table_name WHERE truss_type = 'bracing' AND job_no = '".$_SESSION['job_no']."' AND user = '".$_SESSION['username']."' AND extra = 'yes' ";
	 $bracing_additional_result = mySQL_query($bracing_additional_query);
	 $bracing_additional_num = mysql_num_rows($bracing_additional_result);
	 	if ($bracing_additional_num==0) {
			$b0='';
			$b0a='';
			$b1='';
			$b1a='';
			$b2='.';	
		}
		else {
			    $b0 = mysql_result($bracing_additional_result, 0, "timber_type");
				//$b0a = $arrName2[$b0];
				$b1 = mysql_result($bracing_additional_result, 0, "store_item_id");
				$b2 = mysql_result($bracing_additional_result, 0, "quantity");
				$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$b1."'  ";
				$name_result = mySQL_query($name_query);
				$b1a = mysql_result($name_result, 0, "item_name");
		}      
           
      ?>             
            
        </div>
       
<div class="button_bar_frame" style="width:650px:">
        
      <table width="590" height="50" align="left" id="table_button_bar">
        <tr>
          <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_goToURL('parent','deliverJobWizbase.php?s=&p=2&all=none'); return document.MM_returnValue;MM_showHideLayers('wait','','show');return document.MM_returnValue" tabindex="<?php echo $tab+2?>"/></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="3" />
            <input name="s" type="hidden" id="s" value="3" />
            <input name="all" type="hidden" id="all" value="none" />
            </td>
          <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../store/store_main.php');" value="Cancel" tabindex="<?php echo $tab+3?>"/></td>
          <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; " tabindex="<?php echo $tab+1?>"/></td>
        </tr>
      </table>
      <div>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  //if (document.getElementById('line_checkbox0').checked) {
//  frmvalidator.addValidation("product_select0","req","Please select item on line 1");
//  frmvalidator.addValidation("additional_text0","req","Please enter quantity on line 1");
//  }
  for (i = 0; i < 10; i++) {
	frmvalidator.addValidation("bracing_product_select"+i,"req","Please select item on line "+(i+1));
	frmvalidator.addValidation("bracing_length_select"+i,"req","Please select length on line "+(i+1));
	frmvalidator.addValidation("bracing_reason_text"+i,"req","Please enter a reason on line "+(i+1));
  	frmvalidator.addValidation("bracing_additional_text"+i,"req","Please enter quantity on line "+(i+1));
}
</script>
</div>
</body>      
<?php
}
?>