<section class="container-fluid">	
	<div class="row">
		<div class="col-md-8">
			<div class="card bg-light-transparent" style="margin-bottom: 2rem;">
				<div class="card-header bg-white">
					<div class="float-left">
						<h5 class="card-title">Calendar</h5>
					</div>
				</div>
				<div class="card-body">
					<div class="card bg-white no-shadow">
						<div class="card-body">
							<div class="row">
								<div class="col-2">
									<?php foreach ($carbooking as $type) { ?>
										<br><div data-trigger="hover" data-tooltip="tooltip" title="<?php echo $type['car_name']; ?>" class="text-center mt-2 text-white" style="background-color: <?php echo '#'.$type['color_code']; ?>;-webkit-border-radius:8px; -moz-border-radius:8px; border-radius:8px; border:1px solid #ccc; height:28px;"><?php echo $type['short_name']; ?></div>
									<?php } ?> 
								</div>
								<div class="col-10">
									<div id="calendar"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<div class="card bg-light-transparent" style="margin-bottom: 2rem;">
				<div class="card-header bg-white">
					<h5 class="card-title">Upcoming Car Booking</h5>
				</div>
				<div class="card-body">
					<div class="card bg-white no-shadow">
						<div class="card-body">
							<?php if(!empty($upcoming_request)): foreach($upcoming_request as $type): ?>
								<div class="row">
									<div class="col-auto">
										<p class="text-uppercase" data-trigger="hover" data-tooltip="tooltip" title="<?php echo $type['car_name']; ?>"><?php echo $type['car_name']; ?></p>
									</div>
									<div class="col text-right">
										<p><?php echo date('d-m-Y',strtotime($type['start_date'])).' ['.$type['start_time'].']'; ?></p>
									</div>
								</div>
							<?php endforeach;endif; ?>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>

<section class="container" style="padding-bottom: 2rem;">
	<div class="row">
		<div class="col-sm-12">
			<div class="tab-content" id="tabContent">
				<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">
					<div class="card bg-light-transparent">
						<div class="card-header bg-light">
							<h4 class="card-title float-left"><?php echo (empty($ID))?'New ':'Edit '; ?>Car Booking Form</h4>
						</div>
						<div class="card-body">
							<div class="card no-shadow">
								<div class="card-body">
									<form id="carbookingForm" class="form" action="<?php echo ($ID)?base_url('hr/Serviceform/carbooking_edit'):base_url('hr/Serviceform/carbooking_save'); ?>" method="POST" onsubmit="return confirm('Do you really want to submit the form?')">
										<input type="text" class="form-control" name="carBookingID" id="carBookingID" value="<?php echo $ID; ?>" hidden>

										<div class="form-row">
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label>Name</label>
													<?php if(($ID == 0)){ ?>
														<input type="text" class="form-control" name="reqName" id="reqName" value="<?php echo $_SESSION['user']['name']; ?>" readonly>

														<input type="text" class="form-control" name="reqName_id" id="reqName_id" value="<?php echo $_SESSION['user']['id']; ?>" hidden>

													<?php } else{ ?>
														<?php if(!empty($rsCarGetList)){ ?>
															<?php foreach($rsCarGetList as $row) { ?>
																<input type="text" class="form-control" name="reqName" id="reqName" value="<?php echo $row['requestor']; ?>" readonly>

																<input type="text" class="form-control" name="reqName_id" id="reqName_id" value="<?php echo $row['user_id']; ?>" hidden>
															<?php }?>
														<?php }?>
													<?php }?>
												</div>
											</div>

											<div class="col-12 col-sm-3">
												<div class="form-group">
													<label for="department">Department</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($rsCarGetList)): foreach($rsCarGetList as $row): ?>
															<input type="text" class="form-control" name="department" id="department" value="<?php echo $row['dept_name']; ?>" readonly>
															<input type="text" class="form-control" name="department_id" id="department_id" value="<?php echo $row['department_id']; ?>" hidden>
														<?php endforeach;endif; ?>
													<?php } else { ?>
														<input type="text" class="form-control" name="department" id="department" value="<?php echo $_SESSION['user']['department_name']; ?>" readonly>
														<input type="text" class="form-control" name="department_id" id="department_id" value="<?php echo $_SESSION['user']['department_id']; ?>" hidden>
													<?php }?>
												</div>
											</div>

											<div class="col-12 col-sm-3">
												<div class="form-group">
													<label for="reqDate">Date Request </label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($rsCarGetList)): foreach($rsCarGetList as $row): ?>
															<input type="" class="form-control" name="reqDate" id="reqDate" value="<?php echo (!empty($ID))?date('d-m-Y',strtotime($row['createdTS'])):''; ?>" readonly/>
														<?php endforeach;endif; ?>
													<?php } else { ?>
														<input type="" class="form-control" name="reqDate" id="reqDate" value="<?php echo date('d-m-Y'); ?>" readonly>
													<?php } ?>
												</div>
											</div>
										</div>

										<!-- <div class="form-row">
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<h6>Booking Start Date/Time</h6>
												</div>
											</div>
											<div class="form-group">
												<div class="col-12">
													<h6>Booking End Date/Time</h6>
												</div>
											</div>
										</div> -->

										<div class="form-row">
											<div class="col-12 col-sm-3">
												<div class="form-group">
													<label for="datestart">Start Date</label>
													<?php if(!empty($ID)){ ?>
														<input type="text" class="form-control datepicker" name="start_date" id="start_date" value="<?php echo date('d-m-Y',strtotime($rsCarGetList[0]['start_date'])); ?>" required onchange="check_booking_date()">
													<?php } else { ?>
														<input type="text" name="start_date" id="start_date" class="form-control datepicker" required onchange="check_booking_date()">
													<?php }?>
												</div>
											</div>

											<div class="col-12 col-sm-3">
												<div class="form-group">
													<label for="timestart">Start Time</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($rsCarGetList)): foreach($rsCarGetList as $row): ?>
															<input type="text" class="form-control timepicker" name="start_time" id="start_time" value="<?php echo (!empty($ID))?$row['start_time']:''; ?>" required onchange="check_booking_date()">
														<?php endforeach; endif; ?> 
													<?php } else{ ?>
														<input type="text" name="start_time" id="start_time" class="form-control timepicker" required onchange="check_booking_date()">
													<?php }?>
												</div>
											</div>

											<div class="col-12 col-sm-3">
												<div class="form-group">
													<label for="dateend">End Date</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($rsCarGetList)): foreach($rsCarGetList as $row): ?>
															<input type="text" class="form-control datepicker" name="end_date" id="end_date" value="<?php echo (!empty($ID))?date('d-m-Y',strtotime($row['end_date'])):''; ?>" required onchange="check_booking_date()">
														<?php endforeach; endif; ?>
													<?php } else{ ?>
														<input type="text" name="end_date" id="end_date" class="form-control datepicker" required onchange="check_booking_date()">
													<?php }?>
												</div>
											</div>

											<div class="col-12 col-sm-3">
												<div class="form-group">
													<label for="timestart">End Time</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($rsCarGetList)): foreach($rsCarGetList as $row): ?>
															<input type="text" class="form-control timepicker" name="end_time" id="end_time" value="<?php echo (!empty($ID))?$row['end_time']:''; ?>" class="form-control timepicker" required onchange="check_booking_date()">

														<?php endforeach; endif; ?>
													<?php } else{ ?>
														<input type="text" name="end_time" id="end_time" class="form-control timepicker" required onchange="check_booking_date()">
													<?php }?>
												</div>
											</div>
										</div>

										<h4 class="text-center"><b style="color: red;" id="complete_fill_note">*Please Fill In Date Start, Date End, Time Start, Time End*</b></h4>
										<div id="booking_detail">
											<div class="form-row">
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="booking">Car Type</label>
														<div class="input-group mb-3">
															<div class="input-group-append">
																<?php if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4){ ?>
																	<button type="button" id="updateCarList" class="btn btn-sm btn-warning" onclick="open_modal()" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Update Car"><i class="far fa-edit"></i></button>
																<?php } ?>
															</div>

															<select class="form-control" id="car_id" name="car_id" required>
																<option value="" disabled selected>--Please Select--</option>
																<?php if(!empty($ID)){ ?>
																	<?php if(!empty($rsCarGetList)): foreach($rsCarGetList as $row): ?>
																		<?php if($carbooking) foreach($carbooking as $car){ ?>
																			<option value="<?php echo $car['ID']; ?>" <?php echo ($row['car_id'] == $car['ID'])?"selected":""; ?>><?php echo $car['car_name']; ?></option>
																		<?php } ?>
																	<?php endforeach; endif; ?>
																<?php } else { ?>
																	<?php if($carbooking) foreach($carbooking as $car){ ?>
																		<option value="<?php echo $car['ID']; ?>"><?php echo $car['car_name']; ?></option>
																	<?php } ?>
																<?php } ?>
															</select>
														</div>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="loc">Location</label>
														<?php if(!empty($ID)){ ?>
															<?php if(!empty($rsCarGetList)): foreach($rsCarGetList as $row): ?>
																<?php if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4){ ?>
																	<input type="text" class="form-control" name="location" id="location" value="<?php echo (!empty($ID))?$row['location']:''; ?>" readonly>
																<?php } else {?>
																	<input type="text" class="form-control" name="location" id="location" value="<?php echo (!empty($ID))?$row['location']:''; ?>" required>  
																<?php } ?>
															<?php endforeach;endif; ?>
														<?php } else{ ?>
															<input type="text" class="form-control" name="location" id="location" required>
														<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<label for="purpose">Purpose</label>
														<?php if(!empty($ID)){ ?>
															<textarea class="form-control" name="purpose" id="purpose" value="<?php echo(!empty($ID))?$rsCarGetList[0]['purpose']:''; ?>" required><?php echo (!empty($ID))?$rsCarGetList[0]['purpose']:''; ?></textarea>
														<?php } else { ?>
															<textarea type="text" name="purpose" id="purpose" class="form-control" required></textarea>
														<?php } ?>
													</div>
												</div>
											</div>

											<?php if($ID && $_SESSION['user']['id'] == $rsCarGetList[0]['createdBY']){ ?>
												<div class="form-row" <?php echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?>>
													<div class="col-12">
														<h5><input type="checkbox" name="booking_checker" id="booking_checker" style="height: 1rem; width: 1rem;" onclick="checkbox(this)"> Please tick if you are booking for someone else.</h5>
													</div>
												</div>

												<div class="form-row">
													<div class="col-12 col-sm-6 d-none" id="guest_details_form">
														<div class="form-group">
															<label for="guest_details">Guest Name [Department]</label>
															<select class="form-control select" name="guest_details" id="guest_details">
																<option value="-1" selected disabled>-- Please Select --</option>
																<?php if($listName) foreach($listName as $key => $gID){ 
																	$dept_sName =  ($gID['department_name'])?' ['.$gID['department_short_name'].'] ':' [N/A]';
																	?>
																	<?php if(($_SESSION['user']['name']) != $gID['name']){ ?>
																		<option value="<?php echo $gID['id']; ?>" data-did="$gID['department_id']"><?php echo $gID['name'].$dept_sName; ?></option>
																	<?php } ?>
																<?php } ?>
															</select>
														</div>
													</div>

													<?php if(!empty($ID) && !empty($rsCarGetList)) foreach($rsCarGetList as $row){ ?>
														<?php if($row['user_id'] != $row['createdBY']){ ?>
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="guest_details_input">Guest Name [Department]</label>
																	<input type="text" class="form-control" name="guest_name_input" id="guest_name_input" value="<?php echo $row['requestor'].' ['.$row['department_short_name'].']' ?>" readonly>
																	<input type="text" class="form-control" name="guest_details_input" id="guest_details_input" value="<?php echo $row['user_id']; ?>" hidden>
																</div>
															<?php } ?>
														</div>
													<?php } ?>
												</div>

												<div class="form-row">
													<div class="col-12">
														<div class="float-right" style="padding-top: 2rem;">
															<a class="btn btn-light" href="<?php echo base_url('hr/serviceform/car_booking_list'); ?>">Cancel</a>
															<button type="submit" class="btn btn-primary" id="submitBtn">Submit</button>
														</div> 
													</div>
												</div>
											<?php }else{ ?>
												<div class="form-row" <?php echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?>>
													<div class="col-12">
														<h5><input type="checkbox" name="booking_checker" id="booking_checker" style="height: 1rem; width: 1rem;" onclick="checkbox(this)"> Please tick if you are booking for someone else.</h5>
													</div>
												</div>

												<div class="form-row">
													<div class="col-12 col-sm-6 d-none" id="guest_details_form">
														<div class="form-group">
															<label for="guest_details">Guest Name [Department]</label>
															<select class="form-control select" name="guest_details" id="guest_details">
																<option value="-1" selected disabled>-- Please Select --</option>
																<?php if($listName) foreach($listName as $key => $gID){ 
																	$dept_sName =  ($gID['department_name'])?' ['.$gID['department_short_name'].'] ':' [N/A]';
																	?>
																	<?php if(($_SESSION['user']['name']) != $gID['name']){ ?>
																		<option value="<?php echo $gID['id']; ?>" data-did="$gID['department_id']"><?php echo $gID['name'].$dept_sName; ?></option>
																	<?php } ?>
																<?php } ?>
															</select>
														</div>
													</div>

													<?php if(!empty($ID) && !empty($rsCarGetList)) foreach($rsCarGetList as $row){ ?>
														<?php if($row['user_id'] != $row['createdBY']){ ?>
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="guest_details_input">Guest Name [Department]</label>
																	<input type="text" class="form-control" name="guest_name_input" id="guest_name_input" value="<?php echo $row['requestor'].' ['.$row['department_short_name'].']' ?>" readonly>
																	<input type="text" class="form-control" name="guest_details_input" id="guest_details_input" value="<?php echo $row['user_id']; ?>" hidden>
																</div>
															</div>
														<?php } ?>
													<?php } ?>
												</div>

												<div class="form-row">
													<div class="col-12">
														<div class="float-right" style="padding-top: 2rem;">
															<a class="btn btn-light" href="<?php echo base_url('hr/serviceform/car_booking_list'); ?>">Cancel</a>
															<button type="submit" class="btn btn-primary" id="submitBtn">Submit</button>
														</div> 
													</div>
												</div>
											<?php } ?>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>

<!-- modal edit car detail -->

<div class="modal fade d-print-none" id="update_car_modal" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="modal_title">Add/Update Car</h5>&emsp;
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<form id="carForm" class="form">
				<div class="modal-body">
					<div class="row">
						<div class="col-12">
							<label>Car</label>
							<input type="text" class="form-control" name="modal_car" id="modal_car">
						</div>
					</div>

					<div class="row">
						<div class="col-12">
							<label>Price</label>
							<input type="text" class="form-control" name="modal_car_price" id="modal_car_price">
						</div>
					</div>

					<div class="row pt-3">
						<div class="col-12">
							<div class="btn-group float-right">
								<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
								<button type="button" id="saveCarBtn" class="btn btn-primary">Save</button>
							</div>
						</div>
					</div>

					<hr>

					<div class="row">
						<div class="col-12">
							<label>List Car</label>
							<div class="table-responsive">
								<table id="filter_table_car" class="table table-bordered">
									<thead>
										<th>#</th>
										<th>Car</th>
										<th>Price</th>
										<th>Action</th>
									</thead>
									<tbody></tbody>
								</table>
							</div>
						</div>
					</div>

					<br>

					<div class="modal-footer">
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<!-- modal edit car detail -->

<!-- modal update car detail -->

<div class="modal fade d-print-none" id="update_car_detail_modal" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="modal_title">Add/Update Car</h5>&emsp;
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<form id="carForm" class="form">
				<div class="modal-body">
					<div class="row">
						<div class="col-12">
							<label>Car</label>
							<input type="text" class="form-control" name="edit_modal_car" id="edit_modal_car">
							<input type="text" class="form-control" name="edit_modal_car_id" id="edit_modal_car_id" hidden>
						</div>
					</div>

					<div class="row">
						<div class="col-12">
							<label>Price</label>
							<input type="text" class="form-control" name="edit_modal_car_price" id="edit_modal_car_price">
						</div>
					</div>

					<div class="row pt-3">
						<div class="col-12">
							<div class="btn-group float-right">
								<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
								<button type="button" id="updateCarBtn" class="btn btn-primary">Save</button>
							</div>
						</div>
					</div>

					<br>

					<div class="modal-footer">
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<!-- modal update car detail -->

<?php echo (!empty($approval))?$approval:''; ?>

<style type="text/css">
	.tooltipevent
	{
		width:auto;
		height:auto;
		background:rgba(0,0,0,0.75);
		position:absolute;
		color: #fff;
		z-index:10001;
		padding:10px 10px 10px 10px ;  
		line-height: 200%;
	}
</style>

<script>
	$(document).ready(function(){

		var fc_event= '';
		var resource = <?php echo $resource;?>;

		var fullcalendar = $('#calendar').fullCalendar({ 
			themeSystem: 'bootstrap4',
			header: 
			{
				left: 'prev,next today',
				center: 'title',
				right: 'month,listMonth'
			},
			buttonText: {
				today: 'Today',
				month: 'Calendar',
				listMonth: 'List'
			},

            navLinks: true, // can click day/week names to navigate views
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: <?php echo $fc_event; ?>,

            eventMouseover: function (data, event, param, resource = <?php echo $resource;?>) {
            	var js_res = JSON.parse(JSON.stringify(resource));
            	var hover_item = js_res[data.id];
            	var title = JSON.stringify(data.title);
            	var start_date = moment(hover_item.start_date).format('DD-MM-YYYY');
				var end_date = moment(hover_item.end_date).format('DD-MM-YYYY');
				// var start_time = moment(hover_item.start_date+' '+hover_item.start_time).format('00-00-00');
				// var end_time = moment(hover_item.end_date+' '+hover_item.end_time).format('00-00-00');

				tooltip = '<div class="tooltipevent"> Car Type : '+hover_item.car_type_name+' <br/> Location : '+hover_item.location+'<br/> Purpose : '+hover_item.purpose+'<br/> Start Date : '+start_date+'<br/> End Date : '+end_date+'<br/>Start Time : '+hover_item.start_time+' <br/> End Time : '+hover_item.end_time+' </div>';

            	$("body").append(tooltip);
            	$(this).mouseover(function (e) {
            		$(this).css('z-index', 10000);
            		$('.tooltipevent').fadeIn('500');
            		$('.tooltipevent').fadeTo('10', 1.9);
            	}).mousemove(function (e) {
            		$('.tooltipevent').css('top', e.pageY + 10);
            		$('.tooltipevent').css('left', e.pageX + 20);
            	});
            },

            eventMouseout: function(data, event) {
            	$(this).css('z-index', 8);
            	$('.tooltipevent').remove();
            },
        });

		fullcalendar.fullCalendar();

		check_booking_date();

	});

	function open_modal()
	{
		clearForm('#carForm');

		var table = $('#filter_table_car').DataTable();
		table.clear().draw();

		$.ajax({
			url:'<?php echo base_url('hr/serviceform/getCar') ?>',
			data: {},
			type: 'post',
			dataType: 'json',
			success: (data) => {
				if(data.status == "Success") {
					let car = data.car;

					if(car != null)
					{
						$.each(car,function(key,content)
						{
							var btn_edit = '<button type="button" class="btn btn-sm btn-warning" data-carname="'+content.car_name+'" data-id="'+content.ID+'" data-price="'+content.price+'" onclick="update_car(this)" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Update Car"><i class="far fa-edit"></i></button>';

							var btn_delete = '<button type="button" id="deleteButton" class="btn btn-sm btn-danger" data-carname="'+content.car_name+'" data-id="'+content.ID+'" data-price="'+content.price+'" onclick="delete_car(this)" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Update Car"><i class="fas fa-trash"></i></button>';

							table.row.add({
								0   : '<div class="text-center">'+(key + 1)+'</div>',
								1   : content.car_name,
								2   : content.price,
								3   : '<div class="text-center">'+btn_edit+btn_delete+'</div>',
							}).draw();
						});

						$('#filter_table_car').DataTable().destroy();
					}
				}
			}
		});

		$('#saveCarBtn').attr('onclick', 'saveCar()');
		$('#update_car_modal').modal('show');
	}

	function saveCar() 
	{
		var car_name 	= $('#modal_car').val();
		var car_price 	= $('#modal_car_price').val();

		validateForm("#saveCarBtn", "Add "+car_name+" to car list?", function() {
			$.ajax({
				url:'<?php echo base_url('hr/serviceform/updateCarList/add') ?>',
				data: {
					car_name : car_name,
					car_price : car_price,
				},
				type: 'post',
				dataType: 'json',
				success: (data) => {
					if(data.status == "Success") {

						localStorage.setItem("status", data.status);
						localStorage.setItem("msg", data.msg);

						location.reload();
					}
				}
			});
		});
	}

	function update_car(elem)
	{
		var car_id = $(elem).data('id');
		var car_name = $(elem).data('carname');
		var car_price = $(elem).data('price');

		$('#edit_modal_car_id').val(car_id);
		$('#edit_modal_car').val(car_name);
		$('#edit_modal_car_price').val(car_price);
		$('#updateCarBtn').attr('onclick', 'updateCar()');
		$('#update_car_detail_modal').modal('show');
	}

	function updateCar() 
	{
		var car_id 		= $('#edit_modal_car_id').val();
		var car_name 	= $('#edit_modal_car').val();
		var car_price 	= $('#edit_modal_car_price').val();

		validateForm("#updateCarBtn", "Update "+car_name+"?", function() {
			$.ajax({
				url:'<?php echo base_url('hr/serviceform/updateCarList') ?>',
				data: {
					car_id : car_id,
					car_name : car_name,
					car_price : car_price,
				},
				type: 'post',
				dataType: 'json',
				success: (data) => {
					if(data.status == "Success") {

						localStorage.setItem("status", data.status);
						localStorage.setItem("msg", data.msg);

						location.reload();
					}
				}
			});
		});
	}

	function delete_car(elem) 
	{
		var car_id = $(elem).data('id');
		var car_name = $(elem).data('carname');

		validateForm("#deleteButton", "Delete "+car_name+" from car list?", function() {
			$.ajax({
				url:'<?php echo base_url('hr/serviceform/updateCarList/delete') ?>',
				data: {
					car_id : car_id,
					car_name : car_name,
				},
				type: 'post',
				dataType: 'json',
				success: (data) => {
					if(data.status == "Success") {

						localStorage.setItem("status", data.status);
						localStorage.setItem("msg", data.msg);

						location.reload();
					}
				}
			});
		});
	}

	function checkbox(elem)
	{
		var booking_checker = document.getElementById("booking_checker");

		if(booking_checker.checked == true)
		{
			$('#guest_details_form').removeClass('d-none');
			$('#guest_details').attr('required','required');
		}else{
			$('#guest_details_form').addClass('d-none');
			$('#guest_details').removeAttr('required');
			$('#guest_details').prop('selectedIndex',0);
		}
	}

	function check_booking_date()
    {
    	var start_date 	= $('#start_date').val();
		var start_time 	= $('#start_time').val();
		var end_date 	= $('#end_date').val();
		var end_time 	= $('#end_time').val();
		var car_list	= JSON.parse('<?php echo json_encode($carbooking) ?>');

		var existingBooking = car_list;

		$(existingBooking).each(function(key,row){
			$("#car_id option[value="+row.ID+"]").removeAttr('hidden');
		});
		// var car_id 		= $("#car_id").val();

		// if(car_id > 0)
		if((start_date && end_date && start_time && end_time) != '')
		{			
			$('#booking_detail').css({"filter":"","-webkit-filter":""});
    		$('#booking_detail').css("cursor","default");
    		$('#complete_fill_note').addClass('d-none');
    		
			$.ajax({
	            url:'<?php echo base_url('hr/serviceform/getBookingDate/car') ?>',
	            data: {
	                start_date 	: start_date,
	                start_time 	: start_time,
	                end_date 	: end_date,
	                end_time 	: end_time,
	                // car_id 		: car_id,
	            },
	            type: 'post',
	            dataType: 'json',
	            success: (data) => {

	            	// var temp_select_option_1 = '<option value="" disabled selected>--Please Select--</option>';
	            	// $('#car_id')

	                if(data.status == "Success") {
	     //            	iziToast.success({
						// 	title: 'Success',
						// 	message: data.msg
						// });

						// $('#submitBtn').removeAttr('disabled');
						// $('#submitBtn').css("cursor","pointer");
	     //            	$('#submitBtn').prop('type', 'submit');
	                }else{
	     //            	iziToast.error({
						// 	title: 'Error',
						// 	message: data.msg
						// });
	     //            	$('#submitBtn').attr('disabled', 'disabled');
						// $('#submitBtn').css("cursor","not-allowed");
	     //            	$('#submitBtn').prop('type', 'button');

						var existingBooking = data.getBookingData;
						<?php if($ID){ ?>
							$(existingBooking).each(function(key,row){
								if((row.car_id != '<?php echo $rsCarGetList[0]['car_id']; ?>') || (row.start_date != '<?php echo $rsCarGetList[0]['start_date']; ?>')|| (row.end_date != '<?php echo $rsCarGetList[0]['end_date']; ?>') || (row.start_time != '<?php echo $rsCarGetList[0]['start_time']; ?>') || (row.end_time != '<?php echo $rsCarGetList[0]['end_time']; ?>')){
									$("#car_id option[value="+row.car_id+"]").attr('hidden','hidden');
								}
							});
						<?php }else{ ?>
							$(existingBooking).each(function(key,row){
								$("#car_id option[value="+row.car_id+"]").attr('hidden','hidden');
							});
						<?php } ?>
	                }
	            }
	        });
		}else{
    		$('#booking_detail').css({"filter":"blur(5px)","-webkit-filter":"blur(5px)"});
	        $('#booking_detail').css("cursor","not-allowed");
    		$('#complete_fill_note').removeClass('d-none');
		}
    }
</script>