<?php
session_start();
include("../../php_crud/my_class.php");
$obj = new my_class();
extract($_GET);
//print_r($_GET);
$station = $_GET['station'];
//echo $station;
//exit();
$river_name = $_GET['river_name'];
//$date_array = explode("-", $mm_yr);
$month = $month;
$year = $year;

//echo $year;
//exit()
$curr_date = date('d-m-Y H:i');

$curr_date =  strtotime($curr_date);
//echo $curr_date;
?>
<style type="text/css">
  select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
  display: inline-block;
  height: 1px!important;
  padding: 8px 3px!important;
  margin-bottom: 2px!important;
  font-size: 13px!important;
  line-height: 23px!important;
  color: #555;
  vertical-align: middle;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
}
.table th, .table td {
  padding: 2px!important;
  line-height: 20px;
  text-align: left;
  vertical-align: top;
  border-top: 1px solid #ddd;
}
.button{
position: relative;
top: -20px;
}
.tbl{
position: relative;
top: -15px;
}



</style>
<table id="td_dis_data_table" class="table table-bordered table-hover ">
<button  style="float:left;" id="btn2" class="btn btn-warning" onclick="load_new_row()">New</button>
<div class="row-fluid" style="margin-bottom:5px;">
	<div class="control-group" style="float:right;">
		<div class="controls">
			<button id="td_save_btn" type="button" style="margin-right: 1px; padding: 4px!important; font-size: 12px;" class="btn btn-small btn-success" onclick="td_multiple_save()"><i class="icon-save"></i><b>Save All</b></button>
		</div>
	</div>
</div>
    <thead>
        <tr>
            <!-- <th>sl</th> -->
            <th style="text-align:center; background-color: #b3e0ff;">Date Time</th>
            <th style="text-align:center; background-color: #b3e0ff;">Water Level (m)</th>
            <th style="text-align:center; background-color: #b3e0ff;">Water Width (m)</th>
            <th style="text-align:center; background-color: #b3e0ff;">Area (m2)</th>
            <th style="text-align:center; background-color: #b3e0ff;">Discharge (m3/s)</th>
            <th style="text-align:center; background-color: #b3e0ff;">V Max (m/s)</th>
            <th style="text-align:center; background-color: #b3e0ff;">V Mean (m/s)</th>
            <th style="text-align:center; background-color: #b3e0ff;">Note</th>
            <th style="text-align: center; background-color: #b3e0ff;">Action</th>
        </tr>
    </thead>
    <tbody id="td_dis_data_tbl_body">
        <?php
            $row=0;
            //my code
            if($show_mode=='show_empty'){
              $rows = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15");
              foreach ($rows as $row_id) {

            // Checking for empty field and making float points
            $water_level = "";
            $water_width = "";
            $area = "";
            $discharge = "";
            $vmax= "";
            $vmean = "";
           

            //Water Level
            if($td_discharge_data['WATERLEVEL'] != ""){
              $water_level = number_format ((float)$td_discharge_data['WATERLEVEL'], 2, '.', '');
            }
            else{
              $water_level = $td_discharge_data['WATERLEVEL'];
            }
            //water width
            if($td_discharge_data['WATERWIDTH'] != ""){
              $water_width =  number_format ((float)$td_discharge_data['WATERWIDTH'], 2, '.', '');
            }
            else{
              $water_width= $td_discharge_data['WATERWIDTH'];
            }
            //Area
            if($td_discharge_data['AREA'] != ""){
              $area =  number_format ((float)$td_discharge_data['AREA'], 2, '.', '');
            }
            else{
              $area = $td_discharge_data['AREA'];
            }
            //discharge
            if($td_discharge_data['DISCHARGE'] != ""){
              $discharge = number_format ((float)$td_discharge_data['DISCHARGE'], 2, '.', '');
            }
            else{
              $discharge= $td_discharge_data['DISCHARGE'];
            }
            //vmax
            if($td_discharge_data['VMEANVERTICAL']!= ""){
              $vmax =  number_format ((float)$td_discharge_data['VMEANVERTICAL'], 2, '.', '');
            }
            else{
              $vmax= $td_discharge_data['VMEANVERTICAL'];
            }
            //vmean
            if($td_discharge_data['VMEANSECTION']!= ""){
              $vmean= number_format ((float)$td_discharge_data['VMEANSECTION'], 2, '.', '');
            }
            else{
              $vmean = $td_discharge_data['VMEANSECTION'];
            }
            //  end Checking for empty field and making float points
                  $date_id      = "date_$row_id";
                  $wl_id        = "wl_$row_id";
                  $ww_id        = "ww_$row_id";
                  $area_id      = "area_$row_id";
                  $discharge_id = "dischrg_$row_id";
                  $vmax_id      = "vmax_$row_id";
                  $vmean_id     = "vmean_$row_id";
                  $note_id      = "note_$row_id";

                  $after_note_id="";  
                  $next_row_val          = $row_id + 1;
                  $after_note_id         = "date_$next_row_val";
                  $function_for_nxt_val  = "call_next_val_loader(event,'$note_id',' $after_note_id')";
                  $function_for_wl       = "call_save_function(event,'$vmean_id','$after_note_id ','$row_id')";
                  $call_key_up_function = "call_next_val_loader(event,'$date_id','$wl_id')";
            ?>  
            <tr>
                  <!-- <th><?php echo $sl;?></th> -->
                  <th style="text-align:center;">
                      <input type="text" class=" td_date" name="date-time" id="<?php echo $date_id;?>" style="text-align: center;font-weight:bold; width:60%;" value="" onkeyup="<?php echo $call_key_up_function;?>" <?php echo $is_readonly;?>/>
                  </th>
                  <th style="text-align:center;">
                      <input type="text" class="input-mini td_wl" name="water-level" id="<?php echo $wl_id;?>" style="text-align:center;font-weight:bold; "  value=""  onkeyup="call_next_val_loader(event,'<?php echo $wl_id; ?>','<?php echo $ww_id; ?>')" onkeypress="return isDecimalInput(event)">
                  </th>
                  <th style="text-align:center;">
                      <input type="text" class="input-small td_ww" name="water-width" id="<?php echo $ww_id;?>" style="text-align:center;font-weight:bold; " value="" onkeyup="call_next_val_loader(event,'<?php echo $ww_id;; ?>','<?php echo $area_id; ?>')" onkeypress="return isNumericInput(event)">
                  </th>
                  <th style="text-align:center;">
                      <input type="text" class="input-small td_area" name="area" id="<?php echo $area_id;?>" style="text-align:center;font-weight:bold; " value="" onkeyup="call_next_val_loader(event,'<?php echo $area_id; ?>','<?php echo $discharge_id; ?>')" onkeypress="return isNumericInput(event)">
                  </th>
                  <th style="text-align:center;"> 
                      <input type="text" class="input-mini td_discharge" name="discharge" id="<?php echo $discharge_id;?>" style="text-align:center;font-weight:bold; " value="" onkeyup="call_next_val_loader(event,'<?php echo $discharge_id; ?>','<?php echo $vmax_id; ?>')" onkeypress="return isNumericInput(event)">
                  </th>
                  <th style="text-align:center;">
                      <input type="text" class="input-mini td_v_max" name="v-max" id="<?php echo $vmax_id;?>" style="text-align:center;font-weight:bold; " value="" onkeyup="call_next_val_loader(event,'<?php echo $vmax_id; ?>','<?php echo $vmean_id; ?>')" onkeypress="return isNumericInput(event)">
                  </th>
                  <th style="text-align:center;">
                      <input type="text" class="input-mini td_v_mean" name="v-mean" id="<?php echo $vmean_id;?>" style="text-align:center;font-weight:bold; " value="" onkeyup="call_next_val_loader(event,'<?php echo $vmean_id; ?>','<?php echo  $note_id; ?>')" onkeypress="return isNumericInput(event)">
                  </th>
                  <th style="text-align:center;">
                      <input type="text" class="input-mini td_note" name="note" id="<?php echo $note_id;?>" style="text-align:center;font-weight:bold; " value=""  onkeyup="<?php echo  $function_for_wl  ; ?>">
                  </th>
                  <td style="text-align: center;">
                      <button class="btn btn-minier btn-purple" type="button" onclick="save_single_td_discharge_info('<?php echo $row_id; ?>','btn_click')"><i class="icon-save"></i> <b style="padding:-1%!important;">Save</b></button>
                      <?php
                        if($_SESSION['delete'] == 'Y'){
                          echo '&nbsp;<button class="btn btn-minier btn-danger" type="button" onclick = "delete_tidal_data('.$row_id.')">
                          <i class="icon-trash"></i><b style="font-size: 12px;">Delete</b></button>';
                        }
                ?>
                    </td>
              </tr>
              <!-- <input type="text" id="tot_row" name="tot_row" value="<?php echo $row_id; ?>" /> -->
              <?php
              }
            }
           

            // select * from TIDAL_DISCHARGE where STATIONID='SW179' AND TO_CHAR(DATETIME,'MM-YYYY')='04-2006'
            // echo "TO_CHAR(DATETIME,'YYYY') BETWEEN '$from_year' AND '$to_year ' ORDER BY DATETIME ASC";
            // foreach($obj->View_colmn_By_Cond_hydro("TIDAL_DISCHARGE","*","TO_CHAR(DATETIME,'YYYY') BETWEEN '$from_year' AND '$to_year ' ORDER BY DATETIME ASC") as $td_discharge_data){
            else{
              $cond = "STATIONID='$station' AND TO_CHAR(DATETIME,'MM-YYYY')='$month-$year' ORDER BY DATETIME ASC";
              $data_count = $obj->View_column_details_By_Cond_hydro("TIDAL_DISCHARGE","COUNT(*) AS TOT_DATA",$cond);
              if($data_count['TOT_DATA']>0){
                foreach($obj->View_colmn_By_Cond_hydro("TIDAL_DISCHARGE","STATIONID,TO_CHAR(DATETIME,'DD-MON-YY HH24:MI') AS DT,WATERLEVEL,WATERWIDTH,AREA,DISCHARGE,VMEANVERTICAL,VMEANSECTION,NOTE,UPDT_BY,UPDT_DTM",$cond) as $td_discharge_data){
              //print_r($td_discharge_data);
              //$show_date =  date('d-M-y HH24:MI:SS',strtotime($td_discharge_data['DATETIME']));
              ////////for date
              $show_date =  date('d/m/Y H:i',strtotime($td_discharge_data['DT']));
              $input_date = date('d-m-Y H:i',strtotime($td_discharge_data['DT'])); 
              ///////for date
            // print_r($show_date);
            //echo $input_date;
              $row++;
               // Checking for empty field and making float points
            $water_level = "";
            $water_width = "";
            $area = "";
            $discharge = "";
            $vmax= "";
            $vmean = "";
           

            //Water Level
            if($td_discharge_data['WATERLEVEL'] != ""){
              $water_level = number_format ((float)$td_discharge_data['WATERLEVEL'], 2, '.', '');
            }
            else{
              $water_level = $td_discharge_data['WATERLEVEL'];
            }
            //water width
            if($td_discharge_data['WATERWIDTH'] != ""){
              $water_width =  number_format ((float)$td_discharge_data['WATERWIDTH'], 2, '.', '');
            }
            else{
              $water_width= $td_discharge_data['WATERWIDTH'];
            }
            //Area
            if($td_discharge_data['AREA'] != ""){
              $area =  number_format ((float)$td_discharge_data['AREA'], 2, '.', '');
            }
            else{
              $area = $td_discharge_data['AREA'];
            }
            //discharge
            if($td_discharge_data['DISCHARGE'] != ""){
              $discharge = number_format ((float)$td_discharge_data['DISCHARGE'], 2, '.', '');
            }
            else{
              $discharge= $td_discharge_data['DISCHARGE'];
            }
            //vmax
            if($td_discharge_data['VMEANVERTICAL']!= ""){
              $vmax =  number_format ((float)$td_discharge_data['VMEANVERTICAL'], 2, '.', '');
            }
            else{
              $vmax= $td_discharge_data['VMEANVERTICAL'];
            }
            //vmean
            if($td_discharge_data['VMEANSECTION']!= ""){
              $vmean= number_format ((float)$td_discharge_data['VMEANSECTION'], 2, '.', '');
            }
            else{
              $vmean = $td_discharge_data['VMEANSECTION'];
            }
            //  end Checking for empty field and making float points
              $date_id      = "date_$row";
              $wl_id        = "wl_$row";
              $ww_id        = "ww_$row";
              $area_id      = "area_$row";
              $discharge_id = "dischrg_$row";
              $vmax_id      = "vmax_$row";
              $vmean_id     = "vmean_$row";
              $note_id      = "note_$row";

              $after_note_id="";  
              $next_row_val          = $row + 1;
              $after_note_id         = "date_$next_row_val";
              $function_for_nxt_val  = "call_next_val_loader(event,'$note_id',' $after_note_id')";
              $function_for_wl       = "call_save_function(event,'$vmean_id','$after_note_id ','$row')";
               ////Current Date Issue////
               $input_date = strtotime($input_date);
              //  echo "Input".$input_date;
              //  echo '<br>';
              //  echo "Current".$curr_date;
               if($input_date > $curr_date){
                 $is_readonly = "readonly";
                 $call_key_up_function = "show_alert(event)";
               }
               else{
                 $is_readonly = "";
                 $call_key_up_function = "call_next_val_loader(event,'$date_id','$wl_id')";
               }
               ////Current Date Issue////

          ?>
          <tr>
              <!-- <th><?php echo $sl;?></th> -->
              <th style="text-align:center;">
                  <input type="text" class=" td_date" name="date-time" id="<?php echo $date_id;?>" style="text-align: center;font-weight:bold; width:60%;" value="<?php echo $show_date ;?>" onkeyup="<?php echo $call_key_up_function; ?>" <?php echo $is_readonly; ?>/>
              </th>
              <th style="text-align:center;">
                  <input type="text" class="input-mini td_wl" name="water-level" id="<?php echo $wl_id;?>" style="text-align:center;font-weight:bold; "  value="<?php echo $water_level;?>"  onkeyup="call_next_val_loader(event,'<?php echo $wl_id; ?>','<?php echo $ww_id; ?>')" onkeypress="return isDecimalInput(event)">
              </th>
              <th style="text-align:center;">
                  <input type="text" class="input-small td_ww" name="water-width" id="<?php echo $ww_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $water_width;?>" onkeyup="call_next_val_loader(event,'<?php echo $ww_id;; ?>','<?php echo $area_id; ?>')" onkeypress="return isNumericInput(event)">
              </th>
              <th style="text-align:center;">
                  <input type="text" class="input-small td_area" name="area" id="<?php echo $area_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $area;?>" onkeyup="call_next_val_loader(event,'<?php echo $area_id; ?>','<?php echo $discharge_id; ?>')" onkeypress="return isNumericInput(event)">
              </th>
              <th style="text-align:center;"> 
                  <input type="text" class="input-mini td_discharge" name="discharge" id="<?php echo $discharge_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo  $discharge ;?>" onkeyup="call_next_val_loader(event,'<?php echo $discharge_id; ?>','<?php echo $vmax_id; ?>')" onkeypress="return isNumericInput(event)">
              </th>
              <th style="text-align:center;">
                  <input type="text" class="input-mini td_v_max" name="v-max" id="<?php echo $vmax_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $vmax;?>" onkeyup="call_next_val_loader(event,'<?php echo $vmax_id; ?>','<?php echo $vmean_id; ?>')" onkeypress="return isNumericInput(event)">
              </th>
              <th style="text-align:center;">
                  <input type="text" class="input-mini td_v_mean" name="v-mean" id="<?php echo $vmean_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo  $vmean;?>" onkeyup="call_next_val_loader(event,'<?php echo $vmean_id; ?>','<?php echo  $note_id; ?>')" onkeypress="return isNumericInput(event)">
              </th>
              <th style="text-align:center;">
                  <input type="text" class="input-mini td_note" name="note" id="<?php echo $note_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $td_discharge_data['NOTE'];?>"  onkeyup="<?php echo  $function_for_wl  ; ?>">
              </th>
              <td style="text-align: center;">
                  <button class="btn btn-minier btn-purple" type="button" onclick="save_single_td_discharge_info('<?php echo $row; ?>','btn_click')"><i class="icon-save"></i> <b style="padding:-1%!important;">Save</b></button>
                  <?php
                        if($_SESSION['delete'] == 'Y'){
                          echo '&nbsp;<button class="btn btn-minier btn-danger" type="button" onclick = "delete_tidal_data('.$row.')">
                          <i class="icon-trash"></i><b style="font-size: 12px;">Delete</b></button>';
                        }
                ?>
                </td>
          </tr>
          <!-- <input type="text" id="tot_row" name="tot_row" value="<?php echo $row; ?>" /> -->
          <?php
          
                }
          $tot_row = $row;
       // echo $tot_row;
        }else{
          $rows = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15");
         foreach ($rows as $row_id) {
           // Checking for empty field and making float points
           $water_level = "";
           $water_width = "";
           $area = "";
           $discharge = "";
           $vmax= "";
           $vmean = "";
          
           //Water Level
           if($td_discharge_data['WATERLEVEL'] != ""){
             $water_level = number_format ((float)$td_discharge_data['WATERLEVEL'], 2, '.', '');
           }
           else{
             $water_level = $td_discharge_data['WATERLEVEL'];
           }
           //water width
           if($td_discharge_data['WATERWIDTH'] != ""){
             $water_width =  number_format ((float)$td_discharge_data['WATERWIDTH'], 2, '.', '');
           }
           else{
             $water_width= $td_discharge_data['WATERWIDTH'];
           }
           //Area
           if($td_discharge_data['AREA'] != ""){
             $area =  number_format ((float)$td_discharge_data['AREA'], 2, '.', '');
           }
           else{
             $area = $td_discharge_data['AREA'];
           }
           //discharge
           if($td_discharge_data['DISCHARGE'] != ""){
             $discharge = number_format ((float)$td_discharge_data['DISCHARGE'], 2, '.', '');
           }
           else{
             $discharge= $td_discharge_data['DISCHARGE'];
           }
           //vmax
           if($td_discharge_data['VMEANVERTICAL']!= ""){
             $vmax =  number_format ((float)$td_discharge_data['VMEANVERTICAL'], 2, '.', '');
           }
           else{
             $vmax= $td_discharge_data['VMEANVERTICAL'];
           }
           //vmean
           if($td_discharge_data['VMEANSECTION']!= ""){
             $vmean= number_format ((float)$td_discharge_data['VMEANSECTION'], 2, '.', '');
           }
           else{
             $vmean = $td_discharge_data['VMEANSECTION'];
           }
           //  end Checking for empty field and making float points
          $date_id      = "date_$row_id";
          $wl_id        = "wl_$row_id";
          $ww_id        = "ww_$row_id";
          $area_id      = "area_$row_id";
          $discharge_id = "dischrg_$row_id";
          $vmax_id      = "vmax_$row_id";
          $vmean_id     = "vmean_$row_id";
          $note_id      = "note_$row_id";

          $after_note_id="";  
          $next_row_val          = $row_id + 1;
          $after_note_id         = "date_$next_row_val";
          $function_for_nxt_val  = "call_next_val_loader(event,'$note_id',' $after_note_id')";
          $function_for_wl       = "call_save_function(event,'$vmean_id','$after_note_id ','$row_id')";
          $call_key_up_function = "call_next_val_loader(event,'$date_id','$wl_id')";
     ?>  
       <tr>
            <!-- <th><?php echo $sl;?></th> -->
            <th style="text-align:center;">
                <input type="text" class=" td_date" name="date-time" id="<?php echo $date_id;?>" style="text-align: center;font-weight:bold; width:60%;" value="<?php echo  ($td_discharge_data['DT']) ;?>" onkeyup="<?php echo $call_key_up_function;?>" <?php echo $is_readonly;?> />
            </th>
            <th style="text-align:center;">
                <input type="text" class="input-mini td_wl" name="water-level" id="<?php echo $wl_id;?>" style="text-align:center;font-weight:bold; "  value="<?php echo $water_level; ?>"  onkeyup="call_next_val_loader(event,'<?php echo $wl_id; ?>','<?php echo $ww_id; ?>')" onkeypress="return isDecimalInput(event)">
            </th>
            <th style="text-align:center;">
                <input type="text" class="input-small td_ww" name="water-width" id="<?php echo $ww_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo  $water_width;?>" onkeyup="call_next_val_loader(event,'<?php echo $ww_id;; ?>','<?php echo $area_id; ?>')" onkeypress="return isNumericInput(event)">
            </th>
            <th style="text-align:center;">
                <input type="text" class="input-small td_area" name="area" id="<?php echo $area_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $area ;?>" onkeyup="call_next_val_loader(event,'<?php echo $area_id; ?>','<?php echo $discharge_id; ?>')" onkeypress="return isNumericInput(event)">
            </th>
            <th style="text-align:center;"> 
                <input type="text" class="input-mini td_discharge" name="discharge" id="<?php echo $discharge_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $discharge;?>" onkeyup="call_next_val_loader(event,'<?php echo $discharge_id; ?>','<?php echo $vmax_id; ?>')" onkeypress="return isNumericInput(event)">
            </th>
            <th style="text-align:center;">
                <input type="text" class="input-mini td_v_max" name="v-max" id="<?php echo $vmax_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $vmax;?>" onkeyup="call_next_val_loader(event,'<?php echo $vmax_id; ?>','<?php echo $vmean_id; ?>')" onkeypress="return isNumericInput(event)">
            </th>
            <th style="text-align:center;">
                <input type="text" class="input-mini td_v_mean" name="v-mean" id="<?php echo $vmean_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $vmean;?>" onkeyup="call_next_val_loader(event,'<?php echo $vmean_id; ?>','<?php echo  $note_id; ?>')" onkeypress="return isNumericInput(event)">
            </th>
            <th style="text-align:center;">
                <input type="text" class="input-mini td_note" name="note" id="<?php echo $note_id;?>" style="text-align:center;font-weight:bold; " value="<?php echo $td_discharge_data['NOTE'];?>"  onkeyup="<?php echo  $function_for_wl  ; ?>">
            </th>
            <td style="text-align: center;">
                <button class="btn btn-minier btn-purple" type="button" onclick="save_single_td_discharge_info('<?php echo $row_id; ?>','btn_click')"><i class="icon-save"></i> <b style="padding:-1%!important;">Save</b></button>
                <?php
                        if($_SESSION['delete'] == 'Y'){
                          echo '&nbsp;<button class="btn btn-minier btn-danger" type="button" onclick = "delete_tidal_data('.$row_id.')">
                          <i class="icon-trash"></i><b style="font-size: 12px;">Delete</b></button>';
                        }
                ?>
              </td>
        </tr>
        <!-- <input type="text" id="tot_row" name="tot_row" value="<?php echo $row_id; ?>" /> -->
        <?php
        
         }
        }
      }
        ?>
       
    </tbody>
</table>
<div class="row-fluid">
	<div class="control-group" style="float:right;">
		<div class="controls">
			<button id="td_save_btn" type="button" style="margin-right: 1px; padding: 4px!important; font-size: 12px;" class="btn btn-small btn-success" onclick="td_multiple_save()"><i class="icon-save"></i><b>Save All</b></button>
		</div>
	</div>
</div>
<input type="hidden" id="tot_row" name="tot_row" value="<?php echo $row; ?>" />

<script type="text/javascript">
    function call_next_val_loader(e, sel_col_id,next_col_id){
		// if(event.keyCode==13 || event.keyCode=='tab'){
		// 	var curr_val = $("#"+sel_col_id).val();
		// 	//$("#"+sel_col_id).select();
		// 	//alert('moving to the next column');
		// 	//save_water_level_info(sel_col_id,curr_val,next_col_id);
		// 	$("#"+next_col_id).select();
		// }
    if(event.keyCode==13 || event.keyCode=='tab' || event.keyCode==9){
			var col_name_arr = sel_col_id.split("_");
			var col_name = col_name_arr[0];
			var curr_val = $("#"+sel_col_id).val();
      //for date validation
      // alert(curr_val);
      if(col_name=='date'){
			//alert(col_name);
			var operation = "date_checker";
      var cur_date = encodeURIComponent($("#"+sel_col_id).val());
			var datastr = "operation="+operation+"&sel_in_date="+cur_date;
     // alert(datastr);
			$.ajax({
				url: 'module/ground_water_ex/tidal_discharge_entry_from_ajax.php', 
				type: 'post',
				data: datastr,
				cache: false,
				success: function(result) {
				//	alert(result);
					if(result== 0){
						alert('You only enter data till today');
            $("#"+sel_col_id).val('');
            $("#"+sel_col_id).select();
						return false;
					}
					else{
						$("#"+sel_col_id).val(result);
             $("#"+next_col_id).select();
					}
					
				}
			});
		}
      //for validation end


			//alert(col_name);
      
				// if(curr_val.length==1 || curr_val.length==2){
				// 	curr_val = curr_val+'.00';
				// 	$("#"+sel_col_id).val(curr_val);
				// }
			
        else{
				if (curr_val > Math.floor(curr_val)) {
					curr_val = parseFloat(curr_val).toFixed(2);
				}
				else{
					curr_val = (Math.round(curr_val * 100) / 100).toFixed(2);
				}
				$("#"+sel_col_id).val(curr_val);
      }
			//$("#"+sel_col_id).select();
			//alert('moving to the next column');
			//save_water_level_info(sel_col_id,curr_val,next_col_id);
			$("#"+next_col_id).select();
		}
	}

	function call_save_function(e,sel_col_id,next_col_id,sel_day){
		// if(event.keyCode==13 || event.keyCode=='tab'){
		// 	alert('will be saving now');
		// 	save_single_td_discharge_info(sel_day,press_op)
		// 	$("#"+next_col_id).select();
		// }
    if(event.keyCode==13 || event.keyCode=='tab'|| event.keyCode==9){
			var col_name_arr = sel_col_id.split("_");
			var col_name = col_name_arr[0];
			var curr_val = $("#"+sel_col_id).val();
  
		
				// if(curr_val.length==1 || curr_val.length==2){
				// 	curr_val = curr_val+'.00';
				// 	$("#"+sel_col_id).val(curr_val);
				// }
			// else{
				if (curr_val > Math.floor(curr_val)) {
					curr_val = parseFloat(curr_val).toFixed(2);
				}
				else{
					curr_val = (Math.round(curr_val * 100) / 100).toFixed(2);
				}
				$("#"+sel_col_id).val(curr_val);
		//	}
			//var press_op = "enter_click";
      var press_op = "enter_click";
      //alert(press_op);
			save_single_td_discharge_info(sel_day,press_op);
    	$("#"+next_col_id).select();
		}
	}
</script>

<!--validation-->
<!-- <script type="text/javascript">
 let inputReset = false; // Track whether input should be reset

function isNumericInput(event) {
  const key = event.keyCode || event.which;
  const keyChar = String.fromCharCode(key);

  const regex = /[0-9]|\.|\-/;

  // Only allow numeric, decimal, or minus sign input
  if (!regex.test(keyChar)) {
    event.preventDefault();
    return false;
  }

  const input = event.target;
  const currentValue = input.value;
  // If the input already contains a decimal point or minus sign, disallow another one
  if ((keyChar === "." && currentValue.indexOf(".") !== -1) || 
      (keyChar === "-" && currentValue.indexOf("-") !== -1)) {
    event.preventDefault();
    return false;
  }

  // If the input would result in a value less than -99.99 or greater than 99.99, disallow it
  // const newValue = parseFloat(currentValue + keyChar).toFixed(2);
  // if (newValue < -99.99 || newValue > 99.99) {
  //   event.preventDefault();
  //   return false;
  // }

  // If input should be reset, do so and allow new input
  if (inputReset) {
    input.value = "";
    inputReset = false;
  }
  

  // If the input would result in more than 2 decimal places, set inputReset flag
  const parts = currentValue.split(".");
  if (parts.length === 2 && parts[1].length >= 2 && keyChar !== "-") {
    event.preventDefault();
    event.target.value = "";
    event.target.value += keyChar;
    return false;
  }
  
  if (currentValue === "0" && keyChar !== "." && keyChar !== "-" && currentValue.indexOf(".") === -1) {
    event.preventDefault();
    return false;
  }

  return true;
}
 </script> -->
 <script>
 let inputReset = false; // Track whether input should be reset

function isNumericInput(event) {
  const key = event.keyCode || event.which;
  const keyChar = String.fromCharCode(key);

  const regex = /[0-9]|\.|\-/;

  // Only allow numeric, decimal, or minus sign input
  if (!regex.test(keyChar)) {
    event.preventDefault();
    return false;
  }

  const input = event.target;
  const currentValue = input.value;

  // If the input already contains a decimal point or minus sign, disallow another one
  if ((keyChar === "." && currentValue.indexOf(".") !== -1) || 
      (keyChar === "-" && currentValue.indexOf("-") !== -1)) {
    event.preventDefault();
    event.target.value = "";
    event.target.value += keyChar;
    return false;
  }

  // If the input would result in a value less than -99.99 or greater than 99.99, disallow it
  // const newValue = parseFloat(currentValue + keyChar).toFixed(2);
  // if (newValue < -99.99 || newValue > 99.99) {
  //   event.preventDefault();
  //   return false;
  // }

  // If input should be reset, do so and allow new input
  if (inputReset) {
    input.value = "";
    inputReset = false;
  }

  // If the input would result in more than 2 decimal places, set inputReset flag
  const parts = currentValue.split(".");
  if (parts.length === 2 && parts[1].length >= 2 && keyChar !== "-") {
    event.preventDefault();
    event.target.value = "";
    event.target.value += keyChar;
    return false;
  }
  
  if (currentValue === "0" && keyChar !== "." && keyChar !== "-" && currentValue.indexOf(".") === -1) {
    event.preventDefault();
    return false;
  }

  return true;
}
</script>
 
 <script>
let inputReset = false;
function isNumberKey(evt) {
    const key = event.keyCode || event.which;
  const keyChar = String.fromCharCode(key)
;

  const regex = /[0-9]|\.|\-/;

  // Only allow numeric, decimal, or minus sign input
  if (!regex.test(keyChar)) {
    event.preventDefault();
    return false;
  }

  const input = event.target;
  const currentValue = input.value;

  // If the input already contains a decimal point or minus sign, disallow another one
  if ((keyChar === "." && currentValue.indexOf(".") !== -1) || 
      (keyChar === "-" && currentValue.indexOf("-") !== -1)) {
    event.preventDefault();
    return false;
  }
  
  // If input should be reset, do so and allow new input
  if (inputReset) {
    input.value = '';
    inputReset = false;
  }

  // If the input would result in a value less than -99.99 or greater than 99.99, disallow it
  const newValue = parseFloat(currentValue + keyChar);
  if (newValue < 0000 || newValue > 9999) {
    event.preventDefault();
    event.target.value = "";
    event.target.value += keyChar;
    return false;
  }



  // If the input would result in more than 2 decimal places, set inputReset flag
  const parts = currentValue.split(".");
  if (parts.length === 2 && parts[1].length >= 2 && keyChar !== "-") {
    inputReset = true;
    event.preventDefault();
    return false;
  }
  
  if (currentValue === "0" && keyChar !== "." && keyChar !== "-") {
    event.preventDefault();
    return false;
  }

  return true;
}
</script>

<script>
let inputReset = false; // Track whether input should be reset

function isDecimalInput(event) {
const key = event.keyCode || event.which;
const keyChar = String.fromCharCode(key);

const regex = /[0-9]|\.|\-/;

// Only allow numeric, decimal, or minus sign input
if (!regex.test(keyChar)) {
  event.preventDefault();
  return false;
}

const input = event.target;
const currentValue = input.value;

// If the input already contains a decimal point or minus sign, disallow another one
if ((keyChar === "." && currentValue.indexOf(".") !== -1) || 
    (keyChar === "-" && currentValue.indexOf("-") !== -1)) {
  event.preventDefault();
  event.target.value = "";
  event.target.value += keyChar;
  return false;
}

//If the input would result in a value less than -99.99 or greater than 99.99, disallow it
const newValue = parseFloat(currentValue + keyChar).toFixed(2);
if (newValue < -99.99 || newValue > 99.99) {
  event.preventDefault();
  return false;
}

// If input should be reset, do so and allow new input
if (inputReset) {
  input.value = "";
  inputReset = false;
}

// If the input would result in more than 2 decimal places, set inputReset flag
const parts = currentValue.split(".");
if (parts.length === 2 && parts[1].length >= 2 && keyChar !== "-") {
  event.preventDefault();
  event.target.value = "";
  event.target.value += keyChar;
  return false;
}

if (currentValue === "0" && keyChar !== "." && keyChar !== "-" && currentValue.indexOf(".") === -1) {
  event.preventDefault();
  return false;
}

return true;
}
</script>
<script type="text/javascript">
var filed = <?php echo $row; ?>;
 //alert(filed);
function load_new_row(){
  //alert('load_new_row');
  filed++;
	var datastr="row_num="+filed;
	// alert(datastr);
			$.ajax({
				type:"post",
				url:"module/ground_water_ex/load_item_tbl_for_td_discharge_request.php",
				data:datastr ,
				success:function(st){
				//alert(st);
				$("#td_dis_data_tbl_body").append(st);
        $('#date_'+filed).select();
        $('#tot_row').val(filed);

				}
			}); 
}

</script>
<script>
  function show_alert(event){
		alert('You cannot enter for any day after today');
	}
</script>
<!-- <script type='text/javascript'>
  load();
</script> -->
