<?php
session_start();
include("../../php_crud/my_class.php");
$obj = new my_class();
extract($_GET);
// echo "station: $station, month: $month, year: $year, tidal status: $tidal_status"; 
/*$month = '03';
$year = '2016';
$river = '12';
$station ='SW26';*/
$curr_date = date('d-m-Y');

$curr_date =  strtotime($curr_date);

$is_readonly = "";
$call_key_up_function = "";
?>

<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="obs_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="obs_dis_sva_btn" type="button" style="margin-right: 1px; padding: 4px!important; font-size: 12px;" class="btn btn-small btn-success" onclick="obs_dis_multiple_save()"><i class="icon-save"></i><b>Save All</b></button>
		</div>
	</div>
</div>
  <!-- <button style="margin-right: 5px;margin-left: 89%;" class="btn btn-small btn-success" type="button" onclick="obs_dis_multiple_save()">
		
       <b style="font-size: 12px;">Save All</b>
		</button> -->
    <thead>
        <tr>
        <th style="text-align:center;  background-color: #b3e0ff; width: 15%;">Date</th>
        <th style="text-align:center;  background-color: #b3e0ff;">WL (m)</th>
        <th style="text-align:center;  background-color: #b3e0ff; width:10%;">Discharge (m3/s)</th>
        <th style="text-align:center;  background-color: #b3e0ff;">Area (m2)</th>
        <th style="text-align:center;  background-color: #b3e0ff;">Width (m)</th>
        <th style="text-align:center;  background-color: #b3e0ff; ">Max Depth (m)</th>
        <th style="text-align:center;  background-color: #b3e0ff;">Max Depth Location</th>
        <th style="text-align:center;  background-color: #b3e0ff;">Max Velocity (m/s)</th>
        <th style="text-align:center;  background-color: #b3e0ff;">Location </th>
        <th style="text-align:center;  background-color: #b3e0ff;">Section ID</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 = "ods_tbl_body">
        <?php
        $row_id=0;
        //my code
        if($show_mode=='show_empty'){
          $rows = array("1", "2", "3", "4", "5");
          foreach ($rows as $row_id) {

              //// Checking for empty field and making float points
              $water_lev = "";
              $discharge = "";
              $area = "";
              $width = "";
              $max_depth = "";
              $max_dep_loc = "";
              $max_vel = "";
              $location = "";
              $station_id = "";
  
              //Water Level
              if($obs_discharge_data['WATER_LEVEL'] != ""){
                $water_lev = number_format((float)$obs_discharge_data['WATER_LEVEL'], 2, '.', '');
              }
              else{
                $water_lev = $obs_discharge_data['WATER_LEVEL'];
              }
              //Discharge
              if($obs_discharge_data['DISCHARGE'] != ""){
                $discharge = number_format((float)$obs_discharge_data['DISCHARGE'], 2, '.', '');
              }
              else{
                $discharge = $obs_discharge_data['DISCHARGE'];
              }
              //Area
              if($obs_discharge_data['CRS_SECTION_ARIA'] != ""){
                $area = number_format((float)$obs_discharge_data['CRS_SECTION_ARIA'], 2, '.', '');
              }
              else{
                $area = $obs_discharge_data['CRS_SECTION_ARIA'];
              }
              //Width
              if($obs_discharge_data['RIVER_WIDTH'] != ""){
                $width = number_format((float)$obs_discharge_data['RIVER_WIDTH'], 2, '.', '');
              }
              else{
                $width = $obs_discharge_data['RIVER_WIDTH'];
              }
              //Max Depth
              if($obs_discharge_data['MAX_DEPTH']!= ""){
                $max_depth = number_format((float)$obs_discharge_data['MAX_DEPTH'], 2, '.', '');
              }
              else{
                $max_depth = $obs_discharge_data['MAX_DEPTH'];
              }
              //Max Depth Loction
              if($obs_discharge_data['MAX_DEPTH_LOCATION']!= ""){
                $max_dep_loc = number_format((float)$obs_discharge_data['MAX_DEPTH_LOCATION'], 2, '.', '');
              }
              else{
                $max_dep_loc = $obs_discharge_data['MAX_DEPTH_LOCATION'];
              }
              //Max Velocity
              if($obs_discharge_data['MAX_VELOCITY']!= ""){
                $max_vel = number_format((float)$obs_discharge_data['MAX_VELOCITY'], 2, '.', '');
              }
              else{
                $max_vel = $obs_discharge_data['MAX_VELOCITY'];
              }
              //Location
              if($obs_discharge_data['LOCATION_ID']!= ""){
                $location = number_format((float)$obs_discharge_data['LOCATION_ID'], 2, '.', '');
              }
              else{
                $location = $obs_discharge_data['LOCATION_ID'];
              }
              //Station ID
              if($obs_discharge_data['SECTION_ID']!= ""){
                $station_id = number_format((float)$obs_discharge_data['SECTION_ID'], 2, '.', '');
              }
              else{
                $station_id = $obs_discharge_data['SECTION_ID'];
              }
              //// Checking for empty field and making float points

            $date_id = "date_$row_id";
            $obs_discharge_wl_col_id = "obs_discharge_wl_$row_id";
            $obs_discharge_disch_col_id = "obs_discharge_disch_$row_id";
            $obs_discharge_csa_col_id = "obs_discharge_csa_$row_id";
            $obs_discharge_rw_col_id = "obs_discharge_rw_$row_id";
            $obs_discharge_md_col_id = "obs_discharge_md_$row_id";
            $obs_discharge_mdl_col_id = "obs_discharge_mdl_$row_id";
            $obs_discharge_mval_col_id = "obs_discharge_mval_$row_id";
            $obs_discharge_local_col_id = "obs_discharge_local_$row_id";
            $obs_discharge_sect_col_id = "obs_discharge_sect_col_$row_id";
            $obs_discharge_not_col_id = "obs_discharge_not_col_$row_id";
            $date_row_id = "date_row_$row_id";
            $after_obs_discharge_not_col_id = "";
            $next_row_val = $row_id + 1;
            $after_obs_discharge_not_col_id = "date_$next_row_val";

            $after_note_id="";  
            $next_row_val          = $row_id + 1;
            $after_note_id         = "obs_discharge_wl_$next_row_val";
            $function_for_nxt_val  = "call_next_val_loader(event,'$obs_discharge_not_col_id',' $after_note_id')";
            $function_for_wl       = "save_n_load_next_row(event,'$obs_discharge_sect_col_id','$after_note_id ','$row_id')";
            $call_key_up_function = "call_next_val_loader(event,'$date_id','$obs_discharge_wl_col_id')";

        ?>  
              <tr>
				<td style="text-align: center;">
                  <input type="text" id="<?php echo $date_id; ?>" class="input-mini month_date obs_date" style="text-align: center;font-weight:bold; width: 50%;" value="<?php echo  $show_date; ?>" onkeyup="<?php echo $call_key_up_function; ?>" <?php echo $is_readonly; ?>/>
				</td>

                <td style="text-align: center;">
                  <input onkeypress="return isDecimalInput(event)" type="text" class="input-mini obs_water_level" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_wl_col_id;?>"
                  value="<?php echo  $water_lev; ?>"  onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_wl_col_id; ?>','<?php echo $obs_discharge_disch_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_discharge" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_disch_col_id; ?>"
                  value="<?php echo  $discharge; ?>"onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_disch_col_id; ?>','<?php echo $obs_discharge_csa_col_id ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_section_area" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_csa_col_id; ?>"
                  value="<?php echo  $area; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_csa_col_id; ?>','<?php echo $obs_discharge_rw_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_river_width" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_rw_col_id; ?>"
                  value="<?php echo  $width; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_rw_col_id; ?>','<?php echo $obs_discharge_md_col_id ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_depth" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_md_col_id; ?>"
                  value="<?php echo $max_depth; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_md_col_id; ?>','<?php echo $obs_discharge_mdl_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_depth_locat" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_mdl_col_id; ?>"
                  value="<?php echo  $max_dep_loc; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_mdl_col_id; ?>','<?php echo $obs_discharge_mval_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_velocity" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_mval_col_id; ?>"
                  value="<?php echo $max_vel; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_mval_col_id; ?>','<?php echo $obs_discharge_local_col_id; ?>')">
                </td>

                <th style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_location_id" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_local_col_id; ?>"
                  value="<?php echo  $location; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_local_col_id; ?>','<?php echo $obs_discharge_sect_col_id; ?>')">
                </th>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_section_id" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_sect_col_id; ?>"
                  value="<?php echo  $station_id; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_sect_col_id; ?>','<?php echo $obs_discharge_not_col_id; ?>')">
                </td>
              

                <td style="text-align: center;">
                <input type="text" class="input-mini obs_note" style="text-align: left; font-weight: bold;" 
                id="<?php echo $obs_discharge_not_col_id; ?>" value = "<?php echo trim($obs_discharge_data['NOTE']); ?>" onkeyup="save_n_load_next_row(event,'<?php echo $obs_discharge_not_col_id; ?>','<?php echo $after_obs_discharge_not_col_id; ?>','<?php echo  $row_id; ?>')">                    
                </td>

              <td style="text-align: center;">
                <button class="btn btn-minier btn-purple" type="button" id="<?php echo $date_row_id; ?>" onclick="save_single_observed_discharge_info('<?php echo $row_id; ?>','btn_click')"><i class="icon-save"></i> <b style="font-size: 12px;">Save</b></button>

                <?php
                  if($_SESSION['delete'] == 'Y'){
                    echo '&nbsp;<button class="btn btn-minier btn-danger" type="button" onclick = "delete_observed_data('.$row_id.')">
                    <i class="icon-trash"></i> <b style="font-size: 12px;">Delete</b></button>';
                  }
                ?>
              </td>
              </tr>
          <?php 
          } 
          }else{
            $row_id = 0;
            $cond = "STATION_ID='$station' AND TO_CHAR(DIS_DT, 'YYYY')BETWEEN '$from_year' AND '$to_year' ORDER BY DIS_DT ASC";
            $data_count = $obj->View_column_details_By_Cond_hydro("OBS_DISCHARGE","COUNT(*) AS TOT_DATA",$cond);
            if($data_count['TOT_DATA'] > 0){
              $is_readonly = "";
              $call_key_up_function = "";
            foreach($obj->View_colmn_By_Cond_hydro("OBS_DISCHARGE","*",$cond) as $obs_discharge_data){
              $show_date =  date('d/m/Y',strtotime($obs_discharge_data['DIS_DT']));
              $input_date = date('d-m-Y',strtotime($obs_discharge_data['DIS_DT'])); 
         
              $row_id++;
              
              //// Checking for empty field and making float points
              $water_lev = "";
              $discharge = "";
              $area = "";
              $width = "";
              $max_depth = "";
              $max_dep_loc = "";
              $max_vel = "";
              $location = "";
              $station_id = "";
  
              //Water Level
              if($obs_discharge_data['WATER_LEVEL'] != ""){
                $water_lev = number_format((float)$obs_discharge_data['WATER_LEVEL'], 2, '.', '');
              }
              else{
                $water_lev = $obs_discharge_data['WATER_LEVEL'];
              }
              //Discharge
              if($obs_discharge_data['DISCHARGE'] != ""){
                $discharge = number_format((float)$obs_discharge_data['DISCHARGE'], 2, '.', '');
              }
              else{
                $discharge = $obs_discharge_data['DISCHARGE'];
              }
              //Area
              if($obs_discharge_data['CRS_SECTION_ARIA'] != ""){
                $area = number_format((float)$obs_discharge_data['CRS_SECTION_ARIA'], 2, '.', '');
              }
              else{
                $area = $obs_discharge_data['CRS_SECTION_ARIA'];
              }
              //Width
              if($obs_discharge_data['RIVER_WIDTH'] != ""){
                $width = number_format((float)$obs_discharge_data['RIVER_WIDTH'], 2, '.', '');
              }
              else{
                $width = $obs_discharge_data['RIVER_WIDTH'];
              }
              //Max Depth
              if($obs_discharge_data['MAX_DEPTH']!= ""){
                $max_depth = number_format((float)$obs_discharge_data['MAX_DEPTH'], 2, '.', '');
              }
              else{
                $max_depth = $obs_discharge_data['MAX_DEPTH'];
              }
              //Max Depth Loction
              if($obs_discharge_data['MAX_DEPTH_LOCATION']!= ""){
                $max_dep_loc = number_format((float)$obs_discharge_data['MAX_DEPTH_LOCATION'], 2, '.', '');
              }
              else{
                $max_dep_loc = $obs_discharge_data['MAX_DEPTH_LOCATION'];
              }
              //Max Velocity
              if($obs_discharge_data['MAX_VELOCITY']!= ""){
                $max_vel = number_format((float)$obs_discharge_data['MAX_VELOCITY'], 2, '.', '');
              }
              else{
                $max_vel = $obs_discharge_data['MAX_VELOCITY'];
              }
              //Location
              if($obs_discharge_data['LOCATION_ID']!= ""){
                $location = number_format((float)$obs_discharge_data['LOCATION_ID'], 2, '.', '');
              }
              else{
                $location = $obs_discharge_data['LOCATION_ID'];
              }
              //Station ID
              if($obs_discharge_data['SECTION_ID']!= ""){
                $station_id = number_format((float)$obs_discharge_data['SECTION_ID'], 2, '.', '');
              }
              else{
                $station_id = $obs_discharge_data['SECTION_ID'];
              }
              //// Checking for empty field and making float points
              
              $date_id = "date_$row_id";
              $obs_discharge_wl_col_id = "obs_discharge_wl_$row_id";
              $obs_discharge_disch_col_id = "obs_discharge_disch_$row_id";
              $obs_discharge_csa_col_id = "obs_discharge_csa_$row_id";
              $obs_discharge_rw_col_id = "obs_discharge_rw_$row_id";
              $obs_discharge_md_col_id = "obs_discharge_md_$row_id";
              $obs_discharge_mdl_col_id = "obs_discharge_mdl_$row_id";
              $obs_discharge_mval_col_id = "obs_discharge_mval_$row_id";
              $obs_discharge_local_col_id = "obs_discharge_local_$row_id";
              $obs_discharge_sect_col_id = "obs_discharge_sect_col_$row_id";
              $obs_discharge_not_col_id = "obs_discharge_not_col_$row_id";
              $date_row_id = "date_row_$row_id";
              $after_obs_discharge_not_col_id = "";
              $next_row_val = $row_id + 1;
              $after_obs_discharge_not_col_id = "date_$next_row_val";
  
              $after_note_id="";  
              $next_row_val          = $row_id + 1;
              $after_note_id         = "obs_discharge_wl_$next_row_val";
              $function_for_nxt_val  = "call_next_val_loader(event,'$obs_discharge_not_col_id',' $after_note_id')";
              $function_for_wl       = "save_n_load_next_row(event,'$obs_discharge_sect_col_id','$after_note_id ','$row_id')";
              
              ////Current Date Issue////
              $input_date = strtotime($input_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','$obs_discharge_wl_col_id')";
              }
              ////Current Date Issue////
        ?>  
            <tr>
				<td style="text-align: center;">
                  <input type="text" id="<?php echo $date_id; ?>" class="input-mini month_date obs_date" style="text-align: center;font-weight:bold; width: 50%;" value="<?php echo  $show_date; ?>" onkeyup="<?php echo $call_key_up_function; ?>" <?php echo $is_readonly; ?>/>
				</td>

                <td style="text-align: center;">
                  <input onkeypress="return isDecimalInput(event)" type="text" class="input-mini obs_water_level" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_wl_col_id;?>"
                  value="<?php echo  $water_lev; ?>"  onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_wl_col_id; ?>','<?php echo $obs_discharge_disch_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_discharge" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_disch_col_id; ?>"
                  value="<?php echo  $discharge; ?>"onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_disch_col_id; ?>','<?php echo $obs_discharge_csa_col_id ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_section_area" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_csa_col_id; ?>"
                  value="<?php echo  $area; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_csa_col_id; ?>','<?php echo $obs_discharge_rw_col_id; ?>')">
                </th>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_river_width" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_rw_col_id; ?>"
                  value="<?php echo  $width; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_rw_col_id; ?>','<?php echo $obs_discharge_md_col_id ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_depth" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_md_col_id; ?>"
                  value="<?php echo $max_depth; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_md_col_id; ?>','<?php echo $obs_discharge_mdl_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_depth_locat" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_mdl_col_id; ?>"
                  value="<?php echo  $max_dep_loc; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_mdl_col_id; ?>','<?php echo $obs_discharge_mval_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_velocity" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_mval_col_id; ?>"
                  value="<?php echo $max_vel; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_mval_col_id; ?>','<?php echo $obs_discharge_local_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_location_id" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_local_col_id; ?>"
                  value="<?php echo  $location; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_local_col_id; ?>','<?php echo $obs_discharge_sect_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_section_id" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_sect_col_id; ?>"
                  value="<?php echo  $station_id; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_sect_col_id; ?>','<?php echo $obs_discharge_not_col_id; ?>')">
                </td>
              

                <td style="text-align: center;">
                <input type="text" class="input-mini obs_note" style="text-align: left; font-weight: bold;" 
                id="<?php echo $obs_discharge_not_col_id; ?>" value = "<?php echo trim($obs_discharge_data['NOTE']); ?>" onkeyup="save_n_load_next_row(event,'<?php echo $obs_discharge_not_col_id; ?>','<?php echo $after_obs_discharge_not_col_id; ?>','<?php echo  $row_id; ?>')">                    
                </td>

              <td style="text-align: center;">
                <button class="btn btn-minier btn-purple" type="button" id="<?php echo $date_row_id; ?>" onclick="save_single_observed_discharge_info('<?php echo $row_id; ?>','btn_click')"><i class="icon-save"></i> <b style="font-size: 12px;">Save</b></button>

                <?php
                  if($_SESSION['delete'] == 'Y'){
                    echo '&nbsp;<button class="btn btn-minier btn-danger" type="button" onclick = "delete_observed_data('.$row_id.')">
                    <i class="icon-trash"></i> <b style="font-size: 12px;">Delete</b></button>';
                  }
                ?>
              </td>
              </tr>
              
          <?php 
          }
          $total_row = $row_id;
          //echo $total_row;
        }
        else{
            $row_id = 0;
            $rows = array("1", "2", "3", "4", "5");
            foreach ($rows as $row_id) {
                //// Checking for empty field and making float points
                $water_lev = "";
                $discharge = "";
                $area = "";
                $width = "";
                $max_depth = "";
                $max_dep_loc = "";
                $max_vel = "";
                $location = "";
                $station_id = "";
    
                //Water Level
                if($obs_discharge_data['WATER_LEVEL'] != ""){
                  $water_lev = number_format((float)$obs_discharge_data['WATER_LEVEL'], 2, '.', '');
                }
                else{
                  $water_lev = $obs_discharge_data['WATER_LEVEL'];
                }
                //Discharge
                if($obs_discharge_data['DISCHARGE'] != ""){
                  $discharge = number_format((float)$obs_discharge_data['DISCHARGE'], 2, '.', '');
                }
                else{
                  $discharge = $obs_discharge_data['DISCHARGE'];
                }
                //Area
                if($obs_discharge_data['CRS_SECTION_ARIA'] != ""){
                  $area = number_format((float)$obs_discharge_data['CRS_SECTION_ARIA'], 2, '.', '');
                }
                else{
                  $area = $obs_discharge_data['CRS_SECTION_ARIA'];
                }
                //Width
                if($obs_discharge_data['RIVER_WIDTH'] != ""){
                  $width = number_format((float)$obs_discharge_data['RIVER_WIDTH'], 2, '.', '');
                }
                else{
                  $width = $obs_discharge_data['RIVER_WIDTH'];
                }
                //Max Depth
                if($obs_discharge_data['MAX_DEPTH']!= ""){
                  $max_depth = number_format((float)$obs_discharge_data['MAX_DEPTH'], 2, '.', '');
                }
                else{
                  $max_depth = $obs_discharge_data['MAX_DEPTH'];
                }
                //Max Depth Loction
                if($obs_discharge_data['MAX_DEPTH_LOCATION']!= ""){
                  $max_dep_loc = number_format((float)$obs_discharge_data['MAX_DEPTH_LOCATION'], 2, '.', '');
                }
                else{
                  $max_dep_loc = $obs_discharge_data['MAX_DEPTH_LOCATION'];
                }
                //Max Velocity
                if($obs_discharge_data['MAX_VELOCITY']!= ""){
                  $max_vel = number_format((float)$obs_discharge_data['MAX_VELOCITY'], 2, '.', '');
                }
                else{
                  $max_vel = $obs_discharge_data['MAX_VELOCITY'];
                }
                //Location
                if($obs_discharge_data['LOCATION_ID']!= ""){
                  $location = number_format((float)$obs_discharge_data['LOCATION_ID'], 2, '.', '');
                }
                else{
                  $location = $obs_discharge_data['LOCATION_ID'];
                }
                //Station ID
                if($obs_discharge_data['SECTION_ID']!= ""){
                  $station_id = number_format((float)$obs_discharge_data['SECTION_ID'], 2, '.', '');
                }
                else{
                  $station_id = $obs_discharge_data['SECTION_ID'];
                }
                //// Checking for empty field and making float points
  
              $date_id = "date_$row_id";
              $obs_discharge_wl_col_id = "obs_discharge_wl_$row_id";
              $obs_discharge_disch_col_id = "obs_discharge_disch_$row_id";
              $obs_discharge_csa_col_id = "obs_discharge_csa_$row_id";
              $obs_discharge_rw_col_id = "obs_discharge_rw_$row_id";
              $obs_discharge_md_col_id = "obs_discharge_md_$row_id";
              $obs_discharge_mdl_col_id = "obs_discharge_mdl_$row_id";
              $obs_discharge_mval_col_id = "obs_discharge_mval_$row_id";
              $obs_discharge_local_col_id = "obs_discharge_local_$row_id";
              $obs_discharge_sect_col_id = "obs_discharge_sect_col_$row_id";
              $obs_discharge_not_col_id = "obs_discharge_not_col_$row_id";
              $date_row_id = "date_row_$row_id";
              $after_obs_discharge_not_col_id = "";
              $next_row_val = $row_id + 1;
              $after_obs_discharge_not_col_id = "date_$next_row_val";
  
              $after_note_id="";  
              $next_row_val          = $row_id + 1;
              $after_note_id         = "obs_discharge_wl_$next_row_val";
              $function_for_nxt_val  = "call_next_val_loader(event,'$obs_discharge_not_col_id',' $after_note_id')";
              $function_for_wl       = "save_n_load_next_row(event,'$obs_discharge_sect_col_id','$after_note_id ','$row_id')";
              $call_key_up_function = "call_next_val_loader(event,'$date_id','$obs_discharge_wl_col_id')";
      ?>
			<tr>
				<td style="text-align: center;">
                  <input type="text" id="<?php echo $date_id; ?>" class="input-mini month_date obs_date" style="text-align: center;font-weight:bold; width: 50%;" value="<?php echo  $show_date; ?>" onkeyup="<?php echo $call_key_up_function; ?>" <?php echo $is_readonly; ?>/>
				</td>

                <td style="text-align: center;">
                  <input onkeypress="return isDecimalInput(event)" type="text" class="input-mini obs_water_level" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_wl_col_id;?>"
                  value="<?php echo  $water_lev; ?>"  onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_wl_col_id; ?>','<?php echo $obs_discharge_disch_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_discharge" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_disch_col_id; ?>"
                  value="<?php echo  $discharge; ?>"onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_disch_col_id; ?>','<?php echo $obs_discharge_csa_col_id ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_section_area" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_csa_col_id; ?>"
                  value="<?php echo  $area; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_csa_col_id; ?>','<?php echo $obs_discharge_rw_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_river_width" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_rw_col_id; ?>"
                  value="<?php echo  $width; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_rw_col_id; ?>','<?php echo $obs_discharge_md_col_id ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_depth" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_md_col_id; ?>"
                  value="<?php echo $max_depth; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_md_col_id; ?>','<?php echo $obs_discharge_mdl_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_depth_locat" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_mdl_col_id; ?>"
                  value="<?php echo  $max_dep_loc; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_mdl_col_id; ?>','<?php echo $obs_discharge_mval_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_max_velocity" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_mval_col_id; ?>"
                  value="<?php echo $max_vel; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_mval_col_id; ?>','<?php echo $obs_discharge_local_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_location_id" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_local_col_id; ?>"
                  value="<?php echo  $location; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_local_col_id; ?>','<?php echo $obs_discharge_sect_col_id; ?>')">
                </td>

                <td style="text-align: center;">
                  <input onkeypress="return isNumericInput(event)" type="text" class="input-mini obs_section_id" style="text-align: center; font-weight: bold;" id="<?php echo $obs_discharge_sect_col_id; ?>"
                  value="<?php echo  $station_id; ?>" onkeyup="call_next_val_loader(event,'<?php echo $obs_discharge_sect_col_id; ?>','<?php echo $obs_discharge_not_col_id; ?>')">
                </td>
              

                <td style="text-align: center;">
                <input type="text" class="input-mini obs_note" style="text-align: left; font-weight: bold;" 
                id="<?php echo $obs_discharge_not_col_id; ?>" value = "<?php echo trim($obs_discharge_data['NOTE']); ?>" onkeyup="save_n_load_next_row(event,'<?php echo $obs_discharge_not_col_id; ?>','<?php echo $after_obs_discharge_not_col_id; ?>','<?php echo  $row_id; ?>')">                    
                </td>

              <td style="text-align: center;">
                <button class="btn btn-minier btn-purple" type="button" id="<?php echo $date_row_id; ?>" onclick="save_single_observed_discharge_info('<?php echo $row_id; ?>','btn_click')"><i class="icon-save"></i> <b style="font-size: 12px;">Save</b></button>

                <?php
                  if($_SESSION['delete'] == 'Y'){
                    echo '&nbsp;<button class="btn btn-minier btn-danger" type="button" onclick = "delete_observed_data('.$row_id.')">
                    <i class="icon-trash"></i> <b style="font-size: 12px;">Delete</b></button>';
                  }
                ?>
              </td>
              </tr>
              <?php
              }
            }
          }
          ?>
    </tbody>
</table>
<div class="row-fluid" style="margin-bottom:5px;">
	    <div class="control-group" style="float:right;">
		    <div class="controls">
		  	  <button id="obs_dis_sva_btn" type="button" style="margin-right: 1px; padding: 4px!important; font-size: 12px;" class="btn btn-small btn-success" onclick="obs_dis_multiple_save()"><i class="icon-save"></i><b>Save All</b></button>
		    </div>
	    </div>
    </div>
<input type="hidden" id="total_row" name="total_row" value="<?php echo $row; ?>" />
<!-- <style>
  .appent_class{
    width: 64px;
    margin-left: 6px;
  }
  .appent_class_date{
    width: 98px;
    margin-left: 7px;
  }
  .appent_class_seven{
    width: 65px;
    margin-left: 29px;
  }

</style> -->
<!-- ================ input  validation ================= -->
<script>
function call_next_val_loader(e, sel_col_id,next_col_id){
	//alert('call_next_val_loader');
    if(event.keyCode==13 || event.keyCode=='tab'){
		var curr_val = $("#"+sel_col_id).val();
		var col_name_arr = sel_col_id.split('_');
		var col_name = col_name_arr[0];
    //alert(curr_val);
		if(col_name=='date'){
			//alert(col_name);
			var operation = "date_checker";
			var datastr = "operation="+operation+"&sel_in_date="+curr_val;
      //alert(datastr);
			$.ajax({
				url: 'module/ground_water_ex/observed_discharge_information_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();
					}
					
				}
			});
		}
		else{
			if (curr_val > Math.floor(curr_val)) {
				curr_val = parseFloat(curr_val).toFixed(2);
			}
			$("#"+sel_col_id).val(curr_val);
      $("#"+next_col_id).select();
		}
        //$("#"+next_col_id).select();
      /*if (curr_val > Math.floor(curr_val)) {
          curr_val = parseFloat(curr_val).toFixed(2);
      }
        $("#"+sel_col_id).val(curr_val);
        $("#"+next_col_id).select();*/
    }
}
function save_n_load_next_row(e, sel_col_id,next_col_id,sel_row){
	if(event.keyCode==13 || event.keyCode=='tab'){
		//alert(sel_col_id);
		//alert(next_col_id);
		var curr_val = $("#"+sel_col_id).val();
		var press_op = 'enter_press';
       // $("#"+sel_col_id).select();
        save_single_observed_discharge_info(sel_row,press_op);
        $("#"+next_col_id).select();
		/*var tot_row = <?php echo $row_id; ?>;
		if(tot_row==sel_row){
			load_new_row();
		}*/
	}
}
</script>
<script>
var filed = <?php echo $row_id; ?>;
//alert(filed);
function load_new_row(){
	filed++;
	var datastr="row_num="+filed;
//	alert(datastr);
	$.ajax({
		type:"post",
		url:"module/ground_water_ex/load_new_row_for_observed_discharge.php",
		data:datastr ,
		success:function(st){
		//	alert(st);
      $("#ods_tbl_body").append(st);
			//$("#obs_dis_data_table").append(st);
			$('#date_'+filed).select();
      $('#total_row').val(filed);
		}
	}); 
}
</script>

<!-- 00.00 formating and Alpha-Numeric Checking-->
<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>
<!-- 00.00 formating and Alpha-Numeric Checking-->

<!-- Alpha-Numeric Checking-->
<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>
<!-- Alpha-Numeric Checking-->
<script>
  function show_alert(event){
		alert('You cannot enter for any day after today');
	}
</script>