<head>
<?php   
require_once ('../include/tc_calendar.php');
$receive_date = strtotime($_SESSION['receive_date']);
$d = date("d", $receive_date );
$m = date("m", $receive_date );
$y = date("Y", $receive_date );


$table_name = $_SESSION['db_prefix']."_list_sellers";
$sellers_query = "SELECT item_name FROM $table_name  ORDER BY item_name ASC";
  $sellers_result = execsql($sellers_query);
  $sellers_num = mysql_num_rows($sellers_result);
  $w = 0;
  $arrId2 = array ();
  $arrName2 = array ();
  while ($w < $sellers_num) {
    $arrId2[$w] = mysql_result($sellers_result, $w, "item_name");
    $arrName2[$w] = mysql_result($sellers_result, $w, "item_name");
    $w++;
  }
  
  
$table_name = $_SESSION['db_prefix']."_list_places";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
  $arrId3 = array ();
  $arrName3 = array ();
  $position_result = execsql($position_query);
  if ($position_result!="") {
  $position_num = mysql_num_rows($position_result);
  $b = 0;
  while ($b < $position_num) {
    $arrId3[$b] = mysql_result($position_result, $b, "item_name");
    $arrName3[$b] = mysql_result($position_result, $b, "item_name");
    $b++;
  }
  }
  
$table_name = $_SESSION['db_prefix']."_list_quotation_subjects";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
  $arrId4 = array ();
  $arrName4 = array ();
  $position_result = execsql($position_query);
  if ($position_result!="") {
  $position_num = mysql_num_rows($position_result);
  $b = 0;
  while ($b < $position_num) {
    $arrId4[$b] = mysql_result($position_result, $b, "item_name");
    $arrName4[$b] = mysql_result($position_result, $b, "item_name");
    $b++;
  }
  }

$table_name = $_SESSION['db_prefix']."_list_area";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
  $arrId5 = array ();
  $arrName5 = array ();
  $position_result = execsql($position_query);
  if ($position_result!="") {
  $position_num = mysql_num_rows($position_result);
  $b = 0;
  while ($b < $position_num) {
    $arrId5[$b] = mysql_result($position_result, $b, "item_name");
    $arrName5[$b] = mysql_result($position_result, $b, "item_name");
    $b++;
  }
  }
  
$table_name = $_SESSION['db_prefix']."_mworks_order_components_temp WHERE user_name = '".$_SESSION['username']."' ";
$line2_query = "SELECT * FROM $table_name ";
$line2_result = mySQL_query($line2_query);
$line2_num = mysql_num_rows($line2_result);

?>
<!--jscript-->
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/capitalize_textbox.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/lower_case.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>  

<script language="javascript">
function addRow2(dataTable2) {
 
            var table2 = document.getElementById(dataTable2);
 
            var rowCount = table2.rows.length;
            var row = table2.insertRow(rowCount);
      var line_no = rowCount-1;
 
            var cell1 = row.insertCell(0);
            var element21 = document.createElement("input");
            element21.type = "checkbox";
            element21.name="line_checkbox7"+line_no;
      element21.id="line_checkbox7"+line_no;
      /*element21.checked="checked";*/
            cell1.appendChild(element21);
       
            var cell2 = row.insertCell(1);
            var element22 = document.createElement("input");
            element22.type = "text";
            element22.name = "item_text7"+line_no;
      element22.className = "text300";
      element22.value = "";
      element22.onchange = function(){document.getElementById("line_checkbox7"+line_no).checked = "checked";}
      cell2.appendChild(element22);
      
         
            var cell4 = row.insertCell(2);
      cell4.align="right";
            var element23 = document.createElement("input");
            element23.type = "text";
            element23.name = "quantity_text7"+line_no;
      element23.className = "text60";
      element23.value = "";
      element23.style = "text-align:right";
      element23.onkeypress = function isNumberKey(evt)
                       {
                        var charCode = (evt.which) ? evt.which : event.keyCode
                        if (charCode != 46 && charCode > 31 
                        && (charCode < 48 || charCode > 57))
                         return false;
 
                        return true;
                       }
                  ;
      element23.onkeyup = function() {this.value = this.value.replace (/(\...).*/, '$1')};
      cell4.appendChild(element23);
      
          
      var cell5 = row.insertCell(3);
      cell5.align="left";
      var element26 = document.createElement("input");
            element26.type = "text";
            element26.name = "notes_text7"+line_no;
      element26.className = "text200";
      element26.style = "text-align:left";    

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


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

<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<form id="form1" method="get" action="new_mworks_jobWizbase.php">
<div class="page_middle_frame">
    <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    
          <tr>
            <td width="525" valign="top" ><div class="wizard_frame">
                <table width="649" border="0">
                  <tr>
                    <td width="149"><label class="label_std">Date received:</label></td>
                    <td width="490"><?php

    $myCalendar = new tc_calendar("receive_date", true);
    $myCalendar->setIcon("../images/iconCalendar.gif");
    $myCalendar->setDate($d, $m, $y);
    $myCalendar->setPath("./");
    $myCalendar->setYearInterval(2012, 2999);
    //$myCalendar->dateAllow('2009-02-20', "", false);
    $myCalendar->writeScript();
?></td>
                  </tr>
                  <tr>
                    <td>Project value: 
                      <label class="star">*</label></td>
                    <td><input type="text" name="value_text" id="value_text" onKeyPress="return isNumberKey(event); this.value = parseFloat(this.value).toFixed(2);" style="text-align:right"  value="<?php echo $_SESSION['value'] ?>"></td>
                  </tr>
                </table>
              </div>
             <div class="wizard_frame">
                <table width="656" border="0">
                  <tr>
                    <td width="149"><label class="label_std">Contact person:&nbsp;&nbsp;</label>
                      <label class="star">*</label></td>
                    <td width="497"><input name="comp_contact_text" type="text" class="text200" id="comp_contact_text" onBlur="capitalize(this)" onKeyUp="ToLower(this)" value="<?php echo $_SESSION['comp_contact']?>" autofocus tabindex="1"></td>
                  </tr>
                  <tr>
                    <td><label class="label_std">Cell/phone no: </label>
                      <label class="star">&nbsp;*</label></td>
                    <td><input name="contact_phone_text" type="text" class="text100" id="contact_phone_text" onKeyPress="return numbersonly(this, event)" value="<?php echo $_SESSION['contact_phone']?>" tabindex="2"></td>
                  </tr>
                </table>
                <table width="656" border="0">
                  <tr> </tr>
                </table>
              </div>
              <div class="wizard_frame">
                <table width="656" border="0">
                  <tr>
                    <td >Project: </td>
                    <td colspan="3">M-works</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="144" >Project or plot no:&nbsp;&nbsp;
                      <label class="star">*</label></td>
                    <td width="144"><input name="project_no_text" type="text" class="text60" id="project_no_text" onKeyUp="ToLower(this)" onBlur="capitalize(this)" value="<?php echo $_SESSION['project_no']?>" tabindex="4"></td>
                    <td width="33" align="right">Area:</td>
                    <td width="91"><select name="project_area_select" class="select120" tabindex="5" >
                      <option value="<?php echo $_SESSION['project_area']?>" selected><?php echo $_SESSION['project_area']?></option>
                      <?php
          for ($j = 0; $j < count($arrId5); $j++) {
        echo "<option value=" . "\"" . $arrId5[$j] . "\"" . ">" . $arrName5[$j] . "</option>";
  }
?>
                    </select></td>
                    <td width="71" align="right"><label class="label_std">Place:</label></td>
                    <td width="147"><select name="project_place_select" class="select120" tabindex="6" >
                        <option value="<?php echo $_SESSION['project_place']?>" selected><?php echo $_SESSION['project_place']?></option>
                        <?php
          for ($j = 0; $j < count($arrId3); $j++) {
        echo "<option value=" . "\"" . $arrId3[$j] . "\"" . ">" . $arrName3[$j] . "</option>";
  }
?>
                      </select></td>
                  </tr>
                  <tr>
                    <td valign="top">Short description:</td>
                    <td colspan="5"><textarea name="description_text" cols="70" rows="3" class="text_box" id="textarea" tabindex="7"><?php echo $_SESSION['description']?></textarea></td>
                  </tr>
                  <tr>
                    <td></td>
                    <td colspan="5"><?php

    
?></td>
                  </tr>
                </table>
              </div>
              <div class="wizard_frame"><br>
    <table id="dataTable2" width="630" border="1" style="border-collapse:collapse;">
    <?php
  
     if ($line2_num==0) {
         
       $a71='';
       $a72='';
       $a73='';
            }
     else {
       
       $a71 = mysql_result($line2_result, 0, "component");
       $a72 = mysql_result($line2_result, 0, "quantity");
       $a73 = mysql_result($line2_result, 0, "notes");
       
     }
    ?>
    <thead> 
        <tr>
          <td>&nbsp;</td>
          <td>Order components</td>
          <td align="center">Quantity</td>
          <td align="left">Notes</td>
        </tr>
        </thead>
        <script>
       function check_it7() {
         if (document.getElementById('line_checkbox70').checked) {
                         document.getElementById('item_text70').style.background = '#F0F0F0';
             document.getElementById('quantity_text70').style.background = '#F0F0F0';
             document.getElementById('notes_text70').style.background = '#F0F0F0';
             document.getElementById('item_text70').value = '.';
             document.getElementById('quantity_text70').value = '.';
             document.getElementById('notes_text70').value = '.';
             document.getElementById('item_text70').disabled = true;
             document.getElementById('quantity_text70').disabled = true;
             document.getElementById('notes_text70').disabled = true;
             
                } else {
                        document.getElementById('item_text70').style.background = '#FFF';
            document.getElementById('quantity_text70').style.background = '#FFF';
            document.getElementById('notes_text70').style.background = '#FFF';
            document.getElementById('item_text70').value = '';
            document.getElementById('quantity_text70').value = '';
            document.getElementById('notes_text70').value = '';
            document.getElementById('item_text70').disabled = false;
            document.getElementById('quantity_text70').disabled = false;
            document.getElementById('notes_text70').disabled = false;
                }
        }
         </script>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox70" id="line_checkbox70" checked  style="visibility:hidden;" /></td>
          <td width="233"><input  name="item_text70" type="text" class="text300" id="item_text70" value="<?php echo $a71 ?>" onChange="document.getElementById('line_checkbox70').checked=true;" /></td>
          <td width="74" align="left"><input  name="quantity_text70" type="text" class="text60" width="60px;" id="quantity_text70" value="<?php echo $a72 ?>" style="text-align:right" onKeyPress="return isNumberKey(event)"/></td>
            <td width="275" align="left"><input  name="notes_text70" type="text" class="text200" id="notes_text70" value="<?php echo $a73 ?>" /><input type="hidden" name="line_num2" id="line_num2" value="1" >
         </td>    
            <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
        </tr>
        <?php
    $i=1;
    while ($i<$line2_num) {
       $a71 = mysql_result($line2_result, $i, "component");
       $a72 = mysql_result($line2_result, $i, "quantity");
       $a73 = mysql_result($line2_result, $i, "notes");
       //$a74 = mysql_result($line2_result, $i, "order_no");
    ?>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox7<?php echo $i ?>" id="line_checkbox7<?php echo $i ?>" checked="checked" <?php if ($a71!='') { ?>  <?php } ?> onMouseUp="{
         if (document.getElementById('line_checkbox7<?php echo $i ?>').checked) {
                         document.getElementById('item_text7<?php echo $i ?>').style.background = '#F0F0F0';
                         document.getElementById('quantity_text7<?php echo $i ?>').style.background = '#F0F0F0';
             document.getElementById('notes_text7<?php echo $i ?>').style.background = '#F0F0F0';
             document.getElementById('item_text7<?php echo $i ?>').value = '.';
                         document.getElementById('quantity_text7<?php echo $i ?>').value = '.';
             document.getElementById('notes_text7<?php echo $i ?>').value = '.';
             document.getElementById('item_text7<?php echo $i ?>').disabled = true;
                         document.getElementById('quantity_text7<?php echo $i ?>').disabled = true;
             document.getElementById('notes_text7<?php echo $i ?>').disabled = true;
             
                } else {
                         document.getElementById('item_text7<?php echo $i ?>').style.background = '#FFF';
                         document.getElementById('quantity_text7<?php echo $i ?>').style.background = '#FFF';
             document.getElementById('notes_text7<?php echo $i ?>').style.background = '#FFF';
                         document.getElementById('item_text7<?php echo $i ?>').value = '';
                         document.getElementById('quantity_text7<?php echo $i ?>').value = '';
             document.getElementById('notes_text7<?php echo $i ?>').value = '';
             document.getElementById('item_text7<?php echo $i ?>').disabled = false;
                         document.getElementById('quantity_text7<?php echo $i ?>').disabled = false;
             document.getElementById('notes_text7<?php echo $i ?>').disabled = false;
                }
        }
                "/></td>
          <td width="233"><input  name="item_text7<?php echo $i ?>" type="text" class="text300" id="item_text7<?php echo $i ?>" value="<?php echo $a71 ?>"  onChange="document.getElementById('line_checkbox7<?php echo $i ?>').checked=true;"/></td>
          <td width="74" align="left"><input  name="quantity_text7<?php echo $i ?>" type="text" class="text60" width="60px;" id="quantity_text7<?php echo $i ?>" value="<?php echo $a72 ?>" onKeyPress="return isNumberKey(event)" style="text-align:right"/></td>
            <td width="275" align="left"><input  name="notes_text7<?php echo $i ?>" type="text" class="text200" id="notes_text7<?php echo $i ?>" value="<?php echo $a73 ?>"  /> <input type="hidden" name="line_num2" id="line_num2" value="<?php echo $line2_num?>"></td>
        </tr>
        <?php
    $i++;
    }
    ?>
        
  </table>
  
    <input type="button" class="imagebutton" onClick="addRow2('dataTable2')" value="Add line" />
    <div align="right">
      <label class="label_small">To delete a line: uncheck line box.</label></div>
  
          
        
  </div>
              <div class="wizard_frame">
                <table width="654" border="0">
                  <tr>
                    <td width="149">Sales representative:
                      &nbsp;&nbsp;
                      <label class="star">*</label></td>
                    <td width="495"><select name="seller_select" id="seller_select" class="select300" tabindex="8">
                        <option value="<?php echo $_SESSION['seller']?>" selected><?php echo $_SESSION['seller']?></option>
                        <?php 
      for ($w = 0; $w < count($arrId2); $w++) {
    echo "<option value=\"".$arrId2[$w] . "\"" . ">" . $arrName2[$w] . "</option>";  
      }
     ?>
                      </select></td>
                  </tr>
                </table>
              </div>
              
              <br>
              <br /></td>
            <!--center of tableMain--> 
          </tr>
          
          <tr>
            <td><!--center of tableMain-->
          
              <table  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','new_mworks_jobWizbase.php?s=&amp;p=1');return document.MM_returnValue" tabindex="10" /></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" />
                    </span></td>
                  <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../production/production_main.php?date='); " value="Cancel" tabindex="11"/></td>
                  <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false;  MM_showHideLayers('wait','','show');" tabindex="9"/></td>
                </tr>
              </table>
  </table>
  
</form>
<!--form validation--> 
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("value_text","req","- job value.");
  frmvalidator.addValidation("comp_contact_text","req","- name of the contact person.");
  frmvalidator.addValidation("contact_phone_text","req","- phone number of the contact person.");
  frmvalidator.addValidation("project_no_text","req","- plot no.");
  frmvalidator.addValidation("project_place_select","req","- place.");
  frmvalidator.addValidation("item_text70","req","- component on line 1");
  frmvalidator.addValidation("quantity_text70","req","- quantity  on line 1.");
  frmvalidator.addValidation("seller_select","req","- sales representative.");
  
  
  </script>
</body>
