<?php
$submit_url = $file_name."?page=view_appointment_for_admin&action=$action"; 
$status_submit_url = $file_name."?page=view_appointment_for_admin&name=$name";

$search_url = $file_name."?page=view_appointment_for_admin"; 
$show_all = "page=view_appointment_for_admin";  

?>
<style>
label {
    margin-top: 5px;
}
.hideshowonmob_btn{
	display:none;
	margin-bottom: 5px;
}
.hideshowonmob_hide_btn{
	display:none;
	margin-bottom: 5px;
}
.hideshowonmob_btn_2{
	display:none;
	margin-bottom: 15px;
	text-decoration: underline;
    cursor: pointer;
    font-size: 15px;
}
.hideshowonmob_hide_btn_2{
	display:none;
	margin-bottom: 15px;
    text-decoration: underline;
    cursor: pointer;
    font-size: 15px;
}

select.form-control[multiple], select.form-control[size]{
	height: 115px !important;
}

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

@media only screen and (max-width: 640px){
	.hideshowonmob{
		display:none;
	}
	.hideshowonmob_btn{
		display:block;
	}
	.hideshowonmob_2{
		/* display:none; */
	}
	.hideshowonmob_btn_2{
		/* display:block; */
	}
	.document_delete_list{
		font-size:18px;
	}
}
</style>
 <?if(isset($_SESSION['is_consultant']) && $_SESSION['is_consultant'] !=""){?>
 
 <?}else{?>
	<button data-toggle="collapse" data-target="#booke_appointment_area" type="button" name="" class="btn btn-primary hide_show <?=$add_task_btn_hide;?>" style="margin:0 0 5px 10px;float:left;clear:right;">Add Appointment</button>
<?}?>


<div style="clear:both;"></div>
<div class="panel box box-primary <?=$collapse_booke_appointment_area;?>" id="booke_appointment_area">
	<div class="box-header with-border">
		<div class="col-12">
		<form action="<?php echo $submit_url;?>" method="post" name="add_form" id="add_form">
			<div class="row">
			<div class="col-sm-3">
				<label for="Notes" class="control-label">Description</label>
				<textarea class="form-control" rows="4" id="appointment_text" name="appointment_text" required><?php echo stripslashes($appointment_text);?></textarea>
				
				<label for="Job" class="control-label">Contact</label>
				<? //$krscrm->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2","required"); ?>
				<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2 job_id","required",$source); ?>
				<?//if(!$mobiledetect->isMobile() && !$mobiledetect->isTablet()) {?>
					<!--<label for="Document" class="control-label">Document</label>
					<i class="fa fa-upload" style="font-size: 17px;cursor:pointer;" id="document"></i>
					<i style="display:block;color:red;">(pdf/doc/docx/xls/xlsx)</i><br>-->
				<?//}?>
				<!--<i class="fa fa-check pull-right" id="upload_complete" style="color:#bad23a;font-size: 20px;display:none;"></i>
				<i class="fa fa-refresh fa-spin pull-right" style="font-size: 20px;display:none;" id="page_load_div"></i>-->
				<? if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit'){ ?>
				<div style="overflow:hidden;" class="hide">
					<?
						$appointment_id = (isset($_REQUEST['id']) && $_REQUEST['id'] != "" && $_REQUEST['id'] != 0) ? $_REQUEST['id'] : "1111111111111111";
						$appointment_doc_admin = "";
						$sql_for_doc_admin = "SELECT * FROM documents WHERE appointment_id = '".$appointment_id."' ";
						$rs_for_doc_admin = mysqli_query($conn,$sql_for_doc_admin);
						if(mysqli_num_rows($rs_for_doc_admin) > 0){
							if($mobiledetect->isMobile() || $mobiledetect->isTablet()) {								
								?><label for="Document" class="control-label">Document</label><?
							}
							while($data_admin = mysqli_fetch_assoc($rs_for_doc_admin)){								
								$appointment_doc_admin .= "<p style='clear:both;width:100%;margin: 0;' title='".$data["document_name"]."' id='doc_div".$data_admin["id"]."'>".utility::ellipsis(strtoupper(strip_tags($data_admin["document_name"])),15)." <i class='fa fa-close pull-right document_delete_list' alt='".$data_admin["id"]."' style='margin-top:3px;color:#3C8DBC;cursor:pointer;'></i></p>";
							}
							$appointment_doc_admin = substr($appointment_doc_admin,0,-4);
						}
						echo $appointment_doc_admin;
					?>
				</div>
				<? } ?>
				<div id="document_div" class="hide">
					<?
						//unset($_SESSION['uploadfileArray']);
						if(isset($_SESSION['uploadfileArray'])){
							//print_r($_SESSION['uploadfileArray']);
							foreach($_SESSION['uploadfileArray'] as $key => $uploadfile){
								$doc_no = $key + 1;
								echo "<p id='document_p".$doc_no."'>".$uploadfile."<i class='fa fa-close pull-right document_delete' alt='".$uploadfile."' style='margin-top:3px;color:#3C8DBC;cursor:pointer;'></i></p>";
							}
						}
					?>
				</div><br/>
				<!--<div class="hide">
					<label for="Notes" class="control-label">Notes</label>
					<textarea class="form-control" rows="4" id="notes" name="notes"><?php echo stripslashes($notes);?></textarea>
				</div>
				<label for="Document" class="control-label">Image</label>
				<input type="file" id="fileinput" />
				<img id="source_image"  style="width:100%" class="hide" >
				<input type="button" id="compress" value="Compress" class="btn-primary" style="display: none;">
				<img id="compressed_image"  style="width:100%" class="hide" >
				<input type='text' id="orientation"  class="hide" >
				<input type="button" id="upload" class="btn-success" value="Upload" style="display: none;">
				<i style="display:block;color:red;">(doc type jpg/jpeg/png)</i><br>
				<i class="fa fa-check pull-right" id="upload_complete-123" style="color:#bad23a;font-size: 20px;display:none;"></i>
				<i class="fa fa-refresh fa-spin pull-right" style="font-size: 20px;display:none;" id="page_load_div-123"></i>-->
			</div>
			<?/* if($mobiledetect->isMobile()) {
				$class_hide = "hide";
			} */?>
			<div class="hideshowonmob_2 col-sm-6" style="">
			<div class="row" style="">
			
			<div class="col-sm-6">
				
				
				
				<label for="Staff Member" 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 select_admin_id","",$admin_ids); 
				?>
				</div>
				
				<label for="Appointment" class="control-label">Date <? if(!(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit')){ ?>From<? } ?></label>
				<input type="text" class="form-control datepicker" id="appointment_date" name="appointment_date" value="<?php (isset($appointment_date) && $appointment_date !="") ? utility::getFormatedDate($appointment_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
				
				<span id="description_of_job"><? echo $job_description_text = $krscrm->getDescripByJobId($job_id);?></span>
				
			</div>
			<div class="col-sm-6">
				<label for="Appointment Time" class="control-label">Time From</label>
				<div class="bootstrap-timepicker">
					<!--<input type="text" class="form-control timepicker" id="appointment_time" name="appointment_time" value="<?php //echo $appointment_time;?>" autocomplete="off">-->
					<? utility::getTimeList("appointment_time", $appointment_time, "Time From", "100%");?>
				</div>
				
				<label for="Appointment Time" class="control-label">Time To</label>
				<div class="bootstrap-timepicker">
					<!--<input type="text" class="form-control timepicker" id="appointment_time_to" name="appointment_time_to" value="<?php //echo $appointment_time_to;?>" autocomplete="off">-->
					<? 
					
					utility::getTimeList("appointment_time_to", $appointment_time_to, "Time To", "100%");?>
				</div>
				
				<? if(!(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit')){ ?>
					<label for="Appointment" class="control-label">Date To</label>
					<input type="text" class="form-control datepicker" id="appointment_date_to" name="appointment_date_to" value="<?php utility::getFormatedDate(date($config->dateFormat));?>" required>
				<? } ?>
				
				
				
			</div>
		
			</div>
			</div>
			<?
				/* if($mobiledetect->isMobile()) {
					$display_on_mobile = 'block';				
					$hide_on_mobile = 'none';				
				} */
			
			?>
			<div class="col-sm-3 hide">
			<a style="margin-left: 15px;" class="hideshowonmob_btn_2">Show Details</a>
			<a style="margin-left: 15px;" class="hideshowonmob_hide_btn_2">Hide Details</a>
			</div>
			
			
			<div class="col-sm-3 hide">
				<!--<label for="Location" class="control-label">Location</label>
				<input type="text" class="form-control" id="appointment_location" name="appointment_location" value="<?php //echo $appointment_location;?>">-->
				
				<!--<div style="width:80px;float:left;clear:right;border:0px solid;">
					<label for="Full Day" class="control-label">Full Day</label><br>
					<input class="flat-red" type="checkbox" id="is_full_day" name="is_full_day" <? //echo ($is_full_day) ? "checked" : ""; ?>>
				</div>-->
						
				<!--<label for="Addess" class="control-label">Address</label>
				<? 
					// $jobtypetext = utility::getTableFieldById("job","client_industry","id",$job_id);
					// $jobtypefeild = $krscrm->getkrsJobTypeById($jobtypetext);
					//echo $jobtypefeild;
					// $secondaddress_ap = utility::getTableFieldById("job","second_address","id",$job_id);
					
					// if($jobtypefeild == 'Domestic' or $secondaddress_ap == ''){
				?>
				<input type="text" class="form-control" id="addess" name="addess" value="<?php echo $addess;?>"><br />
				<?//}else{?>
				<input type="text" class="form-control" id="addess" name="addess" value="<?php echo $secondaddress_ap;?>"><br />-->
				<?//}?>
				<!--<input type="text" class="form-control" id="addess" name="addess" value="<?php //echo $addess;?>"><br/>-->
				
				<div style="display:<?=$quotation_area_hide;?>;">
					<!--<div class="form-group">
						<input class="flat-red" type="checkbox" id="attended" name="attended" <? echo ($attended) ? "checked" : ""; ?>>&nbsp;&nbsp;<b>Attended</b>
					</div>
					<div class="form-group">
						<input class="flat-red" type="checkbox" id="client_not_in" name="client_not_in" <? echo ($client_not_in) ? "checked" : ""; ?>>&nbsp;&nbsp;<b>Client not in</b>
					</div>
				
				
					<hr />
					<div class="form-group">
						<input type="checkbox" class="flat-red quotation_status" id="to_quote" name="to_quote" value="1"  <? echo ($to_quote ==1) ? 'checked':''; ?>>&nbsp;&nbsp;<b>To Quote</b>						
						<i class="fa fa-check pull-right" id="to_quote_check" style="color:#bad23a;font-size: 20px;display:none;"></i>
						<i class="fa fa-refresh fa-spin pull-right" style="font-size: 20px;display:none;" id="to_quote_refresh"></i>
					</div>
					<div class="form-group">
						<input type="checkbox" class="flat-red quotation_status" id="quoted" name="quoted" value="1"  <? echo ($quoted ==1) ? 'checked':''; ?>>&nbsp;&nbsp;<b>Quoted</b>						
						<i class="fa fa-check pull-right" id="quoted_check" style="color:#bad23a;font-size: 20px;display:none;"></i>
						<i class="fa fa-refresh fa-spin pull-right" style="font-size: 20px;display:none;" id="quoted_refresh"></i>
					</div>
					<div class="form-group">
						<input type="checkbox" class="flat-red quotation_status" id="quotation_accepted" name="quotation_accepted" value="1"  <? echo ($quotation_accepted ==1) ? 'checked':''; ?>>&nbsp;&nbsp;<b>Quotation Accepted</b>						
						<i class="fa fa-check pull-right" id="quotation_accepted_check" style="color:#bad23a;font-size: 20px;display:none;"></i>
						<i class="fa fa-refresh fa-spin pull-right" style="font-size: 20px;display:none;" id="quotation_accepted_refresh"></i>
					</div>
					<div class="form-group">
						<input type="checkbox" class="flat-red quotation_status" id="accepted_date_given" name="accepted_date_given" value="1"  <? echo ($accepted_date_given ==1) ? 'checked':''; ?>>&nbsp;&nbsp;<b>Accepted Date Given</b>
						<i class="fa fa-check pull-right" id="accepted_date_given_check" style="color:#bad23a;font-size: 20px;display:none;"></i>
						<i class="fa fa-refresh fa-spin pull-right" style="font-size: 20px;display:none;" id="accepted_date_given_refresh"></i>
					</div>
					<div class="form-group">	
						<input type="checkbox" class="flat-red quotation_status" id="quotation_declined" name="quotation_declined" value="1"  <? echo ($quotation_declined ==1) ? 'checked':''; ?>>&nbsp;&nbsp;<b>Quotation Declined</b>
						<i class="fa fa-check pull-right" id="quotation_declined_check" style="color:#bad23a;font-size: 20px;display:none;"></i>
						<i class="fa fa-refresh fa-spin pull-right" style="font-size: 20px;display:none;" id="quotation_declined_refresh"></i>
					</div>-->
				</div>
			</div>
			
			<?
				if($common_appointment_id >0 ){					
					$apply_needs_for_other = 0;
					$current_date = date('Y-m-d H:i:s');
					$sel_appoint = "SELECT * FROM appointment WHERE appointment_date >='".$current_date."' AND common_appointment_id='".$common_appointment_id."' AND id!='".$id."'  ";
					$sql_appoint = mysqli_query($conn,$sel_appoint);
					if(mysqli_num_rows($sql_appoint)){
						$apply_needs_for_other = 1;
					}
				}			
			?>
			<?
				if($apply_needs_for_other==1){?>
				<div class="col-sm-3">
					<label for="Apply to coming event" class="control-label">Apply to coming event &nbsp;&nbsp;</label>
					<input type="checkbox" class="flat-red" id="apply_to_coming_event" name="apply_to_coming_event" value="1" checked>
				</div>
				
			<?	}
			?>
			
			<?if($action == 'insert'){?>
			<div class="col-sm-3">
				<label for="Date of event" class="control-label">Frequency</label>				  
				<? $krscrm->getTypeOfAppointmentList("type_of_appointment",$type_of_appointment,"100%",false,"form-control select2","required"); ?>
				<?
				$fre_display = 'block';
				if($type_of_appointment==1){
					$fre_display = 'none';
				}?>
				
				<div class="form-group the_day_options" style="display:<?=$fre_display?>;margin-top:10px">
                  <div class="radio">
                    <label>
                      <input type="radio" name="dayOptions" id="optionsDay" value="day">
						Day	
					  </label>		
					  <label>		
					   <input type="radio" name="dayOptions" id="optionsThe" value="the">
						The
					  </label>
                  </div>
                </div>
				
				<div class="for_monthly " style="display:<?=$fre_display?>;margin-top:10px">
					
					<div class="form-group day_option">
						<label>Day of Month</label>
						<? $krscrm->getDayOfMonthList("day_of_month",$day_of_month,"100%",true,"form-control select2 day_of_month"); ?>
					</div>
					
					<div class="the_monthly_option">
						<div class="form-group">
							<label>Week</label>
							<? $krscrm->getWeekList("week_of_month",$week_of_month,"100%",true,"form-control select2 week_of_month"); ?>
						</div>
						
						<div class="form-group">
							<label>Day</label>
							<? $krscrm->getDayOfWeekList("frequency_checklist1",$frequency_checklist,"100%",true,"form-control select2 frequency_checklist1"); ?>
						</div>
					</div>
				</div>
				
				<div class="form-group occurrence" style="display:<?=$fre_display?>">
					<!--<label for="Date of event" class="control-label">Frequency</label>-->
					<div class="" style="padding-top:8px">
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="first_week" class="week_checkbox" name="frequency_checklist[]" value="1" <?php echo ($frequency_checklist=="1")?" checked='checked' ":"";?>/>&nbsp;Mon</div>
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="second_week" class="week_checkbox" name="frequency_checklist[]" value="2" <?php echo ($frequency_checklist=="2")?" checked='checked' ":"";?>/>&nbsp;Tue</div>
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="third_week" class="week_checkbox" name="frequency_checklist[]" value="3" <?php echo ($frequency_checklist=="3")?" checked='checked' ":"";?>/>&nbsp;Wed</div>
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="fourth_week" class="week_checkbox" name="frequency_checklist[]" value="4" <?php echo ($frequency_checklist=="4")?" checked='checked' ":"";?>/>&nbsp;Thu</div>
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="fifth_week" class="week_checkbox" name="frequency_checklist[]" value="5" <?php echo ($frequency_checklist=="5")?" checked='checked' ":"";?>/>&nbsp;Fri</div>
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="sixth_week" class="week_checkbox" name="frequency_checklist[]" value="6" <?php echo ($frequency_checklist=="6")?" checked='checked' ":"";?>/>&nbsp;Sat</div>
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="seventh_week" class="week_checkbox" name="frequency_checklist[]" value="7" <?php echo ($frequency_checklist=="7")?" checked='checked' ":"";?>/>&nbsp;Sun</div>
						<div style="margin-right:10px;float:left;"><input type="checkbox" id="every_week"  name="frequency_checklist[]" value="8" <?php echo ($frequency_checklist=="8")?" checked='checked' ":"";?>/>&nbsp;Every Day</div>
					</div>
				</div>
		
			</div>
			<?}?>
			
			<div style="clear:both;"></div>
			<div class="col-sm-3">
					<label for="Full Day" class="control-label">&nbsp;</label><br>
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
					<input type="hidden" id="source" name="source" value="<?php echo $source;?>">
					<button type="submit" name="add_master_data" id="submit_form" class="btn btn-primary"><?=$button_value?>
						<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div"></i>
					</button>
					<button data-toggle="collapse" data-target="#booke_appointment_area" type="button" name="" class="btn btn-primary <?=$collapse_booke_appointment_area;?> cancel_btn <?=$cancel_btn_hide;?>">Cancel</button>
			</div>
			</div>
		</form>
		</div>
	</div>
</div>

<div class="box-header" >
<div class="row" >
	<div class="hideshowonmob" style="margin: 15px 0;">
	<form action="<?php echo $search_url;?>" method="post" name="search_form" id="search_form">		
		<div class="card-body">
		<div class="row">
		<div class="col-sm-3">
			<label for="Job" class="control-label">Contact</label>
			<?// $krscrm->getEnqQuoteJobList("job_id_search",$job_id_search,"100%",false,"form-control select2"); ?>
			<? $gsi->getEnqQuoteJobList("job_id_search",$job_id_search,"100%",false,"form-control select2 job_id","",$source); ?>
		</div>
		<?//if(isset($_SESSION['is_consultant']) && $_SESSION['is_consultant'] !=""){?>
 
		<? if(!isset($_SESSION['is_consultant'])){?>
			<div class="col-sm-2">
				<label for="Consultant" class="control-label">Consultant</label>
				<? Admin::getAdminList("admin_id_search",$admin_id_search,"100%",false,"form-control"); ?>
			</div>
		<?}?>
		<div class="col-sm-2">
			<label for="From Appointment Date" class="control-label">From  Date</label>
			<input type="text" class="form-control datepicker" id="from_appointment_date" name="from_appointment_date" value="<?php (isset($from_appointment_date) && $from_appointment_date !="") ? utility::getFormatedDate($from_appointment_date) : "";?>">
		</div>
		<div class="col-sm-2">
			<label for="Appointment" class="control-label">To Date</label>
			<input type="text" class="form-control datepicker" id="to_appointment_date" name="to_appointment_date" value="<?php (isset($to_appointment_date) && $to_appointment_date !="") ? utility::getFormatedDate($to_appointment_date) : "";?>">
		</div>
		<!--<div class="col-sm-1">
			<label for="Full Day" class="control-label">Full Day</label><br>
			<input class="flat-red" type="checkbox" id="is_full_day" name="is_full_day" <? //echo ($is_full_day) ? "checked" : ""; ?>>
		</div>
		<div style="clear:both;"></div>-->
		<div class="col-sm-3">
			<div style="clear:both;margin-top:28px;"></div>			
			<button type="submit" name="search" class="btn btn-success">Search
				<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div_search"></i>
			</button>
			<button type="button" name="search" class="btn btn-info" onclick="javascript:window.location='?<?php echo $show_all ?>'">Show All</button>
		</div>
		</div>
		</div>
	</form>
	</div>
	<button type="button" id="" name="" value=""  style="margin-left: 15px;" class="btn btn-success hideshowonmob_btn">Show Filter</button>
	<button type="button" id="" name="" value=""  style="margin-left: 15px;" class="btn btn-warning hideshowonmob_hide_btn">Hide Filter</button>
</div>
</div>

<script type="text/javascript">
$(function(){
	$('#add_form').submit(function(){
		$("#add_master_data").attr("disabled", true);
		$('#page_load_div').show();
	});
	$('#search_form').submit(function(){
		$("#submit").attr("disabled", true);
		$('#page_load_div_search').show();
	});
	$("#add_form").on("click","#every_week",function(){
		if($("#every_week:checked").length == 1){
			$('.week_checkbox').prop( "checked", true );
		}else{
			$('.week_checkbox').prop( "checked", false );
		}
	});
	
	$("#add_form").on("change","#type_of_appointment",function(){
		var type_of_appointment = $(this).val();
		
		if(type_of_appointment == 3 || type_of_appointment == 2 ){
			if(type_of_appointment == 2){
				
				$('.the_day_options').show();
				//$('.for_monthly').show();
				$('.occurrence').hide();
			}else{
				$('.occurrence').show();
				$('.the_day_options').hide();
				$('.for_monthly').hide();
				
				$('input[name="dayOptions"]').prop('checked', false);
				$('.week_of_month').select2("val", "");
				$(".frequency_checklist1").select2("val", "");
			}
		}else{
			
			//$('#day_of_week').select2("val", "");
			$('.week_checkbox').prop( "checked", false );
			$('.occurrence').hide();
			$('.for_monthly').hide();
			$(".the_day_options").hide();
			
			$('input[name="dayOptions"]').prop('checked', false);
			$('.week_of_month').select2("val", "");
			$(".frequency_checklist1").select2("val", "");
		}
	});
		
	$("#add_form").on("click", "#optionsDay,#optionsThe",function() {
		$('.for_monthly').show();
		if($(this).val()=='day'){			
			$(".day_option").show();
			$(".the_monthly_option").hide();
			$('.week_of_month').select2("val", "");
			$(".frequency_checklist1").select2("val", "");
		}else{			
			$('.day_of_month').select2("val", "");
			$(".day_option").hide();
			$(".the_monthly_option").show();
		}
	});
	$(".hideshowonmob_btn").on("click",function() {
		$(".hideshowonmob").show('slow');
		$(".hideshowonmob_hide_btn").show();
		$(".hideshowonmob_btn").hide();
	});
	
	$(".hideshowonmob_hide_btn").on("click",function() {
		$(".hideshowonmob").hide('slow');
		$(".hideshowonmob_hide_btn").hide();
		$(".hideshowonmob_btn").show();
	});
	
	<? if($_REQUEST['action'] == 'edit' ){ ?>
	if(window.matchMedia("(max-width: 640px)").matches){
		$(".hideshowonmob_2").hide('slow');
		$(".hideshowonmob_hide_btn_2").hide();
		$(".hideshowonmob_btn_2").show();
		
		$(".hideshowonmob_btn_2").on("click",function() {
			$(".hideshowonmob_2").show('slow');
			$(".hideshowonmob_hide_btn_2").show();
			$(".hideshowonmob_btn_2").hide();
		});
		
		$(".hideshowonmob_hide_btn_2").on("click",function() {
			$(".hideshowonmob_2").hide('slow');
			$(".hideshowonmob_hide_btn_2").hide();
			$(".hideshowonmob_btn_2").show();
		});
	}
	<?}?>
	
	function getOrientation(file, callback) {
	  var reader = new FileReader();

	  reader.onload = function(event) {
		var view = new DataView(event.target.result);

		if (view.getUint16(0, false) != 0xFFD8) return callback(-2);

		var length = view.byteLength,
			offset = 2;

		while (offset < length) {
		  var marker = view.getUint16(offset, false);
		  offset += 2;

		  if (marker == 0xFFE1) {
			if (view.getUint32(offset += 2, false) != 0x45786966) {
			  return callback(-1);
			}
			var little = view.getUint16(offset += 6, false) == 0x4949;
			offset += view.getUint32(offset + 4, little);
			var tags = view.getUint16(offset, little);
			offset += 2;

			for (var i = 0; i < tags; i++)
			  if (view.getUint16(offset + (i * 12), little) == 0x0112)
				return callback(view.getUint16(offset + (i * 12) + 8, little));
		  }
		  else if ((marker & 0xFF00) != 0xFF00) break;
		  else offset += view.getUint16(offset, false);
		}
		return callback(-1);
	  };

	  reader.readAsArrayBuffer(file.slice(0, 64 * 1024));
	};
	
	var output_format = null;
	var file_name = null;
	function readFile(evt) {
		$("#page_load_div").show();
		$("#upload_complete").hide();
		var file = evt.target.files[0];
		getOrientation(file, function(orientation) {			
			$("#orientation").val(orientation);
			console.log("orientation : "+orientation);
		 });
		var reader = new FileReader();
	    reader.onload = function(event) {
			var i = document.getElementById("source_image");
			console.log(i);
	            i.src = event.target.result;
	            i.onload = function(){
	                
	                console.log("Image loaded");
	            }
	    };
		output_format = file.name.split(".").pop();
		file_name = file.name;
	    console.log("Filename:" + file.name);
	    console.log("Fileformat:" + output_format);
	    console.log("Filesize:" + (parseInt(file.size) / 1024) + " Kb");
	    console.log("Type:" + file.type);
	    reader.readAsDataURL(file);
		
		//$("#compress").show();
		setTimeout(function(){
			$("#compress").trigger('click');
		},2000);
		
	    return false;
	}
 // compress image
 	$( "#compress" ).click(function() {
        var source_image = document.getElementById("source_image");
        if (source_image.src == "") {
            alert("You must load an image first!");
            return false;
        }

        var quality = 30;
       	
        console.log("process start...");
        console.log("process start compress ...");
	    compressed_image.src = jic.compress(source_image,quality,output_format).src;
		//$("#upload").trigger('click');
		//$("#upload").show();
		$("#upload").trigger('click');
    	
	});
	// upload imange
	$( "#upload" ).click(function() {
        var compressed_image = document.getElementById("compressed_image");
        if (compressed_image.src == "") {
            alert("You must compress image first!");
            return false;
        }

	    var successCallback= function(response){
			var resultObj = jQuery.parseJSON(response);
		    $.each(resultObj.uploadfileArray, function(key,value) {
				
				id = key+1;
				$("<p id='document_p"+id+"'>"+value+"<i class='fa fa-close pull-right document_delete' alt='"+value+"' style='margin-top:3px;color:#3C8DBC;cursor:pointer;'></i></p>").appendTo("#document_div");
			});
			$("#page_load_div").hide();
			$("#upload_complete").show();
			setTimeout(function(){
				$("#upload_complete").hide();
			},2000);	
			console.log("image uploaded successfully! :)");
            console.log(response);       
        }

        var errorCallback= function(response){
            console.log("image Filed to upload! :)");
            console.log(response);
			$("#page_load_div").hide();
			$("#upload_complete").hide();	
        }
		
    	var orientation = $("#orientation").val();
    	console.log("process start upload ...");
    	jic.upload(compressed_image, "<?php echo $siteURL?>/appointment/index?page=ajax_actions&action=upload_image&orientation="+orientation, "file", file_name,successCallback,errorCallback);
    	
    });

	//document.getElementById("fileinput").addEventListener("change", readFile, false);
	
	/* $("#add_form").on("click",".select_admin_id",function(){
		if($("#job_id").val() == ""){
			alert("First select Enquiry/Quote/Job");
			$(this).val("");
			return false;
		}
	}); */
	<? if($_REQUEST['action'] != 'edit'){ ?>
	/* $("#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/appointment/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 job. First assign consultant.");
						$("#admin_id_div").html(result);
					}
				}
			});
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/appointment/index.php?page=ajax_actions&action=get_descrip_by_job",
				data: form_data,
				success: function(result){  
					if(result){
						//$("#appointment_text").val(result);
						$("#description_of_job").html(result);
					}
				}
			});
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/appointment/index.php?page=ajax_actions&action=get_address_by_job",
				data: form_data,
				success: function(result){  
					if(result){
						$("#addess").val(result);
					}
				}
			}); 
		}
	});*/
	<? } ?>
	$("#submit_form").click(function(){	
		
		var checkboxChecked = $('#apply_to_coming_event').is(':checked');
		if(checkboxChecked===true){
			if(confirm('Are you sure! You want to apply changes to coming event.')){
				//return true;
			}else{
				return false;
			}
		}
		if($("#span").text() == "No consultant assign to this job. First assign consultant."){
			alert("First select Consultant");
			return false;
		}
	});
	
	
	$('.quotation_status').on('ifClicked', function(){
		
		$('.quotation_status').iCheck('uncheck');
		$(this).iCheck('check');
		
		/* if($(this).attr("name") == "quotation_accepted"){
			$("#quotation_accepted_refresh").show();
		}else{
			$("#quotation_declined_refresh").show();
		} */
		if($(this).attr("name") == "to_quote"){
			$("#to_quote_refresh").show();
		}else if($(this).attr("name") == "quoted"){
			$("#quoted_refresh").show();
		}else if($(this).attr("name") == "quotation_accepted"){
			$("#quotation_accepted_refresh").show();
		}else if($(this).attr("name") == "accepted_date_given"){
			$("#accepted_date_given_refresh").show();
		}else if($(this).attr("name") == "quotation_declined"){
			$("#quotation_declined_refresh").show();
		}
		
		var quotation_status = $(this).attr("name");
		var job_id = $("#job_id").val();
		//alert('aaaaaaaaaaa'+job_id);
		var form_data   = {'job_id':job_id,'quotation_status':quotation_status};       
		$.ajax({
			async: true,
			type: "POST",
			url: site_url+"/modules/appointment/index.php?page=ajax_actions&action=update_quotation",
			data: form_data,
			success: function(r){    
				$("#to_quote_refresh").hide();
				$("#quoted_refresh").hide();
				$("#quotation_accepted_refresh").hide();
				$("#accepted_date_given_refresh").hide();
				$("#quotation_declined_refresh").hide();
				
				if(r == "to_quote"){
					$("#to_quote_check").show();
					setTimeout(function(){
						$("#to_quote_check").hide();
					},2000);
				}else if(r == "quoted"){
					$("#quoted_check").show();
					setTimeout(function(){
						$("#quoted_check").hide();
					},2000);
				}else if(r == "quotation_accepted"){
					$("#quotation_accepted_check").show();
					setTimeout(function(){
						$("#quotation_accepted_check").hide();
					},2000);
				}else if(r == "accepted_date_given"){
					$("#accepted_date_given_check").show();
					setTimeout(function(){
						$("#accepted_date_given_check").hide();
					},2000);
				}else if(r == "quotation_declined"){
					$("#quotation_declined_check").show();
					setTimeout(function(){
						$("#quotation_declined_check").hide();
					},2000);
				}
			}
		});
	});
	
	
	////////////////// DOCUMENT DELETE //////////////////////////////////////
	$("#add_form").on("click",".document_delete",function(){
		if(confirm("Do you want to delete the document?")){
			var document_p_id = $(this).parent().attr("id");
			//alert(document_p_id);
			var document_name = $(this).attr("alt");
			if(document_name != ""){
				var form_data   = {'document_name':document_name};  
				$.ajax({
					async: true,
					type: "POST",
					url: site_url+"/modules/appointment/index.php?page=ajax_actions&action=delete_document",
					data: form_data,
					success: function(result){
						var resultObj = jQuery.parseJSON(result); 
						if(resultObj.status == "success"){
							$("#"+document_p_id).hide();
						}
					}
				});	
			}
		}
	});
	$('.hide_show').click(function(){
		$('.hide_show').hide();
		$('.cancel_btn').show();
	});
	$('.cancel_btn').click(function(){
		$('.hide_show').show();
	});
});
</script>