<?php
session_start();
include("../../php_crud/my_class.php");
$obj = new my_class();
$user_id = $_SESSION['LOGIN_USERID'];
extract($_GET);
$user_info = $obj->View_column_details_By_Cond("ST_USER_INFO", "USER_GROUP_ID,OFFICE_ID", "USER_ID='$user_id'");
$user_office_id = $user_info['OFFICE_ID'];
/*$station_list = "";
foreach($obj->View_all_data_row_column_By_Cond("MDM_OFFICE_STATION_MAP", ' * ',"OFFICE_ID='$user_office_id'") AS $off_wise_stat){
	$station_list .= "'".$off_wise_stat['STATION_ID']."',";
}
$station_list = substr($station_list,0,-1);*/
?>

<div class="row-fluid" style="margin-top: 15px;">
    <div class="btn-group" style="float: right;">
		<!--<button style="margin-right: 5px;" class="btn btn-small btn-success" type="button" onclick="multiple_save()">
			<i class="icon-save"></i> Save
		</button>-->
		<button style="margin-right: 5px;" class="btn btn-small btn-purple" type="button" id="btn_save" onclick="multiple_data_save()">
			<i class="icon-check"></i>
			Approve
		</button>
		<button class="btn btn-small btn-danger" type="button" onclick="reject_log_data()">
			<i class="icon-remove"></i>
			Reject
		</button>     
    </div>
    <div style="color: red;">
        <b>REC</b> - Received, <b>VER</b> - Verified, <b>WL</b> - Water Level
    </div>
</div>
<div class="row-fluid" style="margin-top: 15px;">
<table id="ffwc_wl_data_tbl" class="table table-striped table-bordered table-hover">
    <thead>
        <tr style="font-family: 'Open Sans';">
            <th rowspan="2"><input type="checkbox" style="position: relative; opacity: 1;" onclick="select_all_data()" id="btn_save_all_data"/></th>
            <th rowspan="2" style="text-align: center;">Sl</th>
            <!--<th rowspan="2" style="text-align: center;">Mobile Number</th>
			
            <th rowspan="2" style="text-align: center;">Old WELL ID</th>-->
            <th rowspan="2" style="text-align: center;">Station ID</th>
            <th rowspan="2" style="text-align: center;">Log Date</th>
			<th rowspan="2" style="text-align: center;">Verified Log Date</th>
            <th colspan="2" style="text-align: center;">WL (6 AM)</th>
            <th colspan="2" style="text-align: center;">WL (9 AM)</th>
            <th colspan="2" style="text-align: center;">WL (12 PM)</th>
            <th colspan="2" style="text-align: center;">WL (3 PM)</th>
            <th colspan="2" style="text-align: center;">WL (6 PM)</th>
            <th colspan="2" style="text-align: center;">RAINFALL</th>
            <th rowspan="2" style="text-align: center;">Status</th>
			
            <th rowspan="2" style="text-align: center;">Action</th>
        </tr>
		<tr>
			<th style="text-align: center;">REC WL</th>
			<th style="text-align: center;">VER WL</th>
			
			<th style="text-align: center;">REC WL</th>
			<th style="text-align: center;">VER WL</th>
			
			<th style="text-align: center;">REC WL</th>
			<th style="text-align: center;">VER WL</th>
			
			<th style="text-align: center;">REC WL</th>
			<th style="text-align: center;">VER WL</th>
			
			<th style="text-align: center;">REC WL</th>
			<th style="text-align: center;">VER WL</th>

            <th style="text-align: center;">REC</th>
			<th style="text-align: center;">VER</th>
		</tr>
    </thead>
    <tbody>
    <?php
        
        $table_name =  "MDM_WL_RAINFALL_DATA_LOG";
        
        /*if($user_office_id!=""){
			$where_cond ="WELL_ID IN ($station_list) AND";
		}*/
		
        $curr_date      = date('d-M-y');
		$grph_from_date = "";
        $grph_to_date = "";
        $grph_status = "";
		if($from_date!="" && $to_date!="")
        {
			//echo "line 1";
            $from_date = date("d-M-y", strtotime($from_date));
			$from_date = strtoupper($from_date);
			$to_date = date("d-M-y", strtotime($to_date));
			$to_date = strtoupper($to_date);
			$where_cond .= "LOG_DATE>=TO_DATE('$from_date','DD-MON-RR') AND 
LOG_DATE<=TO_DATE('$to_date','DD-MON-RR') AND DATA_READ_TYPE='$data_src'";
            /*if($data_status!="all"){
				$where_cond .= " AND STATUS='$data_status'";
            }
			else if($data_status==""){
				$where_cond .= " AND STATUS='P'";
			}
			else{*/
				$where_cond .= " AND STATUS='P'";
			//}
			$grph_from_date = $from_date;
			$grph_to_date = $to_date;
			$grph_status = $data_status;
		} else {
             //echo"line 2";
			$current_mon_f_date = date("01-M-Y");
			$current_mon_f_date = strtoupper($current_mon_f_date);
            $current_mon_l_date = date("t-M-Y");
			$current_mon_l_date = strtoupper($current_mon_l_date);
            // $current_mon_f_date = date("01-M-y");
            // $current_mon_l_date = date("t-M-y");
			$grph_from_date     = $current_mon_f_date;
			$grph_to_date       = $current_mon_l_date;
			$grph_status        = 'P';
            $where_cond .= " STATUS IN ('P') AND DATA_READ_TYPE='$data_src' AND 
			LOG_DATE>=TO_DATE('$current_mon_f_date','DD-MON-RR') AND LOG_DATE<=TO_DATE('$current_mon_l_date','DD-MON-RR')";
        }
        // // Update the condition to filter only today and previous pending data
        // $where_cond .= " AND LOG_DATE <= $curr_date AND STATUS = 'P'";
		if($station!=""){
			$station = strtolower($station);
			$where_cond .= " AND LOWER(WELL_ID)='$station'";
		}
		$where_cond .=" ORDER BY WELL_ID ASC,LOG_DATE ASC";
        $row = $obj->View_all_data_row_column_By_Cond($table_name, ' * ', $where_cond);
        $sl = 0;
		$data_no = count($row);
        echo '<input type="hidden" id="data_count" value="'.$data_no.'"/>';
		echo '<input type="hidden" id="grph_ffwc_from_date" value="'.$grph_from_date.'"/>';
        echo '<input type="hidden" id="grph_ffwc_to_date" value="'.$grph_to_date.'"/>';
        echo '<input type="hidden" id="grph_ffwc_status" value="'.$grph_status.'"/>';
        foreach ($row as $index => $val) {
            $sl++;
			$duplicate_color = "";
            $old_id = strtoupper($val['WELL_ID']);
			$id = $val['ID'];
			$sms_id_list = $val['SMS_ID_LIST'];
			$log_date = $val['LOG_DATE'];
            $verified_log_date = $val['VERIFIED_LOG_DATE'];

			$show_vr_wl_hr6 = "";
            $show_vr_wl_hr9 = "";
            $show_vr_wl_hr12 = "";
            $show_vr_wl_hr15 = "";
            $show_vr_wl_hr18 = "";
            $show_vr_rainfall = "";
			
			$active_flag_wl_hr6 = "";
            $active_flag_wl_hr9 = "";
            $active_flag_wl_hr12 = "";
            $active_flag_wl_hr15 = "";
            $active_flag_wl_hr18 = "";
            $active_flag_rainfall = "";
		
            if($val['VERIFIED_HR6']!=""){
				$show_vr_wl_hr6 = number_format((float)$val['VERIFIED_HR6'], 2, '.', '');
				$active_flag_wl_hr6 = "disabled";
			}
			else{
				if($val['HR6']!=""){
					$show_vr_wl_hr6 = number_format((float)$val['HR6'], 2, '.', '');
				}
				else{
					$show_vr_wl_hr6 = $val['HR6'];
					$active_flag_wl_hr6 = "disabled";
				}
			}

            if($val['VERIFIED_HR9']!=""){
				$show_vr_wl_hr9 =  number_format((float)$val['VERIFIED_HR9'], 2, '.', '');
				$active_flag_wl_hr9 = "disabled";
			}
			else{
				if($val['HR9']!=""){
					$show_vr_wl_hr9 = number_format((float)$val['HR9'], 2, '.', '');
				}
				else{
					$show_vr_wl_hr9 = $val['HR9'];
					$active_flag_wl_hr9 = "disabled";
				}
			}

            if($val['VERIFIED_HR12']!=""){
				$show_vr_wl_hr12 = number_format((float)$val['VERIFIED_HR12'], 2, '.', '');
				$active_flag_wl_hr12 = "disabled";
			}
			else{
				if($val['HR12']!=""){
					$show_vr_wl_hr12 = number_format((float)$val['HR12'], 2, '.', '');
				}
				else{
					$show_vr_wl_hr12 = $val['HR12'];
					$active_flag_wl_hr12 = "disabled";
				}
			}

            if($val['VERIFIED_HR15']!=""){
				$show_vr_wl_hr15 = number_format((float)$val['VERIFIED_HR15'], 2, '.', '');
				$active_flag_wl_hr15 = "disabled";
			}
			else{
				if($val['HR15']!=""){
					$show_vr_wl_hr15 = number_format((float)$val['HR15'], 2, '.', '');
				}
				else{
					$show_vr_wl_hr15 = $val['HR15'];
					$active_flag_wl_hr15 = "disabled";
				}
			}

            if($val['VERIFIED_HR18']!=""){
				$show_vr_wl_hr18 = number_format((float)$val['VERIFIED_HR18'], 2, '.', '');
				$active_flag_wl_hr18 = "disabled";
			}
			else{
				if($val['HR18']!=""){
					$show_vr_wl_hr18 = number_format((float)$val['HR18'], 2, '.', '');
				}
				else{
					$show_vr_wl_hr18 = $val['HR18'];
					$active_flag_wl_hr18 = "disabled";
				}
			}

            if($val['VERIFIED_RAINFALL']!=""){
				$show_vr_rainfall = number_format((float)$val['VERIFIED_RAINFALL'], 2, '.', '');
				$active_flag_rainfall = "disabled";
			}
			else{
				if($val['RAINFALL']!=""){
					$show_vr_rainfall = number_format((float)$val['RAINFALL'], 2, '.', '');
				}
				else{
					$show_vr_rainfall = $val['RAINFALL'];
					$active_flag_rainfall = "disabled";
				}
			}

			$show_status = "";
			$is_disable = "";
            if($val['STATUS']=='P' || $val['STATUS']=='PA'){
				$show_status = '<span class="label label-warning" style="padding: 5px;">Pending</span>';
				$show_vr_wl_hr6 = '<input type="text" class="vwl_hr6" id="vwl_hr6_'.$sl.'" style="width: 50px;" value="'.$show_vr_wl_hr6.'" '.$active_flag_wl_hr6.' onchange="check_limit(this.value,\''.$val['WELL_ID'].'\',\'vwl_hr6_'.$sl.'\')">';
				$show_vr_wl_hr9 = '<input type="text" class="vwl_hr9" id="vwl_hr9_'.$sl.'" style="width: 50px;" value="'.$show_vr_wl_hr9.'" '.$active_flag_wl_hr9.' onchange="check_limit(this.value,\''.$val['WELL_ID'].'\',\'vwl_hr9_'.$sl.'\')">';
				$show_vr_wl_hr12 = '<input type="text" class="vwl_hr12" id="vwl_hr12_'.$sl.'" style="width: 50px;" value="'.$show_vr_wl_hr12.'" '.$active_flag_wl_hr12.' onchange="check_limit(this.value,\''.$val['WELL_ID'].'\',\'vwl_hr12_'.$sl.'\')">';
				$show_vr_wl_hr15 = '<input type="text" class="vwl_hr15" id="vwl_hr15_'.$sl.'" style="width: 50px;" value="'.$show_vr_wl_hr15.'" '.$active_flag_wl_hr15.' onchange="check_limit(this.value,\''.$val['WELL_ID'].'\',\'vwl_hr15_'.$sl.'\')">';
				$show_vr_wl_hr18 = '<input type="text" class="vwl_hr18" id="vwl_hr18_'.$sl.'" style="width: 50px;" value="'.$show_vr_wl_hr18.'" '.$active_flag_wl_hr18.' onchange="check_limit(this.value,\''.$val['WELL_ID'].'\',\'vwl_hr18_'.$sl.'\')">';
				$show_vr_rainfall = '<input type="text" class="vwl_rf" id="vwl_rf_'.$sl.'" style="width: 50px;" value="'.$show_vr_rainfall.'" '.$active_flag_rainfall.' onchange="check_rf_limit(this.value,\''.$val['WELL_ID'].'\',\'vwl_rf_'.$sl.'\')">';
				$verified_log_date_picker = '<input class="v_date" id="v_date_'.$sl.'" type="text" value="'.$log_date.'" style="width: 70%;" onchange="handleDateChange(this.value,\''.$sl.'\',\''.$log_date.'\')" />';
			}
            else if($val['STATUS']=='VR'){
				$show_status = '<span class="label label-info" style="padding: 5px;">Varified</span>';
				$show_vr_wl_hr6 = "<input type='text' class='vwl_hr6' id='vwl_hr6_$sl' style='width: 50px;' value='$show_vr_wl_hr6' $active_flag_wl_hr6>";
				$show_vr_wl_hr9 = "<input type='text' class='vwl_hr9' id='vwl_hr9_$sl' style='width: 50px;' value='$show_vr_wl_hr9' $active_flag_wl_hr9>";
				$show_vr_wl_hr12 = "<input type='text' class='vwl_hr12' id='vwl_hr12_$sl' style='width: 50px;' value='$show_vr_wl_hr12' $active_flag_wl_hr12>";
				$show_vr_wl_hr15 = "<input type='text' class='vwl_hr15' id='vwl_hr15_$sl' style='width: 50px;' value='$show_vr_wl_hr15' $active_flag_wl_hr15>";
				$show_vr_wl_hr18 = "<input type='text' class='vwl_hr18' id='vwl_hr18_$sl' style='width: 50px;' value='$show_vr_wl_hr18' $active_flag_wl_hr18>";
				$show_vr_rainfall = "<input type='text' class='vwl_rf' id='vwl_rf_$sl' style='width: 50px;' value='$show_vr_rainfall' $active_flag_wl_rainfall>";
				$verified_log_date_picker = '<input class="v_date" id="v_date_'.$sl.'" type="text" value="'.$verified_log_date.'" style="width: 70%;" onchange="handleDateChange(this.value,\''.$sl.'\',\''.$verified_log_date.'\')" />';
			}
			else if($val['STATUS']=='A'){
				$show_status = '<span class="label label-success" style="padding: 5px;">Approved</span>';
				$show_vr_wl_hr6 = "<input type='hidden' class='vwl_hr6' id='vwl_hr6_$sl' style='width: 50px;' value='$show_vr_wl_hr6'>$show_vr_wl_hr6";
				$show_vr_wl_hr9 = "<input type='hidden' class='vwl_hr9' id='vwl_hr9_$sl' style='width: 50px;' value='$show_vr_wl_hr9'>$show_vr_wl_hr9";
                $show_vr_wl_hr12 = "<input type='hidden' class='vwl_hr12' id='vwl_hr12_$sl' style='width: 50px;' value='$show_vr_wl_hr12'>$show_vr_wl_hr12";
				$show_vr_wl_hr15 = "<input type='hidden' class='vwl_hr15' id='vwl_hr15_$sl' style='width: 50px;' value='$show_vr_wl_hr15'>$show_vr_wl_hr15";
				$show_vr_wl_hr18 = "<input type='hidden' class='vwl_hr18' id='vwl_hr18_$sl' style='width: 50px;' value='$show_vr_wl_hr18'>$show_vr_wl_hr18";
				$show_vr_rainfall = "<input type='hidden' class='vwl_rf' id='vwl_rf_$sl' style='width: 50px;' value='$show_vr_rainfall'>$show_vr_rainfall";
				$verified_log_date_picker = "<input class='v_date' id='v_date_$sl' type='hidden' value='$verified_log_date'>$verified_log_date";
				$is_disable = "disabled";				
			}
			else{
				$show_status = '<span class="label" style="padding: 5px; background-color: #e62e00 !important;">Rejected</span>';
				$show_vr_wl_hr6 = "<input type='hidden' class='vwl_hr6' id='vwl_hr6_$sl' style='width: 50px;' value='$show_vr_wl_hr6'>$show_vr_wl_hr6";
				$show_vr_wl_hr9 = "<input type='hidden' class='vwl_hr9' id='vwl_hr9_$sl' style='width: 50px;' value='$show_vr_wl_hr9'>$show_vr_wl_hr9";
                $show_vr_wl_hr12 = "<input type='hidden' class='vwl_hr12' id='vwl_hr12_$sl' style='width: 50px;' value='$show_vr_wl_hr12'>$show_vr_wl_hr12";
				$show_vr_wl_hr15 = "<input type='hidden' class='vwl_hr15' id='vwl_hr15_$sl' style='width: 50px;' value='$show_vr_wl_hr15'>$show_vr_wl_hr15";
				$show_vr_wl_hr18 = "<input type='hidden' class='vwl_hr18' id='vwl_hr18_$sl' style='width: 50px;' value='$show_vr_wl_hr18'>$show_vr_wl_hr18";
				$show_vr_rainfall = "<input type='hidden' class='vwl_rf' id='vwl_rf_$sl' style='width: 50px;' value='$show_vr_rainfall'>$show_vr_rainfall";
				$verified_log_date_picker = "<input class='v_date' id='v_date_$sl' type='hidden' value='$verified_log_date'>$verified_log_date";
				$is_disable = "disabled";	
			}
        echo "<tr>";
      
        ?>

        <td>
            <input type="checkbox" class="data_chk_box" style="position: relative; opacity: 1;" id="data_chk_box_<?php echo $sl; ?>" value="0"   <?php echo $is_disable; ?> />
            <input type="hidden" class="row_id_holder" id="row_id_holder_<?php echo $sl; ?>" value="<?php echo $id; ?>"/>
            <input type="hidden" class="status_holder" id="status_holder_<?php echo $sl; ?>" value="<?php echo $val['STATUS']; ?>"/>
        </td>
         <td style="text-align: center;"><?php echo $sl; ?></td>
       <!--  <td style="text-align: center;"><?php echo $off_stat_map_info['MOBILE_NUMBER']; ?></td>
         <td style="text-align: center;"><?php echo $data['OLD_ID']; ?></td>-->
         <td style="text-align: center;">
		 <input type="hidden" class="well_id" id="well_id_<?php echo $sl; ?>" value="<?php echo $val['WELL_ID'] ?>"/>
		 <?php echo $val['WELL_ID']; ?></td>
         <td style="text-align: center;"><?php echo $val['LOG_DATE']; ?></td>
         <td style="text-align: center;"><?php echo $verified_log_date_picker; ?></td>
         <td style="text-align: center;"><?php echo $val['HR6']; ?></td>
         <td style="text-align: center;"><?php echo $show_vr_wl_hr6; ?></td>
         <td style="text-align: center;"><?php echo $val['HR9']; ?></td>
         <td style="text-align: center;"><?php echo $show_vr_wl_hr9; ?></td>
         <td style="text-align: center;"><?php echo $val['HR12']; ?></td>
         <td style="text-align: center;"><?php echo $show_vr_wl_hr12; ?></td>
         <td style="text-align: center;"><?php echo $val['HR15']; ?></td>
         <td style="text-align: center;"><?php echo $show_vr_wl_hr15; ?></td>
         <td style="text-align: center;"><?php echo $val['HR18']; ?></td>
         <td style="text-align: center;"><?php echo $show_vr_wl_hr18; ?></td>
         <td style="text-align: center;"><?php echo $val['RAINFALL']; ?></td>
         <td style="text-align: center;"><?php echo $show_vr_rainfall; ?></td>
         <td style="text-align: center;"><?php echo $show_status; ?></td>

        <td style="text-align: center;">
            <button class="btn btn-mini btn-info" type="button" href="#modal_show_raw_data_ffwc" data-toggle="modal" style="margin-left: -2px; width: 86px;" onclick="show_raw_data_ffwc(<?php echo $id; ?>)"><i class="fa fa-eye"></i> View</button><br/>
			<div class="btn-group" style="margin-top: 1px;">
            	<button  data-toggle="dropdown" class="btn btn-purple btn-small dropdown-toggle" type="button">
					<i class="icon-bar-chart align-top bigger-100 icon-on-right"></i> Graph
					<i class="icon-angle-down icon-on-right"></i>
				</button>
				<ul class="dropdown-menu dropdown-purple dropdown-menu-right">
					<li style="text-align: left !important;"><a href="#modal_show_graph_wl_data_ffwc" data-toggle="modal" onclick="load_ffwc_wl_graph(<?php echo $sl; ?>)">Water Level</a></li>
					<li style="text-align: left !important;"><a href="#modal_show_graph_rf_data_ffwc" data-toggle="modal" onclick="load_ffwc_rf_graph(<?php echo $sl; ?>)">Rainfall</a></li>
				</ul>
          
			</div>

		  <!--<button class="btn btn-mini btn-purple" type="button" href="#modal_show_graph_data_ffwc" data-toggle="modal" style="margin-left: 10px; width: 65px; margin-top: 5px;" onclick="show_graph_ffwc(<?php echo $sl; ?>)"><i class="fa fa-eye"></i> Graph</button>-->
        <?php if ($_SESSION['edit']=='Y') {
					if($val['STATUS']=='P'){
						// echo '<button class="btn btn-mini btn-success" type="button" href="#modal_edit_data_log" data-toggle="modal" style="margin-left: 10px; background-color: #00b33c !important; border-color: #00b33c !important;" onclick="load_edit_form(' . $id . ')"><i class="icon-edit"></i> Verify </button>';
						//echo '<button class="btn btn-mini btn-success" type="button" style="margin-left: 10px;" onclick="approve_log_data(' . $id . ')"><i class="icon-check"></i> Approve </button>';
						//echo '<button class="btn btn-mini btn-danger" type="button" style="margin-left: 10px;" onclick="reject_log_data(' . $id . ')"><i class="icon-remove"></i> Reject </button>';
					}
                }
                // if ($_SESSION['delete'] == 'Y') {}
                ?>
            </td>
            
        <?php
            echo " </tr>";
        }
        ?>
    </tbody>
</table>
    </div>
	
<script>
    function select_all_data() {
        if(jQuery('#btn_save_all_data').prop("checked")) {
            jQuery('input[type=checkbox]').each(function() {
            !jQuery('#'+this.id).is(':disabled') && jQuery('#'+this.id).prop('checked', true);
        });
        } else {
            jQuery('input[type=checkbox]').each(function() {
				jQuery('#'+this.id).prop('checked', false);
			});
        } 
    }
</script>

<script type="text/javascript">
	$('.date-picker').datepicker().next().on(ace.click_event, function(){
	 $(this).prev().focus();
	
	});
	$(".date-picker").attr("autocomplete", "off");
</script>
<script>
function check_limit(sel_val,sel_stat_id,sel_col_id){
	var operation = "check_wl_limit";
	var datastr = "sel_stat_id="+sel_stat_id+"&operation="+operation;
	//alert(datastr);
	
//	$('#cover-spin').show(0);
	$.ajax({
		type:"get",
		url:"module/mobiledatalog/get_station_wise_data_range.php",
		data:datastr,
		success:function(st){
		//	$('#cover-spin').hide();
		//	alert(st);
			var data_range = st.split("#");
			var high_wl = data_range[0];
			var low_wl = data_range[1];

			if(parseFloat(high_wl)<parseFloat(sel_val)){
				alert("Given Water Level "+sel_val+" is bigger than Recorded Highest Water Level "+high_wl);
				$("#"+sel_col_id).focus();
			}
			else if(parseFloat(low_wl)>parseFloat(sel_val)){
				alert("Given Water Level "+sel_val+" is lower than QC Mean Water Level "+low_wl);
				$("#"+sel_col_id).focus();
			}
			else{
				$("#"+sel_col_id).focus();
			}
		}
	});
}

function check_rf_limit(sel_val,sel_stat_id,sel_col_id){
	var operation = "check_rf_limit";
	var datastr = "sel_stat_id="+sel_stat_id+"&operation="+operation;
	//alert(datastr);
	
//	$('#cover-spin').show(0);
	$.ajax({
		type:"get",
		url:"module/mobiledatalog/get_station_wise_data_range.php",
		data:datastr,
		success:function(st){
		//	$('#cover-spin').hide();
		//	alert(st);
			var data_range = st.split("#");
			var high_rf = data_range[0];
			var low_rf = data_range[1];

			if(parseFloat(high_rf)<parseFloat(sel_val)){
				alert("Given Rainfall "+sel_val+" is bigger than QC High Rainfall "+high_rf);
				$("#"+sel_col_id).focus();
			}
			else if(parseFloat(low_rf)>parseFloat(sel_val)){
				alert("Given Rainfall "+sel_val+" is lower than QC Low Rainfall "+low_rf);
				$("#"+sel_col_id).focus();
			}
			else{
				$("#"+sel_col_id).focus();
			}
		}
	});
}

</script>
<script>
    
function handleDateChange(inputElement,row_num,old_date_val) {
    var data_count = $("#data_count").val();
        var date = $("#v_date_"+row_num+"").val();
        var operation = "date_change";
        if(date != ""){
        var datastr = "date="+date+"&operation="+operation; 
            $.ajax({
            url: 'module/mobiledatalog/hourly_water_level_log_ajax.php', 
            type: 'post',
            data: datastr,
            cache: false,
            success: function(result) {
            //    alert(result);
                if(result== 0){
                alert('You only enter data till today');
                $("#v_date_"+row_num+"").val(old_date_val);
                $("#v_date_"+row_num+"").select();
                return false;
                }
                else{
                $("#v_date_"+row_num+"").val(result);
                $("#v_date_"+row_num+"").select();
                }   
            }
            });
        }
   // } 

}

</script>
<style>
    .box-from {
        padding: 0 0 2% 0;
        background: #ffffff;
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;
    }

    .box-from h3 {
        margin: 0 2% 0 1%;
    }

    .box-from .form-control {
        max-width: 18%;
        margin: 0.5% 0 0 0;
        font-weight: bold;
    }

    .datepicker {
        font-family: 'Exo 2', sans-serif;
    }

    .datepicker--cell.-range-to- {
        background: rgba(248, 266, 236, 0.4);
        border-color: rgba(248, 266, 236, 1);
    }


    .datepicker--cell.-selected-,
    .datepicker--cell.-selected-.-focus- {
        background-color: #f8ceec;
        color: #000000;
    }

    .datepicker--cell.-in-range- {
        background: rgba(248, 266, 236, 0.2);
    }

    .datepicker--cell-day {
        font-weight: 500;
        color: #000000;
    }

    .form-control {
        height: 50px;
        font-size: 16px;
        font-weight: bold;
        color: #414D64;
        background: #ffffff;
        padding: 0 15px;
        border: 2px solid #DADEEA;
        -webkit-border-radius: 5px;
        -moz-border-radius: 5px;
        border-radius: 5px;
        -webkit-transition: all 0.3s ease-in-out;
        -moz-transition: all 0.3s ease-in-out;
        -o-transition: all 0.3s ease-in-out;
        transition: all 0.3s ease-in-out;
        text-align: center;
    }

    textarea.form-control {
        height: 126px;
    }

    .form-control-plaintext {
        font-size: 18px;
        color: #434343;
    }

    button.form-control {
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .form-control:focus {
        border-color: #37B448;
        -webkit-box-shadow: 0px 2px 6px rgba(55, 180, 72, .15);
        -moz-box-shadow: 0px 2px 6px rgba(55, 180, 72, .15);
        box-shadow: 0px 2px 6px rgba(55, 180, 72, .15);
    }
</style>

<style>
    .box-to {
        padding: 0 0 2% 0;
        background: #ffffff;
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;
    }

    .box-to h3 {
        margin: 0 2% 0 1%;
    }

    .box-to .form-control {
        max-width: 18%;
        margin: 0.5% 0 0 0;
        font-weight: bold;
    }

    .datepicker {
        font-family: 'Exo 2', sans-serif;
    }

    .datepicker--cell.-range-to- {
        background: rgba(248, 266, 236, 0.4);
        border-color: rgba(248, 266, 236, 1);
    }


    .datepicker--cell.-selected-,
    .datepicker--cell.-selected-.-focus- {
        background-color: #f8ceec;
        color: #000000;
    }

    .datepicker--cell.-in-range- {
        background: rgba(248, 266, 236, 0.2);
    }

    .datepicker--cell-day {
        font-weight: 500;
        color: #000000;
    }

    .form-control {
        height: 50px;
        font-size: 16px;
        color: #414D64;
        background: #ffffff;
        padding: 0 15px;
        border: 2px solid #DADEEA;
        -webkit-border-radius: 5px;
        -moz-border-radius: 5px;
        border-radius: 5px;
        -webkit-transition: all 0.3s ease-in-out;
        -moz-transition: all 0.3s ease-in-out;
        -o-transition: all 0.3s ease-in-out;
        transition: all 0.3s ease-in-out;
        text-align: center;
    }

    textarea.form-control {
        height: 126px;
    }

    .form-control-plaintext {
        font-size: 18px;
        color: #434343;
    }

    button.form-control {
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .form-control:focus {
        border-color: #37B448;
        -webkit-box-shadow: 0px 2px 6px rgba(55, 180, 72, .15);
        -moz-box-shadow: 0px 2px 6px rgba(55, 180, 72, .15);
        box-shadow: 0px 2px 6px rgba(55, 180, 72, .15);
    }
</style>

