<div class="hide_search_div">
<button type="button" id="add_timesheet_for_clients" class="btn btn-primary" style="margin:0 0 5px 10px;">Add Timesheet</button>
<div class="panel box box-primary <?=$collapse_add_area;?>" id="timesheet_for_clients_area">
  <div class="box-header" >
	<form action="" method="post" name="add_timesheet_for_clients_form" id="add_timesheet_for_clients_form">
		<div class="col-sm-3">
			<label for="Timesheet Text" class="control-label">Description</label>
			<textarea class="form-control" rows="4" id="timesheet_text" name="timesheet_text" required><?php echo stripslashes($timesheet_text);?></textarea>
			
			<label for="Timesheet Option" class="control-label">Timesheet Option</label>
			<? echo Keycode::getKeycodeListValue("timesheet_option", $timesheet_option, $width = "100%", "Timesheet Option", "id", "code", "timesheet_option","","form-control select2","true","required"); ?>
		</div>
		<div class="col-sm-3">
			<label for="From Time" class="control-label">From Time</label>
			<div class="bootstrap-timepicker">
				<? utility::getTimeList("from_time", $from_time, "From Time", "100%");?>
			</div>
			
			<label for="To Time" class="control-label">To Time</label>
			<div class="bootstrap-timepicker">
				<? utility::getTimeList("to_time", $to_time, "To Time", "100%");?>
			</div>
			
			<? if(isset($view_timesheet_for_admin)){ ?>
				<label for="Organisation" class="control-label">Organisation</label>
				<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2 job_id","required",$source); ?>
			<? }else {?>
				<input type="hidden" id="job_id" name="job_id" value="<?php echo $job_id;?>">
			<? }?>
		</div>
		<div class="col-sm-3">
			<label for="Timesheet Date" class="control-label">Date</label>
			<input type="text" class="form-control datepicker" id="timesheet_date" name="timesheet_date" value="<?php (isset($timesheet_date) && $timesheet_date !="") ? utility::getFormatedDate($timesheet_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
			
			<label for="Timesheet Time" class="control-label">Time</label>
			<div class="bootstrap-timepicker">
				<? utility::getTimeList("timesheet_time", $timesheet_time, "Time", "100%");?>
			</div>
		</div>
		<div class="col-sm-3">
			<label for="Consultant" class="control-label">Consultant</label>
			<? 
				Admin::getAdminList("t_admin_id",$t_admin_id,"100%",true,"form-control","required");
			?>
		</div>
		<div class="col-sm-3">
			<div style="clear:both;margin-top:23px;"></div>
			<input type="hidden" id="timesheet_id" name="timesheet_id" value="<?php echo $timesheet_id;?>">
			<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
			<input type="hidden" id="page_action_timesheet" name="page_action_timesheet" value="<?php echo $page_action_timesheet;?>">
			<input type="hidden" id="source" name="source" value="<?php echo $source;?>">
			<button type="submit" name="add_master_data" id="submit_form_timesheet" class="btn btn-primary"><?=$button_value_timesheet;?>
			</button>
			<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div_for_timesheet_for_clients"></i>
			<i class="fa fa-check" id="timesheet_for_clients_done" style="color:#bad23a;font-size: 20px;display:none;"></i>
		</div>
	</form>
  </div>
</div>
</div>
<script type="text/javascript">		
$(function(){
	$("#add_timesheet_for_clients_form").click(function(){	
		if($("#span").text() == "No consultant assign to this job. First assign consultant."){
			alert("First select Consultant");
			return false;
		}
	});
	$('#add_timesheet_for_clients_form').submit(function(){
		$("#add_master_data").attr("disabled", true);
		$('#page_load_div').show();
	});
	<? if(!(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit')){ ?>
	$("#timesheet_option").change(function(){
		var timesheet_option_text = $("#timesheet_option option:selected").text();
		var timesheet_text = $("#timesheet_text").val();
		$("#timesheet_text").val(timesheet_option_text+"\n"+timesheet_text);
	});
	<? } ?>
	/* $("#timesheet_time").focus(function(){
		var from_time = $("#from_time").val();
		var to_time = $("#to_time").val();
		if(from_time != "" && to_time != ""){
			var form_data   = {'from_time':from_time,'to_time':to_time};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/timesheet_management/index.php?page=ajax_actions&action=calculate_time",
				data: form_data,
				success: function(result){  
					var resultObj = jQuery.parseJSON(result); 
					$('#timesheet_time').val(resultObj.calculate_time);
				}
			});
		}
	}); */
	$("#from_time,#to_time").change(function(){
		var from_time = $("#from_time").val();
		var to_time = $("#to_time").val();		
		if(!((from_time == "00:00" || from_time == "00:00:00") && (to_time == "00:00" || to_time == "00:00:00"))){
			var form_data   = {'from_time':from_time,'to_time':to_time};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/timesheet_management/index.php?page=ajax_actions&action=calculate_time",
				data: form_data,
				success: function(result){  
					var resultObj = jQuery.parseJSON(result); 
					$('#timesheet_time').val(resultObj.calculate_time);
				}
			});
		}
	});
});
</script>