<head>
<?php
if ($_SESSION['job_no']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="store_no_return.php";
</script>
<?php
}
else {
   include ('../include/formValidations.php');

$table_name = $_SESSION['db_prefix']."_store_items";
$dropDownQuery = "SELECT store_item_id, item_name, unit FROM $table_name WHERE category= 'Direct materials' AND subCategory = 'Sundries' AND class='' ORDER BY item_name ASC";

$dropDownResult = execsql($dropDownQuery);
	$num = mysql_num_rows($dropDownResult);
	$a = 0;
	$arrId = array ();
	$arrName = array ();
	while ($a < $num) {
		$arrId[$a] = mysql_result($dropDownResult, $a, "store_item_id");
		$arrName[$a] = mysql_result($dropDownResult, $a, "item_name");
		$arrUnit[$a] = mysql_result($dropDownResult, $a, "unit");
		
		$a++;
	}   
?>   

<!--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=4&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;
    }
  }
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>

<script>
function del_all() {
	
	for (var i=0; i < 35; i++) {
		    document.getElementById('quantity'+i).value=document.getElementById('balance_text'+i).value;
	}
}
</script>



<script language="javascript">
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            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 element5 = document.createElement("select");
            element5.name = "product_select"+line_no;
			element5.id = "product_select"+line_no;
			element5.className = "select200";
			element5.style = "width:250px";
			element5.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked"; document.getElementById("additional_reason_text"+line_no).value="";
			document.getElementById("additional_text"+line_no).value="";}
			
			
			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($arrId); $i++) { ?>
				
				var option<?php echo $i?> = document.createElement("option");
   				 	option<?php echo $i?>.text = "<?php echo $arrName[$i]?>";
    				option<?php echo $i?>.value = "<?php echo $arrId[$i]?>";
				element5.add(option<?php echo $i?>);
			<?php	
			}
     ?>	
					 
           			
			var cell3 = row.insertCell(2);
            var element12 = document.createElement("input");
            element12.type = "text";
            element12.name = "additional_reason_text"+line_no;
			element12.id = "additional_reason_text"+line_no;
			element12.className = "text200";
			element12.value = ".";
			cell3.appendChild(element12);
			
			var cell4 = row.insertCell(3);
			var element6 = document.createElement("input");
            element6.type = "text";
            element6.name = "additional_text"+line_no;
			element6.id = "additional_text"+line_no;
			element6.className = "text60";
			element6.value = ".";
			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.onchange = function() {this.value = this.value.replace (/(\...).*/, '$1')};
			element6.style = "text-align:right";		

            var element4 = document.createElement("input");
            element4.type = "hidden";
            element4.name = "add_line_num";
			element4.id = "add_line_num";
			element4.value = rowCount;
            cell4.align = "right";						
			cell4.appendChild(element6);
            cell4.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('product_select'+i,'req','Please select item on line '+(i+1)+'.');frmvalidator.addValidation('additional_reason_text'+i,'req','Please enter a reason on line '+(i+1)+'.');frmvalidator.addValidation('additional_text'+i,'req','Please enter quantity on line '+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element9);
			
			element1.onmouseup = function() {
				 if (document.getElementById('line_checkbox'+line_no).checked) {
                         element5.style.background = '#F0F0F0';
						 element6.style.background = '#F0F0F0';
						 element12.style.background = '#F0F0F0';
						 element5.options.selectedIndex = 1;;
						 element6.value = '0';
						 element12.value = '.';
						 element5.disabled = true;
						 element6.disabled = true;
						 element12.disabled = true;
						 
                } 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;
				
                }
			}			
			
}

</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']."_captured_sundries";
$sundries_query = "SELECT * FROM $table_name WHERE cap_job = '".$_SESSION['job_no']."' ";
$sundries_result = mySQL_query($sundries_query);
$sundries_num = mysql_num_rows($sundries_result);

//$all=$_POST['all'];

$table_name = $_SESSION['db_prefix']."_supply_customer_temp";
$additional_query = "SELECT store_item_id, quantity  FROM $table_name WHERE truss_type = 'Additional' AND job_no = '".$_SESSION['job_no']."' AND user = '".$_SESSION['username']."' AND extra = 'yes' ";
$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_result);
 	
?>

</head>

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

<body onLoad="MM_showHideLayers('wait','','hide'); <?php if ($_SESSION['error6']=='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 if ($additional_num==0) { ?>document.getElementById('product_select0').selectedIndex=0; document.getElementById('additional_reason_text0').value='.'; document.getElementById('additional_text0').value='.'; <?php } ?> ;    " onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');  ">       
<?php $_SESSION['error6']='no'?>
<div class="page_middle_frame">
<form action="deliverJobWizbase.php?p=7&s=6" 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>
<div class="wizard_frame" align="right"></div>
<br>
<br>
        
<br>
<br>

         <div class="wizard_frame" style="height:auto;">
           <table width="645" id="table_details_display">
             <tr>
               <th width="140">Product</th>
               <th width="94">Stock</th>
               <th width="113">Authorised</th>
               <th width="89">Delivered</th>
               <th width="99">Balance</th>
               <th width="82">Deliver</th>
             </tr>
               <?php 
	if ($sundries_num!=0) {
	$i=0;
	while ($i<$sundries_num) {
		$a1 = mysql_result($sundries_result, $i, "cap_item_id");
			$table_name = $_SESSION['db_prefix']."_store_items";
			$item_query = "SELECT item_name, quantity FROM $table_name WHERE store_item_id = '".$a1."'  ";
			$item_result = mySQL_query($item_query);
			$item_num = mysql_num_rows($item_result);
			if ($item_num!=0) {
			      $a1a = mysql_result($item_result, 0, "item_name");
				  $a1b = mysql_result($item_result, 0, "quantity");
			}
		
		//$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 = '".$a1."' 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;
//		}
		
		$a2 = mysql_result($sundries_result, $i, "auth_quantity");
		//$a2=$a2a;
			
		$a4 = mysql_result($sundries_result, $i, "delivered");
		$a5 = $a2 - $a4;
		
		$table_name = $_SESSION['db_prefix']."_supply_customer_temp";
		$qty_query = "SELECT quantity, extra  FROM $table_name WHERE store_item_id = '".$a1."' AND extra <> 'yes'  AND user = '".$_SESSION['username']."' ";
		$qty_result = mySQL_query($qty_query);
		$qty_num = mysql_num_rows($qty_result);
		if ($qty_num!=0) {
				$a6 = mysql_result($qty_result, 0, "quantity");
				$extra = mysql_result($qty_result, 0, "extra");
		}
		else {
			$a6='';
			$extra='std';
		}
		if ($a6<0) {$a6=0;}
		
	?>
             <tr>
               <td align="left" valign="top"><?php echo $a1a ?><input type="hidden" name="item_id<?php echo $i ?>" id="item_id<?php echo $i ?>" value="<?php echo $a1 ?>"></td>
               <td align="left" valign="top"><?php echo $a1b ?></td>
               <td align="left" valign="top">
                 <label for="textfield"></label>
               <input name="supply_text<?php echo $i ?>" type="text" class="text50" id="supply_text<?php echo $i ?>"  value="<?php echo $a2 ?>" 
               
               onChange="
                waarde = document.getElementById('supply_text<?php echo  $i ?>').value - document.getElementById('delivered_text<?php echo  $i ?>').value;
                if (waarde<0) {
                  waarde2 = 0;
                  }
                  else {
                  waarde2 = waarde;
                  }
                document.getElementById('quantity<?php echo  $i ?>').value= waarde2;
                
                document.getElementById('supply_text<?php echo  $i ?>').style.background = '#FFE7CE'; 
                document.getElementById('quantity<?php echo  $i ?>').style.background = '#FFE7CE'; 
                document.getElementById('authorised_text<?php echo  $i ?>').value= 'var';
                "  
               
               onfocus = "this.select();" <?php if ($_SESSION['variations_permission']!='yes') {?> readonly  <?php } ?>  >
               <input type="hidden" name="authorised_text<?php echo $i ?>" id="authorised_text<?php echo $i ?>" value="<?php echo $extra?>">&nbsp;&nbsp;&nbsp;<?php echo $a2 ?>
			   <?php if ($extra=='var'){ echo '**'; } ?></td>
               <td align="left" valign="top"><?php echo $a4 ?>
               <input name="delivered_text<?php echo $i ?>" id="delivered_text<?php echo $i ?>" type="hidden" value="<?php echo $a4 ?>"></td>
               <td align="left" valign="top"><?php echo $a5 ?>
               <input name="balance_text<?php echo $i ?>" id="balance_text<?php echo $i?>" type="hidden" value="<?php echo $a5 ?>"></td>
               <td align="right" valign="top"><input name="quantity<?php echo $i ?>" type="text" class="text60" id="quantity<?php echo $i ?>"  <?php if ($_SESSION['additional_error'.$i]=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['additional_error'.$i]='no' ?>
 onkeypress="return numbersonly(this, event)" onKeyUp="validate_required(quantity<?php echo $i?>, 'The delivery amount exceeds the balance, the entry will be cleared. ' +'\n'+ 'Please enter a valid amount.', <?php echo $a5 ?>)" value="<?php  echo $a6; ?>" autocomplete="off" autofocus onfocus = "this.select();" tabindex="<?php echo $i+1?>"> </td>
             </tr>
             <?php
	$i++;
	$_SESSION['line_no6']=$i;
	}
	}
	$table_name = $_SESSION['db_prefix']."_supply_customer_temp";
	$extra_query = "SELECT store_item_id, quantity FROM $table_name WHERE job_no = '".$_SESSION['job_no']."' AND user = '".$_SESSION['username']."' AND extra='yes' AND timber_type='Sundries' ";
	$extra_result = mySQL_query($extra_query);
	$extra_num = mysql_num_rows($extra_result);
	$j=0;
	while ($j<$extra_num) {
		$b1 = mysql_result($extra_result, $j, "store_item_id");
		  	$table_name = $_SESSION['db_prefix']."_store_items";
			$item_query = "SELECT item_name, quantity 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) {
			      $b1a = mysql_result($item_result, 0, "item_name");
				  $b1b = mysql_result($item_result, 0, "quantity");
			}
        $b2 = mysql_result($extra_result, $j, "quantity");
		if ($b2>$b1b) { 
				$b2 = $b1b;
				$over = 'yes'; }
		else {
			$over='';
		}
			
	?>
    <?php
		 
	$j++;
	}
	?>
           </table>
           
     <?php
	 $table_name = $_SESSION['db_prefix']."_supply_customer_temp";
	 $additional_query = "SELECT store_item_id, quantity, notes_text  FROM $table_name WHERE truss_type = 'Additional' AND job_no = '".$_SESSION['job_no']."' AND user = '".$_SESSION['username']."' AND extra = 'yes' ";
	 $additional_result = mySQL_query($additional_query);
	 $additional_num = mysql_num_rows($additional_result);
	 	if ($additional_num==0) {
			$b1='';
			$b1a='';
			$b2='';	
			$b3='';	
			
		}
		else {
			    $b1 = mysql_result($additional_result, 0, "store_item_id");
				$b2 = mysql_result($additional_result, 0, "quantity");
				$b3 = mysql_result($additional_result, 0, "notes_text");
				$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");
		}      
           
      ?>     
      
      <?php if ($_SESSION['variations_permission']=='yes') { ?>    
           <table id="dataTable" width="645">
           <thead>
               <tr>
                 <td colspan="4">Not authorised, extra deliveries:</td>
               </tr>
             </thead>
             <tr>
               <td>&nbsp;</td>
               <td>Store item</td>
               <td>Reason for extra delivery</td>
               <TD align="left">Qty               
             </tr>
             <tr>
             <script>
			 function check_it() {
				 if (document.getElementById('line_checkbox0').checked) {
                         document.getElementById('additional_text0').style.background = '#E1E1E1';
						 document.getElementById('product_select0').style.background = '#E1E1E1';
						 document.getElementById('additional_reason_text0').style.background = '#E1E1E1';
						 document.getElementById('product_select0').options.selectedIndex = 0;
						 document.getElementById('additional_text0').value = '0';
						 document.getElementById('additional_reason_text0').value = '.';
						 document.getElementById('product_select0').disabled = true;
						 document.getElementById('additional_reason_text0').disabled = true;
						 
                } else {
                        document.getElementById('additional_text0').style.background = '#FFF';
						document.getElementById('product_select0').style.background = '#FFF';
						document.getElementById('additional_reason_text0').style.background = '#FFF';
						document.getElementById('product_select0').options.selectedIndex = 1;
						document.getElementById('additional_text0').value = '';
						document.getElementById('additional_reason_text0').value = '';
						document.getElementById('product_select0').disabled = false;
						document.getElementById('additional_text0').disabled = false;
						document.getElementById('additional_reason_text0').disabled = false;
                }
				}
		     </script>
               <td width="20"><input type="checkbox" name="line_checkbox0" id="line_checkbox0"  onMouseUp="check_it()" <?php if ($b1!='') { ?> checked="checked" <?php } ?>/></td>
               <td width="250"><label id="closeOnSelect">
                 <!--<input type="checkbox" /> Close on selection-->
                 </label>
                 
                 <select name="product_select0" class="select200" id="product_select0" style="width:250px;"  onChange="document.getElementById('line_checkbox0').checked = 'checked'; document.getElementById('additional_text0').value=''; document.getElementById('additional_reason_text0').value='';">
                   <option value=".">.</option>
                   <option value="  "> </option>
                   <option value="<?php echo $b1?>" selected="selected"><?php echo $b1a ?></option>
                   <?php
    	for ($k = 0; $k < count($arrId); $k++) {
		echo "<option value=" . "\"" . $arrId[$k] . "\"" . ">" . $arrName[$k] . "</option>";
		$_SESSION['productName'] = $arrName[$k];
		}
     ?>
               </select></td>
               <td><input name="additional_reason_text0" type="text" class="text200" id="additional_reason_text0" value="<?php echo $b3 ?>"></td>
               <TD width="80" align="right"><input  name="additional_text0" type="text" class="text60" id="additional_text0" value="<?php echo $b2?>" onKeyPress="return isNumberKey(event)" onChange=" this.value = this.value.replace (/(\...).*/, '$1')" <?php if ($_SESSION['additional2_error0']=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['additional2_error0']='no' ?>/>
                 <input type="hidden" name="add_line_num" id="add_line_num" value="1" >
                 <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
             </tr>
             <?php
		$i=1;
		while ($i<$additional_num) {
		$b1 = mysql_result($additional_result, $i, "store_item_id");
		$b2 = mysql_result($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="line_checkbox<?php echo $i ?>" id="line_checkbox<?php echo $i ?>" checked="checked" onClick="{ if (document.getElementById('line_checkbox<?php echo $i ?>').checked) {
                        document.getElementById('additional_text<?php echo $i ?>').style.background = '#FFF';
						document.getElementById('product_select<?php echo $i ?>').style.background = '#FFF'; 
                        document.getElementById('additional_reason_text<?php echo $i ?>').style.background = '#FFF'; 
                        document.getElementById('product_select<?php echo $i ?>').options.selectedIndex = 1;
						document.getElementById('additional_text<?php echo $i ?>').value = '';
                        document.getElementById('additional_reason_text<?php echo $i ?>').value = '';
                        document.getElementById('product_select<?php echo $i ?>').disabled = false;
						document.getElementById('additional_text<?php echo $i ?>').disabled = false;
                        document.getElementById('additional_reason_text<?php echo $i ?>').disabled = false;
                         
                } else {
                        document.getElementById('additional_text<?php echo $i ?>').style.background = '#E1E1E1';
						document.getElementById('product_select<?php echo $i ?>').style.background = '#E1E1E1';
                        document.getElementById('additional_reason_text<?php echo $i ?>').style.background = '#E1E1E1'; 
                        document.getElementById('product_select<?php echo $i ?>').options.selectedIndex = 0;
						document.getElementById('additional_text<?php echo $i ?>').value = '0';
                        document.getElementById('additional_reason_text<?php echo $i ?>').value = '.';
                        document.getElementById('product_select<?php echo $i ?>').disabled = true;
						document.getElementById('additional_text<?php echo $i ?>').disabled = true;
                        document.getElementById('additional_reason_text<?php echo $i ?>').disabled = true;
                }
				}
                "/></td>
               <td><select name="product_select<?php echo $i ?>" class="select200" id="product_select<?php echo $i ?>" style="width:250px;" onChange="document.getElementById('line_checkbox<?php echo $i ?>').checked = 'checked'; document.getElementById('additional_text<?php echo $i ?>').value=''; document.getElementById('additional_reason_text<?php echo $i ?>').value='';">
                 <option value=".">.</option>
                 <option value="  "> </option>
                 <option value="<?php echo $b1?>" selected="selected"><?php echo $b1a ?></option>
                 <?php
    	for ($k = 0; $k < count($arrId); $k++) {
		echo "<option value=" . "\"" . $arrId[$k] . "\"" . ">" . $arrName[$k] . "</option>";
		$_SESSION['productName'] = $arrName[$k];
		}
     ?>
               </select></td>
               <td><input name="additional_reason_text<?php echo $i ?>" type="text" class="text200" id="additional_reason_text<?php echo $i ?>" value="<?php echo $b3 ?>"></td>
               <td align="right"><input  name="additional_text<?php echo $i ?>" type="text" class="text60" id="additional_text<?php echo $i ?>" value="<?php echo $b2?>" onKeyPress="return isNumberKey(event)" onChange=" this.value = this.value.replace (/(\...).*/, '$1')" <?php if ($_SESSION['additional2_error'.$i]=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['additional2_error'.$i]='no' ?>/>
                 <input type="hidden" name="add_line_num" id="add_line_num" value="<?php echo $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 } ?>
  </div>
           
           <div class="button_bar_frame">
         <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=5&all=none'); return document.MM_returnValue;MM_showHideLayers('wait','','show');return document.MM_returnValue" tabindex="<?php echo $i+3?>"/></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="6" />
            <input name="s" type="hidden" id="s" value="6" />
            <input name="all" type="hidden" id="all" value="none" />
            </span></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 $i+4?>"/></td>
          <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; " tabindex="<?php echo $i+2?>"/></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("product_select"+i,"req","Please select item on line "+(i+1));
	frmvalidator.addValidation("additional_reason_text"+i,"req","Please enter a reason on line "+(i+1));
  	frmvalidator.addValidation("additional_text"+i,"req","Please enter quantity on line "+(i+1));
}
</script>
<div>
</body>   
<?php
}
?>   