(function() {
'use strict';
var COUNTRIES = [["AF", "93", "Afghanistan", "\ud83c\udde6\ud83c\uddeb"], ["AL", "355", "Albania", "\ud83c\udde6\ud83c\uddf1"], ["DZ", "213", "Algeria", "\ud83c\udde9\ud83c\uddff"], ["AD", "376", "Andorra", "\ud83c\udde6\ud83c\udde9"], ["AO", "244", "Angola", "\ud83c\udde6\ud83c\uddf4"], ["AG", "1268", "Antigua and Barbuda", "\ud83c\udde6\ud83c\uddec"], ["AR", "54", "Argentina", "\ud83c\udde6\ud83c\uddf7"], ["AM", "374", "Armenia", "\ud83c\udde6\ud83c\uddf2"], ["AU", "61", "Australia", "\ud83c\udde6\ud83c\uddfa"], ["AT", "43", "Austria", "\ud83c\udde6\ud83c\uddf9"], ["AZ", "994", "Azerbaijan", "\ud83c\udde6\ud83c\uddff"], ["BS", "1242", "Bahamas", "\ud83c\udde7\ud83c\uddf8"], ["BH", "973", "Bahrain", "\ud83c\udde7\ud83c\udded"], ["BD", "880", "Bangladesh", "\ud83c\udde7\ud83c\udde9"], ["BB", "1246", "Barbados", "\ud83c\udde7\ud83c\udde7"], ["BY", "375", "Belarus", "\ud83c\udde7\ud83c\uddfe"], ["BE", "32", "Belgium", "\ud83c\udde7\ud83c\uddea"], ["BZ", "501", "Belize", "\ud83c\udde7\ud83c\uddff"], ["BJ", "229", "Benin", "\ud83c\udde7\ud83c\uddef"], ["BT", "975", "Bhutan", "\ud83c\udde7\ud83c\uddf9"], ["BO", "591", "Bolivia", "\ud83c\udde7\ud83c\uddf4"], ["BA", "387", "Bosnia and Herzegovina", "\ud83c\udde7\ud83c\udde6"], ["BW", "267", "Botswana", "\ud83c\udde7\ud83c\uddfc"], ["BR", "55", "Brazil", "\ud83c\udde7\ud83c\uddf7"], ["BN", "673", "Brunei", "\ud83c\udde7\ud83c\uddf3"], ["BG", "359", "Bulgaria", "\ud83c\udde7\ud83c\uddec"], ["BF", "226", "Burkina Faso", "\ud83c\udde7\ud83c\uddeb"], ["BI", "257", "Burundi", "\ud83c\udde7\ud83c\uddee"], ["CV", "238", "Cape Verde", "\ud83c\udde8\ud83c\uddfb"], ["KH", "855", "Cambodia", "\ud83c\uddf0\ud83c\udded"], ["CM", "237", "Cameroon", "\ud83c\udde8\ud83c\uddf2"], ["CA", "1", "Canada", "\ud83c\udde8\ud83c\udde6"], ["CF", "236", "Central African Republic", "\ud83c\udde8\ud83c\uddeb"], ["TD", "235", "Chad", "\ud83c\uddf9\ud83c\udde9"], ["CL", "56", "Chile", "\ud83c\udde8\ud83c\uddf1"], ["CN", "86", "China", "\ud83c\udde8\ud83c\uddf3"], ["CO", "57", "Colombia", "\ud83c\udde8\ud83c\uddf4"], ["KM", "269", "Comoros", "\ud83c\uddf0\ud83c\uddf2"], ["CG", "242", "Congo", "\ud83c\udde8\ud83c\uddec"], ["CD", "243", "Congo (DRC)", "\ud83c\udde8\ud83c\udde9"], ["CR", "506", "Costa Rica", "\ud83c\udde8\ud83c\uddf7"], ["HR", "385", "Croatia", "\ud83c\udded\ud83c\uddf7"], ["CU", "53", "Cuba", "\ud83c\udde8\ud83c\uddfa"], ["CY", "357", "Cyprus", "\ud83c\udde8\ud83c\uddfe"], ["CZ", "420", "Czech Republic", "\ud83c\udde8\ud83c\uddff"], ["DK", "45", "Denmark", "\ud83c\udde9\ud83c\uddf0"], ["DJ", "253", "Djibouti", "\ud83c\udde9\ud83c\uddef"], ["DM", "1767", "Dominica", "\ud83c\udde9\ud83c\uddf2"], ["DO", "1809", "Dominican Republic", "\ud83c\udde9\ud83c\uddf4"], ["EC", "593", "Ecuador", "\ud83c\uddea\ud83c\udde8"], ["EG", "20", "Egypt", "\ud83c\uddea\ud83c\uddec"], ["SV", "503", "El Salvador", "\ud83c\uddf8\ud83c\uddfb"], ["GQ", "240", "Equatorial Guinea", "\ud83c\uddec\ud83c\uddf6"], ["ER", "291", "Eritrea", "\ud83c\uddea\ud83c\uddf7"], ["EE", "372", "Estonia", "\ud83c\uddea\ud83c\uddea"], ["SZ", "268", "Eswatini", "\ud83c\uddf8\ud83c\uddff"], ["ET", "251", "Ethiopia", "\ud83c\uddea\ud83c\uddf9"], ["FJ", "679", "Fiji", "\ud83c\uddeb\ud83c\uddef"], ["FI", "358", "Finland", "\ud83c\uddeb\ud83c\uddee"], ["FR", "33", "France", "\ud83c\uddeb\ud83c\uddf7"], ["GA", "241", "Gabon", "\ud83c\uddec\ud83c\udde6"], ["GM", "220", "Gambia", "\ud83c\uddec\ud83c\uddf2"], ["GE", "995", "Georgia", "\ud83c\uddec\ud83c\uddea"], ["DE", "49", "Germany", "\ud83c\udde9\ud83c\uddea"], ["GH", "233", "Ghana", "\ud83c\uddec\ud83c\udded"], ["GR", "30", "Greece", "\ud83c\uddec\ud83c\uddf7"], ["GD", "1473", "Grenada", "\ud83c\uddec\ud83c\udde9"], ["GT", "502", "Guatemala", "\ud83c\uddec\ud83c\uddf9"], ["GN", "224", "Guinea", "\ud83c\uddec\ud83c\uddf3"], ["GW", "245", "Guinea-Bissau", "\ud83c\uddec\ud83c\uddfc"], ["GY", "592", "Guyana", "\ud83c\uddec\ud83c\uddfe"], ["HT", "509", "Haiti", "\ud83c\udded\ud83c\uddf9"], ["HN", "504", "Honduras", "\ud83c\udded\ud83c\uddf3"], ["HU", "36", "Hungary", "\ud83c\udded\ud83c\uddfa"], ["IS", "354", "Iceland", "\ud83c\uddee\ud83c\uddf8"], ["IN", "91", "India", "\ud83c\uddee\ud83c\uddf3"], ["ID", "62", "Indonesia", "\ud83c\uddee\ud83c\udde9"], ["IR", "98", "Iran", "\ud83c\uddee\ud83c\uddf7"], ["IQ", "964", "Iraq", "\ud83c\uddee\ud83c\uddf6"], ["IE", "353", "Ireland", "\ud83c\uddee\ud83c\uddea"], ["IL", "972", "Israel", "\ud83c\uddee\ud83c\uddf1"], ["IT", "39", "Italy", "\ud83c\uddee\ud83c\uddf9"], ["JM", "1876", "Jamaica", "\ud83c\uddef\ud83c\uddf2"], ["JP", "81", "Japan", "\ud83c\uddef\ud83c\uddf5"], ["JO", "962", "Jordan", "\ud83c\uddef\ud83c\uddf4"], ["KZ", "7", "Kazakhstan", "\ud83c\uddf0\ud83c\uddff"], ["KE", "254", "Kenya", "\ud83c\uddf0\ud83c\uddea"], ["KI", "686", "Kiribati", "\ud83c\uddf0\ud83c\uddee"], ["KW", "965", "Kuwait", "\ud83c\uddf0\ud83c\uddfc"], ["KG", "996", "Kyrgyzstan", "\ud83c\uddf0\ud83c\uddec"], ["LA", "856", "Laos", "\ud83c\uddf1\ud83c\udde6"], ["LV", "371", "Latvia", "\ud83c\uddf1\ud83c\uddfb"], ["LB", "961", "Lebanon", "\ud83c\uddf1\ud83c\udde7"], ["LS", "266", "Lesotho", "\ud83c\uddf1\ud83c\uddf8"], ["LR", "231", "Liberia", "\ud83c\uddf1\ud83c\uddf7"], ["LY", "218", "Libya", "\ud83c\uddf1\ud83c\uddfe"], ["LI", "423", "Liechtenstein", "\ud83c\uddf1\ud83c\uddee"], ["LT", "370", "Lithuania", "\ud83c\uddf1\ud83c\uddf9"], ["LU", "352", "Luxembourg", "\ud83c\uddf1\ud83c\uddfa"], ["MG", "261", "Madagascar", "\ud83c\uddf2\ud83c\uddec"], ["MW", "265", "Malawi", "\ud83c\uddf2\ud83c\uddfc"], ["MY", "60", "Malaysia", "\ud83c\uddf2\ud83c\uddfe"], ["MV", "960", "Maldives", "\ud83c\uddf2\ud83c\uddfb"], ["ML", "223", "Mali", "\ud83c\uddf2\ud83c\uddf1"], ["MT", "356", "Malta", "\ud83c\uddf2\ud83c\uddf9"], ["MH", "692", "Marshall Islands", "\ud83c\uddf2\ud83c\udded"], ["MR", "222", "Mauritania", "\ud83c\uddf2\ud83c\uddf7"], ["MU", "230", "Mauritius", "\ud83c\uddf2\ud83c\uddfa"], ["MX", "52", "Mexico", "\ud83c\uddf2\ud83c\uddfd"], ["FM", "691", "Micronesia", "\ud83c\uddeb\ud83c\uddf2"], ["MD", "373", "Moldova", "\ud83c\uddf2\ud83c\udde9"], ["MC", "377", "Monaco", "\ud83c\uddf2\ud83c\udde8"], ["MN", "976", "Mongolia", "\ud83c\uddf2\ud83c\uddf3"], ["ME", "382", "Montenegro", "\ud83c\uddf2\ud83c\uddea"], ["MA", "212", "Morocco", "\ud83c\uddf2\ud83c\udde6"], ["MZ", "258", "Mozambique", "\ud83c\uddf2\ud83c\uddff"], ["MM", "95", "Myanmar", "\ud83c\uddf2\ud83c\uddf2"], ["NA", "264", "Namibia", "\ud83c\uddf3\ud83c\udde6"], ["NR", "674", "Nauru", "\ud83c\uddf3\ud83c\uddf7"], ["NP", "977", "Nepal", "\ud83c\uddf3\ud83c\uddf5"], ["NL", "31", "Netherlands", "\ud83c\uddf3\ud83c\uddf1"], ["NZ", "64", "New Zealand", "\ud83c\uddf3\ud83c\uddff"], ["NI", "505", "Nicaragua", "\ud83c\uddf3\ud83c\uddee"], ["NE", "227", "Niger", "\ud83c\uddf3\ud83c\uddea"], ["NG", "234", "Nigeria", "\ud83c\uddf3\ud83c\uddec"], ["NO", "47", "Norway", "\ud83c\uddf3\ud83c\uddf4"], ["OM", "968", "Oman", "\ud83c\uddf4\ud83c\uddf2"], ["PK", "92", "Pakistan", "\ud83c\uddf5\ud83c\uddf0"], ["PW", "680", "Palau", "\ud83c\uddf5\ud83c\uddfc"], ["PA", "507", "Panama", "\ud83c\uddf5\ud83c\udde6"], ["PG", "675", "Papua New Guinea", "\ud83c\uddf5\ud83c\uddec"], ["PY", "595", "Paraguay", "\ud83c\uddf5\ud83c\uddfe"], ["PE", "51", "Peru", "\ud83c\uddf5\ud83c\uddea"], ["PH", "63", "Philippines", "\ud83c\uddf5\ud83c\udded"], ["PL", "48", "Poland", "\ud83c\uddf5\ud83c\uddf1"], ["PT", "351", "Portugal", "\ud83c\uddf5\ud83c\uddf9"], ["QA", "974", "Qatar", "\ud83c\uddf6\ud83c\udde6"], ["RO", "40", "Romania", "\ud83c\uddf7\ud83c\uddf4"], ["RU", "7", "Russia", "\ud83c\uddf7\ud83c\uddfa"], ["RW", "250", "Rwanda", "\ud83c\uddf7\ud83c\uddfc"], ["KN", "1869", "Saint Kitts and Nevis", "\ud83c\uddf0\ud83c\uddf3"], ["LC", "1758", "Saint Lucia", "\ud83c\uddf1\ud83c\udde8"], ["VC", "1784", "Saint Vincent and the Grenadines", "\ud83c\uddfb\ud83c\udde8"], ["WS", "685", "Samoa", "\ud83c\uddfc\ud83c\uddf8"], ["SM", "378", "San Marino", "\ud83c\uddf8\ud83c\uddf2"], ["ST", "239", "Sao Tome and Principe", "\ud83c\uddf8\ud83c\uddf9"], ["SA", "966", "Saudi Arabia", "\ud83c\uddf8\ud83c\udde6"], ["SN", "221", "Senegal", "\ud83c\uddf8\ud83c\uddf3"], ["RS", "381", "Serbia", "\ud83c\uddf7\ud83c\uddf8"], ["SC", "248", "Seychelles", "\ud83c\uddf8\ud83c\udde8"], ["SL", "232", "Sierra Leone", "\ud83c\uddf8\ud83c\uddf1"], ["SG", "65", "Singapore", "\ud83c\uddf8\ud83c\uddec"], ["SK", "421", "Slovakia", "\ud83c\uddf8\ud83c\uddf0"], ["SI", "386", "Slovenia", "\ud83c\uddf8\ud83c\uddee"], ["SB", "677", "Solomon Islands", "\ud83c\uddf8\ud83c\udde7"], ["SO", "252", "Somalia", "\ud83c\uddf8\ud83c\uddf4"], ["ZA", "27", "South Africa", "\ud83c\uddff\ud83c\udde6"], ["SS", "211", "South Sudan", "\ud83c\uddf8\ud83c\uddf8"], ["ES", "34", "Spain", "\ud83c\uddea\ud83c\uddf8"], ["LK", "94", "Sri Lanka", "\ud83c\uddf1\ud83c\uddf0"], ["SD", "249", "Sudan", "\ud83c\uddf8\ud83c\udde9"], ["SR", "597", "Suriname", "\ud83c\uddf8\ud83c\uddf7"], ["SE", "46", "Sweden", "\ud83c\uddf8\ud83c\uddea"], ["CH", "41", "Switzerland", "\ud83c\udde8\ud83c\udded"], ["SY", "963", "Syria", "\ud83c\uddf8\ud83c\uddfe"], ["TW", "886", "Taiwan", "\ud83c\uddf9\ud83c\uddfc"], ["TJ", "992", "Tajikistan", "\ud83c\uddf9\ud83c\uddef"], ["TZ", "255", "Tanzania", "\ud83c\uddf9\ud83c\uddff"], ["TH", "66", "Thailand", "\ud83c\uddf9\ud83c\udded"], ["TL", "670", "Timor-Leste", "\ud83c\uddf9\ud83c\uddf1"], ["TG", "228", "Togo", "\ud83c\uddf9\ud83c\uddec"], ["TO", "676", "Tonga", "\ud83c\uddf9\ud83c\uddf4"], ["TT", "1868", "Trinidad and Tobago", "\ud83c\uddf9\ud83c\uddf9"], ["TN", "216", "Tunisia", "\ud83c\uddf9\ud83c\uddf3"], ["TR", "90", "Turkey", "\ud83c\uddf9\ud83c\uddf7"], ["TM", "993", "Turkmenistan", "\ud83c\uddf9\ud83c\uddf2"], ["TV", "688", "Tuvalu", "\ud83c\uddf9\ud83c\uddfb"], ["UG", "256", "Uganda", "\ud83c\uddfa\ud83c\uddec"], ["UA", "380", "Ukraine", "\ud83c\uddfa\ud83c\udde6"], ["AE", "971", "United Arab Emirates", "\ud83c\udde6\ud83c\uddea"], ["GB", "44", "United Kingdom", "\ud83c\uddec\ud83c\udde7"], ["US", "1", "United States", "\ud83c\uddfa\ud83c\uddf8"], ["UY", "598", "Uruguay", "\ud83c\uddfa\ud83c\uddfe"], ["UZ", "998", "Uzbekistan", "\ud83c\uddfa\ud83c\uddff"], ["VU", "678", "Vanuatu", "\ud83c\uddfb\ud83c\uddfa"], ["VE", "58", "Venezuela", "\ud83c\uddfb\ud83c\uddea"], ["VN", "84", "Vietnam", "\ud83c\uddfb\ud83c\uddf3"], ["YE", "967", "Yemen", "\ud83c\uddfe\ud83c\uddea"], ["ZM", "260", "Zambia", "\ud83c\uddff\ud83c\uddf2"], ["ZW", "263", "Zimbabwe", "\ud83c\uddff\ud83c\uddfc"]];
function initPhonePicker() {
var phoneInput = document.querySelector('input[name="phone"]');
if (!phoneInput || phoneInput._jxPhoneInit) return;
phoneInput._jxPhoneInit = true;
var wrapper = document.createElement('div');
wrapper.style.cssText = 'display:flex;gap:0;position:relative;';
phoneInput.parentNode.insertBefore(wrapper, phoneInput);
var countryBtn = document.createElement('button');
countryBtn.type = 'button';
countryBtn.id = 'jxPhoneCountryBtn';
countryBtn.style.cssText = 'display:flex;align-items:center;gap:6px;padding:0 10px;height:46px;border:1.5px solid #ddd;border-right:none;border-radius:6px 0 0 6px;background:#fafafa;cursor:pointer;font-size:14px;white-space:nowrap;min-width:90px;flex-shrink:0;transition:border-color 0.2s';
countryBtn.innerHTML = '🇦🇪+971▾';
phoneInput.style.cssText = 'flex:1;height:46px;border:1.5px solid #ddd;border-radius:0 6px 6px 0;padding:0 14px;font-size:14px;color:#1a1a1a;background:#fafafa;outline:none;min-width:0;transition:border-color 0.2s,box-shadow 0.2s';
phoneInput.placeholder = 'Phone number';
phoneInput.name = 'phone_number';
wrapper.appendChild(countryBtn);
wrapper.appendChild(phoneInput);
var hiddenCode = document.createElement('input'); hiddenCode.type='hidden'; hiddenCode.name='phone_country_code';
var hiddenCountry = document.createElement('input'); hiddenCountry.type='hidden'; hiddenCountry.name='phone_country';
var hiddenFull = document.createElement('input'); hiddenFull.type='hidden'; hiddenFull.name='phone_full';
wrapper.appendChild(hiddenCode);
wrapper.appendChild(hiddenCountry);
wrapper.appendChild(hiddenFull);
var dropdown = document.createElement('div');
dropdown.id = 'jxPhoneDropdown';
dropdown.style.cssText = 'display:none;position:absolute;top:100%;left:0;width:320px;max-height:320px;overflow-y:auto;background:#fff;border:1.5px solid #ddd;border-radius:8px;box-shadow:0 8px 32px rgba(0,0,0,0.15);z-index:999999;margin-top:2px';
var searchWrap = document.createElement('div');
searchWrap.style.cssText = 'padding:8px;border-bottom:1px solid #eee;position:sticky;top:0;background:#fff;z-index:1';
var searchInput = document.createElement('input');
searchInput.type = 'text';
searchInput.placeholder = 'Search country...';
searchInput.style.cssText = 'width:100%;padding:6px 10px;border:1.5px solid #ddd;border-radius:6px;font-size:13px;outline:none;box-sizing:border-box';
searchWrap.appendChild(searchInput);
dropdown.appendChild(searchWrap);
var listEl = document.createElement('div');
dropdown.appendChild(listEl);
wrapper.appendChild(dropdown);
var selected = COUNTRIES.find(function(c){ return c[0]==='AE'; }) || COUNTRIES[0];
function selectCountry(c) {
selected = c;
document.getElementById('jxPhoneFlag').textContent = c[3];
document.getElementById('jxPhoneCode').textContent = '+' + c[1];
hiddenCode.value = '+' + c[1];
hiddenCountry.value = c[2];
updateFullPhone();
dropdown.style.display = 'none';
searchInput.value = '';
renderList('');
}
selectCountry(selected);
function updateFullPhone() {
hiddenFull.value = '+' + selected[1] + ' ' + phoneInput.value.trim();
}
phoneInput.addEventListener('input', updateFullPhone);
function renderList(q) {
listEl.innerHTML = '';
var filtered = q ? COUNTRIES.filter(function(c){
return c[2].toLowerCase().includes(q.toLowerCase()) || ('+'+c[1]).includes(q) || c[0].toLowerCase().includes(q.toLowerCase());
}) : COUNTRIES;
filtered.forEach(function(c) {
var item = document.createElement('div');
item.style.cssText = 'display:flex;align-items:center;gap:10px;padding:8px 12px;cursor:pointer;font-size:13px;transition:background 0.1s';
item.innerHTML = '' + c[3] + '' + c[2] + '+' + c[1] + '';
item.addEventListener('mousedown', function(e) { e.preventDefault(); selectCountry(c); });
item.addEventListener('touchstart', function(e) { e.preventDefault(); selectCountry(c); }, {passive:false});
item.addEventListener('mouseover', function() { item.style.background='#f0f7f4'; });
item.addEventListener('mouseout', function() { item.style.background=''; });
listEl.appendChild(item);
});
if (!filtered.length) {
listEl.innerHTML = 'No countries found';
}
}
renderList('');
countryBtn.addEventListener('click', function(e) {
e.stopPropagation();
var open = dropdown.style.display === 'block';
dropdown.style.display = open ? 'none' : 'block';
if (!open) {
if (window.innerWidth <= 640) {
var bcr = wrapper.getBoundingClientRect();
dropdown.style.position = 'fixed';
dropdown.style.top = (bcr.bottom + 4) + 'px';
dropdown.style.left = '14px';
dropdown.style.right = '14px';
dropdown.style.width = 'auto';
} else {
dropdown.style.position = 'absolute';
dropdown.style.top = 'calc(100% + 4px)';
dropdown.style.left = '0';
dropdown.style.width = '320px';
dropdown.style.right = 'auto';
}
setTimeout(function() { searchInput.focus(); }, 50);
}
});
searchInput.addEventListener('input', function() { renderList(searchInput.value); });
document.addEventListener('click', function(e) {
if (!wrapper.contains(e.target) && e.target !== countryBtn) dropdown.style.display = 'none';
});
document.addEventListener('touchstart', function(e) {
if (!wrapper.contains(e.target) && e.target !== countryBtn) dropdown.style.display = 'none';
}, {passive: true});
phoneInput.addEventListener('focus', function() {
phoneInput.style.borderColor = '#006038';
phoneInput.style.boxShadow = '0 0 0 3px rgba(0,96,56,0.1)';
countryBtn.style.borderColor = '#006038';
});
phoneInput.addEventListener('blur', function() {
phoneInput.style.borderColor = '#ddd';
phoneInput.style.boxShadow = '';
countryBtn.style.borderColor = '#ddd';
});
}
function fixPassengerField() {
var paxSelect = document.querySelector('select[name="pax"]');
if (!paxSelect || paxSelect._jxFixed) return;
paxSelect._jxFixed = true;
var paxInput = document.createElement('input');
paxInput.type = 'number';
paxInput.name = 'pax';
paxInput.min = '1';
paxInput.max = '999';
paxInput.value = '1';
paxInput.required = true;
paxInput.style.cssText = paxSelect.style.cssText || '';
paxInput.className = paxSelect.className;
paxInput.style.cssText = 'width:100%;height:46px;border:1.5px solid #ddd;border-radius:6px;padding:0 14px;font-size:14px;color:#1a1a1a;background:#fafafa;outline:none;box-sizing:border-box;transition:border-color 0.2s,box-shadow 0.2s';
paxInput.addEventListener('focus', function() {
paxInput.style.borderColor = '#006038';
paxInput.style.boxShadow = '0 0 0 3px rgba(0,96,56,0.1)';
});
paxInput.addEventListener('blur', function() {
paxInput.style.borderColor = '#ddd';
paxInput.style.boxShadow = '';
if (parseInt(paxInput.value) < 1 || isNaN(parseInt(paxInput.value))) paxInput.value = '1';
});
paxSelect.parentNode.replaceChild(paxInput, paxSelect);
}
var legCount = 0;
var AIRPORTS_ML = null;
function getAirportsML(cb) {
if (AIRPORTS_ML && AIRPORTS_ML.length > 0) { cb(AIRPORTS_ML); return; }
fetch('/jx-airport-data/')
.then(function(r) { return r.text(); })
.then(function(html) {
var match = html.match(/]*id="jx-airport-raw"[^>]*>([\s\S]*?)<\/pre>/);
if (!match) { cb([]); return; }
var jsonStr = match[1].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,"'");
AIRPORTS_ML = JSON.parse(jsonStr);
cb(AIRPORTS_ML);
})
.catch(function() { cb([]); });
}
function searchAirportsML(q, airports) {
if (!q || q.length < 2 || !airports || !airports.length) return [];
var ql = q.toLowerCase().trim();
var exact=[], starts=[], contains=[];
for (var i=0; i=8) break;
}
var res=exact.concat(starts).concat(contains), seen={}, out=[];
for (var j=0;j'+codes+''+a[2]+''+[a[3],a[4]].filter(Boolean).join(', ')+'';
function sel(e) {
e.preventDefault();
input.value = a[0] + ' — ' + a[2] + (a[3]?', '+a[3]:'');
if (hiddenIATA) hiddenIATA.value = a[0];
if (hiddenDisplay) hiddenDisplay.value = input.value;
dd.style.display='none';
}
item.addEventListener('mousedown', sel);
item.addEventListener('touchstart', sel, {passive:false});
item.addEventListener('mouseover', function(){ item.style.background='#f0f7f4'; });
item.addEventListener('mouseout', function(){ item.style.background=''; });
dd.appendChild(item);
});
dd.style.display='block';
}
input.addEventListener('input', function() {
clearTimeout(timer);
var q=input.value.trim();
if (q.length<1) { dd.style.display='none'; return; }
if (AIRPORTS_ML && AIRPORTS_ML.length>0) {
showDD(searchAirportsML(q, AIRPORTS_ML));
} else {
dd.innerHTML='Loading airports…';
dd.style.display='block';
timer=setTimeout(function() {
getAirportsML(function(airports) {
if (input.value.trim()===q) showDD(searchAirportsML(q, airports));
});
}, 100);
}
});
input.addEventListener('blur', function() {
setTimeout(function() {
if (document.activeElement!==input) dd.style.display='none';
}, 250);
});
document.addEventListener('click', function(e) {
if (!wrap.contains(e.target)) dd.style.display='none';
});
}
function addLeg(prevDestIATA, prevDestDisplay) {
legCount++;
var n = legCount;
var container = document.getElementById('jxMLLegsContainer');
if (!container) return;
var leg = document.createElement('div');
leg.id = 'jxMLLeg' + n;
leg.style.cssText = 'position:relative';
leg.innerHTML =
'' +
'' +
'Leg ' + n + '' +
(n > 1 ? '' : '') +
'' +
'' +
'' +
'' +
'' +
'' +
'→' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'';
container.appendChild(leg);
if (prevDestIATA && prevDestDisplay) {
var fromInput = document.getElementById('jxMLLeg' + n + 'OriginDisplay');
var fromHidden = document.getElementById('jxMLLeg' + n + 'OriginIATA');
if (fromInput) fromInput.value = prevDestDisplay;
if (fromHidden) fromHidden.value = prevDestIATA;
}
var originDisplay = document.getElementById('jxMLLeg' + n + 'OriginDisplay');
var originIATA = document.getElementById('jxMLLeg' + n + 'OriginIATA');
var destDisplay = document.getElementById('jxMLLeg' + n + 'DestDisplay');
var destIATA = document.getElementById('jxMLLeg' + n + 'DestIATA');
attachMLAC(originDisplay, originIATA, null);
attachMLAC(destDisplay, destIATA, null);
getAirportsML(function() {});
}
window.jxRemoveLeg = function(n) {
var leg = document.getElementById('jxMLLeg' + n);
if (leg) leg.remove();
};
function initMultiLeg() {
var tripTypeSelect = document.querySelector('select[name="trip_type"]');
if (!tripTypeSelect || tripTypeSelect._jxMLInit) return;
tripTypeSelect._jxMLInit = true;
var existingML = document.querySelector('.jx-ml-section, #jxMLSection');
if (!existingML) {
var flightSection = tripTypeSelect.closest('.jx-form-grid') || tripTypeSelect.closest('form');
if (!flightSection) return;
var mlSection = document.createElement('div');
mlSection.id = 'jxMLSection';
mlSection.style.cssText = 'display:none;margin-top:0;grid-column:1/-1';
mlSection.innerHTML =
'' +
'';
var yourDetailsTitle = Array.from(flightSection.children).find(function(el) {
return el.classList.contains('jx-form-section-title') && el.textContent.trim() === 'Your Details';
});
if (yourDetailsTitle) {
flightSection.insertBefore(mlSection, yourDetailsTitle);
} else {
flightSection.appendChild(mlSection);
}
document.getElementById('jxAddLegBtn').addEventListener('click', function() {
var lastDestDisplay = '', lastDestIATA = '';
if (legCount > 0) {
var lastDestInput = document.getElementById('jxMLLeg' + legCount + 'DestDisplay');
var lastDestHidden = document.getElementById('jxMLLeg' + legCount + 'DestIATA');
if (lastDestInput) lastDestDisplay = lastDestInput.value;
if (lastDestHidden) lastDestIATA = lastDestHidden.value;
}
addLeg(lastDestIATA, lastDestDisplay);
});
}
var returnInput = document.querySelector('input[name="return_date"]');
var returnGroup = returnInput ? returnInput.closest('.jx-form-group') : null;
function updateReturnDate(val) {
if (!returnGroup) return;
if (val === 'Round Trip') {
returnGroup.style.display = '';
} else {
returnGroup.style.display = 'none';
}
}
var flightSection2 = tripTypeSelect.closest('.jx-form-grid') || tripTypeSelect.closest('form');
if (flightSection2) {
Array.from(flightSection2.querySelectorAll('.jx-form-group')).forEach(function(grp) {
var inp = grp.querySelector(
'input[name="origin_display"], input[id="jxOrigin"], ' +
'input[name="dest_display"], input[id="jxDest"], ' +
'input[name="depart"], input[name="return_date"], ' +
'input[name="pax"], select[name="purpose"]'
);
if (inp) grp.classList.add('jx-std-only');
});
}
var purposeGroup = flightSection2 ? flightSection2.querySelector('.jx-form-group:has(select[name="purpose"])') : null;
if (!purposeGroup) {
var purposeSelect = document.querySelector('select[name="purpose"]');
if (purposeSelect) purposeGroup = purposeSelect.closest('.jx-form-group');
}
function updatePurposeWidth(val) {
if (!purposeGroup) return;
if (val === 'Round Trip') {
purposeGroup.style.gridColumn = '';
} else {
purposeGroup.style.gridColumn = '1 / -1';
}
}
var stdOrigin = document.getElementById('jxOrigin');
var stdDest = document.getElementById('jxDest');
if (stdOrigin && !stdOrigin._jxAC) {
stdOrigin._jxAC = true;
var originIATA = document.querySelector('input[name="origin_iata"]');
attachMLAC(stdOrigin, originIATA, null);
}
if (stdDest && !stdDest._jxAC) {
stdDest._jxAC = true;
var destIATA = document.querySelector('input[name="dest_iata"]');
attachMLAC(stdDest, destIATA, null);
}
tripTypeSelect.addEventListener('change', function() {
var mlSection = document.getElementById('jxMLSection');
var stdFields = document.querySelectorAll('.jx-std-only');
if (tripTypeSelect.value === 'Multi-Leg') {
if (mlSection) { mlSection.style.display = 'block'; }
if (legCount === 0) { addLeg('', ''); addLeg('', ''); }
stdFields.forEach(function(el) { el.style.display = 'none'; });
} else {
if (mlSection) { mlSection.style.display = 'none'; }
stdFields.forEach(function(el) { el.style.display = ''; });
updateReturnDate(tripTypeSelect.value);
updatePurposeWidth(tripTypeSelect.value);
}
});
if (!tripTypeSelect.value || tripTypeSelect.value === '') {
tripTypeSelect.value = 'One Way';
}
if (tripTypeSelect.value === 'Multi-Leg') {
var mlSection = document.getElementById('jxMLSection');
if (mlSection) {
mlSection.style.display = 'block';
if (legCount === 0) { addLeg('', ''); addLeg('', ''); }
}
document.querySelectorAll('.jx-std-only').forEach(function(el) { el.style.display = 'none'; });
} else {
updateReturnDate(tripTypeSelect.value);
updatePurposeWidth(tripTypeSelect.value);
}
}
function initFormSubmit() {
var form = document.querySelector('form');
if (!form || form._jxSubmitInit) return;
form._jxSubmitInit = true;
form.setAttribute('action', '');
form.setAttribute('method', 'post');
var submitBtn = form.querySelector('button[type="submit"], button');
var originalBtnText = submitBtn ? submitBtn.textContent.trim() : 'SUBMIT CHARTER ENQUIRY';
form.addEventListener('submit', function(e) {
e.preventDefault();
if (!window.JXL_AJAX) {
form.submit();
return;
}
var fname = form.querySelector('[name="fname"]');
var email = form.querySelector('[name="email"]');
var tripType = form.querySelector('[name="trip_type"]');
var consent = form.querySelector('[name="consent"], #consent');
if (!fname || !fname.value.trim()) { fname && fname.focus(); alert('Please enter your first name.'); return; }
if (!email || !email.value.trim()) { email && email.focus(); alert('Please enter your email address.'); return; }
if (!tripType || !tripType.value || tripType.value === '' || tripType.value === 'Select…') {
tripType && (tripType.value = 'One Way');
}
if (consent && !consent.checked) { alert('Please consent to data processing to submit your enquiry.'); return; }
var legs = [];
var legEls = document.querySelectorAll('[id^="jxMLLeg"]');
var legNums = {};
legEls.forEach(function(el) {
var m = el.id.match(/jxMLLeg(\d+)$/);
if (m) legNums[m[1]] = true;
});
Object.keys(legNums).sort().forEach(function(n) {
var od = document.getElementById('jxMLLeg'+n+'OriginDisplay');
var oi = document.getElementById('jxMLLeg'+n+'OriginIATA');
var dd = document.getElementById('jxMLLeg'+n+'DestDisplay');
var di = document.getElementById('jxMLLeg'+n+'DestIATA');
var dt = form.querySelector('[name="legs['+n+'][depart]"]');
var tm = form.querySelector('[name="legs['+n+'][time]"]');
var px = form.querySelector('[name="legs['+n+'][pax]"]');
if (od) legs.push({
origin_display: od ? od.value : '',
origin_iata: oi ? oi.value : '',
dest_display: dd ? dd.value : '',
dest_iata: di ? di.value : '',
depart: dt ? dt.value : '',
time: tm ? tm.value : '',
pax: px ? px.value : '1',
});
});
var fd = new FormData(form);
fd.append('action', 'jxl_submit_lead');
fd.append('nonce', JXL_AJAX.nonce);
fd.append('legs_json', JSON.stringify(legs));
var phoneCode = form.querySelector('[name="phone_country_code"]');
var phoneNum = form.querySelector('[name="phone_number"]');
if (phoneCode && phoneNum) {
fd.set('phone_full', phoneCode.value + ' ' + phoneNum.value.trim());
}
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.textContent = 'Sending…';
}
fetch(JXL_AJAX.url, {
method: 'POST',
body: fd,
credentials: 'same-origin',
})
.then(function(r) { return r.json(); })
.then(function(data) {
if (data.success) {
form.innerHTML =
'' +
'✅' +
'Enquiry Received!
' +
'' + data.data.message + '
' +
'Reference: #' + data.data.lead_id + '
' +
'';
} else {
alert(data.data && data.data.message ? data.data.message : 'Submission failed. Please try again or contact us directly.');
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.textContent = originalBtnText;
}
}
})
.catch(function() {
alert('Network error. Please check your connection and try again.');
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.textContent = originalBtnText;
}
});
});
}
function fixMobileDropdowns() {
var style = document.createElement('style');
style.textContent =
'.jxl-ml-row { display:flex;align-items:flex-end;gap:8px;padding:10px 12px;background:#f8f9fa;border:1.5px solid #e8e8e8;border-radius:10px;margin-bottom:8px; }' +
'.jxl-ml-leg-label { display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:4px;flex-shrink:0;min-width:44px; }' +
'.jxl-ml-leg-num { font-size:10px;font-weight:700;letter-spacing:0.1em;text-transform:uppercase;color:#006038;white-space:nowrap; }' +
'.jxl-ml-leg-placeholder { display:block;height:26px; }' +
'.jxl-ml-label { display:block;font-size:10px;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;color:#888;margin-bottom:4px;white-space:nowrap; }' +
'.jxl-ml-field { display:flex;flex-direction:column;min-width:0; }' +
'.jxl-ml-from,.jxl-ml-to { flex:2;min-width:120px; }' +
'.jxl-ml-date { flex:1.6;min-width:110px; }' +
'.jxl-ml-time { flex:1.2;min-width:90px; }' +
'.jxl-ml-pax { flex:0.6;min-width:56px; }' +
'.jxl-ml-arrow { display:flex;align-items:flex-end;padding-bottom:11px;flex-shrink:0;color:#006038;font-size:16px; }' +
'.jxl-remove-leg-btn { display:flex;align-items:center;justify-content:center;width:26px;height:26px;border:1.5px solid #cc0000;border-radius:50%;background:transparent;color:#cc0000;cursor:pointer;font-size:13px;font-weight:700;flex-shrink:0;transition:all 0.2s;padding:0; }' +
'.jxl-remove-leg-btn:hover { background:#cc0000;color:#fff; }' +
'.jxl-add-leg-btn { width:100%;height:44px;background:transparent;border:2px dashed #006038;border-radius:8px;color:#006038;font-size:13px;font-weight:600;cursor:pointer;transition:all 0.2s;margin-bottom:4px; }' +
'.jxl-add-leg-btn:hover { background:rgba(0,96,56,0.05); }' +
'.jxl-ml-input { height:42px;border:1.5px solid #ddd;border-radius:6px;padding:0 10px;font-size:13px;color:#1a1a1a;background:#fff;outline:none;box-sizing:border-box;width:100%;transition:border-color 0.2s,box-shadow 0.2s; }' +
'.jxl-ml-input:focus { border-color:#006038;box-shadow:0 0 0 3px rgba(0,96,56,0.1); }' +
'.jx-form-group select { text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding-right:32px !important;max-width:100%; }' +
'select[name="trip_type"] option[value=""] { display:none; }' +
'@media (max-width: 640px) {' +
' #jxPhoneDropdown { position:fixed !important; left:14px !important; right:14px !important; width:auto !important; z-index:999999 !important; }' +
' .jxl-ml-row { flex-wrap:wrap;gap:6px;padding:10px; }' +
' .jxl-ml-leg-label { flex-direction:row;align-items:center;justify-content:space-between;width:100%;min-width:100%;order:-1;margin-bottom:2px; }' +
' .jxl-ml-leg-placeholder { display:none; }' +
' .jxl-ml-from,.jxl-ml-to { flex:1;min-width:calc(50% - 20px); }' +
' .jxl-ml-arrow { padding-bottom:11px;flex-shrink:0; }' +
' .jxl-ml-date { flex:1;min-width:calc(33% - 8px); }' +
' .jxl-ml-time { flex:1;min-width:calc(33% - 8px); }' +
' .jxl-ml-pax { flex:1;min-width:calc(33% - 8px); }' +
' .jxl-ml-input { height:40px !important;font-size:13px !important;padding:0 8px !important; }' +
' .jxl-ml-label { font-size:9px !important; }' +
' .jx-form-group select { font-size:14px !important;height:46px !important; }' +
'}'
document.head.appendChild(style);
}
function init() {
initPhonePicker();
fixPassengerField();
initMultiLeg();
initFormSubmit();
fixMobileDropdowns();
setTimeout(function() { getAirportsML(function() {}); }, 1500);
}
var _initAttempts = 0;
function tryInit() {
var phoneInput = document.querySelector('input[name="phone"]');
var paxSelect = document.querySelector('select[name="pax"]');
if (phoneInput && paxSelect) {
init();
} else if (_initAttempts < 30) {
_initAttempts++;
setTimeout(tryInit, 200);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', tryInit);
} else {
tryInit();
}
})();