
<form action="" method="post" class="form form-request form-vertical form-size-100">
	<fieldset>
		
		<h1>Manage your booking</h1>

		<div class="control-group">
			<div class="control-label">
				<label for="carrental_order_number">Order Number:</label>
			</div>
			<div class="control-field">
				<input type="text" name="id_order" id="carrental_order_number" class="control-input">
			</div>
		</div>
		
		<div class="control-group">
			<div class="control-label">
				<label for="carrental_order_email">Your E-mail:</label>
			</div>
			<div class="control-field">
				<input type="text" name="email" id="carrental_order_email" class="control-input">
			</div>
		</div>
		
		<div class="control-group">
			<div class="control-field align-right">
				<input type="hidden" name="page" value="carrental">
				<button type="submit" name="manage_booking" class="btn btn-primary">SHOW ORDER DETAILS</button>	
			</div>
		</div>
		
	</fieldset>
</form>
<script type="text/javascript">
	var enter_location = 0;
	var carrental_fixed_dates = {};
	var branches = {};
	var branch_hours = {};
	var default_branch = 0;
	var default_enter_time = '09:00';
	var default_return_time = '21:00';
	var ajaxurl = 'https://www.orion-rentals.com/wp-admin/admin-ajax.php';
		var time_pricing_type = 'standard';
	
			var allowed_days = [1,1,1,1,1,1,1];
	var carrental_timeformat = 24;
	
		var holidays = {};
	
		var carrental_minimum_booking_time = {"1":3,"2":3,"3":3,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":3,"12":3};
	
	jQuery(document).ready(function() {
		
								
							jQuery('.ecalypse_call_price').click(function(e){
				e.preventDefault();
				alert('This car is not available. Call us for details.');
			});
						
	
		var car_availability = {};
		var ajax_loading = {};
		jQuery('.car-available-button').datepicker({
				//showOn: "both",
				dateFormat: "dd.mm.yy",
				firstDay: "1",
				dayNamesMin: ["Su", "Mo", "Tu", "Wu", "Th", "Fr", "Sa"],
				monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
				dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
				nextText: "Next",
				prevText: "Prev",
				onChangeMonthYear: function(year, month, instance) {
					var key = jQuery(instance.input).attr('data-car-id')+'-'+year+'-'+(month < 10 ? '0'+month : month);
					if (car_availability[key] === undefined) {
						carrental_load_availability(jQuery(instance.input).attr('data-car-id'), year, month);
					}
				},
				beforeShow: function(element, instance) {
					month = new Date().getMonth()+1;
					var key = jQuery(instance.input).attr('data-car-id')+'-'+(new Date().getFullYear())+'-'+(month < 10 ? '0'+month : month);
					if (car_availability[key] === undefined) {
						carrental_load_availability(jQuery(instance.input).attr('data-car-id'), new Date().getFullYear(), new Date().getMonth()+1);
					}
				},
				beforeShowDay: function(date) {
					month = date.getMonth()+1;
					var key = jQuery(this).attr('data-car-id')+'-'+date.getFullYear()+'-'+(month < 10 ? '0'+month : month);
					if (car_availability[key] === undefined) {
						return [false, 'carrental-car-available'];
					}
					if (car_availability[key][date.getDate()] === undefined) {
						return [false, 'carrental-car-available'];
					}
					return [false, car_availability[key][date.getDate()] ? 'carrental-car-no-available' : 'carrental-car-available'];
				}
		});
		
		var carrental_load_availability = function(car_id, year, month) {
			var key = car_id+'-'+year+'-'+month;
			if (car_availability[key] === undefined) {
				jQuery.ajax({
					url: ajaxurl,
					type: "POST",
					cache: false,
					dataType: 'json',
					async: false,
					data: 'fe_ajax=1&car_id='+car_id+'&year='+year+'&month='+month+'&action=carrental_available_cars',
					success: function(data){
							jQuery.each(data, function(k,v){
								car_availability[k] = v;
							})
						}
				}); 
			}
		};
		
		jQuery('.carrental-book-this-car-btn').on('click', function() {
			jQuery('#carrental-hidden-booking-form').attr('data-car-id',jQuery(this).attr('data-car-id'));
			jQuery('#carrental-hidden-booking-form').attr('data-branch-id',jQuery(this).attr('data-branch-id'));
			var id_branch = parseInt(jQuery(this).attr('data-branch-id'));
			
			jQuery('#carrental_enter_location_popup option:selected').removeAttr('selected');
			if (id_branch == 0) {
				jQuery('#carrental_enter_location_popup option').show();
				if (default_branch > 0) {
					jQuery('#carrental_enter_location_popup option[value='+default_branch+']').attr('selected',true);
				}
			} else {
				if (jQuery('#carrental_enter_location_popup option[value='+id_branch+']').length) {				
					jQuery('#carrental_enter_location_popup option').hide();
					jQuery('#carrental_enter_location_popup option[value='+id_branch+']').show().attr('selected',true);
				}
			}
			
			jQuery('.booking-form-overflow').fadeIn(400);
			jQuery('#carrental-hidden-booking-form').fadeIn(800);
		});
		
		jQuery('#carrental-hidden-booking-form #carrental_booking_form_popup').submit(function(e){
			var is_available = true;
			jQuery('#carrental_booking_form_id_car').val(jQuery('#carrental-hidden-booking-form').attr('data-car-id'));
			jQuery.ajax({
				url: ajaxurl,
				type: "POST",
				cache: false,
				dataType: 'json',
				async: false,
				data: 'fe_ajax=1&car_id='+jQuery('#carrental-hidden-booking-form').attr('data-car-id')+'&enter_location='+jQuery('#carrental_enter_location_popup').val()+'&pickup_date='+jQuery('#carrental_from_date_popup').val()+'&pickup_time='+(jQuery('#carrental_from_hour_popup').length ? jQuery('#carrental_from_hour_popup').val() : '')+'&period='+jQuery('#carrental_period_popup').val()+'&return_date='+jQuery('#carrental_to_date_popup').val()+'&return_time='+(jQuery('#carrental_to_hour_popup').length ? jQuery('#carrental_to_hour_popup').val() : '')+'&action=carrental_book_now_check',
				success: function(data){
						if (data && data == '1') {
							is_available = true;
						} else {
							is_available = false;
						}
					}
			});
			if (!is_available) {
				jQuery('#carrental_book_errors_popup').html('<li>Car not available on these dates, please try again or try to search all cars for those dates.</li>');
				e.preventDefault();
			}
		});

		jQuery('p.close-win').on('click', function() {
			jQuery('#carrental-hidden-booking-form').fadeOut(400);
			jQuery('.booking-form-overflow').fadeOut(800);
		});

		jQuery('.booking-form-overflow').on('click', function() {
			jQuery('#carrental-hidden-booking-form').fadeOut(400);
			jQuery(this).fadeOut(800);
		});

		if (jQuery('#carrental_enter_location').length) {
			// call time update after page reload
			carrental_booking_init('');
			init_fixed_dates('');
			carrental_update_business_hours('');
		}

		if (jQuery('#carrental_enter_location_popup').length) {
			// call time update after page reload
			carrental_booking_init('_popup');
			init_fixed_dates('_popup');
			carrental_update_business_hours('_popup');
		}
		
		jQuery('.carrental_car_details').hide();
		jQuery('.carrental_car_details_link').click(function() {			
			jQuery(this).parent().parent().find('.carrental_car_details').toggle('fast');
		});
		
		function init_fixed_dates(element_id) {
			var date_from = jQuery('#carrental_from_date' + element_id).val();
			if (typeof date_from === "undefined" || date_from == '') {
				date_from = jQuery.datepicker.formatDate('dd.mm.yy', new Date());
			}

			var date_to = jQuery('#carrental_to_date' + element_id).val();
			if (typeof date_to === "undefined" || date_to == '') {
				date_to = jQuery.datepicker.formatDate('dd.mm.yy', new Date());
			}

			// reformat to YYYY-MM-DD
			date_from = jQuery.datepicker.formatDate('yy-mm-dd', jQuery.datepicker.parseDate('dd.mm.yy', date_from));
			date_to = jQuery.datepicker.formatDate('yy-mm-dd', jQuery.datepicker.parseDate('dd.mm.yy', date_to));
			if (typeof carrental_fixed_dates_call == 'function') { 
				if (carrental_fixed_dates_call(element_id, date_from, date_to) >= 0) {
					var errors = [];
					errors.push('There is fixed price on this dates.');
					jQuery('#carrental_book_errors' + element_id).html('<li>' + errors.join('</li><li>') + '</li>');
				} else {
					jQuery('#carrental_book_errors' + element_id + ' li' ).remove();
				}
			}
		}

		function carrental_booking_init(element_id) {
		
			if (time_pricing_type == 'half_day') {
				jQuery('#carrental_period' + element_id).change(function(){
					if (jQuery(this).val() != 'day') {
						jQuery('#carrental_to_date'+element_id).parent().hide();
					} else {
						jQuery('#carrental_to_date'+element_id).parent().show();
					}
				});
			}

			jQuery('#carrental_return_location' + element_id).hide();

	
			jQuery('#carrental_different_loc' + element_id).click(function(e) {
				jQuery('#carrental_return_location' + element_id).toggle('fast');
			});
			
			jQuery('#carrental_from_date' + element_id).parent().click(function(){
				jQuery( '#carrental_from_date' + element_id).datepicker( "show" );
			});
			
			jQuery('#carrental_to_date' + element_id).parent().click(function(){
				jQuery( '#carrental_to_date' + element_id).datepicker( "show" );
			});

			jQuery('#carrental_from_date' + element_id + ', #carrental_to_date' + element_id).datepicker({
				//showOn: "both",
				beforeShow: carrental_customRange,
				dateFormat: "dd.mm.yy",
				firstDay: "1",
				dayNamesMin: ["Su", "Mo", "Tu", "Wu", "Th", "Fr", "Sa"],
				monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
				dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
				nextText: "Next",
				prevText: "Prev",				
				onSelect: function() {
					carrental_update_business_hours(element_id);
					if (typeof carrental_fixed_dates !== "undefined" && carrental_fixed_dates.length) {
						init_fixed_dates(element_id);
						carrental_update_business_hours(element_id);
					}
				},
				beforeShowDay: function(date) {
					// test allowed days
					if (allowed_days[date.getDay()] === 0) {
						return [false, ''];
					}
					
					// test if is not holiday
					month = date.getMonth()+1;
					month = month < 10 ? '0'+month : month;
					day = date.getDate();
					day = day < 10 ? '0'+day : day;
					if (typeof holidays[month+'-'+day] !== "undefined") {
						return [false, ''];
					}
					return [true, ''];
				}
			});

			jQuery('#carrental_enter_location' + element_id).on('change', function() {
				carrental_update_business_hours(element_id);
			});

			jQuery('#carrental_return_location' + element_id).on('change', function() {
				carrental_update_business_hours(element_id);
			});

			jQuery('#carrental_different_loc' + element_id).on('click', function() {
				carrental_update_business_hours(element_id);
			});

			jQuery('#carrental_booking_form' + element_id).on('submit', function() {

				var errors = [];

				// Check enter location
				if (jQuery('#carrental_enter_location' + element_id).val() > 0) {
				} else {
					errors.push('Please, select enter location.');
				}

				// Check return location (if checked)
				if (jQuery('#carrental_different_loc' + element_id + ':checked').val() == 'on') {
					if (jQuery('#carrental_return_location' + element_id).val() > 0) {
					} else {
						errors.push('Please, select return location or disable the *Returning to Different location*.');
					}
				}

				// Check dates (from and to)
				var from_date = jQuery.datepicker.parseDate('dd.mm.yy', jQuery('#carrental_from_date' + element_id).val());
				
				var date_compare = new Date();
				date_compare.setHours(0,0,0,0);
				
				if (from_date != null && from_date != 'Invalid Date' && from_date >= date_compare) {
				} else {
					errors.push('Please, select pick-up date properly.');
				}

				var to_date = jQuery.datepicker.parseDate('dd.mm.yy', jQuery('#carrental_to_date' + element_id).val());
				if (to_date != null && to_date != 'Invalid Date' && to_date >= date_compare) {
				} else {
					if (time_pricing_type == 'half_day' && jQuery('#carrental_period' + element_id).val() != 'day') {
					} else {
						errors.push('Please, select return date properly.');
					}
				}

				// Check times (from and to)
				if (time_pricing_type == 'standard') {
					if (jQuery('#carrental_from_hour' + element_id).val() != '') {
						if (from_date != null && from_date != 'Invalid Date') {
							time = jQuery('#carrental_from_hour' + element_id).val().split(':');
							from_date.setHours(time[0]);
							from_date.setMinutes(time[1]);
						}
					} else {
						errors.push('Please, select pick-up time properly.');
					}

					if (jQuery('#carrental_to_hour' + element_id).val() != '') {
						if (to_date != null && to_date != 'Invalid Date') {
							time = jQuery('#carrental_to_hour' + element_id).val().split(':');
							to_date.setHours(time[0]);
							to_date.setMinutes(time[1]);
						}
					} else {
						errors.push('Please, select return time properly.');
					}
				}
				
				// check minimum rental times
				if (from_date != null && from_date != 'Invalid Date') {
					var diff_hours = Math.abs(to_date - from_date) / 36e5;				
					key = parseInt(from_date.getMonth())+1;
					if (carrental_minimum_booking_time[key] !== undefined && carrental_minimum_booking_time[key] > 0) {
						if (diff_hours < (carrental_minimum_booking_time[key] * 24)) {
							errors.push('Minimum days of booking for this month is '+carrental_minimum_booking_time[key]);
						}
					}
				}
				
				if (to_date < from_date) {
					if (!(time_pricing_type == 'half_day' && jQuery('#carrental_period' + element_id).val() != 'day')) {
						errors.push('Please select dates and times properly. Return date must be greater than pickup.');
					}
				}
				
				// Filters
				var flt = [];

				// Price range
				if (jQuery('#carrental_filter_price_range' + element_id).is(':hidden') == false) {
					flt.push('spr:' + parseInt(jQuery('#carrental_filter_price_range' + element_id + ' .inputSliderMin').val()));
					flt.push('epr:' + parseInt(jQuery('#carrental_filter_price_range' + element_id + ' .inputSliderMax').val()));
				}

				// Extras
				if (jQuery('#carrental_filter_extras' + element_id).is(':hidden') == false) {
					if (jQuery('[name=ac]').is(':checked') == true) {
						flt.push('ac:' + parseInt(jQuery('[name=ac]').val()));
					}
					if (jQuery('[name=nonac]').is(':checked') == true) {
						flt.push('nac:' + parseInt(jQuery('[name=nonac]').val()));
					}
				}

				// Fuel
				if (jQuery('#carrental_filter_fuel' + element_id).is(':hidden') == false) {
					if (jQuery('[name=petrol]').is(':checked') == true) {
						flt.push('pl:' + parseInt(jQuery('[name=petrol]').val()));
					}
					if (jQuery('[name=diesel]').is(':checked') == true) {
						flt.push('dl:' + parseInt(jQuery('[name=diesel]').val()));
					}
				}

				// Passengers
				if (jQuery('#carrental_filter_passangers' + element_id).is(':hidden') == false) {
					flt.push('sp:' + parseInt(jQuery('#carrental_filter_passangers' + element_id + ' .slider-input-start').val()));
					flt.push('ep:' + parseInt(jQuery('#carrental_filter_passangers' + element_id + ' .slider-input-end').val()));
				}

				// Categories
				if (jQuery('#carrental_filter_categories' + element_id).is(':hidden') == false) {
					var cats = [];
					jQuery('.categories_checkall:checked').each(function() {
						cats.push(jQuery(this).val());
					});
					if (cats.length > 0) {
						flt.push('cats:' + cats.join(','));
					}
				}

				// Vehicles
				if (jQuery('#carrental_filter_vehicles' + element_id).is(':hidden') == false) {
					var cats = [];
					jQuery('.vehicles_checkall:checked').each(function() {
						cats.push(jQuery(this).val());
					});
					if (cats.length > 0) {
						flt.push('vh:' + cats.join(','));
					}
				}
				
				//seri = jQuery('.custom_parameter_checkbox:checked, .custom_parameter_input.slider-input-start, .custom_parameter_input.slider-input-end').serializeArray();
				
				// custom parameters
				if (jQuery('.custom-parameter-values').length) {
					jQuery.each(jQuery('.custom-parameter-values'), function (k, v){
						if (jQuery(v).is(':hidden')) {
							return;
						}
						checkbox = jQuery(v).find('.custom_parameter_checkbox:checked');
						var cats = [];
						parameter_id = 0;
						checkbox.each(function(kk, vv){
							cats.push(parseInt(jQuery(vv).val()));
							parameter_id = parseInt(jQuery(vv).attr('data-parameter'));
						});
						flt.push('cp-'+parameter_id+':' + cats.join(','));
					});
				}
				
				if (jQuery('.custom-parameter-range').length) {
					jQuery.each(jQuery('.custom-parameter-range'), function (k, v){
						if (jQuery(v).is(':hidden')) {
							return;
						}
						flt.push('cp-'+jQuery(v).find('.slider-input-start').attr('data-parameter')+'-range:' + parseInt(jQuery(v).find('.slider-input-start').val()) + '-' +parseInt(jQuery(v).find('.slider-input-end').val()));
						//flt.push('cp-'+jQuery(v).find('.slider-input-end').attr('data-parameter')+'-t:' + parseInt(jQuery(v).find('.slider-input-end').val()));
					});
				}
				
				if (flt.length > 0) {
					jQuery('[name=flt]').val(flt.join('|'));
				} else {
					jQuery('[name=flt]').val('');
				}

				if (errors.length == 0) {
					return true;
				} else {
					jQuery('#carrental_book_errors' + element_id).html('<li>' + errors.join('</li><li>') + '</li>');
					return false;
				}
			});
		}

		function carrental_customRange(input) {
						var min_time = new Date(1788153351000);
			var max_time = new Date(1874294151000);
			
			if (input.id.substr(0, 17) == 'carrental_to_date') {
				var postfix = '';
				if (input.id.length > 17) {
					postfix = input.id.substr(17);
				}
				
				if (jQuery('#carrental_from_date' + postfix).val() == '') {
					jQuery('#carrental_from_date' + postfix).focus();
					alert('Set pick-up date first.');					
				}
				
				var minDate = jQuery.datepicker.parseDate('dd.mm.yy', jQuery('#carrental_from_date' + postfix).val()); //new Date(jQuery.datepicker.formatDate('yy-mm-dd', );jQuery('#carrental_from_date').val());
				minDate.setDate(minDate.getDate());
				
				enterDate = jQuery( "#carrental_from_date"+postfix ).datepicker( "getDate" );
				key = parseInt(enterDate.getMonth())+1;
				if (carrental_minimum_booking_time[key] !== undefined && carrental_minimum_booking_time[key] > 0) {
					minTime = enterDate;
					minTime.setDate(minTime.getDate() + carrental_minimum_booking_time[key]);
					if (minTime > minDate) {
						minDate = minTime;
					}
				}
				
				return {minDate: minDate};
			}
			return {minDate: min_time, maxDate: max_time}
		}

		function carrental_update_business_hours(element_id) {
			try {
				
				if (time_pricing_type !== 'standard') {
					return;
				}

				var id_branch = jQuery('#carrental_enter_location' + element_id).val();
				var id_branch_return = jQuery('#carrental_return_location' + element_id).val();

				if (typeof id_branch_return === "undefined" || id_branch_return == '' || jQuery('#carrental_different_loc' + element_id + ':checked').val() != 'on') {
					id_branch_return = id_branch;
				}
				
				var date_from = jQuery('#carrental_from_date' + element_id).val();
				if (typeof date_from === "undefined" || date_from == '') {
					date_from = jQuery.datepicker.formatDate('dd.mm.yy', new Date());
				}

				var date_to = jQuery('#carrental_to_date' + element_id).val();
				if (typeof date_to === "undefined" || date_to == '') {
					date_to = jQuery.datepicker.formatDate('dd.mm.yy', new Date());
				}

				// reformat to YYYY-MM-DD
				date_from = jQuery.datepicker.formatDate('yy-mm-dd', jQuery.datepicker.parseDate('dd.mm.yy', date_from));
				date_to = jQuery.datepicker.formatDate('yy-mm-dd', jQuery.datepicker.parseDate('dd.mm.yy', date_to));

				var full_date_from = new Date(date_from);
				var day_week_from = full_date_from.getUTCDay();
				if (day_week_from == 0) {
					day_week_from = 7;
				} // sunday

				var full_date_to = new Date(date_to);
				var day_week_to = full_date_to.getUTCDay();
				if (day_week_to == 0) {
					day_week_to = 7;
				} // sunday
				
				if (id_branch != '' && typeof branches[id_branch]['specific_times'] !== 'undefined' && branches[id_branch]['specific_times']) {
					
					// DATE FROM
					if (typeof branches[id_branch]['enter_hours'][day_week_from] !== "undefined" && branches[id_branch]['enter_hours'][day_week_from]) {

						var from = carrental_time_format(branches[id_branch]['enter_hours'][day_week_from]['from'], 24);//.substring(0, 5); // get off seconds
						var to = carrental_time_format(branches[id_branch]['enter_hours'][day_week_from]['to'], 24);//.substring(0, 5);
						var prev_val = jQuery("#carrental_from_hour" + element_id).val();

						jQuery("#carrental_from_hour" + element_id).attr('disabled', false);
						jQuery('#carrental_from_hour' + element_id).find('option').remove().end().append('<option value="">Time</option>'); // delete all previous options

						for (x = parseInt(from); x <= parseInt(to); x++) {
							var hour = String(x);
							if (hour.length == 1) {
								hour = '0' + hour;
							}

							if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
								// Do not show
							} else {
								newTime = carrental_time_format(hour + ':00', carrental_timeformat);
								is_selected = hour + ':00' == default_enter_time ? true : false;
								jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
							}

							if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
								// Do not show
							} else {
								newTime = carrental_time_format(hour + ':30', carrental_timeformat);
								is_selected = hour + ':30' == default_enter_time ? true : false;
								jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
							}
						}
						
						// FROM_2
						if (branches[id_branch]['enter_hours'][day_week_from]['from_2'] && branches[id_branch]['enter_hours'][day_week_from]['to_2']) {
							var from = carrental_time_format(branches[id_branch]['enter_hours'][day_week_from]['from_2'], 24);//.substring(0, 5); // get off seconds
							var to = carrental_time_format(branches[id_branch]['enter_hours'][day_week_from]['to_2'], 24);//.substring(0, 5);
							for (x = parseInt(from); x <= parseInt(to); x++) {
								var hour = String(x);
								if (hour.length == 1) {
									hour = '0' + hour;
								}

								if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
									// Do not show
								} else {
									newTime = carrental_time_format(hour + ':00', carrental_timeformat);
									is_selected = hour + ':00' == default_enter_time ? true : false;
									jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
								}

								if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
									// Do not show
								} else {
									newTime = carrental_time_format(hour + ':30', carrental_timeformat);
									is_selected = hour + ':30' == default_enter_time ? true : false;
									jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
								}
							}
						}

						if (prev_val != '' && jQuery("#carrental_from_hour" + element_id + " option[value='" + prev_val + "']").val() !== undefined) {
							jQuery("#carrental_from_hour" + element_id).val(prev_val);
						}

					} else {
						jQuery('#carrental_from_hour' + element_id).find('option').remove().end().append('<option value="">Closed</option>'); // delete all previous options
						jQuery("#carrental_from_hour" + element_id).attr('disabled', true);
					}
				
				} else {
					// DATE FROM
						if (id_branch != '' && typeof branch_hours[id_branch][day_week_from] !== "undefined" && branch_hours[id_branch][day_week_from]) {

							var from = carrental_time_format(branch_hours[id_branch][day_week_from]['from'], 24);//.substring(0, 5); // get off seconds
							var to = carrental_time_format(branch_hours[id_branch][day_week_from]['to'], 24);//.substring(0, 5);
							var prev_val = jQuery("#carrental_from_hour" + element_id).val();

							jQuery("#carrental_from_hour" + element_id).attr('disabled', false);
							jQuery('#carrental_from_hour' + element_id).find('option').remove().end().append('<option value="">Time</option>'); // delete all previous options

							for (x = parseInt(from); x <= parseInt(to); x++) {
								var hour = String(x);
								if (hour.length == 1) {
									hour = '0' + hour;
								}

								if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
									// Do not show
								} else {
									newTime = carrental_time_format(hour + ':00', carrental_timeformat);
									is_selected = hour + ':00' == default_enter_time ? true : false;
									jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
								}

								if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
									// Do not show
								} else {
									newTime = carrental_time_format(hour + ':30', carrental_timeformat);
									is_selected = hour + ':30' == default_enter_time ? true : false;
									jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
								}
							}
							
							if (branch_hours[id_branch][day_week_from]['from_2'] && branch_hours[id_branch][day_week_from]['to_2']) {
								var from = carrental_time_format(branch_hours[id_branch][day_week_from]['from_2'], 24);//.substring(0, 5); // get off seconds
								var to = carrental_time_format(branch_hours[id_branch][day_week_from]['to_2'], 24);//.substring(0, 5);

								for (x = parseInt(from); x <= parseInt(to); x++) {
									var hour = String(x);
									if (hour.length == 1) {
										hour = '0' + hour;
									}

									if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
										// Do not show
									} else {
										newTime = carrental_time_format(hour + ':00', carrental_timeformat);
										is_selected = hour + ':00' == default_enter_time ? true : false;
										jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
									}

									if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
										// Do not show
									} else {
										newTime = carrental_time_format(hour + ':30', carrental_timeformat);
										is_selected = hour + ':30' == default_enter_time ? true : false;
										jQuery("#carrental_from_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
									}
								}
							}

							if (prev_val != '' && jQuery("#carrental_from_hour" + element_id + " option[value='" + prev_val + "']").val() !== undefined) {
								jQuery("#carrental_from_hour" + element_id).val(prev_val);
							}

						} else {
							jQuery('#carrental_from_hour' + element_id).find('option').remove().end().append('<option value="">Closed</option>'); // delete all previous options
							jQuery("#carrental_from_hour" + element_id).attr('disabled', true);
						}
					}
					
					if (id_branch_return != '' && typeof branches[id_branch_return]['specific_times'] !== 'undefined' && branches[id_branch_return]['specific_times']) {
						// DATE TO
						if (typeof branches[id_branch_return]['return_hours'][day_week_to] !== "undefined" && branches[id_branch_return]['return_hours'][day_week_to]) {

							var from = carrental_time_format(branches[id_branch_return]['return_hours'][day_week_to]['from'], 24);//.substring(0, 5); // get off seconds
							var to = carrental_time_format(branches[id_branch_return]['return_hours'][day_week_to]['to'], 24);//.substring(0, 5);
							var prev_val = jQuery("#carrental_to_hour" + element_id).val();

							jQuery("#carrental_to_hour" + element_id).attr('disabled', false);
							jQuery('#carrental_to_hour' + element_id).find('option').remove().end().append('<option value="">Time</option>'); // delete all previous options

							for (x = parseInt(from); x <= parseInt(to); x++) {
								var hour = String(x);
								if (hour.length == 1) {
									hour = '0' + hour;
								}

								if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
									// Do not show
								} else {
									newTime = carrental_time_format(hour + ':00', carrental_timeformat);
									is_selected = hour + ':00' == default_return_time ? true : false;
									jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
								}

								if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
									// Do not show
								} else {
									//if (prev_val == hour + ':30') { var selected = true; } else { var selected = false; }
									newTime = carrental_time_format(hour + ':30', carrental_timeformat);
									is_selected = hour + ':30' == default_return_time ? true : false;
									jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
								}

							}
							
							// FROM_2
							if (branches[id_branch_return]['return_hours'][day_week_to]['from_2'] && branches[id_branch_return]['return_hours'][day_week_to]['to_2']) {
								var from = carrental_time_format(branches[id_branch_return]['return_hours'][day_week_to]['from_2'], 24);//.substring(0, 5); // get off seconds
								var to = carrental_time_format(branches[id_branch_return]['return_hours'][day_week_to]['to_2'], 24);//.substring(0, 5);

								for (x = parseInt(from); x <= parseInt(to); x++) {
									var hour = String(x);
									if (hour.length == 1) {
										hour = '0' + hour;
									}

									if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
										// Do not show
									} else {
										newTime = carrental_time_format(hour + ':00', carrental_timeformat);
										is_selected = hour + ':00' == default_return_time ? true : false;
										jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
									}

									if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
										// Do not show
									} else {
										//if (prev_val == hour + ':30') { var selected = true; } else { var selected = false; }
										newTime = carrental_time_format(hour + ':30', carrental_timeformat);
										is_selected = hour + ':30' == default_return_time ? true : false;
										jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
									}

								}
							}

							if (prev_val != '' && jQuery("#carrental_to_hour" + element_id + " option[value='" + prev_val + "']").val() !== undefined) {
								jQuery("#carrental_to_hour" + element_id).val(prev_val);
							}

						} else {
							jQuery('#carrental_to_hour' + element_id).find('option').remove().end().append('<option value="">Closed</option>');
							jQuery("#carrental_to_hour" + element_id).attr('disabled', true);
						}
					} else {
						// DATE TO
						if (id_branch_return != '' && typeof branch_hours[id_branch_return][day_week_to] !== "undefined" && branch_hours[id_branch_return][day_week_to]) {

							var from = carrental_time_format(branch_hours[id_branch_return][day_week_to]['from'], 24);//.substring(0, 5); // get off seconds
							var to = carrental_time_format(branch_hours[id_branch_return][day_week_to]['to'], 24);//.substring(0, 5);
							var prev_val = jQuery("#carrental_to_hour" + element_id).val();

							jQuery("#carrental_to_hour" + element_id).attr('disabled', false);
							jQuery('#carrental_to_hour' + element_id).find('option').remove().end().append('<option value="">Time</option>'); // delete all previous options

							for (x = parseInt(from); x <= parseInt(to); x++) {
								var hour = String(x);
								if (hour.length == 1) {
									hour = '0' + hour;
								}

								if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
									// Do not show
								} else {
									newTime = carrental_time_format(hour + ':00', carrental_timeformat);
									is_selected = hour + ':00' == default_return_time ? true : false;
									jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
								}

								if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
									// Do not show
								} else {
									//if (prev_val == hour + ':30') { var selected = true; } else { var selected = false; }
									newTime = carrental_time_format(hour + ':30', carrental_timeformat);
									is_selected = hour + ':30' == default_return_time ? true : false;
									jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
								}

							}
							
							if (branch_hours[id_branch_return][day_week_to]['from_2'] && branch_hours[id_branch_return][day_week_to]['to_2']) {
								var from = carrental_time_format(branch_hours[id_branch_return][day_week_to]['from_2'], 24);//.substring(0, 5); // get off seconds
								var to = carrental_time_format(branch_hours[id_branch_return][day_week_to]['to_2'], 24);//.substring(0, 5);

								for (x = parseInt(from); x <= parseInt(to); x++) {
									var hour = String(x);
									if (hour.length == 1) {
										hour = '0' + hour;
									}

									if (x == parseInt(from) && parseInt(from.substr(-2)) >= 30) {
										// Do not show
									} else {
										newTime = carrental_time_format(hour + ':00', carrental_timeformat);
										is_selected = hour + ':00' == default_return_time ? true : false;
										jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':00', is_selected, is_selected));
									}

									if (x == parseInt(to) && parseInt(to.substr(-2)) < 30) {
										// Do not show
									} else {
										//if (prev_val == hour + ':30') { var selected = true; } else { var selected = false; }
										newTime = carrental_time_format(hour + ':30', carrental_timeformat);
										is_selected = hour + ':30' == default_return_time ? true : false;
										jQuery("#carrental_to_hour" + element_id).append(new Option(newTime, hour + ':30', is_selected, is_selected));
									}

								}
							}

							if (prev_val != '' && jQuery("#carrental_to_hour" + element_id + " option[value='" + prev_val + "']").val() !== undefined) {
								jQuery("#carrental_to_hour" + element_id).val(prev_val);
							}

						} else {
							jQuery('#carrental_to_hour' + element_id).find('option').remove().end().append('<option value="">Closed</option>');
							jQuery("#carrental_to_hour" + element_id).attr('disabled', true);
						}

					}
				
			} catch (e) {
				alert(e);
			}
		}

	});

Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};


</script>
{"id":7,"date":"2016-08-06T14:39:33","date_gmt":"2016-08-06T14:39:33","guid":{"rendered":"https:\/\/www.orion-rentals.com\/?page_id=7"},"modified":"2017-01-23T11:10:15","modified_gmt":"2017-01-23T11:10:15","slug":"manage-booking","status":"publish","type":"page","link":"https:\/\/www.orion-rentals.com\/?page_id=7","title":{"rendered":"Manage booking"},"content":{"rendered":"\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"manage-booking-template.php","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"class_list":["post-7","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.3 (Yoast SEO v28.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Manage booking - Orion Rent a car - Koutouloufari, Crete<\/title>\n<meta name=\"description\" content=\"Orion Rent a car in Koutouloufari, Hersonissos, Crete. Iraklion airport car rentals. We deliver cars to all airports, ports, docks and hotels on Crete\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.orion-rentals.com\/?page_id=7\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Manage booking\" \/>\n<meta property=\"og:description\" content=\"Orion Rent a car in Koutouloufari, Hersonissos, Crete. Iraklion airport car rentals. We deliver cars to all airports, ports, docks and hotels on Crete\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.orion-rentals.com\/?page_id=7\" \/>\n<meta property=\"og:site_name\" content=\"Orion Rent a car - Koutouloufari, Crete\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/orionrentals\/?fref=ts\" \/>\n<meta property=\"article:modified_time\" content=\"2017-01-23T11:10:15+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@manodicandia\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7\",\"url\":\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7\",\"name\":\"Manage booking - Orion Rent a car - Koutouloufari, Crete\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/#website\"},\"datePublished\":\"2016-08-06T14:39:33+00:00\",\"dateModified\":\"2017-01-23T11:10:15+00:00\",\"description\":\"Orion Rent a car in Koutouloufari, Hersonissos, Crete. Iraklion airport car rentals. We deliver cars to all airports, ports, docks and hotels on Crete\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.orion-rentals.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Manage booking\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/#website\",\"url\":\"https:\\\/\\\/www.orion-rentals.com\\\/\",\"name\":\"Orion Rent a car - Koutouloufari, Crete\",\"description\":\"Orion Car Rentals Koutouloufari, Crete. 50 Years of Trust, Smiles, and Safe Journeys\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/#organization\"},\"alternateName\":\"Orion Rentals - Trusted Car Rentals Since 1977\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.orion-rentals.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Organization\",\"Place\"],\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/#organization\",\"name\":\"ORION Rent a car\",\"url\":\"https:\\\/\\\/www.orion-rentals.com\\\/\",\"logo\":{\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7#local-main-organization-logo\"},\"image\":{\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7#local-main-organization-logo\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/orionrentals\\\/?fref=ts\",\"https:\\\/\\\/x.com\\\/manodicandia\",\"https:\\\/\\\/www.instagram.com\\\/orioncarrentals\\\/\",\"https:\\\/\\\/gr.linkedin.com\\\/in\\\/emmanouel-katsoulakis-7b587350\",\"https:\\\/\\\/gr.pinterest.com\\\/ManoDiCandia\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCFAm67OIZCBm22Jn7kinK6Q\"],\"telephone\":[],\"openingHoursSpecification\":[{\"@type\":\"OpeningHoursSpecification\",\"dayOfWeek\":[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\"],\"opens\":\"09:00\",\"closes\":\"17:00\"}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.orion-rentals.com\\\/?page_id=7#local-main-organization-logo\",\"url\":\"https:\\\/\\\/www.orion-rentals.com\\\/wp-content\\\/uploads\\\/2017\\\/01\\\/Orion-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.orion-rentals.com\\\/wp-content\\\/uploads\\\/2017\\\/01\\\/Orion-Logo.jpg\",\"width\":521,\"height\":261,\"caption\":\"ORION Rent a car\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Manage booking - Orion Rent a car - Koutouloufari, Crete","description":"Orion Rent a car in Koutouloufari, Hersonissos, Crete. Iraklion airport car rentals. We deliver cars to all airports, ports, docks and hotels on Crete","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.orion-rentals.com\/?page_id=7","og_locale":"en_US","og_type":"article","og_title":"Manage booking","og_description":"Orion Rent a car in Koutouloufari, Hersonissos, Crete. Iraklion airport car rentals. We deliver cars to all airports, ports, docks and hotels on Crete","og_url":"https:\/\/www.orion-rentals.com\/?page_id=7","og_site_name":"Orion Rent a car - Koutouloufari, Crete","article_publisher":"https:\/\/www.facebook.com\/orionrentals\/?fref=ts","article_modified_time":"2017-01-23T11:10:15+00:00","twitter_card":"summary_large_image","twitter_site":"@manodicandia","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.orion-rentals.com\/?page_id=7","url":"https:\/\/www.orion-rentals.com\/?page_id=7","name":"Manage booking - Orion Rent a car - Koutouloufari, Crete","isPartOf":{"@id":"https:\/\/www.orion-rentals.com\/#website"},"datePublished":"2016-08-06T14:39:33+00:00","dateModified":"2017-01-23T11:10:15+00:00","description":"Orion Rent a car in Koutouloufari, Hersonissos, Crete. Iraklion airport car rentals. We deliver cars to all airports, ports, docks and hotels on Crete","breadcrumb":{"@id":"https:\/\/www.orion-rentals.com\/?page_id=7#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.orion-rentals.com\/?page_id=7"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.orion-rentals.com\/?page_id=7#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.orion-rentals.com\/"},{"@type":"ListItem","position":2,"name":"Manage booking"}]},{"@type":"WebSite","@id":"https:\/\/www.orion-rentals.com\/#website","url":"https:\/\/www.orion-rentals.com\/","name":"Orion Rent a car - Koutouloufari, Crete","description":"Orion Car Rentals Koutouloufari, Crete. 50 Years of Trust, Smiles, and Safe Journeys","publisher":{"@id":"https:\/\/www.orion-rentals.com\/#organization"},"alternateName":"Orion Rentals - Trusted Car Rentals Since 1977","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.orion-rentals.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Organization","Place"],"@id":"https:\/\/www.orion-rentals.com\/#organization","name":"ORION Rent a car","url":"https:\/\/www.orion-rentals.com\/","logo":{"@id":"https:\/\/www.orion-rentals.com\/?page_id=7#local-main-organization-logo"},"image":{"@id":"https:\/\/www.orion-rentals.com\/?page_id=7#local-main-organization-logo"},"sameAs":["https:\/\/www.facebook.com\/orionrentals\/?fref=ts","https:\/\/x.com\/manodicandia","https:\/\/www.instagram.com\/orioncarrentals\/","https:\/\/gr.linkedin.com\/in\/emmanouel-katsoulakis-7b587350","https:\/\/gr.pinterest.com\/ManoDiCandia\/","https:\/\/www.youtube.com\/channel\/UCFAm67OIZCBm22Jn7kinK6Q"],"telephone":[],"openingHoursSpecification":[{"@type":"OpeningHoursSpecification","dayOfWeek":["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],"opens":"09:00","closes":"17:00"}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.orion-rentals.com\/?page_id=7#local-main-organization-logo","url":"https:\/\/www.orion-rentals.com\/wp-content\/uploads\/2017\/01\/Orion-Logo.jpg","contentUrl":"https:\/\/www.orion-rentals.com\/wp-content\/uploads\/2017\/01\/Orion-Logo.jpg","width":521,"height":261,"caption":"ORION Rent a car"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P7MoXb-7","_links":{"self":[{"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=\/wp\/v2\/pages\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":1,"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=\/wp\/v2\/pages\/7\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=\/wp\/v2\/pages\/7\/revisions\/69"}],"wp:attachment":[{"href":"https:\/\/www.orion-rentals.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}