<?php 
if ($_SESSION['job_card_no']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="production_no_return.php";
</script>
<?php
}
else {
$table_name = $_SESSION['db_prefix']."_mworks_job_components_temp";
$line_query = "SELECT * FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."' AND  user_name = '".$_SESSION['username']."' ";  
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$i=0;
?>
<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("input");
            element5.type = "text";
			element5.value = "";
            element5.name = "component_text"+line_no;
			element5.id = "component_text"+line_no;
			element5.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";}
			element5.className = "text200";
			element5.autocomplete="off";
			element5.onkeyup= function(){ ToUpper(this); }
			cell2.appendChild(element5);
			
			var element4 = document.createElement("input");
            element4.type = "hidden";
            element4.name = "line_num";
			element4.value = rowCount;					
 
            var cell3 = row.insertCell(2);
            var element2 = document.createElement("input");
            element2.type = "text";
            element2.name = "notes_text"+line_no;
			element2.className = "text300";
			element2.value = "";
			cell3.appendChild(element2);
			cell3.appendChild(element4);
			
			var cell4 = row.insertCell(3);
			cell4.align="center"
            var element5 = document.createElement("input");
            element5.type = "text";
            element5.name = "quantity_text"+line_no;
			element5.className = "text50";
			element5.value = "";
			element5.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if ( charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			cell4.appendChild(element5);
								
			
			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('component_text'+i,'req','- component 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';
						 element5.style.background = '#F0F0F0';
						 element2.value = '-----';
						 element5.value = '-----';
						 element2.disabled = true;
						 element5.disabled = true;
						
                } else {
                        element2.style.background = '#FFF';
						element5.style.background = '#FFF';
						element2.value = '';
						element5.value = '';
						element2.disabled = false;
						element5.disabled = false;
						 
                }
				};
			
}

</script>



</head>

<?php include('../include/wait.php') ?>
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">

<div class="wizard_page_middle_frame">
<form action="m_compileJobWizbase.php?p=3&s=2" method="get" name="form1" id="form1" >
    <div class="wizard_frame" >
           <table width="667" id="table_display_wizard">
             <tr>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>
             <tr>
                <td width="226">M-works total project cost:</td>
                <td><input name="mworks_charge_text" id="mworks_charge_text" type="text"  class="text100"  style="text-align:right" onKeyPress="return isNumberKey(event)" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" value="<?php echo $_SESSION['mworks_charge'] ?>" onfocus = "this.select();" autofocus></td>
             </tr>
             <tr>
               <td>Labour charges:</td>
               <td><input name="mworks_labour_text" id="mworks_labour_text" type="text"  class="text100"  style="text-align:right" onKeyPress="return isNumberKey(event)" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" value="<?php echo $_SESSION['mworks_labour'] ?>" onfocus = "this.select();"></td>
             </tr>	
      </table>
        </div>
        <div class="wizard_frame" style="min-height:175px;">
          <table id="dataTable" width="650" border="1" style="border-collapse:collapse;">
            <?php
	  if ($line_num==0) {
	       
		   $a21 = '';
		   $a22 = '';
		   $a23 = '';
		   
	   }
	   else {
		   
		   $a21 = mysql_result($line_result, $i, "component");
		   $a22 = mysql_result($line_result, $i, "notes");
		   $a23 = mysql_result($line_result, $i, "quantity"); 
	   }
		?>
            <thead> 
        <tr>
          <td>&nbsp;</td>
          <td>Component</td>
          <td>Notes</td>
          <td>Quantity</td>
        </tr>
        </thead>
        <script>
			 function check_it2() {
				 if (document.getElementById('line_checkbox20').checked) {
                         document.getElementById('item_select20').style.background = '#F0F0F0';
						 document.getElementById('quantity_text20').style.background = '#F0F0F0';
						 document.getElementById('amount_text20').style.background = '#F0F0F0';
						 document.getElementById('item_select20').value = '.';
						 document.getElementById('quantity_text20').value = '.';
						 document.getElementById('amount_text20').value = '.';
						 document.getElementById('item_select20').disabled = true;
						 document.getElementById('item_text20').disabled = true;
						 document.getElementById('quantity_text20').disabled = true;
						 document.getElementById('amount_text20').disabled = true;
						 
                } else {
                        document.getElementById('item_select20').style.background = '#FFF';
						document.getElementById('quantity_text20').style.background = '#FFF';
						 document.getElementById('amount_text20').style.background = '#FFF';
						 document.getElementById('quantity_text20').value = '';
						 document.getElementById('amount_text20').value = '';
						 document.getElementById('item_select20').disabled = false;
						 document.getElementById('quantity_text20').disabled = false;
						 document.getElementById('amount_text20').disabled = false;
                }
				}
		     </script>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox0" id="line_checkbox0" onMouseUp="check_it2()" checked /></td>
          <td width="168"><input class="text200" name="component_text0" id="component_text0" value="<?php echo $a21?>" onChange="document.getElementById('line_checkbox0').checked = 'checked';" onKeyUp="ToUpper(this)" autocomplete="off" maxlength="50" /></td>
          <td width="214" align="left"><input name="notes_text0" type="text" class="text300" id="notes_text0"  value="<?php echo $a22?>" autocomplete="off" maxlength="200"/>
            <input type="hidden" name="line_num" id="line_num" value="1"/><input type="hidden" name="line_num" id="line_num" value="1" >
            
            
            
          </td>
          <td width="220" align="center"><input type="text" name="quantity_text0" id="quantity_text0" class="text50" value="<?php echo $a23?>" onKeyPress="return numbersonly(this, event)"></td>    
            <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
        </tr>
        <?php
		$i=1;
		while ($i<$line_num) {
		   $a21 = mysql_result($line_result, $i, "component");
		   $a22 = mysql_result($line_result, $i, "notes");
		   $a23 = mysql_result($line_result, $i, "quantity");
		?>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox<?php echo $i ?>" id="line_checkbox<?php echo $i ?>"  <?php if ($a21!='') { ?> checked="checked" <?php } ?> onMouseUp="{
				 if (document.getElementById('line_checkbox<?php echo $i ?>').checked) {
                         document.getElementById('component_text<?php echo $i ?>').style.background = '#F0F0F0';
                         document.getElementById('notes_text<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('component_text<?php echo $i ?>').value = '.';
                         document.getElementById('notes_text<?php echo $i ?>').value = '.';
						 document.getElementById('component_text<?php echo $i ?>').disabled = true;
                         document.getElementById('notes_text<?php echo $i ?>').disabled = true;
						
                } else {
                         document.getElementById('component_text<?php echo $i ?>').style.background = '#FFF';
                         document.getElementById('notes_text<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('component_text<?php echo $i ?>').value = '';
                         document.getElementById('notes_text<?php echo $i ?>').value = '';
						 document.getElementById('component_text<?php echo $i ?>').disabled = false;
                         document.getElementById('notes_text<?php echo $i ?>').disabled = false;
						 document.getElementById('amount_text<?php echo $i ?>').disabled = false;
                }
				}
                "/></td>
          <td width="168"><input class="text200" name="component_text<?php echo $i ?>" id="component_text<?php echo $i ?>" value="<?php echo $a21 ?>" onChange="document.getElementById('line_checkbox0').checked = 'checked';" onKeyUp="ToUpper(this)" autocomplete="off" maxlength="50"/></td>
          <td width="214" align="left"><input name="notes_text<?php echo $i ?>" type="text" class="text300" id="notes_text<?php echo $i ?>"  value="<?php echo $a22 ?>" autocomplete="off" maxlength="200"/>            <input type="hidden" name="line_num" id="line_num" value="<?php echo $line_num?>"></td>
          <td width="220" align="center"><input type="text" name="quantity_text<?php echo $i ?>" id="quantity_text<?php echo $i ?>" class="text50" value="<?php echo $a23?>" onKeyPress="return numbersonly(this, event)"></td>
        </tr>
        <?php
		$i++;
		}
		?>
        
</table>

<div align="left">
<input type="button" class="imagebutton" onClick="addRow('dataTable')" value="Add line" />
</div>
  <div align="right">
    <label class="label_small">To delete a line: uncheck line box and click Temp Save.</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','m_compileJobWizbase.php?s=&amp;p=1');return document.MM_returnValue" /></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="2" />
            <input name="s" type="hidden" id="s" value="2" />
           <input type="hidden" name="preset" id="preset">
            <input type="hidden" name="preset_list_name" id="preset_list_name">   
          <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton"  onClick="needToConfirm = false; cancel_confirmation(1, '../production/production_main.php');" value="Cancel" /></td>
          <td width="110" align="right"><input type="submit" name="next_button" id="next_button" class="imagebutton" value="Next"  onClick="needToConfirm = false; MM_showHideLayers('wait','','show'); " /></td>
        </tr>
      </table>
    </div>
</form>
</div>
</div>

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

<?php
}
?>    