PageSourceSearch

https://rainforestadventure.com/wp-content/plugins/ph-bookings-app…?ver=16b35b8bf8bd84955781e3898fab44ab

js rainforestadventure.com collected 2026-10-02 10:17:13 UTC 74,666 bytes, 2,099 lines download raw bytes

1/********* html-ph-booking-add-to-cart.php *********/
2
3jQuery(document).ready(function ($) {
4	$is_booking_end_time_clicked = false;
5	$is_booking_end_date_clicked = false;
6	$is_booking_from_time_clicked = false;
7
8	$date_from_previous_value = '';
9	$ph_date_from_previous_value = '';
10
11	$(document).on('click', '.single_add_to_cart_button', function (e) {
12		if ($(this).hasClass("disabled")) {
13			e.preventDefault();
14		}
15		if ($(".ph-date-from").val() == '' && $(".ph-date-to").val() == '') {
16			$(".callender-error-msg").html(phive_booking_locale.pick_booking).focus();
17			e.preventDefault();
18		}
19		else if ($(".ph-date-from").val() != '' && !$('.theme-martfury').length) {
20			$('.ph_book_now_button').addClass("disabled");
21		}
22	});
23
24
25
26	$(document).on("click", ".input-person-minus", function (e) {
27		e.preventDefault();
28		if(jQuery(this).hasClass("input-resources-minus")){
29			return false;
30		}
31		if (!$(this).hasClass('input-disabled')) {
32			var $button = $(this);
33			flag = 0;
34			min = $button.parent().find("input.input-person").attr('min');
35			e.preventDefault();
36			var oldValue = $button.parent().find("input").val();
37			if (oldValue > 0) {
38				var newVal = parseFloat(oldValue) - 1;
39			}
40			else {
41				flag++;
42			}
43			if (min) {
44				if (newVal < min) {
45					$button.attr('disabled', true);
46					$button.css('opacity', 0.2);
47					ref_this = '.participant_count_error_' + $button.parent().find("input.input-person").attr('rule-key');
48					
49					// console.log(phive_booking_ajax.single_min_participant_warning);
50					message = phive_booking_ajax.single_min_participant_warning;
51					message = message.replace('%pname', $button.parent().find("input.input-person").attr('data-name'));
52					message = message.replace('%min', parseInt($button.parent().find("input.input-person").attr("min")));
53
54					$(ref_this).html(message);
55
56					$(ref_this).fadeIn('fast', function () {
57						$(ref_this).delay(5000).fadeOut();
58					});
59					return;
60				}
61			}
62			if (flag == 0) {
63				$button.parent().find(".input-person-plus").attr('disabled', false);
64				$button.parent().find(".input-person-plus").css('opacity', 1);
65				$button.parent().find("input.input-person").val(newVal).change();
66			}
67		}
68	});
69/* extra recouces minus */
70$(document).on("click", ".input-resources-minus", function (e) {
71	e.preventDefault();
72	if (!$(this).hasClass('input-disabled')) {
73		var $button = $(this);
74		flag = 0;
75		min = $button.parent().find("input.input-resources-extra-plus-minus").attr('min');
76		e.preventDefault();
77		var oldValue = $button.parent().find("input").val();
78		if (oldValue > 0) {
79			var newVal = parseFloat(oldValue) - 1;
80		}
81		else {
82			flag++;
83		}
84		if (min) {
85			if (newVal < min) {
86				$button.attr('disabled', true);
87				$button.css('opacity', 0.2);
88				ref_this = '.participant_count_error_' + $button.parent().find("input.input-resources-extra-plus-minus").attr('rule-key');
89				
90				// console.log(phive_booking_ajax.single_min_participant_warning);
91				message = phive_booking_ajax.single_min_participant_warning;
92				message = message.replace('%pname', $button.parent().find("input.input-resources-extra-plus-minus").attr('data-name'));
93				message = message.replace('%min', parseInt($button.parent().find("input.input-resources-extra-plus-minus").attr("min")));
94
95				$(ref_this).html(message);
96
97				$(ref_this).fadeIn('fast', function () {
98					$(ref_this).delay(5000).fadeOut();
99				});
100				return;
101			}
102		}
103		if (flag == 0) {
104			$button.parent().find(".input-resources-plus").attr('disabled', false);
105			$button.parent().find(".input-resources-plus").css('opacity', 1);
106			$button.parent().find("input.input-resources-extra-plus-minus").val(newVal).change();
107		}
108	}
109});
110$(document).on("click", ".input-resources-plus", function (e) {
111	e.preventDefault();
112	if(jQuery(this).hasClass("input-resources-plus")){
113		return false;
114	}
115	if (!$(this).hasClass('input-disabled')) {
116		flag = 0;
117		var $button = $(this);
118		var oldValue = $button.parent().find("input").val();
119		if (!oldValue) {
120			oldValue = 0;
121		}
122		max = $button.parent().find("input.input-resources-extra-plus-minus").attr('max');
123		var newVal = parseFloat(oldValue) + 1;
124		if (max) {
125			if (newVal > max) {
126				$button.attr('disabled', true);
127				$button.css('opacity', 0.2);
128				ref_this = '.participant_count_error_' + $button.parent().find("input.input-resources-extra-plus-minus").attr('rule-key');
129				var message = phive_booking_locale.max_individual_participant;
130				pname = $button.parent().find("input.input-resources-extra-plus-minus").attr('data-name');
131				pmax = parseInt($button.parent().find("input.input-resources-extra-plus-minus").attr("max"));
132				message = message.replace('%pname', pname);
133				message = message.replace('%pmax', pmax);
134				/* if found atv aviable  */
135				feild_key =  $button.parent().find("input.input-resources-extra-plus-minus").attr("feild-key");
136				if(feild_key == "ATV"){
137					// Number of Participant(s) cannot exceed 1
138					message = message.replace('Number of Participant(s)', "ATV");
139				}
140				/*  if found atv aviable */
141				$(ref_this).html(message);
142				$(ref_this).fadeIn('fast', function () {
143					$(ref_this).delay(5000).fadeOut();
144				});
145				return;
146				// flag++;
147			}
148		}
149		if (flag == 0) {
150			$button.parent().find(".input-resources-minus").attr('disabled', false);
151			$button.parent().find(".input-resources-minus").css('opacity', 1);
152			$button.parent().find("input.input-resources-extra-plus-minus").val(newVal).change();
153		}
154	}
155});
156// person
157	$(document).on("click", ".input-person-plus", function (e) {
158		e.preventDefault();
159		if (!$(this).hasClass('input-disabled')) {
160			flag = 0;
161			var $button = $(this);
162			var oldValue = $button.parent().find("input").val();
163			if (!oldValue) {
164				oldValue = 0;
165			}
166			max = $button.parent().find("input.input-person").attr('max');
167			var newVal = parseFloat(oldValue) + 1;
168			if (max) {
169				if (newVal > max) {
170					$button.attr('disabled', true);
171					$button.css('opacity', 0.2);
172					ref_this = '.participant_count_error_' + $button.parent().find("input.input-person").attr('rule-key');
173
174					var message = phive_booking_locale.max_individual_participant;
175
176					pname = $button.parent().find("input.input-person").attr('data-name');
177					pmax = parseInt($button.parent().find("input.input-person").attr("max"));
178					message = message.replace('%pname', pname);
179					message = message.replace('%pmax', pmax);
180					$(ref_this).html(message);
181					$(ref_this).fadeIn('fast', function () {
182						$(ref_this).delay(5000).fadeOut();
183					});
184					return;
185					// flag++;
186				}
187			}
188			if (flag == 0) {
189				$button.parent().find(".input-person-minus").attr('disabled', false);
190				$button.parent().find(".input-person-minus").css('opacity', 1);
191				$button.parent().find("input.input-person").val(newVal).change();
192			}
193		}
194	});
195
196});
197
198/***********************************************************************
199**** ALL CALLENDER PAGE (date picker, time ticker and month picker) ****
200************************************************************************/
201
202function calculate_price() {
203	jQuery(".single_add_to_cart_button").addClass("disabled");
204	date_from = jQuery(".ph-date-from").val();
205	if (!date_from) {
206		date_from = jQuery(".selected-date").first().find(".callender-full-date").val();
207	}
208	if (!date_from) {
209		return;
210	}
211	if (jQuery(".selected-date").length == 0) {
212		jQuery(".booking-info-wraper").html('<p id="booking_info_text"  style="text-align:center;">Oops! Something went wrong.Try again</p>');
213		// jQuery(".ph-date-from").val(date_from);
214		return;
215	}
216	date_to = jQuery(".selected-date").last().find(".callender-full-date").val();
217
218	//If charge_per_night, need to pick To date
219	if (date_from == date_to && jQuery('#calender_type').val() == 'date' && jQuery("#book_interval_type").val() != 'fixed' && jQuery('#charge_per_night').length && jQuery('#charge_per_night').val() == 'yes') {
220		jQuery(".booking-info-wraper").html('<p id="booking_info_text"  style="text-align:center;">' + phive_booking_locale.pick_an_end_date + '</p>');
221		jQuery(".ph-date-from").val(date_from);
222		return;
223	}
224	jQuery(".ph-date-from").val(date_from);
225	jQuery(".ph-date-to").val(date_to).change(); //trigger .ph-date-to for update the price
226}
227
228jQuery(document).ready(function ($) {
229	//override_deactive_by_charge_by_night();
230	var full_month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
230November", "December"];
231	var date_from = '';
232	var date_to = '';
233	var click = 0;
234	var reched_to = false;
235	var reached_to_flag = 0;
236	var second_selected_date = '';
237	var next_time_source = 'manual';
238	block_unavailable_dates();
239	function block_unavailable_dates() {
240		if (jQuery('#calender_type').val() == 'time') {
241			product_id = jQuery("#phive_product_id").val();
242			start_date = jQuery(".callender-full-date").first().val();
243			var data = {
244				action: 'phive_get_blocked_dates',
245				product_id: product_id,
246				start_date: start_date,
247				asset: $(".input-assets").val(),
248			};
249			// $(".ph-calendar-overlay").show();
250			$.post(phive_booking_ajax.ajaxurl, data, function (res) {
251				// console.log('success');
252				result = jQuery.parseJSON(res);
253				$.each(result, function (key, value) {
254					first_el = $("input[value='" + value + "']").closest("li.ph-calendar-date");
255					first_el.addClass('de-active');
256					first_el.addClass('not-available');
257				});
258				// $(".ph-calendar-overlay").hide();
259			}).fail(function () {
260				// console.log('failed');
261				$(".ph-calendar-overlay").hide();
262			});
263		}
264	}
265
266	$(document).on("change", ".resources_check", function () {
267		val = $(this).is(":checked") ? 'yes' : 'no';
268		$(this).closest("div").find(".phive_book_resources").val(val);
269	})
270
271	$(document).on("change", ".input-person", function (e) {
272		if ($(this).hasClass('input-disabled')) {
273			e.preventDefault();
274
275			$(this).val($(this).attr("last-val")); //Forcefully taking previous value. preventDefault() is not preventing the changes.
276			return;
277		}
278
279		$(this).attr("last-val", $(this).val());
280
281		return;
282	});
283
284	$(document).on("change", ".input-person", function () {
285		$('.participant_count_error').html('');
286		if (parseInt($(this).val()) > parseInt($(this).attr("max"))) {
287			$(this).val($(this).attr("max"));
288			ref_this = '.participant_count_error_' + $(this).attr('rule-key');
289			var message = phive_booking_locale.max_individual_participant;
290
291			pname = $(this).attr('data-name');
292			pmax = parseInt($(this).attr("max"));
293			message = message.replace('%pname', pname);
294			message = message.replace('%pmax', pmax);
295			$(ref_this).html(message);
296
297			$(ref_this).fadeIn('fast', function () {
298				$(ref_this).delay(5000).fadeOut();
299			});
300			return;
301		} else if (parseInt($(this).val()) < parseInt($(this).attr("min"))) {
302			$(this).val($(this).attr("min"));
303			ref_this = '.participant_count_error_' + $(this).attr('rule-key');
304			$(ref_this).html("Minimum number of " + $(this).attr('data-name') + " required is " + parseInt($(this).attr("min")));
305			$(ref_this).fadeIn('fast', function () {
306				$(ref_this).delay(5000).fadeOut();
307			});
308			return;
309		}
310	});
311
312	$(document).on('change', ".shipping-price-related", function (e) {
313		e.stopImmediatePropagation();
314		if ($(this).hasClass('input-disabled')) {
315			e.preventDefault();
316			return;
317		}
318		
319		// to check if minimum number of slots are clicked
320		if($('.selected-date').length > 0)
321		{
322			// console.log('sel');
323			var min_allowed_booking = $("#book_min_allowed_slot").val();
324			if ((min_allowed_booking) && ($("#book_interval_type").val() == 'customer_choosen') && 
325				($('#auto_select_min_block').length && $('#auto_select_min_block').val() != 'yes') )
326			{
327				min_allowed_booking = parseInt(min_allowed_booking);
328				if(min_allowed_booking == 1)
329				{
330					calculate_price();
331				}
332				else if(($('.across_the_day_booking').length && $('.across_the_day_booking').val() != 'yes'))
333				{
334					selected_blocks = parseInt(jQuery(".selected-date").length);
335					book_interval = parseInt(jQuery("#book_interval").val());
336					selected_blocks = selected_blocks/book_interval;
337					// console.log('selected_blocks', selected_blocks);
338					if ( selected_blocks >= min_allowed_booking ) 
339					{
340						calculate_price();
341					}
342				}
343				else
344				{
345					phive_book_to_date = $('input[name=phive_book_to_date]').val();
346					if(phive_book_to_date)
347					{
348						calculate_price();
349					}
350				}
351			}
352			else
353			{
354				calculate_price();
355			}			
356		}
357	})
358
359
360	// placed this code after date click functions after ajax compatibility code change
361
362	// $(document).on("click", ".non-bookable-slot", function () {
363	// 	if ($(this).hasClass('de-active')) {
364	// 		loop_elm = $(this)
365	// 	} else {
366	// 		loop_elm = $(this).nextAll(".de-active:first");
367	// 	}
368	// 	show_not_bookable_message(loop_elm);
369	// })
370
371	function get_formated_date(date) {
372
373		date_obj = new Date(date);
374
375		return { "date": date_obj.getUTCDate(), "month": phive_booking_locale.months[date_obj.getUTCMonth()], "year": date_obj.getUTCFullYear(), };
376	}
377
378	function show_not_bookable_message(loop_elm) {
379		if (loop_elm.length == 0) { //case of last item or no de-active after curent elm.
380			return;
381		}
382
383		from_text = $(loop_elm).text();
384
385		msg_html = "";
386		min_booking = $("#book_min_allowed_slot").val();
387		book_interval = parseInt($("#book_interval").val());
388
389		min_limit = min_booking > 0 ? book_interval * min_booking : book_interval;
390		min_limit -= $('.selected-date').length; //Substract aleready selected dates
391
392		while ((loop_elm.length > 0) && (min_limit > 0)) {
393
394			min_limit--;
395			to_text = $(loop_elm).text();
396			if (msg_html.length > 0) {
397				msg_html = msg_html.replace(" and", ", ");
398				msg_html += " and <b>" + to_text + "</b>";
399			} else {
400				msg_html = "<b>" + to_text + "</b>";
401			}
402
403			loop_elm = min_limit > 0 ? loop_elm.next(".de-active") : false;
404		}
405		msg_html += (from_text == to_text) ? " " + phive_booking_locale.is_not_avail : " " + phive_booking_locale.are_not_avail;
406		$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + msg_html + '</span></p>');
407	}
408
409	$.fn.isAfter = function (sel) {
410		return this.prevAll(sel).length !== 0;
411	}
412	$.fn.isBefore = function (sel) {
413		return this.nextAll(sel).length !== 0;
414	}
415	$('.reset_action').change(function () {
416		resetSelection();
417	});
418	function resetSelection(fullReset) {
419		fullReset = fullReset || 'yes';
420		$date_from_previous_value = date_from;
421		date_from = '';
422		date_to = '';
423		click = 0;
424
425		$(".single_add_to_cart_button").addClass("disabled");
426		$(".selected-date").each(function () {
427			$(this).removeClass("selected-date");
428		});
429		$(".timepicker-selected-date").each(function () {
430			last_sel_date = $(".timepicker-selected-date").last().find('.callender-full-date').val();
431			current_date = $(this).last().find('.callender-full-date').val();
432			if (last_sel_date != current_date) {
433				$(this).removeClass("timepicker-selected-date");
434			}
435		});
436		$ph_date_from_previous_value = $(".ph-date-from").val();
437		$(".ph-date-from").val("");
438		$(".ph-date-to").val("");
439		$('.element_from').val("");
440		$('.element_to').val("");
441
442		// $('.element_from_date').val("");
443		// $('.element_from_time').val("");
444		// $('.element_to_date').val("");
445		// $('.element_to_time').val("");
446		if (fullReset == 'yes') {
447			var previous_info_message = $(".booking-info-wraper").html();
448			$(".booking-info-wraper").html("");
449			if (jQuery('#calender_type').val() == 'month') {
450				display_text = phive_booking_locale.pick_a_month;
451			}
452			else {
453				display_text = phive_booking_locale.Please_Pick_a_Date;
454			}
455			html_text = '<p id="booking_info_text" style="text-align:center;">' + display_text + '</p>';
456			if (!jQuery('.timepicker-selected-date').length) {
457				$(".booking-info-wraper").html(html_text);
458				$(".ph-ul-time").hide();
459			} else {
460				$(".booking-info-wraper").html(previous_info_message);
461			}
462		}
463
464		if ($(".not-startable").length) {
465			$(".not-startable").removeClass("hide-not-startable");
466		}
467
468		$(".ph-calendar-days li").removeClass('can-be-checkout-date');
469	}
470
471	function resetHover() {
472		$(".hover-date").each(function () {
473			$(this).removeClass("hover-date");
474		});
475	}
476	function resetCalender() {
477		if (($('.book_interval_period').val() == 'minute' || $('.book_interval_period').val() == 'hour')) {
478			from = new Date($('.ph-date-from').val());
479			current_date = new Date($('.timepicker-selected-date').find('.callender-full-date').val());
480			// if(from!=current_date)
481			// {
482
483			$('.timepicker-selected-date').click();
484			// setTimeout(function(){ 
485			//  }, 1000);
486			// }
487
488		}
489	}
490	function get_minimum_booking() {
491		min_allowed = $("#book_min_allowed_slot").val();
492		max_booking = $("#book_max_allowed_slot").val();
493
494		min_allowed = min_allowed.length ? parseInt(min_allowed) : 1;
495		min_booking = min_allowed > 1 ? min_allowed + parseInt($("#book_interval").val()) : parseInt($("#book_interval").val());
496		if (max_booking.length && min_booking > max_booking) {
497			min_booking = max_booking;
498		}
499		return min_booking;
500	}
501
502  /**
503  * Make selection to given range
504  * param from: obj, Starting element
505  * param to: obj, Ending lelement
506  */
507	function makeSelection(from, to, prev_days_booking_count) {
508		var from_date_value = $(from).find(".callender-full-date").val();
509		book_interval = parseInt($("#book_interval").val());    //integer, booking interval period.
510		min_limit = $("#book_min_allowed_slot").val();
511		calender_type = jQuery('#calender_type').val();
512
513		if ($("#book_interval_type").val() == 'customer_choosen' && ((jQuery('#auto_select_min_block').length && jQuery('#auto_select_min_block').val() != 'yes') || $('#calendar_design').val() == '3')) {
514			min_limit = '';
515		}
516		// alert(min_limit);
517		max_limit = $("#book_max_allowed_slot").val();
518		booking_start_date = new Date(date_from);
519		booking_end_date = $(to).find(".callender-full-date").val();
520		booking_end_date = new Date(booking_end_date);
521		if ($('#calendar_design').val() == '3' && from_date_value && booking_end_date) {
522			if (new Date(from_date_value) > booking_end_date) {
523				// Check whether selected TO value is before the FROM value -- Only done for design 3 now
524				$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + phive_booking_locale.pick_later_time + '</span></p>');
525				resetSelection();
526				return;
527			}
528		}
529		// min_booking  = get_minimum_booking();
530
531		min_limit = min_limit || 1;
532		max_limit = max_limit || 0;
533		className = 'selected-date';
534
535		if (book_interval > 1) {
536			min_limit = min_limit * book_interval;
537			max_limit = max_limit * book_interval;
538		}
539
540		min_limit = min_limit > 0 ? round_to_next_stop(min_limit, book_interval) : 0;
541		max_limit = max_limit > 0 ? round_to_next_stop(max_limit, book_interval) : 0;
542		i = 1 + prev_days_booking_count;
543
544		elem = from;
545		reched_to = false;
546		while (elem && i < 1500) {
547			if (elem.length == 0) {
548				i = 1500;
549				continue;
550			}
551			if (elem.find('span').length == 0 && calender_type != 'month') {
552				elem = elem.next();
553				continue;
554			}
555			if (to != '' && elem.get(0) == to) {
556				reched_to = true;
557			}
558			if (booking_start_date.getMonth() != booking_end_date.getMonth() && ($('#calender_type').val() != 'time' && $('#calender_type').val() != 'month') && $("#charge_per_night").val() != 'yes') {
559				final_date = $(elem).find(".callender-full-date").val();
560				if (!is_reached_time_period(final_date)) {
561					elem = false;
562					continue;
563				}
564			}
565			if (elem.hasClass("de-active") && !is_overridable_by_charge_per_night(elem)) {
566
567				show_not_bookable_message(elem);
568				resetSelection('no');
569				return false;
570			}
571
572			else if (max_limit > 0 && i >= (max_limit + 1)) {
573				// console.log("max_limit");
574				// select_date( elem );
575				resetSelection();
576				msg_html = phive_booking_locale.max_limit_text;
577				msg_html = msg_html.replace('%max_block', max_limit);
578				$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + msg_html + '</span></p>');
579				// setTimeout(function(){ 
580				//      resetCalender();
581				//     }, 2000);
582				return false;
583				// elem = false;
584			}
585			//Case of first click
586			else if (to == '' && i >= min_limit) {
587				// console.log("min_limit");
588				if (i == min_limit && from.hasClass("not-startable")) {
589					resetSelection();
590					return false;
591				} else {
592					select_date(elem);
593
594					//Override not-startable CSS to allow pick TO date
595					$(".not-startable").each(function () {
596						$(this).addClass('hide-not-startable');
597					})
598					elem = false;
599				}
600			}
601			//Need to complite an interval.
602			else if (reched_to && round_to_next_stop(i, book_interval) == i) {
603				if (booking_start_date.getMonth() != booking_end_date.getMonth() && ($('#calender_type').val() != 'time' && $('#calender_type').val() != 'month')) {
604					final_date = $(elem).find(".callender-full-date").val();
605
606					if((booking_end_date.getMonth()) || (booking_end_date.getMonth() == 0))
607					{
608						var Difference_In_Time = booking_end_date.getTime() - booking_start_date.getTime(); 
609						// To calculate the no. of days between two dates 
610						var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24); 
611						i = Difference_In_Days;
612					}
613
614					if (!is_reached_time_period(final_date)) {
615						elem = false;
616					}
617					else {
618						select_date(elem);
619						elem = elem.next();
620					}
621				}
622				else {
623					select_date(elem);
624					elem = false;
625
626				}
627
628			} else {
629				if (booking_start_date.getMonth() != booking_end_date.getMonth() && ($('#calender_type').val() != 'time' && $('#calender_type').val() != 'month')) {
630					final_date = $(elem).find(".callender-full-date").val();
631
632					if((booking_end_date.getMonth()) || (booking_end_date.getMonth() == 0))
633					{
634						var Difference_In_Time = booking_end_date.getTime() - booking_start_date.getTime(); 
635						// To calculate the no. of days between two dates 
636						var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24); 
637						i = Difference_In_Days;
638					}
639					
640					if (!is_reached_time_period(final_date)) {
641						elem = false;
642					}
643					else {
644						select_date(elem);
645						elem = elem.next();
646					}
647				}
648				else {
649					select_date(elem);
650					elem = elem.next();
651				}
652			}
653			i++;
654		}
655
656		if (!validate_charge_by_night_selections()) {
657			return false;
658		}
659
660		return true;
661	}
662
663
664
665	function select_date(elem, className) {
666		className = className || 'selected-date';
667		if (!elem.hasClass("de-active") || is_overridable_by_charge_per_night(elem)) {
668			elem.addClass(className);
669			return true;
670		}
671		return false;
672	}
673	function is_reached_time_period(to) {
674		if (reched_to == true) {
675			interval = parseInt($("#book_interval").val());
676
677			if (second_selected_date == '') {
678				second_selected_date = to;
679			}
680			start_date = new Date(date_from);
681			end_date = new Date(to);
682			last_date = new Date(second_selected_date);
683			end_date_limit = last_date;
684			end_date_limit.setDate(last_date.getDate() + interval);
685			iterartion = 0;
686			while (start_date <= end_date_limit) {
687				if (iterartion == 1 && $("#charge_per_night").val() == 'yes' && interval != 1) {
688					interval--;
689				}
690				start_date.setDate(start_date.getDate() + interval);
691				iterartion++;
692			}
693			start_date.setDate(start_date.getDate() - interval);
694			if (end_date < start_date) {
695				return true;
696			}
697			else {
698				return false;
699			}
700		}
701		return true;
702	}
703	//check if any de-active date coming in between selected (Case of Charge by night enabled)
704	function validate_charge_by_night_selections() {
705		if ($('#calender_type').val() == 'date' && $("#book_interval_type").val() != 'fixed' && $('#charge_per_night').length && $('#charge_per_night').val() == 'yes') {
706			$(".de-active").each(function () {
707				next_item = $(this).next('.selected-date');
708				//If next item is selected-date and it is not fist selected-date
709				if (next_item.length && !$(".selected-date").first().is(next_item)) {
710					resetSelection();
711					return false;
712				}
713			});
714		}
715		return true;
716	}
717
718	/* Complite an interval */
719	function round_to_next_stop(number, divisor) {
720
721		// To Handle Per Night Charge
722		var second_time_selection_with_per_night = false;
723		if ($("#charge_per_night").val() == 'yes' && jQuery("input[name=phive_book_from_date]").val().length != 0 && parseInt(jQuery(".book_interval").val()) > 0) {
724			second_time_selection_with_per_night = true;
725		}
726
727		if (number > 0) {
728			var result = Math.ceil(number / divisor) * divisor;
729
730			// Handle Enable Per night case for round off for second time selection
731			if (second_time_selection_with_per_night) {
732				var count = 1;  // 1 if the Bookings start in same month and end in same month, else 0
733				// To Handle the Bookings which start in one month and end in next month
734				var elem = jQuery("ul.ph-calendar-days li.ph-calendar-date:nth-child(8)").get(0)
735				if (jQuery("input[name=phive_book_from_date]").val() != undefined && jQuery(elem).find('input[class=callender-full-date]').val() != undefined) {
736					var start_date = new Date(jQuery("input[name=phive_book_from_date]").val());
737					var current_date = new Date(jQuery(elem).find('input[class=callender-full-date]').val());
738					if (current_date.getUTCMonth() > start_date.getUTCMonth() || current_date.getUTCFullYear() > start_date.getUTCFullYear()) count = 0;
739				}
740				if (((divisor - 1) * Math.floor(number / (divisor - 1)) + count) == number) {
741					result = number;
742				}
743			}
744			return result;
745		}
746		else if (number < 0)
747			return Math.floor(number / divisor) * divisor;
748		else
749			return divisor;
750	}
751
752	function override_deactive_by_charge_by_night() {
753		if ($('#calender_type').val() == 'date' && $("#book_interval_type").val() != 'fixed' && $('#charge_per_night').length && $('#charge_per_night').val() == 'yes') {
754			$(".de-active").each(function () {
755				next = $(this).next('.ph-calendar-date');
756				if (!next.hasClass("booking-full") && !next.hasClass("booking-disabled") && !next.hasClass("de-active")) {
757					// $(this).removeClass('booking-full');
758					// $(this).removeClass('booking-disabled');
759					// $(this).removeClass('de-active');
760				}
761			})
762		}
763	}
764
765	function is_overridable_by_charge_per_night(el) {
766
767		if ($('#calender_type').val() == 'date' && $("#book_interval_type").val() != 'fixed' && $('#charge_per_night').length && $('#charge_per_night').val() == 'yes') {
768			prev = el.prev('.ph-calendar-date');
769			if (!prev.hasClass("booking-full") && !prev.hasClass("booking-disabled") && !prev.hasClass("de-active")) {
770				// Override only for TO date
771				if ($(".selected-date").length) {
772					return true;
773				}
774			}
775		}
776		return false;
777	}
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793	function enhance_values_for_design_3() {
794		if ($is_booking_end_date_clicked) {
795			click = 1;
796			// The previous selection was invalid, hence, restore the value of date_from
797			date_from = date_from ? date_from : $date_from_previous_value;
798		}
799		else if ($is_booking_end_time_clicked) {
800			if ($('.ph-date-from').val() == '') {
801				// End Time was opened when previous selection was invalid
802				date_from = date_from ? date_from : $date_from_previous_value;
803				$('.ph-date-from').val($ph_date_from_previous_value);
804			}
805			click = 2;
806		} else if ($is_booking_from_time_clicked) {
807			$is_booking_from_time_clicked = false;
808			click = 2;
809		}
810		$is_booking_end_date_clicked = false;
811	}
812
813
814
815
816
817
818	// Picking a date/time/month from calendar.
819	//  $('.month-picker-wraper,.date-picker-wraper,.time-picker-wraper #ph-calendar-time').on("click", ".ph-calendar-date", function(){
820	$(document).on("click", '.month-picker-wraper .ph-calendar-date,.date-picker-wraper .ph-calendar-date,.time-picker-wraper .ph-ul-time .ph-calendar-date', function () {
821		enhance_values_for_design_3();
822		$(".callender-error-msg").html("&nbsp;");
823
824		second_selected_date = '';
825		//if click on already booked or past date
826		if (!is_overridable_by_charge_per_night($(this)) && ($(this).hasClass("booking-full") || $(this).hasClass("booking-disabled") || $(this).hasClass("de-active"))) {
827			if (jQuery('#calender_type').val() == 'date' || jQuery('#calender_type').val() == 'month') {
828				$('#please_pick_a_date_text').show();
829			}
830			$is_booking_from_time_clicked = false;
831			return;
832		}
833
834
835		//if Fixed range, don't allow to choose second date
836		if ($("#book_interval_type").val() == 'fixed') {
837			if ($(this).hasClass('not-startable')) {
838				return;
839			}
840			resetSelection();
841			$(".single_add_to_cart_button").removeClass("disabled");
842			$(this).addClass("selected-date");
843
844			book_to = $(this);
845			for (var i = parseInt($("#book_interval").val()); i > 1; i--) {
846				book_to = book_to.next().addClass("selected-date");
847				if (book_to.hasClass('de-active') && !is_overridable_by_charge_per_night(book_to)) {
848					resetSelection();
849					return;
850				}
851			};
852
853			if (!validate_charge_by_night_selections()) {
854				return false;
855			}
856
857			if ($('#calendar_design').val() == '3') {
858				if (jQuery('#calender_type').val() == 'date') {
859					from_date = convert_date_to_wp_format($(this).find(".callender-full-date").val(), '');
860					$('.element_from').val(from_date);
861				}
862				else if (jQuery('#calender_type').val() == 'month') {
863
864					from_month = convert_month_to_wp_format($(this).find(".callender-full-date").val());
865					$('.element_from').val(from_month);
866				}
867				else {
868					date_time = $(this).find(".callender-full-date").val();
869					// var [date,time] = date_time.split(' ');
870					var date = date_time.split(' ')[0];
871					var time = date_time.split(' ')[1];
872					time = convert_time_to_wp_format(date_time, '');
873					$('.element_from_time').val(time);
874					$('.ph-calendar-container').hide();
875					$('.please_pick_a_date_text').hide();
876					$('.time-calendar-date-section').show();
877					$('.ph-calendar-container .time-picker').hide();
878				}
879
880				$('.ph-calendar-container').hide();
881			}
882
883			calculate_price();
884			if (jQuery('#calender_type').val() == 'date' || jQuery('#calender_type').val() == 'month') {
885				$('#please_pick_a_date_text').hide();
886			}
887			return;
888		}
889		else if ($("#book_interval_type").val() == 'customer_choosen') {
890			click++;
891			if ($('#calendar_design').val() == '3') {
892				if (click % 2 == 1) {
893					if ($(this).hasClass('not-startable')) {
894						resetSelection();
895						return;
896					}
897					// console.log('jQuery().val(): ', jQuery('#calender_type').val());
898					if (jQuery('#calender_type').val() == 'date') {
899						from_date = convert_date_to_wp_format($(this).find(".callender-full-date").val(), '');
900						// $('.element_to').val(from_date);
901						$('.element_from').val(from_date);
902						$('.element_to').val('');
903						$('.element_to').trigger('click');
904						$('.element_to').focus();
905					}
906					else if (jQuery('#calender_type').val() == 'month') {
907						from_month = convert_month_to_wp_format($(this).find(".callender-full-date").val());
908						$('.element_from').val(from_month);
909						$('.element_to').val('');
910						$('.element_to').trigger('click');
911						$('.element_to').focus();
912					}
913					else {
914						date_time = $(this).find(".callender-full-date").val();
915
916						if ($is_booking_end_time_clicked) {
917							// Customer has selected To Time --- And all fields are filled
918							$(".selected-date").each(function () {
919								$(this).removeClass("selected-date");
920							});
921							book_interval = jQuery(".book_interval").val();
922							var date = date_time.split(' ')[0];
923							var time = convert_time_to_wp_format(date_time, parseInt(book_interval));
924							var to_date = convert_date_to_wp_format(date, '');
925							$('.element_to_date').val(to_date);
926							$('.element_to_time').val(time);
927							// $('.element_to_date').trigger('click');
928							$('.time-calendar-date-section').hide();
929							$('.ph-calendar-container .time-picker').hide();
930							click = 0;
931
932						} else {
933							// var [date,time] = date_time.split(' ');
934							var date = date_time.split(' ')[0];
935							var time = date_time.split(' ')[1];
936							// to_date = convert_date_to_wp_format($(this).find(".callender-full-date").val(), '');
937
938							from_date = convert_date_to_wp_format(date, '');
939							if (!$is_booking_from_time_clicked) {
940								$('.element_from_date').val(from_date);
941							}
942							time = convert_time_to_wp_format(date_time, '');
943							$('.element_from_time').val(time);
944							var across_the_day_booking = jQuery('.across_the_day_booking').val();
945							$('.element_to_date').val('');
946							$('.element_to_time').val('');
947
948							if (across_the_day_booking == 'no') {
949
950								$('.element_to_date').val(from_date);
951								$('.element_to_time').val('');
952								$('.element_to_time').trigger('click');
953								$('.element_to_time').focus();
954								$('.time-calendar-date-section').hide();
955								$('.ph-calendar-container .time-picker').show();
956							}
957							else {
958								if ($('.element_from_date').val() == $('.element_to_date').val()) {
959
960									$('.element_to_time').val('');
961									$('.element_to_time').trigger('click');
962									$('.element_to_time').focus();
963									$('.time-calendar-date-section').hide();
964									$('.ph-calendar-container .time-picker').show();
965								}
966								else {
967
968									$('.element_to_date').val('');
969									$('.element_to_time').val('');
970									$('.element_to_date').trigger('click');
971									$('.element_to_date').focus();
972									$('.time-calendar-date-section').show();
973									$('.ph-calendar-container .time-picker').hide();
974								}
975							}
976
977
978
979						}
980
981					}
982
983					// alert($(this).find(".callender-full-date").val());
984
985
986
987				}
988				else if (click % 2 == 0) {
989					if (jQuery('#calender_type').val() == 'date') {
990						book_interval = jQuery(".book_interval").val();
991						if (parseInt(book_interval) == 1) {
992							to_date = convert_date_to_wp_format($(this).find(".callender-full-date").val(), '');
993						}
994						else {
995							to_date = convert_date_to_wp_format($(this).find(".callender-full-date").val(), parseInt(book_interval));
996						}
997
998						// to_date
999						$('.element_to').val(to_date);
1000						$('.ph-calendar-container').hide();
1001						$('.please_pick_a_date_text').hide();
1002					}
1003					else if (jQuery('#calender_type').val() == 'month') {
1004						to_month = convert_month_to_wp_format($(this).find(".callender-full-date").val());
1005						$('.element_to').val(to_month);
1006						$('.ph-calendar-container').hide();
1007						$('.please_pick_a_date_text').hide();
1008					}
1009					else {
1010						date_time = $(this).find(".callender-full-date").val();
1011						book_interval = jQuery(".book_interval").val();
1012						// var [date,time] = date_time.split(' ');
1013						var date = date_time.split(' ')[0];
1014						var time = date_time.split(' ')[1];
1015						to_date = convert_date_to_wp_format(date, '');
1016						$('.element_to_date').val(to_date);
1017
1018						time = convert_time_to_wp_format(date_time, parseInt(book_interval));
1019						$('.element_to_time').val(time);
1020
1021						$('.ph-calendar-container').hide();
1022						// $('.time-calendar-date-section').show();
1023						$('.ph-calendar-container .time-picker').hide();
1024					}
1025
1026
1027				}
1028			}
1029
1030			//Reset all selection on third click
1031			if (!$is_booking_end_time_clicked && click % 3 == 0) {
1032				resetSelection();
1033
1034				$(this).trigger('click');
1035				// setTimeout(function(){ 
1036				//      resetCalender();
1037				//     }, 1000);
1038				return;
1039			}
1040
1041			//if selected a date_to, which is past to date_from
1042			if (date_from != '' && date_to == '' && $(this).isBefore(".selected-date")) {
1043				// resetSelection()
1044				if (jQuery('#calender_type').val() == 'date' || jQuery('#calender_type').val() == 'month') {
1045					$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + phive_booking_locale.pick_later_date + '</span></p>');
1046					// $('#please_pick_a_date_text').show();
1047					resetSelection();
1048				}
1049				else {
1050					$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + phive_booking_locale.pick_later_time + '</span></p>');
1051					resetSelection();
1052				}
1053				$is_booking_from_time_clicked = false;
1054				return;
1055			}
1056
1057			// first_el = $( ".selected-date:first" );
1058
1059			//if click for FROM date // Odd click
1060			if (!$is_booking_end_time_clicked && ($is_booking_from_time_clicked || date_from == "" || click % 2 != 0 || $("#book_interval_type").val() != 'customer_choosen')) {
1061				date_from = $(this).find(".callender-full-date").val();
1062				$(this).addClass("selected-date");
1063				handle_min_booking = true;
1064				slected = makeSelection($(this), '', 0);
1065				
1066				// Checkout date hovering and display
1067				first = $(".ph-calendar-days .selected-date").first();
1068				first_index = $(".ph-calendar-days li").index(first);
1069				current_index = $(".ph-calendar-days  li").index(this);
1070				added_class = false;
1071
1072				next = $(first).next();
1073				next_index = $(".ph-calendar-days li").index(next);
1074
1075				if ($(next).hasClass('de-active') || $(next).hasClass('not-available'))
1076				{
1077					if (is_overridable_by_charge_per_night($(next))) 
1078					{
1079						$(next).addClass("can-be-checkout-date");
1080						added_class = true;
1081					}
1082				}	
1083				if (added_class == false) 
1084				{
1085					while (parseInt(next_index) != -1) {
1086						next = $(next).next();
1087						next_index = $(".ph-calendar-days li").index(next);
1088						if ($(next).hasClass('de-active') || $(next).hasClass('not-available'))
1089						{
1090							// console.log(this);
1091							if (is_overridable_by_charge_per_night($(next))) 
1092							{
1093								$(next).addClass("can-be-checkout-date");
1094								break;
1095							}
1096						}
1097					}	
1098				}
1099				// Checkout date hovering and display end
1100
1101				var calendar_type = jQuery('#calender_type').val();
1102				var across_the_day_booking = jQuery('.across_the_day_booking').val();
1103				if (calendar_type == 'time' && across_the_day_booking != 'no') {
1104					if (jQuery('#auto_select_min_block').val() == 'yes' && $('#calendar_design').val() != '3') {
1105						handle_min_booking = handle_min_bookings();
1106					}
1107
1108				}
1109
1110				if (slected && (calendar_type == 'date' || calendar_type == 'month')) {
1111					$('#please_pick_a_date_text').hide();
1112				}
1113				if (slected && handle_min_booking) {
1114					if (((jQuery('#auto_select_min_block').length && jQuery('#auto_select_min_block').val() != 'yes') && jQuery('#book_min_allowed_slot').val() != '' && jQuery('#book_min_allowed_slot').val() != 1 || $('#calendar_design').val() == '3')) {
1115						date_from = jQuery(".ph-date-from").val();
1116						if (!date_from) {
1117							date_from = jQuery(".selected-date").first().find(".callender-full-date").val();
1118						}
1119						jQuery(".ph-date-from").val(date_from);
1120						if (jQuery('#calender_type').val() == 'month') {
1121							jQuery(".booking-info-wraper").html('<p id="booking_info_text"  style="text-align:center;">' + phive_booking_locale.pick_a_end_month + '</p>');
1122						}
1123						else if (jQuery('#calender_type').val() == 'time') {
1124							jQuery(".booking-info-wraper").html('<p id="booking_info_text"  style="text-align:center;">' + phive_booking_locale.pick_a_end_time + '</p>');
1125						}
1126						else {
1127							jQuery(".booking-info-wraper").html('<p id="booking_info_text"  style="text-align:center;">' + phive_booking_locale.pick_an_end_date + '</p>');
1128						}
1129						// calculate_price();
1130					}
1131					else {
1132						if (jQuery('#calender_type').val() == 'date' || jQuery('#calender_type').val() == 'month') {
1133							calculate_price();
1134						}
1135						else {
1136							slected = check_min_max(slected, 0);
1137							if (slected) {
1138								calculate_price();
1139							}
1140						}
1141						// calculate_price();
1142					}
1143				}
1144			}
1145			//click for TO date
1146			else {
1147				// if ($is_booking_end_time_clicked) {
1148				// 	click = 2;
1149				// }
1150
1151				$(".ph-calendar-days li").removeClass('can-be-checkout-date');	// Checkout date hovering and display
1152
1153				$is_booking_end_time_clicked = false;
1154				first_el = $("input[value='" + date_from + "']").closest("li.ph-calendar-date");
1155				var booked_no_of_interval_count = 0;
1156				if (!first_el.length) {
1157					first_el = $("li.ph-calendar-date").first();
1158					// alert(start_date_and_time);
1159					if ($('#calender_type').val() == 'time') {
1160						//            var start_date_and_time = jQuery("#ph-calendar-time .callender-full-date").val();
1161						var start_date_and_time = jQuery(".ph-ul-time .callender-full-date").val();
1162						if (typeof start_date_and_time != 'undefined' && start_date_and_time != "") {
1163							if (date_from.substr(0, date_from.indexOf(' ')) != start_date_and_time.substr(0, start_date_and_time.indexOf(' '))) {
1164								booked_no_of_interval_count = ph_booked_no_of_interval_count();
1165								first_el = $("input[value='" + start_date_and_time + "']").closest("li");
1166							}
1167						}
1168					}
1169					else if ($('#calender_type').val() == 'date') {
1170						i = 0;
1171						while (first_el && i < 30) {
1172							if (first_el.find('span').length == 0) {
1173								first_el = first_el.next();
1174								continue;
1175							}
1176							break;
1177							i++;
1178						}
1179
1180						//            var start_date_and_time = jQuery("#ph-calendar-days .callender-full-date").val();
1181						var start_date_and_time = jQuery(".ph-ul-date .callender-full-date").val();
1182						// alert(start_date_and_time);
1183						if (typeof start_date_and_time != 'undefined' && start_date_and_time != "") {
1184							if (date_from != start_date_and_time) {
1185								booked_no_of_interval_count = ph_booked_no_of_interval_count_days();
1186								first_el = $("input[value='" + start_date_and_time + "']").closest("li");
1187							}
1188						}
1189					}
1190				}
1191				slected = makeSelection(first_el, this, booked_no_of_interval_count);
1192				// if ((jQuery('#auto_select_min_block').length && jQuery('#auto_select_min_block').val() != 'yes') || $('#calendar_design').val() == '3') {
1193					// should be called all the time when two date is clicked
1194					slected = check_min_max(slected, booked_no_of_interval_count);
1195				// }
1196				if (slected) {
1197					calculate_price();
1198				}
1199				else {
1200					if (jQuery('#calender_type').val() == 'date' || jQuery('#calender_type').val() == 'month') {
1201						$('#please_pick_a_date_text').show();
1202					}
1203				}
1204			}
1205		}
1206		$is_booking_from_time_clicked = false;
1207
1208
1209	});
1210
1211
1212	$(document).on("click", ".non-bookable-slot", function () {
1213		if ($(this).hasClass('de-active')) {
1214			loop_elm = $(this)
1215		} else {
1216			loop_elm = $(this).nextAll(".de-active:first");
1217		}
1218		show_not_bookable_message(loop_elm);
1219	})
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234	function check_min_max(return_value, booked_no_of_interval_count) {
1235		jQuery(".single_add_to_cart_button").addClass("disabled");
1236		date_from = jQuery(".ph-date-from").val();
1237
1238		if (!date_from) {
1239			date_from = jQuery(".selected-date").first().find(".callender-full-date").val();
1240		}
1241		if (!date_from) {
1242			return return_value;
1243		}
1244
1245		date_to = jQuery(".selected-date").last().find(".callender-full-date").val();
1246		if (date_from && date_to) {
1247			if (new Date(date_from) > new Date(date_to)) {
1248				// Check whether selected TO value is before the FROM value
1249				$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + phive_booking_locale.pick_later_time + '</span></p>');
1250				return false;
1251			}
1252		}
1253
1254		if (jQuery("#book_interval_type").val() != 'fixed') {
1255			book_interval = parseInt(jQuery("#book_interval").val());     //integer, booking interval period.
1256			min_limit = jQuery("#book_min_allowed_slot").val();
1257			length = jQuery(".selected-date").length;
1258			length = parseInt(length) + parseInt(booked_no_of_interval_count) * parseInt(book_interval);
1259
1260			// min limit not working with charge per night
1261			check_min_limit = parseInt(min_limit) * parseInt(book_interval);
1262			if ($("#charge_per_night").val() == 'yes') 
1263			{
1264				date_from_obj = new Date(date_from);
1265				date_from_month = date_from_obj.getMonth();
1266				// console.log("date_from_month : ",date_from_month);
1267				
1268				date_to_obj = new Date(date_to);
1269				date_to_month = date_to_obj.getMonth();
1270				// console.log("date_to_month : ",date_to_month);
1271
1272				if(date_from_month != date_to_month)
1273				{
1274					check_min_limit = (parseInt(min_limit) * parseInt(book_interval)) - 1;
1275				}
1276			}
1277
1278			if (parseInt(length) < check_min_limit) {
1279				resetSelection();
1280
1281				pick_min_date = phive_booking_locale.pick_min_date;
1282				pick_min_date = pick_min_date.replace('%d', min_limit);
1283				jQuery(".booking-info-wraper").html('<p id="booking_info_text"><span class="not-available-msg">' + pick_min_date + '</span></p>');
1284				return false;
1285			}
1286		}
1287		return return_value;
1288		// jQuery(".ph-date-from").val(date_from);
1289		// jQuery(".ph-date-to").val( date_to ).change(); //trigger .ph-date-to for update the price
1290	}
1291	function ph_booked_no_of_interval_count_days() {
1292		var booking_count = 0;
1293		var booking_from_date_time = jQuery(".ph-date-from").val();
1294		var booked = 0;
1295		month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1296		if (typeof booking_from_date_time == 'string') {
1297			var start_date_obj = new Date(booking_from_date_time);
1298			no_of_days_in_month = month[start_date_obj.getMonth()];
1299			year = start_date_obj.getFullYear();
1300			if (start_date_obj.getMonth() == 1 && ((year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0))) {
1301				no_of_days_in_month = 29;
1302			}
1303			// booking_from_date_time will be in the form '2020-06-30'. new Date('2020-06-30') will consider the input date as UTC
1304			// and output the corresponding Local time for it. Hence, to get the DATE, use getUTCDate()
1305			var booked = no_of_days_in_month - parseInt(start_date_obj.getUTCDate());
1306			booking_count = parseInt(booked);
1307		}
1308		// alert(booking_count);
1309		if ($("#charge_per_night").val() != 'yes') {
1310			booking_count++;
1311		}
1312		return booking_count;
1313	}
1314	// Handle Minimum Bookings in case of end of the day or month
1315	function handle_min_bookings() {
1316		var min_allowed_booking = jQuery("#book_min_allowed_slot").val();
1317		if (min_allowed_booking <= 1) {
1318			return true;
1319		}
1320		jQuery(".single_add_to_cart_button").addClass("disabled");
1321		date_from = jQuery(".ph-date-from").val();
1322		if (!date_from) {
1323			date_from = jQuery(".selected-date").first().find(".callender-full-date").val();
1324			jQuery(".ph-date-from").val(date_from);
1325		}
1326		if (!date_from) {
1327			return false;
1328		}
1329		date_to = jQuery(".selected-date").last().find(".callender-full-date").val();
1330
1331		var date_to_obj = new Date(date_to);
1332		var calendar_type = jQuery('#calender_type').val();
1333		var book_interval = parseInt(jQuery(".book_interval").val());
1334		var end_date_obj = new Date(date_from);
1335		var date_to_select = "";
1336		var status = true;
1337		if (calendar_type == 'date') {
1338			var to_modify = book_interval * min_allowed_booking - 1;
1339			end_date_obj.setDate(end_date_obj.getDate() + to_modify);
1340			if (end_date_obj > date_to_obj) {
1341				status = false;
1342				jQuery(".ph-next").click()
1343				setTimeout(function () {
1344					date_to_obj.setDate(01);
1345					while (date_to_obj <= end_date_obj) {
1346						var year = date_to_obj.getFullYear();
1347						var month = ("0" + (date_to_obj.getMonth() + 1)).slice(-2);
1348						var date = ("0" + date_to_obj.getDate()).slice(-2);
1349						date_to_select = year + '-' + month + '-' + date;
1350						var elem = jQuery("input[value=" + date_to_select + "]").closest("li")
1351						status = select_date(elem, "selected-date");
1352						if (!status) {
1353							msg_html = elem.find("span").html() + " " + phive_booking_locale.is_not_avail;
1354							$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + msg_html + '</span></p>');
1355							return false;
1356						}
1357						date_to_obj.setDate(date_to_obj.getDate() + 1)
1358					}
1359					calculate_price();
1360				}, 2000)
1361			}
1362		}
1363		else if (calendar_type == 'time') {
1364			var interval_period = jQuery(".book_interval_period").val();    // hour, day etc
1365			var to_modify = book_interval * (min_allowed_booking - 1);
1366			if (interval_period == "hour") {
1367				to_modify = to_modify * 60;
1368				book_interval = book_interval * 60;
1369			}
1370			end_date_obj.setMinutes(end_date_obj.getMinutes() + to_modify);
1371
1372			if (end_date_obj > date_to_obj) {
1373				status = false;
1374				next_time_source = 'automatic';
1375				jQuery(".ph-next-day-time").click();
1376				setTimeout(function () {
1377					while (end_date_obj > date_to_obj) {
1378						date_to_obj.setMinutes(date_to_obj.getMinutes() + book_interval);
1379						var year = date_to_obj.getFullYear();
1380						var month = ("0" + (date_to_obj.getMonth() + 1)).slice(-2);
1381						var date = ("0" + date_to_obj.getDate()).slice(-2);
1382						var hour = ("0" + date_to_obj.getHours()).slice(-2);
1383						var minute = ("0" + date_to_obj.getMinutes()).slice(-2);
1384						date_to_select = year + '-' + month + '-' + date + ' ' + hour + ':' + minute;
1385						var elem = jQuery("input[value='" + date_to_select + "']").closest("li")
1386						status = select_date(elem, "selected-date");
1387						if (!status) {
1388							msg_html = elem.find("span").html() + " " + phive_booking_locale.is_not_avail;
1389							$('.booking-info-wraper').html('<p id="booking_info_text"><span class="not-available-msg">' + msg_html + '</span></p>');
1390							return false;
1391						}
1392					}
1393					calculate_price();
1394				}, 2000);
1395			}
1396		}
1397		return status;
1398	}
1399
1400	function ph_booked_no_of_interval_count() {
1401		var booking_count = 0;
1402		var booking_from_date_time = jQuery(".ph-date-from").val();
1403		if (typeof booking_from_date_time == 'string') {
1404			var booking_start_from = booking_from_date_time.split(' ')[1];
1405			var status = false;
1406			//      jQuery("ul#ph-calendar-time li").each( function(){
1407			jQuery("ul.ph-ul-time li").each(function () {
1408				if (status) {
1409					booking_count++;
1410				}
1411				else {
1412					if ($(this).find('input').val().split(' ')[1] == booking_start_from && !status) {
1413						status = true;
1414						booking_count++;
1415					}
1416				}
1417			});
1418			var start_date_obj = new Date(booking_from_date_time.split(' ')[0]);
1419			//      var end_date_obj  = new Date(jQuery("ul#ph-calendar-time li").last().find('input').val().split(' ')[0]);
1420			var end_date_obj = new Date(jQuery("ul.ph-ul-time li").last().find('input').val().split(' ')[0]);
1421			var date_diff = end_date_obj.getTime() - start_date_obj.getTime();
1422			if (date_diff != 1) {
1423				//        booking_count = booking_count + ( ( date_diff / (24 * 3600 * 1000) - 1) * jQuery("ul#ph-calendar-time li").length);
1424				booking_count = booking_count + ((date_diff / (24 * 3600 * 1000) - 1) * jQuery("ul.ph-ul-time li").length);
1425			}
1426		}
1427		// alert(booking_count);
1428		return booking_count;
1429	}
1430
1431	//time picker month calendar
1432
1433	//  $('.time-picker-wraper #ph-calendar-days').on("click", ".ph-calendar-date", function(){
1434	$(document).on("click", ".time-picker-wraper .ph-ul-date .ph-calendar-date", function (e) {
1435		if ($(this).hasClass('not-startable') || $(this).hasClass("de-active")) {
1436			e.preventDefault();
1437			return;
1438		}
1439		$('.ph-calendar-date').removeClass("timepicker-selected-date");
1440
1441		var across_the_day_booking = jQuery('.across_the_day_booking').val();
1442		if (across_the_day_booking == 'no')
1443			resetSelection();
1444		$(this).addClass("timepicker-selected-date");
1445		return;
1446	});
1447
1448	$(document).on("hover", ".date-picker-wraper .ph-calendar-date,.time-picker-wraper .ph-calendar-date", function (event) {
1449		if (event.type == "mouseenter") {
1450			if ($(this).hasClass("selected-date")
1451				|| $(this).hasClass("booking-disabled")
1452				|| $(this).hasClass("de-active")) {
1453				return
1454			}
1455			if ($("#book_interval_type").val() == 'fixed') {
1456				$(this).addClass("hover-date");
1457
1458				book_to = $(this);
1459				for (var i = parseInt($("#book_interval").val()); i > 1; i--) {
1460					book_to = book_to.next().addClass("hover-date");
1461					if (book_to.hasClass('de-active')) {
1462						resetHover();
1463						return;
1464					}
1465				};
1466			} else {
1467
1468			}
1469		} else if (event.type == "mouseleave") {
1470			resetHover();
1471		}
1472	});
1473
1474	$(document).on("click", ".date-picker-wraper .ph-next,.time-picker-wraper .ph-next", function () {
1475
1476		product_id = jQuery("#phive_product_id").val();
1477		month = jQuery(".callender-month").val();
1478		year = jQuery(".callender-year").val();
1479		calender_type = jQuery("#calender_type").val();
1480		if (calender_type == 'time') {
1481			calendar_for = 'time-picker';
1482			loding_ico_url = $("#plugin_dir_url").val() + "/resources/icons/loading2.gif";
1483			//      $("#ph-calendar-time").html('<img class="loading-ico" align="middle" src="'+loding_ico_url+'">');
1484			$(".ph-ul-time").html('<img class="loading-ico" align="middle" src="' + loding_ico_url + '">');
1485		}
1486		else if (calender_type == 'date') {
1487			calendar_for = 'date-picker';
1488		} else {
1489			calendar_for = '';
1490		}
1491		if ($("#book_interval_type").val() == 'fixed') {
1492			resetSelection();
1493		}
1494		// Case of 'To' date on next month, if de-active found after selection need to rest 'From'
1495		if ($('.de-active').last().isAfter('.selected-date')) {
1496			resetSelection();
1497		}
1498		var data = {
1499			action: 'phive_get_callender_next_month',
1500			// security : phive_booking_locale.security,
1501			product_id: product_id,
1502			month: month,
1503			year: year,
1504			calendar_for: calendar_for,
1505			asset: $(".input-assets").val(),
1506		};
1507
1508		//    $("#ph-calendar-overlay").show();
1509		$(".ph-calendar-overlay").show();
1510		$.post(phive_booking_locale.ajaxurl, data, function (res) {
1511			//      $("#ph-calendar-overlay").hide();
1512			$(".ph-calendar-overlay").hide();
1513			if (calender_type == 'time') {
1514				//        $("#ph-calendar-time").html( '<center>'+phive_booking_locale.Please_Pick_a_Date+'</center>');
1515				// $(".ph-ul-time").html( '<center>'+phive_booking_locale.Please_Pick_a_Date+'</center>');
1516				$(".ph-ul-time").html('');
1517				$(".ph-ul-time").hide();
1518
1519				html_text = '<p id="booking_info_text" style="text-align:center;">' + phive_booking_locale.Please_Pick_a_Date + '</p>';
1520				$(".booking-info-wraper").html(html_text);
1521			}
1522			else if (calender_type == 'date ' && !$(".ph-date-from").val()) {
1523				// $('#please_pick_a_date_text').show();
1524
1525				html_text = '<p id="booking_info_text" style="text-align:center;">' + phive_booking_locale.Please_Pick_a_Date + '</p>';
1526				$(".booking-info-wraper").html(html_text);
1527			}
1528			result = jQuery.parseJSON(res);
1529
1530			//      $("#ph-calendar-days").html(result.days);
1531			$(".ph-ul-date").html(result.days);
1532
1533			jQuery(".callender-month").val(result.month).change()
1534			jQuery(".callender-year").val(result.year)
1535
1536			jQuery(".span-month").html(phive_booking_locale.months[full_month.indexOf(result.month)])
1537			jQuery(".span-year").html(result.year)
1538
1539			if (!$(".ph-date-from").val()) {
1540				$(".single_add_to_cart_button").addClass("disabled");
1541			}
1542			block_unavailable_dates();
1543			//override_deactive_by_charge_by_night();
1544		});
1545	})
1546
1547	$(document).on("click", ".date-picker-wraper .ph-prev,.time-picker-wraper .ph-prev", function () {
1548
1549		resetSelection() // The plugin is not supports to select backward.
1550		product_id = jQuery("#phive_product_id").val();
1551		month = jQuery(".callender-month").val();
1552		year = jQuery(".callender-year").val();
1553		calender_type = jQuery("#calender_type").val();
1554		if (calender_type == 'time') {
1555			calendar_for = 'time-picker';
1556			loding_ico_url = $("#plugin_dir_url").val() + "/resources/icons/loading2.gif";
1557			//      $("#ph-calendar-time").html('<img class="loading-ico" align="middle" src="'+loding_ico_url+'">');
1558			$(".ph-ul-time").html('<img class="loading-ico" align="middle" src="' + loding_ico_url + '">');
1559		}
1560		else if (calender_type == 'date') {
1561			calendar_for = 'date-picker';
1562		} else {
1563			calendar_for = '';
1564		}
1565		var data = {
1566			action: 'phive_get_callender_prev_month',
1567			// security : phive_booking_locale.security,
1568			product_id: product_id,
1569			month: month,
1570			year: year,
1571			calendar_for: calendar_for,
1572			asset: $(".input-assets").val(),
1573		};
1574
1575		//    $("#ph-calendar-overlay").show();
1576		$(".ph-calendar-overlay").show();
1577
1578		$.post(phive_booking_locale.ajaxurl, data, function (res) {
1579			//      $("#ph-calendar-overlay").hide();
1580			$(".ph-calendar-overlay").hide();
1581			if (calender_type == 'time') {
1582				//        $("#ph-calendar-time").html( '<center>'+phive_booking_locale.Please_Pick_a_Date+'</center>');
1583				// $(".ph-ul-time").html( '<center>'+phive_booking_locale.Please_Pick_a_Date+'</center>');
1584				$(".ph-ul-time").html('');
1585				$(".ph-ul-time").hide();
1586
1587				html_text = '<p id="booking_info_text" style="text-align:center;">' + phive_booking_locale.Please_Pick_a_Date + '</p>';
1588				$(".booking-info-wraper").html(html_text);
1589			}
1590			else if (calender_type == 'date') {
1591				// $('#please_pick_a_date_text').show();
1592
1593				html_text = '<p id="booking_info_text" style="text-align:center;">' + phive_booking_locale.Please_Pick_a_Date + '</p>';
1594				$(".booking-info-wraper").html(html_text);
1595			}
1596
1597			result = jQuery.parseJSON(res);
1598
1599			//      $("#ph-calendar-days").html(result.days);
1600			$(".ph-ul-date").html(result.days);
1601
1602			jQuery(".callender-month").val(result.month).change()
1603			jQuery(".callender-year").val(result.year)
1604
1605			jQuery(".span-month").html(phive_booking_locale.months[full_month.indexOf(result.month)])
1606			jQuery(".span-year").html(result.year)
1607			block_unavailable_dates();
1608			//override_deactive_by_charge_by_night();
1609
1610		});
1611	})
1612	function check_not_available_slots() {
1613		first = $('.time-picker .selected-date');
1614		next = $(first).next();
1615		next_index = $(".ph-calendar-days li").index(next);
1616		while (parseInt(next_index) != -1) {
1617			if ($(next).hasClass('de-active') || $(next).hasClass('not-available'))
1618				show_not_bookable_message(next);
1619			next = $(next).next();
1620			next_index = $(".ph-calendar-days li").index(next);
1621
1622		}
1623		return true;
1624	}
1625  /**
1626   * For Getting Next Day Time
1627   */
1628	$(document).on("click", ".date-picker-wraper .ph-next-day-time,.time-picker-wraper .ph-next-day-time", function () {
1629		//    $("#ph-calendar-time #ph-calendar-overlay").show();
1630		$(".ph-ul-time").show();
1631		$(".ph-ul-time .ph-calendar-overlay").show();
1632		var product_id = jQuery("#phive_product_id").val();
1633		var date = jQuery("#ph-booking-time-for-the-date").val();
1634		var date_obj = new Date(date);
1635		var next_day_date_obj = new Date(date_obj.getTime() + 86400000);
1636		var next_day_date = next_day_date_obj.getFullYear() + '-' + (next_day_date_obj.getMonth() + 1) + '-' + next_day_date_obj.getDate();
1637		var selected_date = jQuery('.ph-date-from').val();
1638		// if(selected_date!='' )
1639		// {
1640		//  check_not_available_slots();
1641		// }
1642		//    jQuery('#ph-calendar-days li').each(function(){
1643		jQuery('.ph-ul-date li').each(function () {
1644			jQuery(this).removeClass('timepicker-selected-date');
1645			sel_date = new Date(jQuery(this).find('.callender-full-date').val());
1646			next_prev_date = new Date(next_day_date);
1647			first_date = new Date(selected_date);
1648			if (parseInt(sel_date.getDate()) == parseInt(next_prev_date.getDate()) && parseInt(sel_date.getMonth()) == parseInt(next_prev_date.getMonth()) && parseInt(sel_date.getFullYear()) == parseInt(next_prev_date.getFullYear())) {
1649				jQuery(this).addClass('timepicker-selected-date');
1650			}
1651			else if (selected_date != '') {
1652				first_date = new Date(selected_date.split(" ")[0]);
1653				if (first_date <= sel_date && sel_date <= next_prev_date) {
1654					jQuery(this).addClass('timepicker-selected-date');
1655				}
1656			}
1657
1658		});
1659		var data = {
1660			action: 'phive_get_booked_datas_of_date',
1661			product_id: product_id,
1662			date: next_day_date,
1663			type: 'time-picker',
1664			asset: $(".input-assets").val(),
1665			selected_date: selected_date,
1666		};
1667		jQuery(".ph-calendar-date").prop('disabled', true);
1668		$.post(phive_booking_locale.ajaxurl, data, function (res) {
1669			jQuery(".ph-calendar-date").prop('disabled', false);
1670			//      $("#ph-calendar-time").html(res).trigger('change');
1671			$(".ph-ul-time").html(res);
1672			$("#ph-calendar-time").trigger('change');
1673			$(this).addClass("timepicker-selected-date");
1674			if (next_time_source == 'manual') {
1675				check_blocked_slots();  //trigger only when manually moving to next day time slots
1676			}
1677
1678
1679		});
1680	})
1681
1682  /**
1683   * For Getting Previous Day Time
1684   */
1685	$(document).on("click", ".date-picker-wraper .ph-prev-day-time,.time-picker-wraper .ph-prev-day-time", function () {
1686
1687		//    $("#ph-calendar-time #ph-calendar-overlay").show();
1688		$(".ph-ul-time").show();
1689		$(".ph-ul-time .ph-calendar-overlay").show();
1690		var product_id = jQuery("#phive_product_id").val();
1691		var date = jQuery("#ph-booking-time-for-the-date").val();
1692		var date_obj = new Date(date);
1693		var prev_day_date_obj = new Date(date_obj.getTime() - 86400000);
1694		var prev_day_date = prev_day_date_obj.getFullYear() + '-' + (prev_day_date_obj.getMonth() + 1) + '-' + prev_day_date_obj.getDate();
1695		//    jQuery('#ph-calendar-days li').each(function(){
1696		jQuery('.ph-ul-date li').each(function () {
1697			jQuery(this).removeClass('timepicker-selected-date');
1698			sel_date = new Date(jQuery(this).find('.callender-full-date').val());
1699			next_prev_date = new Date(prev_day_date);
1700			if (parseInt(sel_date.getDate()) == parseInt(next_prev_date.getDate()) && parseInt(sel_date.getMonth()) == parseInt(next_prev_date.getMonth()) && parseInt(sel_date.getFullYear()) == parseInt(next_prev_date.getFullYear())) {
1701				jQuery(this).addClass('timepicker-selected-date');
1702			}
1703		});
1704		var data = {
1705			action: 'phive_get_booked_datas_of_date',
1706			product_id: product_id,
1707			date: prev_day_date,
1708			type: 'time-picker',
1709			asset: $(".input-assets").val(),
1710		};
1711		jQuery(".ph-calendar-date").prop('disabled', true);
1712		$.post(phive_booking_locale.ajaxurl, data, function (res) {
1713			jQuery(".ph-calendar-date").prop('disabled', false);
1714			//      $("#ph-calendar-time").html(res).trigger('change');
1715			$(".ph-ul-time").html(res);
1716			$("#ph-calendar-time").trigger('change');
1717			$(this).addClass("timepicker-selected-date");
1718		});
1719	})
1720	function check_blocked_slots() {
1721		//    jQuery('#ph-calendar-time li').each(function(){
1722		jQuery('.ph-ul-time li').each(function () {
1723			if (jQuery(this).hasClass('de-active') || jQuery(this).hasClass('not-available') || jQuery(this).hasClass('booking-full') || jQuery(this).hasClass('booking-disabled')) {
1724				resetSelection();
1725			}
1726		});
1727	}
1728	$(document).on("change", ".input-assets", function () {
1729		$(".timepicker-selected-date").removeClass("timepicker-selected-date");
1730		//    $("#ph-calendar-time").html('');
1731		$(".ph-ul-time").html('');
1732		product_id = jQuery("#phive_product_id").val();
1733		month = jQuery(".callender-month").val();
1734		year = jQuery(".callender-year").val();
1735		ph_load_calendar_values()
1736	})
1737
1738	function ph_load_calendar_values() {
1739		calender_type = jQuery("#calender_type").val();
1740		if (calender_type == 'time') {
1741			calendar_for = 'time-picker';
1742		}
1743		else if (calender_type == 'date') {
1744			calendar_for = 'date-picker';
1745		} else {
1746			calendar_for = '';
1747		}
1748
1749		if (calender_type == 'date') {
1750			if ($("#book_interval_type").val() == 'fixed') {
1751				resetSelection();
1752			}
1753			// Case of 'To' date on next month, if de-active found after selection need to rest 'From'
1754			if ($('.de-active').last().isAfter('.selected-date')) {
1755				resetSelection();
1756			}
1757		}
1758		var data = {
1759			action: 'phive_reload_callender',
1760			// security : phive_booking_locale.security,
1761			product_id: product_id,
1762			month: month,
1763			year: year,
1764			asset: $(".input-assets").val(),
1765			calendar_for: calendar_for,
1766		};
1767		//    $("#ph-calendar-overlay").show();
1768		$(".ph-calendar-overlay").show();
1769		$.post(phive_booking_locale.ajaxurl, data, function (res) {
1770			//      $("#ph-calendar-overlay").hide();
1771			$(".ph-calendar-overlay").hide();
1772
1773			result = jQuery.parseJSON(res);
1774
1775			if (calender_type == 'time') {
1776				//        $("#ph-calendar-time").html(result.time_slots);
1777				$(".ph-ul-time").html(result.time_slots);
1778				$(".ph-ul-time").html('');
1779			}
1780
1781			if (jQuery('#calender_type').val() == 'month') {
1782				display_text = phive_booking_locale.pick_a_month;
1783			}
1784			else {
1785				display_text = phive_booking_locale.Please_Pick_a_Date;
1786			}
1787			html_text = '<p id="booking_info_text" style="text-align:center;">' + display_text + '</p>';
1788			if (!jQuery('.timepicker-selected-date').length) {
1789				$(".booking-info-wraper").html(html_text);
1790				$(".ph-ul-time").hide();
1791			}
1792			// $("#ph-calendar-days").html(result.days).change();     
1793			//added .change() so that on change of calender days, auto selection of available dates is possible after assets change   
1794
1795			$(".ph-ul-date").html(result.days);
1796			$("#ph-calendar-days").change();
1797
1798			jQuery(".callender-month").val(result.month)
1799			jQuery(".callender-year").val(result.year)
1800
1801			jQuery(".span-month").html(phive_booking_locale.months[full_month.indexOf(result.month)])
1802			jQuery(".span-year").html(result.year)
1803
1804			if (!$(".ph-date-from").val()) {
1805				$(".single_add_to_cart_button").addClass("disabled");
1806			}
1807			//override_deactive_by_charge_by_night();
1808		});
1809	}
1810
1811
1812	$(document).on('mouseover', '.ph-calendar-date', function (ev) {
1813		// alert($(ev.target).find('.callender-full-date').val());
1814		calender_type = $('#book_interval_type').val();
1815		// alert(click);
1816		if (calender_type == 'fixed')
1817			return true;
1818		else if (calender_type == 'customer_choosen') {
1819			from = $('.ph-date-from').val();
1820			$(".ph-calendar-days li").removeClass('mouse_hover');
1821			$(".ph-calendar-days li").removeClass('mouse_hover_past');
1822			if (from != '' && click != 2 && !$is_booking_from_time_clicked) {
1823				// alert($( ".ph-calendar-days  li" ).index( this ));
1824				first = $(".ph-calendar-days .selected-date").first();
1825				first_index = $(".ph-calendar-days li").index(first);
1826				current_index = $(".ph-calendar-days  li").index(this);
1827				// alert($( ".ph-calendar-days li").index( first ));
1828				if (first_index != -1 && parseInt(first_index) < parseInt(current_index)) // for next days
1829				{
1830					// next=$( ".ph-calendar-days .selected-date:eq( "+(parseInt(first_index)+1)+" )" );
1831					next = $(first).next();
1832					next_index = $(".ph-calendar-days li").index(next);
1833
1834					if ($(next).hasClass('de-active') || $(next).hasClass('not-available'))
1835					{
1836						// console.log(this);
1837						if ((is_overridable_by_charge_per_night($(next))) && (this == next[0])) 
1838						{
1839							// console.log(is_overridable_by_charge_per_night($(next)));
1840							$(next).addClass("mouse_hover");
1841						}
1842					}
1843					else
1844					{
1845						$(next).addClass("mouse_hover");	
1846					}
1847					while (parseInt(next_index) != -1 && parseInt(next_index) < parseInt(current_index)) {
1848						next = $(next).next();
1849						next_index = $(".ph-calendar-days li").index(next);
1850						if ($(next).hasClass('de-active') || $(next).hasClass('not-available'))
1851							break;
1852						$(next).addClass("mouse_hover");
1853					}
1854				}
1855				else if (first_index != -1 && parseInt(first_index) > parseInt(current_index)) // if hovering past days
1856				{
1857					if (!$(this).hasClass('selected-date')) {
1858						$(this).addClass("mouse_hover_past");
1859
1860						// $( ".ph-calendar-days li" ).each(function() {
1861						//  $(this).removeClass('mouse_hover');
1862						// });
1863					}
1864					else {
1865						last = $(".ph-calendar-days li").last();
1866						last_index = $(".ph-calendar-days li").index(last);
1867						next = $(first).next();
1868						next_index = $(".ph-calendar-days li").index(next);
1869						while (parseInt(next_index) != -1 && parseInt(next_index) < parseInt(last_index)) {
1870							$(next).addClass("mouse_hover");
1871							next = $(next).next();
1872							next_index = $(".ph-calendar-days li").index(next);
1873							if ($(next).hasClass('de-active') || $(next).hasClass('not-available'))
1874								break;
1875							$(next).addClass("mouse_hover");
1876						}
1877					}
1878
1879				}
1880			}
1881		}
1882
1883	});
1884	$(document).on('click', '.ph-calendar-date', function () {
1885		$(".ph-calendar-days li").removeClass('mouse_hover');
1886		$(".ph-calendar-days li").removeClass('mouse_hover_past');
1887
1888	});
1889	$(document).on('mouseleave', '.ph-calendar-date', function () {
1890		$(".ph-calendar-days li").removeClass('mouse_hover');
1891		$(".ph-calendar-days li").removeClass('mouse_hover_past');
1892
1893	});
1894
1895	function convert_month_to_wp_format(date) {
1896		var wp_date_format = jQuery("#ph_booking_wp_date_format").val();
1897		date = ph_convert_month_to_wp_date_format(wp_date_format, date);
1898		return date;
1899	}
1900	function convert_date_to_wp_format(date, interval) {
1901		var wp_date_format = jQuery("#ph_booking_wp_date_format").val();
1902		date = ph_convert_date_to_wp_date_format(wp_date_format, date, interval);
1903		return date;
1904	}
1905	function timezoneOffset(date_string) {
1906		// passing default parameter value doesn't work in safari
1907		if (date_string === undefined || !date_string) {
1908			date_string = '';
1909		}
1910		let date = new Date(date_string),
1911			timezoneOffset = date.getTimezoneOffset(),
1912			hours = ('00' + Math.floor(Math.abs(timezoneOffset / 60))).slice(-2),
1913			minutes = ('00' + Math.abs(timezoneOffset % 60)).slice(-2),
1914			string = (timezoneOffset >= 0 ? '-' : '+') + hours + ':' + minutes;
1915		return string;
1916	}
1917	function convert_time_to_wp_format(date, interval) {
1918		var wp_time_format = jQuery("#ph_booking_wp_time_format").val();
1919		var across_the_day_booking = jQuery('.across_the_day_booking').val();
1920
1921		date_time = date.split(' ');
1922		date = date_time[0] + 'T' + date_time[1] + timezoneOffset(date_time[0] + 'T' + date_time[1]);
1923		date_obj = new Date(date);
1924
1925		if ($('.book_interval_period').val() == 'hour' && interval != '') {
1926			date_obj = new Date(date_obj.getTime() + ((interval) * 3600000));
1927
1928			if (across_the_day_booking != 'no') {
1929				date = ("0" + date_obj.getDate()).slice(-2);
1930				month = date_obj.getMonth();
1931				month = ("0" + (month + 1)).slice(-2);
1932
1933				year = date_obj.getFullYear();
1934				next_date = year + '-' + month + '-' + date;
1935				next_date = convert_date_to_wp_format(next_date, '');
1936				$('.element_to_date').val(next_date);
1937			}
1938		}
1939		else if ($('.book_interval_period').val() == 'minute' && interval != '') {
1940			date_obj = new Date(date_obj.getTime() + ((interval) * 60000));
1941			if (across_the_day_booking != 'no') {
1942				date = ("0" + date_obj.getDate()).slice(-2);
1943				month = date_obj.getMonth();
1944				month = ("0" + (month + 1)).slice(-2);
1945
1946				year = date_obj.getFullYear();
1947				next_date = year + '-' + month + '-' + date;
1948				next_date = convert_date_to_wp_format(next_date, '');
1949				$('.element_to_date').val(next_date);
1950			}
1951
1952		}
1953		var hours = date_obj.getHours();
1954		var ampm = hours >= 12 ? 'pm' : 'am';
1955		time = ph_convert_time_to_wp_time_format(wp_time_format, date_obj, ampm);
1956		return time;
1957	}
1958	function ph_convert_month_to_wp_date_format(wp_format, date) {
1959
1960		months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
1960November", "December"];
1961		new_date = new Date(date);
1962
1963		switch (wp_format) {
1964			case 'F j, Y': display_date = months[new_date.getMonth()] + ', ' + new_date.getFullYear();
1965				break;
1966			case 'Y-m-d': display_date = new_date.getFullYear() + '-' + (new_date.getMonth() + 1);
1967				break;
1968			case 'm/d/Y': display_date = (new_date.getMonth() + 1) + '/' + new_date.getFullYear();
1969				break;
1970			case 'd/m/Y': display_date = (new_date.getMonth() + 1) + '/' + new_date.getFullYear();
1971				break;
1972			default: display_date = new_date.getFullYear() + '-' + (new_date.getMonth() + 1);
1973				break;
1974
1975		}
1976		return display_date;
1977	}
1978	function ph_convert_date_to_wp_date_format(wp_format, date, interval) {
1979		months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
1980		new_date = new Date(date + 'T' + '00:00' + timezoneOffset(date));
1981		if (interval != '') {
1982			from_date = new Date($('.ph-date-from').val());
1983			days_between = Date.daysBetween(from_date, new_date);
1984			// console.log(interval);
1985			// console.log(from_date);
1986			// console.log(date);
1987			// console.log(days_between);
1988			// console.log(new_date);
1989			// console.log(parseInt(days_between));
1990			days_between = parseInt(days_between) + 1;
1991			no_of_blocks = (days_between) / interval;
1992			if (days_between % interval != 0)
1993				no_of_blocks += 1;
1994			days_to_add = (parseInt(no_of_blocks) * interval) - 1;
1995			new_date = new Date(from_date.getTime() + (parseInt(days_to_add) * 86400000));
1996		}
1997		month = ("0" + (new_date.getMonth() + 1)).slice(-2);
1998		date = ("0" + new_date.getDate()).slice(-2);
1999		switch (wp_format) {
2000			case 'j F Y': display_date = date + ' ' + phive_booking_locale.months[new_date.getMonth()] + ' ' + new_date.getFullYear();
2001				break;
2002			case 'F j, Y': display_date = phive_booking_locale.months[new_date.getMonth()] + ' ' + date + ', ' + new_date.getFullYear();
2003				break;
2004			case 'Y-m-d': display_date = new_date.getFullYear() + '-' + month + '-' + date;
2005				break;
2006			case 'm/d/Y': display_date = month + '/' + date + '/' + new_date.getFullYear();
2007				break;
2008			case 'd/m/Y': display_date = date + '/' + month + '/' + new_date.getFullYear();
2009				break;
2010			default: display_date = new_date.getFullYear() + '-' + month + '-' + date;
2011				break;
2012
2013		}
2014		return display_date;
2015	}
2016	Date.daysBetween = function (date1, date2) {
2017		//Get 1 day in milliseconds
2018		var one_day = 1000 * 60 * 60 * 24;
2019
2020		// Convert both dates to milliseconds
2021		var date1_ms = date1.getTime();
2022		var date2_ms = date2.getTime();
2023
2024		// Calculate the difference in milliseconds
2025		var difference_ms = date2_ms - date1_ms;
2026
2027		// Convert back to days and return
2028		return Math.round(difference_ms / one_day);
2029	}
2030	function ph_convert_time_to_wp_time_format(wp_format, date, am_pm) {
2031		var hours = date.getHours();
2032		var minutes = date.getMinutes();
2033		wp_format = wp_format + "";
2034		switch (wp_format) {
2035			case "g:i a":
2036				hours = hours % 12;
2037				hours = hours ? hours : 12; // the hour '0' should be '12'
2038				minutes = minutes < 10 ? '0' + minutes : minutes;
2039				display_time = hours + ':' + minutes + ' ' + am_pm.toLowerCase();
2040				break;
2041			case "g:i A":
2042				hours = hours % 12;
2043				hours = hours ? hours : 12; // the hour '0' should be '12'
2044				minutes = minutes < 10 ? '0' + minutes : minutes;
2045				display_time = hours + ':' + minutes + ' ' + am_pm.toUpperCase();
2046				break;
2047			case "H:i":
2048				hours = hours.toString().padStart(2, 0);
2049				minutes = minutes.toString().padStart(2, 0);
2050				display_time = hours + ':' + minutes;
2051				break;
2052			case "G \\h i \\m\\i\\n":
2053				minutes = minutes < 10 ? '0' + minutes : minutes;
2054				display_time = hours + ' h ' + minutes + ' min';
2055				break;
2056			default:
2057				hours = hours % 12;
2058				hours = hours ? hours : 12; // the hour '0' should be '12'
2059				minutes = minutes < 10 ? '0' + minutes : minutes;
2060				display_time = hours + ':' + minutes + ' ' + am_pm.toUpperCase();
2061				break;
2062
2063		}
2064		return display_time;
2065	}
2066	$('.phive_book_assets').change(function () {
2067		// if($('#calendar_design').val()=='3')
2068		{
2069
2070			$(".ph-date-from").val("");
2071			$(".ph-date-to").val("");
2072			$('.element_from').val("");
2073			$('.element_to').val("");
2074			$('.element_from_date').val("");
2075			$('.element_from_time').val("");
2076			$('.element_to_date').val("");
2077			$('.element_to_time').val("");
2078			resetSelection();
2079		}
2080	});
2081})
2082
2083// Set the height of dates in date Calender
2084jQuery(window).on('load', function () {
2085	var display_capacity = jQuery("#ph_display_booking_capacity").val();
2086	var calender_type = jQuery("#calender_type").val();
2087
2088	if (display_capacity != 'yes' || calender_type == 'time')
2089		jQuery("li.ph-calendar-date").css("min-height", "0");
2090});
2091
2092// Set the height of times in Time period Calender
2093jQuery(document).ajaxComplete(function () {
2094	var display_capacity = jQuery("#ph_display_booking_capacity").val();
2095	var calender_type = jQuery("#calender_type").val();
2096	if (calender_type == 'time' && display_capacity != 'yes')
2097		jQuery(".time-picker .ph-calendar-days li").css("min-height", "0");
2098});
2099

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.