<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="javascript" src="../jscript/chainedselects.js"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>    


<?php
include('../include/session.php');
require_once ('../include/tc_calendar.php');


$quote_no=$_GET['quote_no'];
$table_name = $_SESSION['db_prefix']."_maintenance_quotations";
$quote_query = "SELECT * FROM $table_name WHERE quote_no = '".$quote_no."' ";
$quote_result = mySQL_query($quote_query);
$cust_id = mysql_result($quote_result, 0, "cust_id");
$value = mysql_result($quote_result, 0, "value");
$request_date = strtotime(mysql_result($quote_result, 0, "request_date"));
$d = date("d", $request_date );
$m = date("m", $request_date );
$y = date("Y", $request_date );
$project_description = mysql_result($quote_result, 0, "project_description");
$project = mysql_result($quote_result, 0, "project");
$project_no = mysql_result($quote_result, 0, "project_no");
$project_place = mysql_result($quote_result, 0, "project_place");
$project_area = mysql_result($quote_result, 0, "project_area");



$table_name = $_SESSION['db_prefix']."_list_area";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
  $arrId18 = array ();
  $arrName18 = array ();
  $position_result = execsql($position_query);
  if ($position_result!="") {
  $position_num = mysql_num_rows($position_result);
  $b = 0;
  while ($b < $position_num) {
    $arrId18[$b] = mysql_result($position_result, $b, "item_name");
    $arrName18[$b] = mysql_result($position_result, $b, "item_name");
    $b++;
  }
  }
  
$table_name = $_SESSION['db_prefix']."_list_places";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
  $arrId19 = array ();
  $arrName19 = array ();
  $position_result = execsql($position_query);
  if ($position_result!="") {
  $position_num = mysql_num_rows($position_result);
  $b = 0;
  while ($b < $position_num) {
    $arrId19[$b] = mysql_result($position_result, $b, "item_name");
    $arrName19[$b] = mysql_result($position_result, $b, "item_name");
    $b++;
  }
  }  

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

<?php


$table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
$line_query = "SELECT * FROM $table_name WHERE quote_number = '".$quote_no."' ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);
$option_text = mysql_result($line_result, 0, "quote_option_text");
?>
<?php
if (($project=='Maintenance Fence (Residential)') OR ($project=='Maintenance Fence (Commercial)') OR ($project=='Maintenance Gate Motor') OR ($project=='Maintenance miscellaneous') ) { ?>
<script language="javascript">
function addRow3(dataTable3) {
 
            var table = document.getElementById(dataTable3);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
      var line_no = rowCount-1;
 
            var cell31 = row.insertCell(0);
            var element31 = document.createElement("input");
            element31.type = "checkbox";
            element31.name="line_checkbox"+line_no;
      element31.id="line_checkbox"+line_no;
      /*element1.checked="checked";*/
      cell31.style.verticalAlign="top";
            cell31.appendChild(element31);
       
            var cell32 = row.insertCell(1);
            var element32 = document.createElement("textarea");
            element32.cols=85;
      element32.rows=1;
            element32.name = "item_text"+line_no;
      element32.id = "item_text"+line_no;
      element32.className = "text_box";
      element32.value = "";
      element32.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";}
      
      cell32.style.verticalAlign="top";
      cell32.appendChild(element32);
            
              
      var cell34 = row.insertCell(2);
      cell34.align="right";
      
      var element36 = document.createElement("input");
            element36.type = "text";
            element36.name = "amount_text"+line_no;
      element36.id = "amount_text"+line_no;
      element36.className = "text100";
      element36.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;
                       }
                  ;
      element36.onkeyup = function() {this.value = this.value.replace (/(\...).*/, '$1')};
      element36.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";}
      element36.style = "text-align:right";    

            var element34 = document.createElement("input");
            element34.type = "hidden";
            element34.name = "line_num";
      element34.value = rowCount;
            
      
      var element33 = document.createElement("input");
            element33.type = "hidden";
            element33.name = "line_id"+line_no;;
      element33.value = "0";
            
      cell34.style.verticalAlign="top";
      cell34.appendChild(element36);
      cell34.appendChild(element33);
            cell34.appendChild(element34);
      
      var element38 = document.createElement("script");
      element38.setAttribute('type', 'text/javascript');
      element38.innerHTML="var frmvalidator  = new Validator('form1');frmvalidator.EnableMsgsTogether();for (i = 0; i < 10; i++) {frmvalidator.addValidation('item_text'+i,'req','- price details '+(i+1)+' in option 1 .');frmvalidator.addValidation('amount_text'+i,'req','- price '+(i+1)+' in option 1');}"; 
      document.getElementsByTagName('head').item(0).appendChild(element38);
    
      element31.onmouseup = function() {
         if (document.getElementById('line_checkbox'+line_no).checked) {
                         element32.style.background = '#F0F0F0';
             element36.style.background = '#F0F0F0';
             element32.selectedIndex=0;
             element36.value = '.';
             element32.disabled = true;
             element36.disabled = true;
             
                } else {
                        element32.style.background = '#FFF';
            element36.style.background = '#FFF';
            element32.selected_index=0;
            element36.value = '';
            element32.disabled = false;
            element36.disabled = false;
             
                }
        };
      
}
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>
 
<?php } ?>

</head>


<body>

<form id="form1" name="form1" method="POST" action="edit_maintenance_quotation_save.php">
<?php
include ("../navigation/header.php");
$page_name = "maintenance-edit quote";
include ("../navigation/access.php");

if ($permission_num==1) {
  include ("../navigation/maintenance_sidebar.php");
?>
<div class="main_frame">
<div class="page_head_frame">
          <table width="650" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="553"><label class="label_page_head">Edit Maintenance quotation</label></td>
              <td width="97"><label class="label_quote_no"><?php echo $quote_no;  ?></label>
              </td>
            </tr>
          </table>
  </div>
<div class="page_middle_frame">          
<div class="page_inside_frame">
<?php 
include('../include/customer_block.php');
?>
</div>


<div class="page_inside_frame">
<table width="650" id="table_details_display">
    <tr>
      <td width="99" align="left" valign="middle">Project:</td>
      <td colspan="4" align="left" valign="middle">
      <?php 
if (($project=='Maintenance Fence (Residential)') OR ($project=='Maintenance Fence (Commercial)') OR ($project=='Maintenance Gate Motor') OR ($project=='Maintenance miscellaneous') ) { ?>
    <select name="project_select" id="project_select" class="select250" tabindex="3">
        <option value="<?php echo $project?>"><?php echo $project?></option>
        <option value="Maintenance Fence (Residential)">Maintenance Fence (Residential)</option>
        <option value="Maintenance Fence (Commercial)">Maintenance Fence (Commercial)</option>
        <option value="Maintenance Gate Motor">Maintenance Gate Motor</option>
        <option value="Maintenance miscellaneous">Maintenance miscellaneous</option>
      </select>
      <?php
}
?>
<?php
if (($project=='Monthly maintenance') ) { ?>
<select name="project_select" id="project_select" class="select250" tabindex="3">
        <option value="<?php echo $project?>"><?php echo $project?></option>
        <option value="Monthly maintenance">Monthly maintenance</option>
      </select>
      <?php
}
?>
<input name="project_text" id="project_text" type="hidden" value="<?php echo $project ?>">
</td>
      <td align="left" valign="middle"><?php echo 'Quotation no:'; ?><?php echo $quote_no;  ?></td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td colspan="5" align="left" valign="middle">&nbsp;</td>
      </tr>
    <tr>
      <td align="left" valign="middle">Order date:</td>
      <td colspan="3" align="left" valign="middle"><?php

    $myCalendar = new tc_calendar("request_date", true);
    $myCalendar->setIcon("../images/iconCalendar.gif");
    $myCalendar->setDate($d, $m, $y);
    $myCalendar->setPath("./");
    $myCalendar->setYearInterval(2012, 2099);
    //$myCalendar->dateAllow('2009-02-20', "", false);
    $myCalendar->writeScript();
?></td>
      <td width="112" align="left" valign="middle">Quote value:</td>
      <td width="154" align="left" valign="middle"><?php echo $value ?></td>
    </tr>
    <tr>
      <td valign="middle" >Project no:</td>
      <td width="144" valign="middle"><input name="project_no_text" type="text" class="text80" id="project_no_text" onKeyUp="ToLower(this)" onBlur="capitalize(this)" value="<?php echo $project_no?>" ></td>
      <td width="65" align="right" valign="middle">Area:</td>
      <td width="48" valign="middle"><select name="project_area_select" class="select120" tabindex="5" >
        <option value="<?php echo $project_area?>" selected><?php echo $project_area?></option>
        <?php
          for ($j = 0; $j < count($arrId18); $j++) {
        echo "<option value=" . "\"" . $arrId18[$j] . "\"" . ">" . $arrName18[$j] . "</option>";
  }
?>
        </select></td>
      <td align="right" valign="middle"><label class="label_std">Place:</label></td>
      <td valign="middle"><select name="project_place_select" class="select120" tabindex="6" >
        <option value="<?php echo $project_place?>" selected><?php echo $project_place?></option>
        <?php
          for ($j = 0; $j < count($arrId19); $j++) {
        echo "<option value=" . "\"" . $arrId19[$j] . "\"" . ">" . $arrName19[$j] . "</option>";
  }
?>
        </select></td>
    </tr>
    <tr>
      <td align="left" valign="top">Project description:</td>
      <td colspan="5" align="left" valign="top">
        <textarea name="notes_text" cols="80" rows="3" class="text_box" id="notes_text"><?php echo $project_description ?></textarea></td>
    </tr>
  </table>
</div>

<?php 
if (($project=='Maintenance Fence (Residential)') OR ($project=='Maintenance Fence (Commercial)') OR ($project=='Maintenance Gate Motor') OR ($project=='Maintenance miscellaneous') ) { ?>
<div class="page_inside_frame">

      Re:&nbsp;&nbsp;
      <input name="option_text" type="text" class="text300" id="option_text" value="<?php echo $option_text ?>" size="60" maxlength="100" autocomplete="off" autofocus>
      <br>
      <br>
      <br>
    

    <table id="dataTable3" width="590" border="1" style="border-collapse:collapse;">
      <thead>
        <tr>
          <td colspan="2">&nbsp;</td>
          <td>Price</td>
        </tr>
      </thead>
      
      <?php
    $i=0;
    while ($i<$line_num) {
    $item_text = mysql_result($line_result, $i, "quote_item_text");  
    $amount_text = mysql_result($line_result, $i, "quote_item_price");
    $line_id = mysql_result($line_result, $i, "line_id");
   ?>
      <tr>
      <script>
       function check_it<?php echo $i?>() { 
         if (document.getElementById('line_checkbox<?php echo $i?>').checked) {
                         document.getElementById('item_text<?php echo $i?>').style.background = '#F0F0F0';
             document.getElementById('amount_text<?php echo $i?>').style.background = '#F0F0F0';
             document.getElementById('item_text<?php echo $i?>').value = '.';
             document.getElementById('amount_text<?php echo $i?>').value = '.';
             document.getElementById('item_text<?php echo $i?>').disabled = true;
             document.getElementById('amount_text<?php echo $i?>').disabled = true;
             
                } else {
                        document.getElementById('item_text<?php echo $i?>').style.background = '#FFF';
             document.getElementById('amount_text<?php echo $i?>').style.background = '#FFF';
             document.getElementById('item_text<?php echo $i?>').value = '';
             document.getElementById('amount_text<?php echo $i?>').value = '';
             document.getElementById('item_text<?php echo $i?>').disabled = false;
             document.getElementById('amount_text<?php echo $i?>').disabled = false;
                }
        }
         </script>  
      
        <td width="20" valign="top"><input type="checkbox" name="line_checkbox<?php echo $i?>" id="line_checkbox<?php echo $i?>" onMouseUp="check_it<?php echo $i?>()" checked <?php if ($i==0) { echo 'hidden=hidden' ;} ?>/></td>
        <td width="408" valign="top"></textarea>
          <textarea name="item_text<?php echo $i?>" id="item_text<?php echo $i?>" class="text_box" cols="85" rows="1" onChange="document.getElementById('line_checkbox').checked='checked';" ><?php echo $item_text ?></textarea></td>
        <td width="140" align="right" valign="top"><input  name="amount_text<?php echo $i?>" id="amount_text<?php echo $i?>" type="text" class="text100" value="<?php if ($amount_text!='') { echo $amount_text; } ?>" onKeyPress="return isNumberKey(event);" onKeyUp="this.value = this.value.replace (/(\...).*/, '$1');" onChange="document.getElementById('line_checkbox').checked='checked';" style="text-align:right" onfocus = "this.select();" autocomplete="off"/>
          <input type="hidden" name="line_id<?php echo $i?>" id="line_id<?php echo $i?>" value="<?php echo $line_id?>" ></td>

     
      </tr>
      <?php 
    $i++;
    }
?>
<input type="hidden" name="line_num" id="line_num" value="<?php echo $i?>" >
</table>
    <input type="button" class="imagebutton" onClick="addRow3('dataTable3')" value="Add line" />
    <div align="right"><label class="label_small">To delete a line: uncheck line box.</label></div>
 </div>
      
<input type="hidden" name="check2" id="check2" value='2'>
<br>
<?php
}
?>

<?php
if (($project=='Monthly maintenance') ) { ?>
<div class="page_inside_frame">
      Re:&nbsp;&nbsp;
      <input name="option_text" type="text" class="text300" id="option_text" value="<?php echo $option_text ?>" size="60" maxlength="100" autocomplete="off">
      <br>
      <br>
      <br>
      <?php
      $table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
    $line_query = "SELECT * FROM $table_name WHERE quote_number = '".$quote_no."' AND quote_item_text = 'Year rate (11 months)' ";
    $line_result = mySQL_query($line_query);
    $line_num = mysql_num_rows($line_result);
      $amount_text = mysql_result($line_result, 0, "quote_item_price");
    $line_id = mysql_result($line_result, 0, "line_id");
    ?>

    <table id="dataTable3" width="564" border="1" style="border-collapse:collapse;">
      <thead>
        <tr>
          <td width="408">&nbsp;</td>
          <td width="140">Price</td>
        </tr>
      </thead>
      <tr>
        <td valign="top">Year rate (11 months):</td>
        <td align="right" valign="top"><input  name="amount_text" id="amount_text" type="text" class="text100" value="<?php if ($amount_text!='') { echo $amount_text; } ?>" onKeyPress="return isNumberKey(event);" onKeyUp="this.value = this.value.replace (/(\...).*/, '$1');"  style="text-align:right" onfocus = "this.select();" autocomplete="off"/></td>
      </tr>
     
    </table>
    <input type="button" class="imagebutton" onClick="addRow3('dataTable3')" value="Add line" />
    <div align="right"><label class="label_small">To delete a line: uncheck line box.</label></div>
 </div>
      
<input type="hidden" name="check2" id="check2" value='2'>
<br>
<?php
}
?>
  
<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="quote_no" id="quote_no" value="<?php echo $quote_no ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../maintenance/maintenance_main.php');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onClick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onClick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
  </table>
</div>  
  
  
</div>
</div>  
</form>
<?php include ('../navigation/side_bar.php'); ?>

</body>
<?php } else {
$_SESSION['denied_return'] = "production/production_main.php";  
include ("../navigation/production_sidebar.php");?>
<body onLoad="accessdenied(); return false">
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php }
?>

</html>