<style>
em{color:red;font-size: 20px;position: absolute;}
</style>
<div class="hide_search_div">
<button type="button" id="add_post_out" class="btn btn-primary hide_show" style="margin:0 0 5px 10px;" >Add Timesheet</button>
	<div class="panel box box-primary <?=$collapse_add_area;?>" id="post_out_area">
		<div class="box-header with-border">
			<form action="" method="post" name="add_form" id="add_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","","required"); ?>
				</div>
				<div class="col-sm-3">	
					<label for="Organisation" class="control-label">Organisation<em>*</em></label>
					<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2 job_id","required"); ?> 
					
					<label for="Consultant" class="control-label">Consultant</label>
					<div id="admin_id_div">
						<? 
							$admin_ids = "";
							$sql_for_admin = "SELECT * FROM job_admin_mapping WHERE job_id = $job_id";
							$rs_for_admin = mysqli_query($conn,$sql_for_admin);
							if(mysqli_num_rows($rs_for_admin) > 0){
								while($row_for_admin = mysqli_fetch_assoc($rs_for_admin)){
									$admin_ids .= $row_for_admin["admin_id"].",";
								}
								$admin_ids = substr($admin_ids,0,-1);
							}
							Admin::getAdminList("admin_id",$admin_id,"100%",true,"form-control","required",$admin_ids); 
						?>
					</div>
				</div>
				<div class="col-sm-3">
					<label for="From Time" class="control-label">From Time</label>
					<div class="bootstrap-timepicker">
						<!--<input type="text" class="form-control timepicker" id="from_time" name="from_time" value="<?php //echo $from_time;?>">-->
						<? utility::getTimeList("from_time", $from_time, "From Time", "100%");?>
					</div>
					
					<label for="To Time" class="control-label">To Time</label>
					<div class="bootstrap-timepicker">
						<!--<input type="text" class="form-control timepicker" id="to_time" name="to_time" value="<?php //echo $to_time;?>">-->
						<? utility::getTimeList("to_time", $to_time, "To Time", "100%");?>
					</div>
				</div>
				<div class="col-sm-3">
					<label for="Timesheet" 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">
						<!--<input type="text" class="form-control timepicker" id="timesheet_time" name="timesheet_time" value="<?php //echo $timesheet_time;?>">-->
						<? utility::getTimeList("timesheet_time", $timesheet_time, "Time", "100%");?>
					</div>
				</div>
				<div style="clear:both;"></div>
				<div class="col-sm-3">
				<div style="clear:both;margin-top:23px;"></div>
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					<input type="hidden" id="hidden_admin_id" name="hidden_admin_id" value="">
					<input type="hidden" id="page_action" name="page_action" value="<?php echo $page_action;?>">
					<button type="submit" name="add_master_data" id="submit_form"  class="btn btn-primary"><?=$button_value?></button>
					<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div_for_post_out"></i>
					<i class="fa fa-check" id="post_out_notes_done" style="color:#bad23a;font-size: 20px;display:none;"></i>
					<button data-toggle="collapse" data-target="#post_out_area" type="button" name="" class="btn btn-primary cancel_btn">Cancel</button>
				</div>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
$(function(){
	<? 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);
	});
	<? } ?>
	
	$("#admin_id").change(function(){	
		if($("#job_id").val() == ""){
			alert("First select Client");
			$(this).val("");
			return false;
		}
	});
	function getAdmin(job_id,hidden_admin_id){
		var form_data   = {'job_id':job_id,'admin_id':hidden_admin_id};       
		$.ajax({
			async: false,
			type: "POST",
			url: site_url+"/modules/notes/index.php?page=ajax_actions&action=get_admin_by_job",
			data: form_data,
			success: function(result){  
				if(result){
					$("#admin_id_div").html(result);
				}else{
					alert("No consultant assign to this client. First assign consultant.");
					$("#admin_id_div").html(result);
				}
			}
		});
	}
	$("#job_id").change(function(){	
		<? //if(!(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit_post_out')){ ?>
		var job_id = $(this).val();
		var hidden_admin_id = $("#hidden_admin_id").val();
		if(job_id != ""){
			setTimeout(function(){
				getAdmin(job_id,hidden_admin_id);
			},1000);
		}
		<? //} ?>
	});
	$("#submit_form").click(function(){	
		if($("#span").text() == "No consultant assign to this client. First assign consultant."){
			alert("First select Consultant");
			return false;
		}
	});
	/* $("#job_id").change(function(){	
		var job_id = $(this).val();
		if(job_id != ""){
		var form_data   = {'job_id':job_id};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/enquiry_management/index.php?page=ajax_actions&action=get_project_by_client_id",
				data: form_data,
				success: function(result){  
					if(result){
						$("#project_div_search").html(result);
					}else{
						alert("No project added to this client. First add project.");
						$("#project_div_search").html(result);
					}
				}
			});
		}
	}); */
	$('.hide_show').click(function(){
		$('.hide_show').hide();
		$('.cancel_btn').show();
		//$('#search_list').hide();
		//$('#listing').hide();
	});
	$('.cancel_btn').click(function(){
		$('#post_out_area').hide();
		$('.hide_show').show();
		//$('#search_list').show();
		//$('#listing').show();
	});
});
</script>