var lang="ru"; $(document).ready(function () { var langParam = (typeof lang !== 'undefined' && lang) ? lang : 'en'; var i18n = { loadingAirports: "Loading Airports...", selectDestination: "Select destination from list", loadingAirlines: "Loading Airlines...", errorLoading: "Unable to load routes. Please try again." }; function setActiveStep(step) { var steps = { 1: $('#origininstructions1'), 2: $('#destinationinstructions1'), 3: $('#airlineinstructions1') }; $.each(steps, function (num, $el) { if (parseInt(num, 10) === step) { $el.removeClass('text-slate-800').addClass('text-[#2484C0]'); } else { $el.removeClass('text-[#2484C0]').addClass('text-slate-800'); } }); } function setAirlineMessage(text) { $('#airlinegroup').html( $('
', { 'class': 'flex h-full items-center justify-center text-center text-slate-400', text: text }) ); } function trackSearchEvent(action, label) { if (typeof window.gtag === 'function') { window.gtag('event', action, { event_category: 'Searchbox', event_label: label || '' }); } else if (typeof window._gaq !== 'undefined') { window._gaq.push(['_trackEvent', 'Searchbox', action, label || '']); } } // Initial state: highlight Step 1 and clear any browser-cached selection setActiveStep(1); $('#Origin').attr('selectedIndex', -1); // Step 1 -> Step 2: Load destinations for selected origin $('#Origin').change(function () { var origin = $('#Origin').val(); if (!origin) return; setActiveStep(2); $('#ajaxLoaderStep2').show(); $('#Destination').empty().append($('', { text: i18n.loadingAirports })); setAirlineMessage(i18n.selectDestination); $.ajax({ url: '/airline_box1_json.php', dataType: 'json', data: { selected_origin: origin, lang: langParam }, success: function (json) { var $dest = $('#Destination').empty(); if (json && json.routes) { $.each(json.routes, function (id, route) { var $optgroup = $('').attr({ label: route.country }).appendTo($dest); $.each(route.destinations || [], function (idx, airport) { $('') .attr({ value: airport.tocode }) .text(airport.airportname + ' (' + airport.tocode + ')') .appendTo($optgroup); }); }); } }, error: function () { $('#Destination').empty().append($('', { text: i18n.errorLoading })); }, complete: function () { $('#ajaxLoaderStep2').hide(); } }); trackSearchEvent('Box1Click', origin); }); // Step 2 -> Step 3: Load airlines for selected origin & destination $('#Destination').change(function () { var origin = $('#Origin').val(); var destination = $('#Destination').val(); if (!origin || !destination) return; $('#ajaxLoaderStep3').show(); setAirlineMessage(i18n.loadingAirlines); $.ajax({ url: '/airline_box2.php', dataType: 'html', data: { selected_origin: origin, selected_destination: destination, lang: langParam }, success: function (data) { $('#airlinegroup').html(data); setActiveStep(3); }, error: function () { setAirlineMessage(i18n.errorLoading); }, complete: function () { $('#ajaxLoaderStep3').hide(); } }); trackSearchEvent('Box2Click', origin + '-' + destination); }); });