if (typeof(LG_MODUL) != "undefined" && LG_MODUL !== null) {
	var LG_MODUL_OLD = LG_MODUL;
}
var LG_MODUL = new Array('cus_booking', 0, 1);
var PICKUP_LOCATION_TIMEZONE = 0;
var STOP_LOCATIONS = {};
var STOPOVER_COUNT = 0;
const MAX_STOPOVER = 10;

if (typeof(JSON_stringify) == 'undefined') {
	function JSON_stringify(s, emit_unicode) {
		var json = JSON.stringify(s);
		var result = emit_unicode ? json : json.replace(/[\u007f-\uffff]/g, function(c) {
			return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
		});
		result = result.replace('&', "%26");
		return result;
	}
}
if (typeof(trackRequestError) == 'undefined') {
	function trackRequestError(rq_token, step, data, type, info) {
		if (typeof(type) == 'undefined') {
			type = 2;
		}
		if (typeof(info) == 'undefined') {
			info = '';
		}
		if (typeof(data) == 'undefined') {
			return false;
		}
		var currd = new Date();
		var rndx = currd.getTime() + "_" + Math.floor(Math.random() * 1345646);
		var xrul = _GURL + '/system/ajax/ajax.track_rq.php';
		if (info != '') {
			info += ' ';
		}
		info += "(LC)";
		$.ajax(xrul + '?rndx=' + rndx, {
			type: 'GET',
			data: 'step=' + step + '&rq_token=' + rq_token + '&data=' + encodeURIComponent(data) + '&info=' + info + '&type=' + type,
			success: function(transport) {}
		});
	}
}
var lcdrqf = {
	dropoff_ok: -1,
	pickup_ok: -1,
	sel_currency: '',
	sel_order: 1,
	tp1: null,
	tp2: null,
	ord_price: null,
	ord_rating: null,
	dispo: false,
	dispo_h: 0,
	poz_left: 0,
	wrapper_poz: 0,
	pu_lat: 0,
	pu_lon: 0,
	pu_iso: '',
	do_lat: 0,
	do_lon: 0,
	do_iso: '',
	id_carcat: 0,
	last_pickup_address: "",
	last_pickup_lat: 0,
	last_pickup_lon: 0,
	akt_pickup_address: "",
	akt_dropoff_lat: 0,
	akt_dropoff_lon: 0,
	last_dropoff_lat: 0,
	last_dropoff_lon: 0,
	date: 0,
	do_country: "",
	pu_country: "",
	do_route: "",
	do_city: "",
	pu_city: "",
	pu_route: "",
	administrative_area_level_1: "",
	street_number: "",
	rq_token: 0,
	cat_id: 0,
	do_zip: "",
	pu_zip: "",
	pu_changed: 0,
	do_changed: 0,
	pu_time_h: '-1',
	pu_time_m: '-1',
	pu_time_date: '',
	ajax_check_1: 0,
	ajax_check_2: 0,
	pu_right_now: 0,
	id_maincat: -1,
	do_formatted_address: '',
	pu_formatted_address: ''
};
var componentForm = {
	street_number: 'short_name',
	route: 'long_name',
	locality: 'long_name',
	administrative_area_level_1: 'short_name',
	country: 'long_name',
	country_iso: 'short_name',
	postal_code: 'short_name',
	city: 'long_name',
	zip: 'long_name',
	formatted_address: "long_name"
};

function toFixed(p) {
	p = "0" + p;
	p = p.replace(" ", "");
	p = parseFloat(Math.round(p * 100) / 100).toFixed(2);
	return p;
}

function changeOrder(type) {
	type = type.value;
	lcdrqf.sel_order = type;
	if (type == 0) {
		drawTp2(0);
	} else {
		drawTp2(1);
	}
}

function ubsev(bewid) {
	btxt = document.getElementById("rewievcnt_" + bewid).innerHTML;
	btxt = btxt.replace(/<br>/gi, '\n');
	btxt = btxt.trim();
	window.open("http://www.google.com/translate_t?langpair=auto|" + _DLNG.substring(0, 2) + "&text=" + escape(btxt), "_blank");
}

function showReviews(fid, fid2) {
	if (typeof(fid2) == 'undefined') {
		fid2 = 0;
	}
	$.ajax(_GURL + '/system/ajax/ajax.get_reviews.php', {
		type: 'POST',
		timeout: 10000,
		dataType: 'json',
		data: 'id_firma=' + fid + '&fid2=' + fid2,
		success: function(transport) {
			if (typeof(LG_MODUL) != "undefined" && LG_MODUL !== null) {
				var LG_MODUL_OLD = LG_MODUL;
			}
			LG_MODUL = new Array('cus_booking', 0, 1);
			block_screen_bg2("");
			var c = '<div style="height: 90%;">';
			c += '<div style="background-color: #e0dedb; margin-bottom: 20px; padding: 15px; font-size: 24px;">';
			c += '<span style="">' + transport.firma.title + '</span>';
			c += '<span style="float: right; padding-right: 20px;">';
			c += '<span style="font-weight: bold; padding-right: 50px; ">' + transport.c_name.toUpperCase() + ' / ' + transport.l_name.toUpperCase() + '</span>';
			c += LG('Partner since').toUpperCase() + ': <span style="font-weight: bold;">' + transport.firma.dt_added + '</span></span>';
			c += '</div>';
			if (transport.reviews.length == 0) {
				c += '<div style="text-align: center;">' + LG("No reviews for the company yet.") + '</div>';
			} else {
				c += transport.reviewsHTML;
			}
			c += '</div>';
			$('#reviews_window_content').html(c);
			$('#reviews_window').fadeIn();
			$('div#feedbacks_div').height($('div#reviews_window').height() - 220);
			LG_MODUL = LG_MODUL_OLD;
		}
	});
}

function check_reset() {
	akt_pickup_lon = lcdrqf.pu_lon;
	akt_pickup_lat = lcdrqf.pu_lat;
	akt_dropoff_lon = lcdrqf.do_lon;
	akt_dropoff_lat = lcdrqf.do_lat;
	if (akt_pickup_lon != lcdrqf.last_pickup_lon) {
		$(".result_container").html('');
		$("#list_results").html('');
	} else if (akt_pickup_lat != lcdrqf.last_pickup_lat) {
		$(".result_container").html('');
		$("#list_results").html('');
	} else if (akt_dropoff_lon != lcdrqf.last_dropoff_lon) {
		$(".result_container").html('');
		$("#list_results").html('');
	} else if (akt_dropoff_lat != lcdrqf.last_dropoff_lat) {
		$(".result_container").html('');
		$("#list_results").html('');
	}
	$('#order_settings').hide();
}

function setBookingDatas(address_details, id) {
	if (typeof(address_details["id_maincat"]) != 'undefined') {
		lcdrqf.id_maincat = parseInt(address_details["id_maincat"], 10);
	}
	if (id == 'lcdrqf_pickup_str') {
		if (typeof(address_details["pu_time_h"]) !== 'undefined') {
			lcdrqf.pu_time_h = address_details["pu_time_h"];
			$('#lcdrqf_hour_select').val(lcdrqf.pu_time_h);
		}
		if (typeof(address_details["pu_time_m"]) !== 'undefined') {
			lcdrqf.pu_time_m = address_details["pu_time_m"];
			$('#lcdrqf_min_select').val(lcdrqf.pu_time_m);
		}
		if (typeof(address_details["pu_time_date"]) == 'undefined') {
			address_details["pu_time_date"] = '';
		}
		if (typeof(address_details["pu_time_date"]) != '') {
			lcdrqf.pu_time_date = address_details["pu_time_date"];
			if (address_details["pu_right_now"] != 0) {
				$("#lcdrqf_right_now_input").addClass("lcdrqf_time_input_changed");
			}
			if ($("#lcdrqf_right_now_input").hasClass("lcdrqf_time_input_changed")) {
				$("#lcdrqf_date_input, .lcdrqf_select_time").addClass("disable");
			} else {
				$("#lcdrqf_date_input, .lcdrqf_select_time").removeClass("disable");
			}
		}
		if (address_details["dispo"] == true) {
			lcdrqf.dispo = true;
		} else {
			lcdrqf.dispo = false;
		}
		if (lcdrqf.dispo) {
			if ((lcdrqf.dispo_h == 0)) {
				lcdrqf.dispo_h = address_details["r_dispo_h"];
			}
			$("#lcdrqf_not_dispo_input").removeClass("lcdrqf_dispo_input_changed");
			$("#lcdrqf_dispo_input").addClass("lcdrqf_dispo_input_changed");
			$("#lcdrqf_dispo_h_div").show();
			$("#lcdrqf_dispo_input").addClass("lcdrqf_dispo_input_changed");
			$("#lcdrqf_dropoff_img, #dropoff_star, #lcdrqf_dropoff_str").hide();
			$('#lcdrqf_dispo_h>option[value="' + lcdrqf.dispo_h + '"]').prop('selected', true);
		}
		if (address_details["asap"] == 1) {
			$("#lcdrqf_right_now_input").addClass("lcdrqf_time_input_changed");
			$("#lcdrqf_date_input, #lcdrqf_hour_picker").addClass("disable");
		}
		lcdrqf.pu_zip = address_details["pu_zip"];
		lcdrqf.pu_changed = 1;
		lcdrqf.pu_country = address_details["pu_country"];
		lcdrqf.pu_city = address_details["pu_city"];
		lcdrqf.pu_lat = address_details["pu_lat"];
		lcdrqf.pu_lon = address_details["pu_lon"];
		lcdrqf.pu_iso = address_details["pu_iso"];
		lcdrqf.pu_address = address_details["pu_address"];
		lcdrqf.pu_location = address_details["pu_location"];
		lcdrqf.pu_country_iso = address_details["pu_iso"];
		lcdrqf.pu_route = address_details["pu_route"];
		lcdrqf.pu_street_number = address_details["pu_street_number"];
	} else {
		lcdrqf.do_zip = address_details["do_zip"];
		lcdrqf.do_changed = 1;
		lcdrqf.do_country = address_details["do_country"];
		lcdrqf.do_city = address_details["do_city"];
		lcdrqf.do_lat = address_details["do_lat"];
		lcdrqf.do_lon = address_details["do_lon"];
		lcdrqf.do_iso = address_details["do_iso"];
		lcdrqf.do_address = address_details["do_address"];
		lcdrqf.do_location = address_details["do_location"];
		lcdrqf.do_country_iso = address_details["do_iso"];
		lcdrqf.do_route = address_details["do_route"];
		lcdrqf.do_street_number = address_details["do_street_number"];
	}
	if (id == 'lcdrqf_pickup_str') {
		if (typeof(lcdrqf.pu_administrative_area_level_1) == "undefined") {
			lcdrqf.pu_administrative_area_level_1 = "";
		}
		if (typeof(lcdrqf.pu_route) == "undefined") {
			lcdrqf.pu_route = "";
		}
		if (typeof(lcdrqf.pu_street_number) == "undefined") {
			lcdrqf.pu_street_number = "";
		}
		if (typeof(lcdrqf.pu_address) == "undefined") {
			lcdrqf.pu_address = "";
		}
		if (typeof(lcdrqf.pu_location) == "undefined") {
			lcdrqf.pu_location = "";
		}
		if (typeof(lcdrqf.pu_city) == "undefined") {
			lcdrqf.pu_city = "";
		}
		if (lcdrqf.pu_location == lcdrqf.pu_city) {
			lcdrqf.pu_location = "";
		}
		if (lcdrqf.pu_address == lcdrqf.pu_city) {
			lcdrqf.pu_address = "";
		}
		if (typeof(lcdrqf.pu_zip) == "undefined") {
			lcdrqf.pu_zip = "";
		}
	} else if (id == 'lcdrqf_dropoff_str') {
		if (typeof(lcdrqf.do_administrative_area_level_1) == "undefined") {
			lcdrqf.do_administrative_area_level_1 = "";
		}
		if (typeof(lcdrqf.do_route) == "undefined") {
			lcdrqf.do_route = "";
		}
		if (typeof(lcdrqf.do_street_number) == "undefined") {
			lcdrqf.do_street_number = "";
		}
		if (typeof(lcdrqf.do_address) == "undefined") {
			lcdrqf.do_address = "";
		}
		if (typeof(lcdrqf.do_location) == "undefined") {
			lcdrqf.do_location = "";
		}
		if (typeof(lcdrqf.do_city) == "undefined") {
			lcdrqf.do_city = "";
		}
		if (lcdrqf.do_location == lcdrqf.do_city) {
			lcdrqf.do_location = "";
		}
		if (lcdrqf.do_address == lcdrqf.do_city) {
			lcdrqf.do_address = "";
		}
		if (typeof(lcdrqf.do_zip) == "undefined") {
			lcdrqf.do_zip = "";
		}
	}
	if (id == 'lcdrqf_pickup_str') {
		formatted_address = '';
		if (lcdrqf.pu_location != "" && lcdrqf.pu_location !== undefined) {
			formatted_address += " " + lcdrqf.pu_location;
		} else {
			formatted_address += "";
		}
		if (lcdrqf.pu_address != "" && lcdrqf.pu_address !== undefined) {
			formatted_address += lcdrqf.pu_address
		} else {
			formatted_address += "";
		}
		if (lcdrqf.pu_street_number != "" && lcdrqf.pu_street_number !== undefined && lcdrqf.pu_address != lcdrqf.pu_street_number) {
			formatted_address += " " + lcdrqf.pu_street_number
		} else {
			formatted_address += "";
		}
		if (lcdrqf.pu_route != "" && lcdrqf.pu_route !== undefined) {
			formatted_address += " " + lcdrqf.pu_route
		} else {
			formatted_address += "";
		}
		if (lcdrqf.pu_city != "" && lcdrqf.pu_city !== undefined) {
			formatted_address += ", " + lcdrqf.pu_city
		} else {
			formatted_address += "";
		}
		if (lcdrqf.pu_zip != "" && lcdrqf.pu_zip !== undefined) {
			formatted_address += ", " + lcdrqf.pu_zip
		} else {
			formatted_address += "";
		}
		if (lcdrqf.pu_country != "" && lcdrqf.pu_country !== undefined) {
			formatted_address += ", " + lcdrqf.pu_country
		} else {
			formatted_address += "";
		}
		if (formatted_address) {
			$("#lcdrqf_pickup_str").val(formatted_address);
		}
		lcdrqf.pu_formatted_address = formatted_address;
	}
	if (id == 'lcdrqf_dropoff_str') {
		formatted_address = '';
		if (lcdrqf.do_location != "" && lcdrqf.do_location !== undefined) {
			formatted_address += " " + lcdrqf.do_location;
		} else {
			formatted_address += "";
		}
		if (lcdrqf.do_address != "" && lcdrqf.do_address !== undefined) {
			formatted_address += lcdrqf.do_address;
		} else {
			formatted_address += "";
		}
		if (lcdrqf.do_street_number != "" && lcdrqf.do_address != lcdrqf.do_street_number && lcdrqf.do_street_number !== undefined) {
			formatted_address += " " + lcdrqf.do_street_number;
		} else {
			formatted_address += "";
		}
		if (lcdrqf.do_route != "" && lcdrqf.do_route !== undefined) {
			formatted_address += " " + lcdrqf.do_route;
		} else {
			formatted_address += "";
		}
		if (lcdrqf.do_city != "" && lcdrqf.do_city !== undefined) {
			formatted_address += ", " + lcdrqf.do_city;
		} else {
			formatted_address += "";
		}
		if (lcdrqf.do_zip != "" && lcdrqf.do_zip !== undefined) {
			formatted_address += ", " + lcdrqf.do_zip;
		} else {
			formatted_address += "";
		}
		if (lcdrqf.do_country != "" && lcdrqf.do_country !== undefined) {
			formatted_address += ", " + lcdrqf.do_country;
		} else {
			formatted_address += "";
		}
		if (formatted_address) {
			$("#lcdrqf_dropoff_str").val(formatted_address);
		}
		lcdrqf.do_formatted_address = formatted_address;
	}
	if (!lcdrqf.pu_right_now) {
		$('#lcdrqf_hour_select>option[value="' + lcdrqf.pu_time_h + '"]').prop('selected', true);
		$('#lcdrqf_min_select>option[value="' + lcdrqf.pu_time_m + '"]').prop('selected', true);
		if (lcdrqf.date != "0") {
			$('#lcdrqf_date_input').val(lcdrqf.date);
			$('#lcdrqf_date_input_actual').val(lcdrqf.date);
		}
	} else {
		if (lcdrqf.date != "0") {
			$('#lcdrqf_date_input_actual').val(lcdrqf.date);
			setTimeout(function() {
				$('#lcdrqf_date_input').datepicker('setDate', lcdrqf.date);
			}, 10);
		}
	}
	check_reset();
}

function check_address(id) {
	if (id == "pu") {
		lcdrqf.pickup_ok = true;
		if (typeof(lcdrqf.pu_address) == "undefined") {
			lcdrqf.pickup_ok = false;
		}
		if (typeof(lcdrqf.pu_location) == "undefined") {
			lcdrqf.pickup_ok = false;
		}
		if (lcdrqf.pu_location == lcdrqf.pu_city) {
			lcdrqf.pickup_ok = false;
		}
		if (typeof(lcdrqf.pu_zip) == "undefined") {
			lcdrqf.pickup_ok = false;
		}
		return lcdrqf.pickup_ok;
	} else if (id == "do") {
		lcdrqf.dropoff_ok = true;
		if (typeof(lcdrqf.do_address) == "undefined") {
			lcdrqf.dropoff_ok = false;
		}
		if (typeof(lcdrqf.do_location) == "undefined") {
			lcdrqf.dropoff_ok = false;
		}
		if (lcdrqf.do_location == lcdrqf.do_city) {
			lcdrqf.dropoff_ok = false;
		}
		if (typeof(lcdrqf.do_zip) == "undefined") {
			lcdrqf.dropoff_ok = false;
		}
		return lcdrqf.dropoff_ok;
	}
}
var add_pu = 0;
var add_do = 0;

function initialize_addr(id, lat_id, lon_id) {
	var input = document.getElementById(id);
	var address_details = {};
	var autocomplete = new google.maps.places.Autocomplete(input);
	if (typeof(initialize_addr2) == 'function') {
		initialize_addr2(id, lat_id, lon_id);
	}
	google.maps.event.addListener(autocomplete, 'place_changed', function() {
        
		place = autocomplete.getPlace();
		address_details = {};
		if (!place.geometry) {
			return;
		} else {
            if (id.includes("stopover-row")) {
				var gps_lat = place.geometry.location.lat();
				var gps_lon = place.geometry.location.lng();
				delete place.utc_offset
				STOP_LOCATIONS[id].place = {
					coordinates: {
						latitude: gps_lat,
						longitude: gps_lon
					},
					address_components: place.address_components,
					formatted_address: place.formatted,
					utc_offset_minutes: place.utc_offset_minutes,
					name: place.name,
					place_id: place.place_id,
					plus_code: place.plus_code
				};
			}
            
			var gps_lat = place.geometry.location.lat();
			var gps_lon = place.geometry.location.lng();
			var isocode = place.address_components[place.address_components.length - 1].short_name;
			for (i = 0; i < place.address_components.length; i++) {
				temp = place.address_components[i];
				if ((temp.types[0] == "country") && (temp.types[1] == "political")) {
					isocode = temp.short_name;
					country = temp.long_name;
					for (var i = 0; i < place.address_components.length; i++) {
						var addressType = place.address_components[i].types[0];
						if (componentForm[addressType]) {
							address_details[addressType] = place.address_components[i][componentForm[addressType]];
						}
					}
				}
			}
			if ((typeof(address_details.locality) == "undefined") || (address_details.locality == '')) {
				geocoder = new google.maps.Geocoder();
				var latlng = new google.maps.LatLng(gps_lat, gps_lon);
				geocoder.geocode({
					'latLng': latlng
				}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						var r = -1;
						if (typeof(results[1]) != "undefined") {
							r = 1;
						} else {
							if (typeof(results[0]) != "undefined") {
								r = 0;
							}
						}
						r = 1;
						if (r > -1) {
							var place = results[r];
							for (var i = 0; i < place.address_components.length; i++) {
								var addressType = place.address_components[i].types[0];
								if (addressType == "locality") {
									address_details[addressType] = place.address_components[i][componentForm[addressType]];
								}
							}
						}
						if (id == 'lcdrqf_pickup_str') {
							lcdrqf.pu_city = address_details.locality;
						} else {
							lcdrqf.do_city = address_details.locality;
						}
					}
				});
			}

            if (id.includes("stopover-row")) {
				let city = "";

				if (place.address_components[0].types[0] == "locality") {
					city = place.address_components[0].long_name;
				} else {
					city = address_details["locality"];
				}

				STOP_LOCATIONS[id].address = buildAddress([place.name, place.vicinity, address_details["street_number"], address_details["route"], city, address_details["postal_code"], address_details["country"]]);	
			} else {
                if (id == 'lcdrqf_pickup_str') {
                    lcdrqf.pu_zip = '';
                    try {
                        lcdrqf.pu_zip = place.address_components[2].long_name;
                    } catch (e) {}
                    lcdrqf.pu_changed = 1;
                    lcdrqf.pu_country = address_details.country;
                    lcdrqf.pu_route = address_details["route"];
                    if (place.address_components[0].types[0] == "locality") {
                        lcdrqf.pu_city = place.address_components[0].long_name;
                    } else {
                        lcdrqf.pu_city = address_details.locality;
                    }
                    lcdrqf.pu_administrative_area_level_1 = address_details["administrative_area_level_1"];
                    lcdrqf.pu_street_number = address_details["street_number"];
                    lcdrqf.pu_zip = address_details["postal_code"];
                    lcdrqf.pu_country_iso = address_details["country_iso"];
                    lcdrqf.pu_lat = gps_lat;
                    lcdrqf.pu_lon = gps_lon;
                    lcdrqf.pu_iso = isocode;
                    lcdrqf.pu_address = place.vicinity;
                    lcdrqf.pu_location = place.name;
                    lcdrqf.pickup_ok = -1;

                    if (place.utc_offset_minutes) {
                        PICKUP_LOCATION_TIMEZONE = place.utc_offset_minutes
                    }
                } else {
                    lcdrqf.do_zip = '';
                    try {
                        lcdrqf.do_zip = place.address_components[2].long_name;
                    } catch (e) {}
                    lcdrqf.do_changed = 1;
                    lcdrqf.do_country = address_details.country;
                    lcdrqf.do_country_iso = address_details["country_iso"];
                    lcdrqf.do_route = address_details["route"];
                    if (place.address_components[0].types[0] == "locality") {
                        lcdrqf.do_city = place.address_components[0].long_name;
                    } else {
                        lcdrqf.do_city = address_details.locality;
                    }
                    lcdrqf.do_administrative_area_level_1 = address_details["administrative_area_level_1"];
                    lcdrqf.do_street_number = address_details["street_number"];
                    lcdrqf.do_zip = address_details["postal_code"];
                    lcdrqf.do_lat = gps_lat;
                    lcdrqf.do_lon = gps_lon;
                    lcdrqf.do_iso = isocode;
                    lcdrqf.do_address = place.vicinity;
                    lcdrqf.do_location = place.name;
                    lcdrqf.dropoff_ok = -1;
                }
            }
		}
	});
}

function buildAddress($array) {
	var address='';
	for (var i = 0; i < $array.length; i++) {
		if (i>0) {
			for (var j = 0; j < i; j++) {
				if ((typeof($array[i])!='undefined') && (typeof($array[j])!='undefined')) {
					if (($array[i]==$array[j]) || (($array[j].length>=$array[i].length) &&  ($array[j].substring(($array[j].length-$array[i].length))==$array[i]))) {
						$array[i]='';
					}
				}
			}			
		}
	}
	for (var i = 0; i < $array.length; i++) {
		if ($array[i]) {
			if (address!='') {
				if (isNumeric($array[i])) { address+=' '; } else { address+=', '; }
			}
			address+=$array[i];
		}
	}
	return address;
}

function isNumeric(n) {
	return !isNaN(parseFloat(n)) && isFinite(n);
}

function getLocationFromCoords(lat, lon, id) {
	var prefix = "do";
	if (id == "lcdrqf_pickup_str") {
		prefix = "pu";
	}
	navigator.geolocation.getCurrentPosition(function(pos) {
		geocoder = new google.maps.Geocoder();
		var latlng = new google.maps.LatLng(lat, lon);
		geocoder.geocode({
			'latLng': latlng
		}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				if (id == "lcdrqf_pickup_str") {
					prefix = "pu";
				} else {
					prefix = "do";
				}
				var result = results[0];
				var country = "";
				var route = "";
				var city = "";
				var state = "";
				var street_number = "";
				var postal_code = "";
				var country_iso = "";
				for (var i = 0, len = result.address_components.length; i < len; i++) {
					var ac = result.address_components[i];
					if (ac.types.indexOf("country") >= 0) {
						country = ac.long_name;
					}
					if (ac.types.indexOf("route") >= 0) {
						route = ac.long_name;
					}
					if (ac.types.indexOf("locality") >= 0) {
						city = ac.long_name;
					}
					if (ac.types.indexOf("administrative_area_level_1") >= 0) {
						state = ac.long_name;
					}
					if (ac.types.indexOf("street_number") >= 0) {
						street_number = ac.long_name;
					}
					if (ac.types.indexOf("postal_code") >= 0) {
						postal_code = ac.long_name;
					}
					if (ac.types.indexOf("country_iso") >= 0) {
						country_iso = ac.long_name;
					}
				}
				prefix2 = 'lcdrqf.' + prefix;
				eval(prefix2 + "_changed" + " = " + 1);
				eval(prefix2 + "_country" + " = country");
				eval(prefix2 + "_route" + " = route");
				eval(prefix2 + "_city" + " = city");
				eval(prefix2 + "_administrative_area_level_1" + " = state");
				eval(prefix2 + "_street_number" + " = street_number");
				eval(prefix2 + "_zip" + " = postal_code");
				eval(prefix2 + "_country_iso" + " = country_iso");
				eval(prefix2 + "_lat" + " = lat");
				eval(prefix2 + "_lon" + " = lon");
				eval(prefix2 + "_address" + " = result.address_components[0].long_name");
				eval(prefix2 + "_location" + " = result.name");
				eval(prefix2 + "_iso" + " = country_iso");
				check_reset();
				if (prefix == "pu") {
					if (typeof(lcdrqf.pu_route) == "undefined") {
						lcdrqf.pu_route = "";
					}
					if (typeof(lcdrqf.pu_street_number) == "undefined") {
						lcdrqf.pu_street_number = "";
					}
					if (typeof(lcdrqf.pu_address) == "undefined") {
						lcdrqf.pu_address = "";
					}
					if (typeof(lcdrqf.pu_location) == "undefined") {
						lcdrqf.pu_location = "";
					}
					if (lcdrqf.pu_location == lcdrqf.pu_city) {
						lcdrqf.pu_location = "";
					}
					if (lcdrqf.pu_address == lcdrqf.pu_city) {
						lcdrqf.pu_address = "";
					}
					if (typeof(lcdrqf.pu_zip) == "undefined") {
						lcdrqf.pu_zip = "";
					}
				} else if (prefix == "do") {
					if (typeof(lcdrqf.do_route) == "undefined") {
						lcdrqf.do_route = "";
					}
					if (typeof(lcdrqf.do_street_number) == "undefined") {
						lcdrqf.do_street_number = "";
					}
					if (typeof(lcdrqf.do_address) == "undefined") {
						lcdrqf.do_address = "";
					}
					if (typeof(lcdrqf.do_location) == "undefined") {
						lcdrqf.do_location = "";
					}
					if (lcdrqf.do_location == lcdrqf.do_city) {
						lcdrqf.do_location = "";
					}
					if (lcdrqf.do_address == lcdrqf.do_city) {
						lcdrqf.do_address = "";
					}
					if (typeof(do_zip) == "undefined") {
						lcdrqf.do_zip = "";
					}
				}
				$("#" + id).val(result.formatted_address);
			}
		});
	});
}

function initSelectors() {
	if (typeof(LG_MODUL) != "undefined" && LG_MODUL !== null) {
		var LG_MODUL_OLD = LG_MODUL;
	}
	LG_MODUL = new Array('cus_booking', 0, 1);
	var sel0 = '';
	var sel1 = ' selected="selected" ';
	if (lcdrqf.sel_order == 0) {
		sel0 = ' selected="selected" ';
		sel1 = '';
	}
	o = '<div id="order_settings" style="text-align: right; position: relative; top: 0px; ">';
	o += '<div class="select_wrapper">';
	o += '<select id="selected_currency" class="filter_select" onchange="recalc_prices(this)">';
	var sel = '';
	if (lcdrqf.sel_currency == '') {
		sel = ' selected="selected" ';
	}
	o += '<option value="-1" data-rel="" ' + sel + '>' + LG('Original currency') + '</option>';
	for (var i = 0; i < currencies.length; i++) {
		if (lcdrqf.sel_currency == currencies[i]["iso_code"]) {
			sel = ' selected="selected" ';
		} else {
			sel = '';
		}
		o += '<option value="' + currencies[i]["relative_to_chf"] + '" data-rel="' + currencies[i]["iso_code"] + '" ' + sel + '>' + currencies[i]["iso_code"] + '</option>';
		if (currencies[i]["iso_code"] == 'SEK') {
			o += '<option value="-2" disabled="disabled">---</option>';
		}
	}
	o += '</select>';
	o += '</div>';
	o += '<div class="select_wrapper" id="order_setter" style="display: none; width: 265px; margin: 0;">';
	o += '<select id="order_select" class="filter_select"  onchange="changeOrder(this)">';
	o += '<option value="0" ' + sel0 + ' >' + LG('Order by price') + '</option>';
	o += '<option value="1" ' + sel1 + ' >' + LG('Order by ratings') + '</option>';
	o += '</select>';
	o += '</div>';
	$('div#order_settings_div').hide();
	$('div#order_settings_div').html(o);
	LG_MODUL = LG_MODUL_OLD;
}

function drawTp1() {
	var transport = lcdrqf.tp1;
	lcdrqf.last_pickup_lon = lcdrqf.pu_lon;
	lcdrqf.last_pickup_lat = lcdrqf.pu_lat;
	lcdrqf.last_dropoff_lon = lcdrqf.do_lon;
	lcdrqf.last_dropoff_lat = lcdrqf.do_lat;
	if (typeof(transport.status) != 'undefined') {
		link_pe = transport.link_pe;
		if (transport.result.length > 0) {
			we_have_price_any = true;
		}
	}
	var noty_object = null;
	var jump_url = '';
	if (we_have_price_any) {
		var lcdrqf_temp = lcdrqf;
		lcdrqf_temp.tp1 = null;
		lcdrqf_temp.tp2 = null;
		lcdrqf_temp.ajax_check_1 = 0;
		lcdrqf_temp.ajax_check_2 = 0;
		lcdrqf_temp.last_pickup_address = '';
		lcdrqf_temp.last_pickup_lat = 0;
		lcdrqf_temp.last_pickup_lon = 0;
		lcdrqf_temp.akt_pickup_address = '';
		lcdrqf_temp.akt_dropoff_lat = 0;
		lcdrqf_temp.akt_dropoff_lon = 0;
		lcdrqf_temp.lc_d_index = document.getElementById('req_carcat').value;
		jump_url = lcd_url + '/' + $booking_urlkey + '/?ajax_lang=' + _LNG + '&lcdrqf=' + JSON_stringify(lcdrqf_temp);
        if (STOP_LOCATIONS && Object.keys(STOP_LOCATIONS).length > 0 && lcdrqf.dispo === false) {
            jump_url += `&stopoverLocations=${JSON.stringify(STOP_LOCATIONS)}`;
        }
		document.location.href = jump_url;
	} else
	if ((!we_have_price_any) && (!we_have_partner_any)) {
		noty_object = {
			"text_main": LG("Currently we have no local partner companies at the area."),
			"buttons": [{
				"text": LG("Ask your Limousine Center team for an offer!"),
				"action": function() {
					document.location.href = link_pe;
				}
			}, {
				"text": LG("Close and try another address!"),
				"action": function() {
					return false;
				},
				"addClass": "background-color_red"
			}]
		};
	} else
	if ((!we_have_price_any) && (we_have_partner_any)) {
		if (we_have_partner_match) {
			jump_url = we_have_partner_match_link;
		} else {
			jump_url = we_have_partner_any_link;
		}
		var second_event = function() {
			document.location.href = jump_url;
		};
		if ((typeof(lc_subpage) != 'undefined') && (lc_subpage)) {
			if (url_current == jump_url) {
				second_event = scrollto_price_equiry;
			}
		}
		noty_object = {
			"text_main": LG("Sorry, but we cannot provide a price for this vehicle category at the area."),
			"buttons": [{
				"text": LG("Ask our local partners directly for personalized offers!"),
				"action": function() {
					second_event();
				}
			}, {
				"text": LG("Ask your Limousine Center team for an offer!"),
				"action": function() {
					document.location.href = link_pe;
				}
			}, {
				"text": LG("Close"),
				"action": function() {
					return false;
				},
				"addClass": "background-color_red"
			}]
		};
	}
	if (noty_object != null) {
		myalert_orange(noty_object);
	}
	unblock_screen_bg();
}

function calculate_price(rq_token) {
	if ((typeof(navigator.appName) !== undefined) && (navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.appVersion.indexOf("MSIE 9") != -1)) {
		_GURL = '';
	}
	block_screen_bg(LG("I'm working..."));
	var LG_MODUL_OLD = LG_MODUL;
	LG_MODUL = new Array('cus_booking', 0, 1);
	$('#order_settings').show();
	lcdrqf.dispo_h = $('#lcdrqf_dispo_h').val();
	lcdrqf.rq_token = rq_token;
	if (!check_fields(rq_token)) {
		return false;
	}
	$("#list_results").html('');
	date = $("#lcdrqf_date_input_actual").val();
	hour = $("#lcdrqf_hour_select").val();
	min = $("#lcdrqf_min_select").val();
	lcdrqf.pu_time_h = hour;
	lcdrqf.pu_time_m = min;
	lcdrqf.pu_time_date = date;
	lcdrqf.date = date;
	if (typeof(lcdrqf.pu_city) == "undefined") {
		lcdrqf.pu_city = "";
	}
	if (typeof(lcdrqf.do_administrative_area_level_1) == "undefined") {
		lcdrqf.do_administrative_area_level_1 = "";
	}
	if (typeof(lcdrqf.pu_administrative_area_level_1) == "undefined") {
		lcdrqf.pu_administrative_area_level_1 = "";
	}
	if (typeof(lcdrqf.pu_route) == "undefined") {
		lcdrqf.pu_route = "";
	}
	if (typeof(lcdrqf.pu_street_number) == "undefined") {
		lcdrqf.pu_street_number = "";
	}
	if (typeof(lcdrqf.pu_address) == "undefined") {
		lcdrqf.pu_address = "";
	}
	if (typeof(lcdrqf.pu_location) == "undefined") {
		lcdrqf.pu_location = "";
	}
	if (lcdrqf.pu_location == lcdrqf.pu_city) {
		lcdrqf.pu_location = "";
	}
	if (lcdrqf.pu_address == lcdrqf.pu_city) {
		lcdrqf.pu_address = "";
	}
	if (typeof(lcdrqf.pu_zip) == "undefined") {
		lcdrqf.pu_zip = "";
	}
	if (typeof(lcdrqf.do_city) == "undefined") {
		lcdrqf.do_city = "";
	}
	if (typeof(lcdrqf.do_route) == "undefined") {
		lcdrqf.do_route = "";
	}
	if (typeof(lcdrqf.do_street_number) == "undefined") {
		lcdrqf.do_street_number = "";
	}
	if (typeof(lcdrqf.do_address) == "undefined") {
		lcdrqf.do_address = "";
	}
	if (typeof(lcdrqf.do_location) == "undefined") {
		lcdrqf.do_location = "";
	}
	if (lcdrqf.do_location == lcdrqf.do_city) {
		lcdrqf.do_location = "";
	}
	if (lcdrqf.do_address == lcdrqf.do_city) {
		lcdrqf.do_address = "";
	}
	if (typeof(lcdrqf.do_zip) == "undefined") {
		lcdrqf.do_zip = "";
	}
	if (typeof(lcdrqf.dispo_h) == "undefined") {
		lcdrqf.dispo_h = 0;
	}
	if (typeof(lcdrqf.id_maincat) == "undefined") {
		lcdrqf.id_maincat = -1;
	}
	var rq = {
		"req_from": "0",
		"req_type": "get_prices_for_addresses",
		"req_data": {
			"dispo": (lcdrqf.dispo ? 1 : 0),
			"id_maincat": lcdrqf.id_maincat,
			"rq_token": rq_token,
			"pu_time_date": lcdrqf.date,
			"date": lcdrqf.date,
			"pu_time_h": hour,
			"pu_time_m": min,
			"pu_lat": lcdrqf.pu_lat,
			"pu_lon": lcdrqf.pu_lon,
			"do_lat": lcdrqf.do_lat,
			"do_lon": lcdrqf.do_lon,
			"pu_iso": lcdrqf.pu_iso,
			"do_iso": lcdrqf.do_iso,
			"pu_zip": lcdrqf.pu_zip,
			"do_zip": lcdrqf.do_zip,
			"id_carcat": 0,
			"pu_country": lcdrqf.pu_country,
			"pu_route": lcdrqf.pu_route,
			"pu_city": lcdrqf.pu_city,
			"pu_administrative_area_level_1": lcdrqf.pu_administrative_area_level_1,
			"pu_street_number": lcdrqf.pu_street_number,
			"do_country": lcdrqf.do_country,
			"do_administrative_area_level_1": lcdrqf.do_administrative_area_level_1,
			"do_city": lcdrqf.do_city,
			"do_route": lcdrqf.do_route,
			"do_street_number": lcdrqf.do_street_number,
			"pu_right_now": lcdrqf.pu_right_now,
			"pu_country_iso": lcdrqf.pu_iso,
			"do_country_iso": lcdrqf.do_iso,
			"pu_address": lcdrqf.pu_route + " " + lcdrqf.pu_street_number,
			"do_address": lcdrqf.do_route + " " + lcdrqf.do_street_number,
			"do_location": lcdrqf.do_location,
			"pu_location": lcdrqf.pu_location,
			"dispo_h": lcdrqf.dispo_h
		}
	};
	if (rq.req_data.pu_address == " ") {
		rq.req_data.pu_address = lcdrqf.pu_address;
	}
	if (rq.req_data.do_address == " ") {
		rq.req_data.do_address = lcdrqf.do_address;
	}
	rndx = (new Date()).getTime() + "_" + Math.floor(Math.random() * 1345646);
	$.ajax(_GURL + '/system/lib/get_prices.php', {
		type: 'GET',
		timeout: 30000,
		data: 'rq=' + encodeURIComponent(JSON_stringify(rq, false)) + "&mit=1&ajax_lang=" + _LNG + "&rndx=" + rndx,
		cache: false,
		dataType: 'json',
		success: function(transport) {
			var stuff = {};
			stuff.request = lcdrqf;
			if (typeof(transport.result) != 'undefined') {
				stuff.result = transport.result;
				trackRequestError(rq_token, 1, JSON_stringify(stuff, false), 1);
			} else {
				trackRequestError(rq_token, 1, "ERROR: no result array in the response!", 1);
			}
			lcdrqf.tp1 = transport;
			drawTp1();
		}
	}).fail(function(transport) {
		trackRequestError(rq_token, 1, "ERROR: server error or Ajax timeout have happened!", 1);
		var et = error_text_3;
		if (typeof(reservation_link) == 'undefined') {
			reservation_link = 'http://direct.limousine-center.com/price-enquiry';
		}
		et = et.replace('[%LINK%]', reservation_link);
		unblock_screen_bg();
	});
	LG_MODUL = LG_MODUL_OLD;
}
var we_have_price_any = false;
var we_have_price_any_link = '';
var we_have_price_match = false;
var we_have_price_match_link = '';
var we_have_partner_any = false;
var we_have_partner_any_link = '';
var we_have_partner_match = false;
var we_have_partner_match_link = '';
var link_pe = "http://direct.limousine-center.com/price-enquiry/";

function isBookingPickupDateTimeLessThan24Hours() {
	const currentDate = getPickupLocationCurrentDateTime(PICKUP_LOCATION_TIMEZONE);
	const selectedDate = $("#lcdrqf_date_input_actual").val().trim()
	let selectedHours = $("#lcdrqf_hour_select").val().trim()
	let selectedMins = $("#lcdrqf_min_select").val().trim()
	selectedHours = selectedHours < 10 ? `0${selectedHours}` : selectedHours
	selectedMins = selectedMins == '0' ? '00' : selectedMins
	const selectedDateTime = new Date(`${selectedDate}T${selectedHours}:${selectedMins}:00`)
	
	if (currentDate > selectedDateTime) {
		return true;
	}
	
	const hoursDiff = parseInt((selectedDateTime - currentDate) / (1000 * 60 * 60))

	return !(hoursDiff >= 24);
}

function getPickupLocationCurrentDateTime(timezoneOffsetInMinutes = 60) {
	const localDate = new Date(); // Local date and time
	const utcDate = new Date(localDate.getTime() + localDate.getTimezoneOffset() * 60000); // CONVERT LOCAL TIME INTO GMT +0

	const pickupLocationCurrentDateTime = new Date(utcDate.getTime() + (timezoneOffsetInMinutes * 60000)) // Add the pickup location timezone
	
	return pickupLocationCurrentDateTime
}

function check_fields(rq_token) {
	var LG_MODUL_OLD = LG_MODUL;
	LG_MODUL = new Array('cus_booking', 0, 1);
	$("*").removeClass("placeholder");
	var dateObj = new Date();
	var month = dateObj.getUTCMonth() + 1;
	var day = dateObj.getUTCDate();
	var year = dateObj.getUTCFullYear();
	if (month < 10) {
		month = "0" + month;
	}
	if (day < 10) {
		day = "0" + day;
	}
	$("#lcdrqf_date_input_actual").val($("#lcdrqf_date_input_actual").val().trim());
	newdate = year + "-" + month + "-" + day;
	if (lcdrqf.pu_right_now == 0) {
		if ($("#lcdrqf_date_input").val() == "" || $("#lcdrqf_date_input_actual").val() < newdate) {
			myalert(LG("Please select a valid date!"), "#lcdrqf_date_input");
			trackRequestError(rq_token, 0, "Error: Please select a valid date!", 1);
			return false;
		} else {
			$("#lcdrqf_date_input").removeClass("placeholder");
			$("#lcdrqf_date_input").css("background-color", "rgba(233,233,233,1)", 1);
		}
        if (isBookingPickupDateTimeLessThan24Hours()) {
			myalert(LG("Pickup time should be atleast 24 hours or later to proceed!"), "#lcdrqf_date_input");
			trackRequestError(rq_token, 0, "Error: Pickup time should be atleast 24 hours or later to proceed!", 1);
			return false;
		}else {
			$("#lcdrqf_date_input").removeClass("placeholder");
		}
		if ($("#lcdrqf_hour_select").val() == -1) {
			myalert(LG("Please select a valid time!"), "#lcdrqf_hour_select");
			trackRequestError(rq_token, 0, "Error: Please select a valid time!", 1);
			return false;
		} else {
			$("#lcdrqf_hour_select").removeClass("placeholder");
			$("#lcdrqf_hour_select").css("background-color", "rgba(233,233,233,1)");
		}
		if ($("#lcdrqf_min_select").val() == -1) {
			myalert(LG("Please select a valid time!"), "#lcdrqf_min_select");
			trackRequestError(rq_token, 0, "Error: Please select a valid time!", 1);
			return false;
		} else {
			$("#lcdrqf_min_select").removeClass("placeholder");
			$("#lcdrqf_min_select").css("background-color", "rgba(233,233,233,1)");
		}
	} else {
		var date = new Date();
		date = Math.floor(date.getDate() / 1000);
	}
	if ($("#lcdrqf_pickup_str").val() == "") {
		myalert(LG("Please enter the pickup address!"), "#lcdrqf_pickup_str");
		trackRequestError(rq_token, 0, "Error: Please enter the pickup address!", 1);
		return false;
	} else if (lcdrqf.pu_changed == 0) {
		myalert(LG("Please enter the pickup address!"), "#lcdrqf_pickup_str");
		trackRequestError(rq_token, 0, "Error: Please enter the pickup address!", 1);
		return false;
	} else {
		$("#lcdrqf_pickup_str").removeClass("placeholder");
		$("#lcdrqf_pickup_str").css("background-color", "rgba(233,233,233,1)");
	}
	if (!lcdrqf.dispo) {
		if ($("#lcdrqf_dropoff_str").val() == "") {
			myalert(LG("Please enter the dropoff address!"), "#lcdrqf_dropoff_str");
			trackRequestError(rq_token, 0, "Error: Please enter the dropoff address!", 1);
			return false;
		} else if (lcdrqf.do_changed == 0) {
			myalert(LG("Please enter the dropoff address!"), "#dlcdrqf_ropoff_str");
			trackRequestError(rq_token, 0, "Error: Please enter the dropoff address!", 1);
			return false;
		} else {
			$("#lcdrqf_dropoff_str").removeClass("placeholder");
			$("#lcdrqf_dropoff_str").css("background-color", "rgba(233,233,233,1)");
		}
	} else {
		if ($('#lcdrqf_dispo_h').val() < 1) {
			myalert(LG("Please specify the dispo time!"), "#lcdrqf_dispo_h");
			trackRequestError(rq_token, 0, "Error: Please specify the dispo time!", 1);
			return false;
		}
	}
	if (typeof(lcdrqf.pu_route) == "undefined") {
		lcdrqf.pu_route = "";
	}
	if (typeof(lcdrqf.pu_location) == "undefined") {
		lcdrqf.pu_location = "";
	}
	if (typeof(lcdrqf.pu_city) == "undefined") {
		lcdrqf.pu_city = "";
	}
	if (typeof(lcdrqf.pu_street_number) == "undefined") {
		lcdrqf.pu_street_number = "";
	}
	if (typeof(lcdrqf.pu_address) == "undefined") {
		lcdrqf.pu_address = "";
	}
	if (typeof(lcdrqf.pu_location) == "undefined") {
		lcdrqf.pu_location = "";
	}
	if (typeof(lcdrqf.pu_zip) == "undefined") {
		lcdrqf.pu_zip = "";
	}
	if (lcdrqf.pu_location == lcdrqf.pu_city) {
		lcdrqf.pu_location = "";
	}
	if (lcdrqf.pu_address == lcdrqf.pu_city) {
		lcdrqf.pu_address = "";
	}
	if (!lcdrqf.dispo) {
		if (typeof(lcdrqf.do_location) == "undefined") {
			lcdrqf.do_location = "";
		}
		if (lcdrqf.do_location == lcdrqf.do_city) {
			lcdrqf.do_location = "";
		}
		if (lcdrqf.do_address == lcdrqf.do_city) {
			lcdrqf.do_address = "";
		}
		if (typeof(lcdrqf.do_route) == "undefined") {
			lcdrqf.do_route = "";
		}
		if (typeof(lcdrqf.do_city) == "undefined") {
			lcdrqf.do_city = "";
		}
		if (typeof(lcdrqf.do_street_number) == "undefined") {
			lcdrqf.do_street_number = "";
		}
		if (typeof(lcdrqf.do_address) == "undefined") {
			lcdrqf.do_address = "";
		}
		if (typeof(lcdrqf.do_location) == "undefined") {
			lcdrqf.do_location = "";
		}
		if (typeof(lcdrqf.do_zip) == "undefined") {
			lcdrqf.do_zip = "";
		}
	}

    if (STOP_LOCATIONS && Object.keys(STOP_LOCATIONS).length > 0 && lcdrqf.dispo === false) {
		let hasInvalidStopover = false;
		let errorMessage = ""
		
		Object.keys(STOP_LOCATIONS).forEach((propKey) => {
			if (STOP_LOCATIONS[propKey].place === null) {
				errorMessage = "Please enter a valid stopover location address";
				$(`#${propKey}`).addClass("invalid-input");
				hasInvalidStopover = true;
			} else {
				$(`#${propKey}`).removeClass("invalid-input");
			}

			const identifier = propKey.replace("-input", "");
			const timeInput = $(`select#${identifier}-hour-input`);
			STOP_LOCATIONS[propKey].hours =  timeInput.val();
			// if (["", null, undefined, "-1"].includes(timeInput.val())) {
			
			// 	hasInvalidStopover = true;
			// 	errorMessage = errorMessage === "" ? "Please enter a waiting time." : errorMessage
			// } else {
			// 	STOP_LOCATIONS[propKey].hours = timeInput.val()
			// 	timeInput.removeClass("invalid-input");
			// }
		})

		if (hasInvalidStopover) {
			myalert(`${LG(errorMessage)}`);
			return false;
		}
	}

	LG_MODUL = LG_MODUL_OLD;
	trackRequestError(rq_token, 0, "OK", 1);
	return true;
}

function resetStopoverLocations(isHourly) {
	// STOP_LOCATIONS = {};
	// i = 1;
	// const parentSelector = "div#calculator_form_container";

	// if (isHourly) {
	// 	$('div#filter').height(160);
	// 	$(`${parentSelector} tr.calc_tr_table td.add-stop-button-container`).hide();
	// 	$(`${parentSelector} tr td[class*="stopover-row-"] div.stop_container`).hide();
	// 	$(`${parentSelector} tr td[class*="stopover-row-"] label.input_labels`).hide();
	// 	$(`${parentSelector} tr td[class*="stopover-row-"] label[id*="hrs_labels_stop_"]`).hide();
	// 	$(`${parentSelector} tr td[class*="stopover-row-"] div.stop_hrs_container`).hide();
	// } else {
	// 	const keys = Object.keys(STOP_LOCATIONS);
	// 	$('div#filter').height(keys.length > 0 ? 225 : 160);
	// 	$(`${parentSelector} tr.calc_tr_table td.add-stop-button-container`).show();

	// 	keys.forEach((key, index) => {
	// 		$(`${parentSelector} tr td[class*="stopover-row-${index}"] div.stop_container`).show();
	// 		$(`${parentSelector} tr td[class*="stopover-row-${index}"] label.input_labels`).show();
	// 		$(`${parentSelector} tr td[class*="stopover-row-${index}"] label[id*="hrs_labels_stop_"]`).show();
	// 		$(`${parentSelector} tr td[class*="stopover-row-${index}"] div.stop_hrs_container`).show();
	// 	})
	// }

	if (isHourly) {
		$(`tr.calc_tr_table`).addClass("d-none");
	} else {
		$(`tr.calc_tr_table`).removeClass("d-none");
	}
}

function stackedStopoverText() {
	const elem = $("#stopover-parent-container .stopover-toggle-display");
	const text = LG("Stopovers");
	if (elem) {
		elem.empty();
		text.toUpperCase().split("").forEach(letter => {
			const span = document.createElement("span");
			span.textContent = letter;
			elem.append(span);
		});
		// setTimeout(() => {
		// 	$("#stopover-parent-container").removeClass("d-none")
		// }, 2000)
	}
}

function resetStopoverInputs(isApplyStopOverValue = false) {
	const keys = Object.keys(STOP_LOCATIONS);

	for (let index = 0; index < MAX_STOPOVER; index++) {
		const identifier = `stopover-row-${index}`;
		const row = $(`label[class^='${identifier}-'], div[class^='${identifier}-']`)
		const locationElem = $(`input#${identifier}-input`)
		const timeInputElem = $(`select#${identifier}-hour-input`)
		const stopOver = STOP_LOCATIONS[keys[index]];

		if (locationElem) {
			const address = stopOver && isApplyStopOverValue ? stopOver.address : "";
			locationElem.val(address);
		}

		if (timeInputElem) {
			const hours = stopOver && isApplyStopOverValue ? stopOver.hours : "0";
			timeInputElem.val(hours);
		}

		if (isApplyStopOverValue) {
			if (stopOver) {
				if (row.hasClass("d-none")) {
					row.removeClass("d-none")
				}
			} else {
				if (!row.hasClass("d-none")) {
					row.addClass("d-none")
				}
			}
		}
	}
}

function getStopoverHours() {
	Object.keys(STOP_LOCATIONS).forEach(key => {
		const identifier = key.replace("-input", "");
		const waitingTime = $(`select#${identifier}-hour-input`);
		STOP_LOCATIONS[key]['hours'] = waitingTime.val();
	})
}

function reorganizeStopoverLocationsPropertyKeys() {
	let newStopover = {};

	Object.keys(STOP_LOCATIONS).forEach((key, index) => {
		const stopoverRowId = `stopover-row-${index}-input`;
		newStopover[stopoverRowId] = STOP_LOCATIONS[key];
	})

	STOP_LOCATIONS = newStopover;
}

function removeStopOver(identifier) {
	getStopoverHours()
	delete STOP_LOCATIONS[`${identifier}-input`];
	$(`label[class^='${identifier}-'], div[class^='${identifier}-']`).removeClass("d-none");
	reorganizeStopoverLocationsPropertyKeys();
	resetStopoverInputs(true);
	if(Object.keys(STOP_LOCATIONS).length < MAX_STOPOVER) {
		$(`tr.calc_tr_table .add_stop`).removeClass("d-none");
	}
}

$(document).ready(function() {
	stackedStopoverText();
	var LG_MODUL_OLD = LG_MODUL;
	LG_MODUL = new Array('cus_booking', 0, 1);
	$(".filter_select").click(function() {
		$(this).toggleClass("selected_select");
		$("*").not(this).removeClass("selected_select");
	});
	$(".lcdrqf_loc_input").change(function() {
		return true;
	});
	$("#lcdrqf_dispo_h, #lcdrqf_hour_select, #lcdrqf_min_select").change(function() {
		if ($(this).val() == -1) {
			$(this).css("color", "gray");
		} else {
			$(this).css("color", "black");
		}
	});
	if ($("#lcdrqf_dispo_h").val() == -1) {
		$("#lcdrqf_dispo_h").css("color", "gray");
	} else {
		$("#lcdrqf_dispo_h").css("color", "black");
	}
	if ($("#lcdrqf_hour_select").val() == -1) {
		$("#lcdrqf_hour_select").css("color", "gray");
	} else {
		$("#lcdrqf_hour_select").css("color", "black");
	}
	if ($("#lcdrqf_min_select").val() == -1) {
		$("#lcdrqf_min_select").css("color", "gray");
	} else {
		$("#lcdrqf_min_select").css("color", "black");
	}
	try {
		initialize_addr("lcdrqf_pickup_str", "pu_lat", "pu_lon");
		initialize_addr("lcdrqf_dropoff_str", "do_lat", "do_lon");
	} catch (e) {}
	$("#lcdrqf_pickup_str").change(function() {
		lcdrqf.pu_changed = 0;
	});
	$("#lcdrqf_dropoff_str").change(function() {
		lcdrqf.do_changed = 0;
	});
	$('#lcdrqf_date_input').keydown(function(e) {
		e.preventDefault();
		return false;
	});
	$(".lcdrqf_time_input").click(function() {
		$("*").removeClass("lcdrqf_time_input_changed");
		if (lcdrqf.pu_right_now == 0) {
			lcdrqf.pu_right_now = 1;
			$(this).addClass("lcdrqf_time_input_changed");
			$(".lcdrqf_select_time, #lcdrqf_date_input").addClass("disable").prop("disabled", true);
		} else {
			lcdrqf.pu_right_now = 0;
			$(".lcdrqf_select_time, #lcdrqf_date_input").removeClass("disable").prop("disabled", false);
		}
	});
	$(".lcdrqf_dispo_input").click(function() {
		$("*").removeClass("lcdrqf_dispo_input_changed");
		$(this).addClass("lcdrqf_dispo_input_changed");
		if ($(this)[0].id == 'lcdrqf_dispo_input') {
			lcdrqf.dispo = true;
			resetStopoverLocations(true);
			$("#lcdrqf_dropoff_str").hide();
			$("#lcdrqf_fav_loc_select_2").hide();
			$("#dropoff_star").hide();
			$("#dropoff_label").hide();
			$("#dispo_h_label").fadeIn();
			$("#lcdrqf_dropoff_img").hide();
			$("#lcdrqf_dispo_h").fadeIn();
		} else {
			lcdrqf.dispo = false;
			resetStopoverLocations(false);
			$("#lcdrqf_dispo_h").hide();
			$("#lcdrqf_dropoff_img").fadeIn();
			$("#lcdrqf_dropoff_str").fadeIn();
			$("#dropoff_star").fadeIn();
			$("#dispo_h_label").hide();
			$("#dropoff_label").fadeIn();
		}
	});
	$('#lcdrqf_date_input').datetimepicker({
		numberOfMonths: 1,
		minDate: "@-1y",
		maxDate: "@+5y",
		dateFormat: "dd-mm-yy",
		defaultDate: "",
		yearRange: "-1:+5",
		changeMonth: true,
		changeYear: true,
		altField: "#lcdrqf_date_input_actual",
		altFormat: "yy-mm-dd",
		showButtonPanel: true,
		showOn: 'both',
		showTime: false,
		showHour: false,
		showMinute: false,
		showSecond: false,
		showMillisec: false,
		showMicrosec: false,
		showTimezone: false,
		showTimepicker: false,
		onChangeMonthYear: function(y, m, i) {
			if (typeof($("#lcdrqf_date_input").data("datepicker").currentDay) !== 'undefined') {
				if ($("#lcdrqf_date_input").data("datepicker").currentDay !== 0) {
					try {
						var d = $("#lcdrqf_date_input").data("datepicker").currentDay;
						var d2 = (new Date(y, (m), 0)).getDate();
						if (d > d2) {
							$("#lcdrqf_date_input").datetimepicker("setDate", m + "/" + (d2) + "/" + y);
						} else {
							$("#lcdrqf_date_input").datetimepicker("setDate", m + "/" + (d) + "/" + y);
						}
					} catch (e) {}
				} else {
					var d2 = (new Date(y, (m), 1)).getDate();
					$("#lcdrqf_date_input").datetimepicker("setDate", m + "/" + (d2) + "/" + y);
				}
			}
		}
	});
	$(".lcdrqf_current_position").click(function() {
		var LG_MODUL_OLD = LG_MODUL;
		LG_MODUL = new Array('cus_booking', 0, 1);
		element_id = $(this).prev().attr("id");
		if (!navigator.geolocation) {
			return;
		}
		block_screen_bg(LG("I'm working..."));
		navigator.geolocation.getCurrentPosition(function(pos) {
			geocoder = new google.maps.Geocoder();
			var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
			geocoder.geocode({
				'latLng': latlng
			}, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK) {
					var result = results[0];
					var country = "";
					var route = "";
					var city = "";
					var state = "";
					var street_number = "";
					var postal_code = "";
					var country_iso = "";
					for (var i = 0, len = result.address_components.length; i < len; i++) {
						var ac = result.address_components[i];
						if (ac.types.indexOf("country") >= 0) {
							country = ac.long_name;
						}
						if (ac.types.indexOf("route") >= 0) {
							route = ac.long_name;
						}
						if (ac.types.indexOf("locality") >= 0) {
							city = ac.long_name;
						}
						if (ac.types.indexOf("administrative_area_level_1") >= 0) {
							state = ac.long_name;
						}
						if (ac.types.indexOf("street_number") >= 0) {
							street_number = ac.long_name;
						}
						if (ac.types.indexOf("postal_code") >= 0) {
							postal_code = ac.long_name;
						}
						if (ac.types.indexOf("country") >= 0) {
							country_iso = ac.short_name;
						}
					}
					if (element_id == "lcdrqf_pickup_str") {
						if (city != '' && state != '') {
							lcdrqf.pu_changed = 1;
							$("#" + element_id).val(result.formatted_address);
							lcdrqf.pu_country = country;
							lcdrqf.pu_route = result.address_components[1].long_name;
							lcdrqf.pu_city = city;
							lcdrqf.pu_administrative_area_level_1 = state;
							lcdrqf.pu_street_number = street_number;
							lcdrqf.pu_zip = postal_code;
							lcdrqf.pu_iso = country_iso;
							lcdrqf.pu_lat = pos.coords.latitude;
							lcdrqf.pu_lon = pos.coords.longitude;
							lcdrqf.pu_address = result.address_components[0].long_name;
							lcdrqf.pu_location = result.name;
							if (typeof(lcdrqf.pu_route) == "undefined") {
								lcdrqf.pu_route = "";
							}
							if (typeof(lcdrqf.pu_street_number) == "undefined") {
								lcdrqf.pu_street_number = "";
							}
							if (typeof(lcdrqf.pu_address) == "undefined") {
								lcdrqf.pu_address = "";
							}
							if (typeof(lcdrqf.pu_location) == "undefined") {
								lcdrqf.pu_location = "";
							}
							if (lcdrqf.pu_location == lcdrqf.pu_city) {
								lcdrqf.pu_location = "";
							}
							if (lcdrqf.pu_address == lcdrqf.pu_city) {
								lcdrqf.pu_address = "";
							}
							if (typeof(lcdrqf.pu_zip) == "undefined") {
								lcdrqf.pu_zip = "";
							}
							if (lcdrqf.pu_location == "") {
								lcdrqf.pu_location = result.address_components[1].short_name;
							}
						}
					} else {
						if (city != '' && state != '') {
							lcdrqf.do_changed = 1;
							$("#" + element_id).val(result.formatted_address);
							lcdrqf.do_country = country;
							lcdrqf.do_route = result.address_components[1].long_name;
							lcdrqf.do_city = city;
							lcdrqf.do_administrative_area_level_1 = state;
							lcdrqf.do_street_number = street_number;
							lcdrqf.do_zip = postal_code;
							lcdrqf.do_iso = country_iso;
							lcdrqf.do_lat = pos.coords.latitude;
							lcdrqf.do_lon = pos.coords.longitude;
							lcdrqf.do_address = result.address_components[0].long_name;
							lcdrqf.do_location = result.name;
							if (typeof(lcdrqf.do_route) == "undefined") {
								lcdrqf.do_route = "";
							}
							if (typeof(lcdrqf.do_street_number) == "undefined") {
								lcdrqf.do_street_number = "";
							}
							if (typeof(lcdrqf.do_address) == "undefined") {
								lcdrqf.do_address = "";
							}
							if (typeof(lcdrqf.do_location) == "undefined") {
								lcdrqf.do_location = "";
							}
							if (lcdrqf.do_location == lcdrqf.do_city) {
								lcdrqf.do_location = "";
							}
							if (lcdrqf.do_address == lcdrqf.do_city) {
								lcdrqf.do_address = "";
							}
							if (typeof(lcdrqf.do_zip) == "undefined") {
								lcdrqf.do_zip = "";
							}
							if (lcdrqf.do_location == "") {
								lcdrqf.do_location = result.address_components[5].short_name;
							}
						}
					}
				}
			});
		}, function(error) {
			unblock_screen_bg();
		});
		unblock_screen_bg();
		LG_MODUL = LG_MODUL_OLD;
	});
	LG_MODUL = LG_MODUL_OLD;

    // initialize_addr("stop_loc_input_1", "stop_loc_lat_1", "stop_loc_lon_1");
	// initialize_addr("stop_loc_input_2", "stop_loc_lat_2", "stop_loc_lon_2");

    // let i = 1;
    $(document).on('click', '.add_stop', function (){
        // $("#filter").animate({'height': '225px'}, 200);
		// if(!$('#stop_container_1').is(':visible')){
		// 	$('#stop_container_1').show();
		// 	$('#input_labels_stop_1').show();
		// 	$('#hrs_labels_stop_1').show();
		// 	$('#stop_hrs_container_1').show();
		// } else if(!$('#stop_container_2').is(':visible')){
		// 	$('#stop_container_2').show();
		// 	$('#input_labels_stop_2').show();
        //     $('#hrs_labels_stop_2').show();
		// 	$('#stop_hrs_container_2').show();
		// }
        
        // const stopoverObject = { place: null, hours: 0, address: "" }
		// STOP_LOCATIONS[`stop_loc_input_${i}`] = stopoverObject;

        // i += 1;

		const currentCount = Object.keys(STOP_LOCATIONS).length;
		if (currentCount < MAX_STOPOVER) {
			const stopoverRowId = `stopover-row-${currentCount}`;
			const stopoverObject = { place: null, hours: 0, address: "", zip_code: "", city: "" }
			STOP_LOCATIONS[`${stopoverRowId}-input`] = stopoverObject;

			$(`label[class^='${stopoverRowId}-'], div[class^='${stopoverRowId}-']`).removeClass("d-none");
			setTimeout(() => {
				initialize_addr(`${stopoverRowId}-input`, `lat-${stopoverRowId}`, `lon-${stopoverRowId}`)
			}, 1500)
		}

		if(Object.keys(STOP_LOCATIONS).length >= MAX_STOPOVER) {
			$(`#add_stop`).addClass("d-none");
		}
	});

    // $(document).on('click', '.remove_stop', function(){
	// 	var $this = $(this);
	// 	var num = $(this).attr('data-num');
    //     delete STOP_LOCATIONS[`stop_loc_input_${num}`]
	// 	$this.parent().parent().hide();
	// 	$('#input_labels_stop_'+num).hide();
	// 	$('#hrs_labels_stop_'+num).hide();
	// 	$('#stop_container_'+num).hide();

    //     i-=1;

    //     if(i <= 1) {
    //         $("#filter").animate({'height': '160px'}, 200);
    //     }
	// });
});
var lcdrqf_calc_loaded = true;
if (typeof(LG_MODUL_OLD) != "undefined" && LG_MODUL_OLD !== null) {
	LG_MODUL = LG_MODUL_OLD;
}