") .appendTo(ul); }; // jq-origin autocomplete ends $("#jq-destination").autocomplete({ source: function(request, response) { var term = request.term; autocompleteSelected = false; //console.log(cache); if (term in cache) { response(cache[term]); } else { $.ajax({ url: "https://meroflight.com/flight/intl/locations", dataType: "json", data: { term: request.term }, success: function(data) { response(data); } }); } }, minLength: 0, select: function(event, ui) { event.preventDefault(); event.stopPropagation(); $("#intlflightForm").find("#jq-destination").val(ui.item.display); $("#jq-destination-val").val(ui.item.value); $('#intlflightForm input[name="destination"]').val(ui.item.value); autocompleteSelected = true; if (!event.keyCode || event.keyCode === 13) { if ($(this).val() != '') { if ($(this).parents('form').find('input[name="origin_lbl"]').val() === '') { $(this).parents('form').find('input[name="origin_lbl"]').focus(); } else if ($(this).parents('form').find('input[name="depaturedate"]') .val() === '') { $(this).parents('form').find('input[name="depaturedate"]').focus(); } else if ($(this).parents('form').find('input[name="returnedate"]') .val() === '') { $(this).parents('form').find('input[name="returnedate"]').focus(); } else if (!paxselected) { $(this).parents('form').find('#jq-passangers').focus(); } } } }, focus: function(event, ui) { event.preventDefault(); //$('#intlflightForm input[name="destination_lbl"]').val(ui.item.label); } }) .focus(function(event, ui) { //alert("www"); $('.cal').remove(); event.preventDefault(); if (!$(this).val().trim()) { //console.log('aa'); $(this).autocomplete("search"); } else { $(this).select(); } }) .autocomplete("instance")._renderItem = function(ul, item) { return $("
  • ") .append("
    " + item.label + item.desc + "
    ") .appendTo(ul); }; // jq-destination autocomplete ends $('#intlflightForm .jq-btn-number, #jq-intlMultiSeach .jq-btn-number').click(function(e) { e.preventDefault(); var fieldName = $(this).attr('data-field'); var type = $(this).attr('data-type'); var input = $(this).prev("input[name='" + fieldName + "']"); if (!input.is('input')) { input = $(this).next("input[name='" + fieldName + "']"); } var currentVal = parseInt(input.val()); if (!isNaN(currentVal)) { if (type == 'minus') { var minValue = parseInt(input.attr('min')); if (!minValue) minValue = 0; if (currentVal > minValue) { input.val(currentVal - 1).change(); } if (parseInt(input.val()) == minValue) { $(this).attr('disabled', true); } } else if (type == 'plus') { var maxValue = parseInt(input.attr('max')); if (!maxValue) maxValue = 9999999999999; if (currentVal < maxValue) { input.val(currentVal + 1).change(); } if (parseInt(input.val()) == maxValue) { $(this).attr('disabled', true); } } } else { input.val(0); } }); $('#intlflightForm .jq-input-number, #jq-intlMultiSeach .jq-input-number').focusin(function() { $(this).data('oldValue', $(this).val()); }); $('#intlflightForm .jq-input-number, #jq-intlMultiSeach .jq-input-number').change(function() { var minValue = parseInt($(this).attr('min')); var maxValue = parseInt($(this).attr('max')); if (!minValue) minValue = 0; if (!maxValue) maxValue = 9999999999999; var valueCurrent = parseInt($(this).val()); var name = $(this).attr('name'); if (valueCurrent >= minValue) { $(".jq-btn-number[data-type='minus'][data-field='" + name + "']").removeAttr('disabled') } else { //alert('Sorry, the minimum value was reached'); $(this).val($(this).data('oldValue')); } if (valueCurrent <= maxValue) { $(".jq-btn-number[data-type='plus'][data-field='" + name + "']").removeAttr('disabled') } else { // alert('Sorry, the maximum value was reached'); $(this).val($(this).data('oldValue')); } displayPassangerI($(this)); }); $("#intlflightForm .jq-input-number, #intlflightForm .jq-modify-input-number, #jq-intlMultiSeach .jq-input-number, #jq-intlMultiSeach .jq-modify-input-number") .keydown(function(e) { // Allow: backspace, delete, tab, escape, enter and . if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 || // Allow: Ctrl+A (e.keyCode == 65 && e.ctrlKey === true) || // Allow: home, end, left, right (e.keyCode >= 35 && e.keyCode <= 39)) { // let it happen, don't do anything return; } // Ensure that it is a number and stop the keypress if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { e.preventDefault(); } }); $('#intlflightForm .jq-modify-btn-number, #jq-intlMultiSeach .jq-modify-btn-number').click(function(e) { e.preventDefault(); var fieldName = $(this).attr('data-field'); var type = $(this).attr('data-type'); var input = $(this).prev("input[name='" + fieldName + "']"); if (!input.is('input')) { input = $(this).next("input[name='" + fieldName + "']"); } if (!input.is('input')) { input = $(this).prev().prev("input[name='" + fieldName + "']"); } var currentVal = parseInt(input.val()); if (!isNaN(currentVal)) { if (type == 'minus') { var minValue = parseInt(input.attr('min')); if (!minValue) minValue = 0; if (currentVal > minValue) { input.val(currentVal - 1).change(); } if (parseInt(input.val()) == minValue) { $(this).attr('disabled', true); } } else if (type == 'plus') { var maxValue = parseInt(input.attr('max')); if (!maxValue) maxValue = 9999999999999; if (currentVal < maxValue) { input.val(currentVal + 1).change(); } if (parseInt(input.val()) == maxValue) { $(this).attr('disabled', true); } } } else { input.val(0); } }); $('#intlflightForm .jq-modify-input-number, #jq-intlMultiSeach .jq-modify-input-number').focusin( function() { $(this).data('oldValue', $(this).val()); }); $('#intlflightForm .jq-modify-input-number, #jq-intlMultiSeach .jq-modify-input-number').change( function() { var minValue = parseInt($(this).attr('min')); var maxValue = parseInt($(this).attr('max')); if (!minValue) minValue = 0; if (!maxValue) maxValue = 9999999999999; var valueCurrent = parseInt($(this).val()); var name = $(this).attr('name'); if (valueCurrent >= minValue) { $(".jq-modify-btn-number[data-type='minus'][data-field='" + name + "']").removeAttr( 'disabled') } else { $(this).val($(this).data('oldValue')); } if (valueCurrent <= maxValue) { $(".jq-modify-btn-number[data-type='plus'][data-field='" + name + "']").removeAttr( 'disabled') } else { $(this).val($(this).data('oldValue')); } displayModifyPassanger($(this)); }); travelcore.autocomplete(); $('.jq-toggle-more-opt').on('click', function(e) { e.preventDefault(); if ($(this).find('a').text() == "more options!") { $(this).find('a').text("less options!") } else { $(this).find('a').text("more options!"); } $(this).parents('form').find('.jq-more-opts').slideToggle(); }); $('.jq-nationality').change(function() { var val = $(this).prop('value'); console.log(val); if (val == 'NP' || val == 'IN') $('.jq-currency option').eq(0).prop('selected', true); else $('.jq-currency option').eq(1).prop('selected', true); tot = $(this).parents('form').find('#jq-passangers').prop('value').split(","); if (tot[0] == '') { totalp = "1 Pax"; } else { totalp = tot[0]; } nati = $(this).parents('form').find('.jq-nationality').prop('value'); clsi = $(this).parents('form').find('.jq-classi').prop('value'); avali = totalp; if (nati != '' && nati != 'undefined') { avali = avali + " ," + nati; } if (clsi != '' && clsi != 'undefined') { avali = avali + " ," + clsi; } $(this).parents('form').find('#jq-passangers').prop('value', avali); }); $('.jq-classi').change(function() { //alert("aa"); var val = $(this).prop('value'); tot = $(this).parents('form').find('#jq-passangers').prop('value').split(","); if (tot[0] == '') { totalp = "1 Pax"; } else { totalp = tot[0]; } nati = $(this).parents('form').find('.jq-nationality').prop('value'); clsi = $(this).parents('form').find('.jq-classi').prop('value'); //alert(clsi); avali = totalp; if (nati != '') { avali = avali + " ," + nati; } if (clsi != '') { avali = avali + " ," + clsi; } $(this).parents('form').find('#jq-passangers').prop('value', avali); }); $('#jq-intl-search').click(function(e) { e.preventDefault(); //$('#intlflightForm').find('input[name="depaturedate"]').focus(); //return false; //$('#CommingSoonModal').modal('show'); //return false; return submitSearchForm(e); }); $('.jq-more-cities').click(function(e) { e.preventDefault(); if (travelcore.multicity < 6) { travelcore.multicity++; travelcore.multicitycount++; if ($(this).hasClass('jq-is-multi')) { $('.jq-multi-city-wrapper') .append('
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + 'From' + '' + '' + '
    ' + '
    ' + '
    ' + '
    Icon
    ' + '
    ' + '
    ' + '
    ' + 'To' + '' + '' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + ' Date' + '' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '

    ' + '
    ' + '
    ' + '
    ' ); } else { $('.jq-multi-city-wrapper') .append('
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '' + '' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '' + '' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '
    ' + '
    ' + '
    ' + '

    ' + '
    ' + '
    ' + '
    ' ); } travelcore.autocomplete(); } if (travelcore.multicity >= 6) { $('.jq-more-cities').hide(); } }); $('#jq-intl-multi-search').click(function(e) { e.preventDefault(); var $message = []; error = false; var i = 0; var originLength = $('input[name^="origin[]"]').length; var destinationLength = $('input[name^="destination[]"]').length; $('input[name^="origin[]"]').each(function(index) { var me = $(this); me.removeClass('error'); var val = me.prop('value'); val = $.trim(val); $('#jq-intlMultiSeach').find('input[name^="origin_lbl[]"]').eq(index) .removeClass('error'); $('#jq-intlMultiSeach').find('input[name^="destination_lbl[]"]').eq(index) .removeClass('error'); if (i <= 1) { if (val == '' || val.length == 0) { $message['origin'] = 'From field missing. You should atleast choose 2 destinations.'; error = true; me.addClass('error'); $('#jq-intlMultiSeach').find('input[name^="origin_lbl[]"]').eq(index) .addClass('error'); } if ((val != '' && val != 0) && ($('input[name^="destination[]"]').eq(index) .prop('value') != '' && $('input[name^="destination[]"]').eq(index) .prop('value').length != 0)) { if (val == $('input[name^="destination[]"]').eq(index).prop('value')) { error = true; $message['same_city'] = 'Please enter different from and to city.'; me.addClass('error'); $('#jq-intlMultiSeach').find('input[name^="origin_lbl[]"]').eq( index).addClass('error'); $('#jq-intlMultiSeach').find('input[name^="destination_lbl[]"]').eq( index).addClass('error'); } } } if (originLength > 2 && i >= 2) { if ((val != '' && val != 0) && ($('input[name^="destination[]"]').eq(index) .prop('value') != '' && $('input[name^="destination[]"]').eq(index) .prop('value').length != 0)) { if (val == $('input[name^="destination[]"]').eq(index).prop('value')) { error = true; $message['same_city'] = 'Please enter different from and to city.'; me.addClass('error'); $('#jq-intlMultiSeach').find('input[name^="origin_lbl[]"]').eq( index).addClass('error'); $('#jq-intlMultiSeach').find('input[name^="destination_lbl[]"]').eq( index).addClass('error'); } } } i++; }); var j = 0; $('input[name^="destination[]"]').each(function(index) { var me = $(this); me.removeClass('error'); var val = me.prop('value'); val = $.trim(val); if (j <= 1) { if (val == '' || val.length == 0) { $message['destination'] = 'To field is missing. You should atleast choose 2 destinations.'; error = true; me.addClass('error'); $('#jq-intlMultiSeach').find('input[name^="destination_lbl[]"]').eq( index).addClass('error'); } } j++; }); var d = 0; $('input[name^="depaturedate[]"]').each(function(index) { var me = $(this); me.removeClass('error'); var val = me.prop('value'); val = $.trim(val); if (d <= 1) { if (val == '' || val.length == 0) { $message['departure_date'] = 'Departure date is missing.'; error = true; me.addClass('error'); } } d++; }); var pax1 = $('#jq-intlMultiSeach').find('input[name="adults"]').prop('value'); var pax2 = $('#jq-intlMultiSeach').find('input[name="studnets"]').prop('value'); var pax = pax1 + pax2; if (pax == '' || pax == 0 || pax == undefined || pax == null) { console.log(pax); $message['pax'] = 'Please Make Sure At least one pax.'; $('#jq-intlMultiSeach').find('input[name^="adults"]').addClass('error'); error = true; } if (error) { //$('.alert').html($message).show(); var message = ''; if ($message['origin']) { message = $message['origin'] + '
    '; } if ($message['destination']) { message += $message['destination'] + '
    '; } if ($message['same_city']) { message += $message['same_city'] + '
    '; } if ($message['departure_date']) { message += $message['departure_date'] + '
    '; } if ($message['pax']) { message += $message['pax'] + '
    '; } var $element = '
    ' + '' + message + '
    '; $('.multi-alert').html($element).show(); return false; } $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': travelcore.token } }) var formData = $('#jq-intlMultiSeach').serialize(); $.ajax({ type: 'GET', url: "https://meroflight.com/flight/multi/search", data: formData, dataType: 'json', beforeSend: function(xhr) { $('#ModifySearchPopup').modal('hide'); $('#searchingModal').find('p').text($('#searchingModal').find('p') .text().replace(":trip", 'multicity')); $('#searchingModal').modal('show'); }, success: function(data) { if (data.success) { succUrl = travelcore.flight_intl_list_url.replace('TOKEN', data .token); window.location = succUrl; } else { $('#searchingModal').modal('hide'); alert(data.message); } }, error: function(data) { console.log('Error:', data); } }); }); $('.jq-more-opt').click(function() { var toggleElement = $(this).parents('.jq-each-city').find('.jq-default-segment'); toggleElement.toggle(); $(this).text() == $(this).data('count') + ' More Options' ? $(this).text('Hide Options') : $(this).text($(this).data('count') + ' More Options'); }); $('.jq-fligh-options').find('input[type="radio"]').click(function() { var txt = $(this).parents('.jq-div-select:first').find('.jq-flight-time:first').html(); var info = $(this).parents('.jq-each-city').find('.jq-default-segment'); info.find('.FlightTime:first').html(txt); var txt = $(this).parents('.jq-div-select:last').find('.jq-flight-time:last').html(); var info = $(this).parents('.jq-each-city').find('.jq-default-segment'); info.find('.FlightTime:last').html(txt); var txt = $(this).parents('.jq-div-select:first').find('.jq-input-flight-duration').prop( 'value'); info.find('.FlightDuration').html(txt); var txt = $(this).parents('.jq-div-select:first').find('.jq-stopove').prop('value'); info.find('.FlightStop').html(txt); }); $('.jq-prev-next-nav').click(function(e) { e.preventDefault(); //alert("aa"); var trip = travelcore.trip; var nvaType = $(this).data('nav'); var direction = $('select[name="navTravelDirection"]').prop('value'); if (trip == 2) { // One Way var givenDay = $(this).data('day'); } else if (trip == 1) { // Two Way var givenDay = $(this).data('day'); var dateParts = givenDay.split('-'); if (direction == 1) givenDay = $.trim(dateParts[0]); else givenDay = $.trim(dateParts[1]); } else { // Multicity var givenDay = $(this).data('day'); } //console.log('Toady Is '+givenDay); let D = new Date(givenDay); if (nvaType == 1) var date = new Date(D.getFullYear(), D.getMonth(), (D.getDate() - 1)); else var date = new Date(D.getFullYear(), D.getMonth(), (D.getDate() + 1)); var d = date.getDate(); var m = date.getMonth() + 1; //Month from 0 to 11 var y = date.getFullYear(); var newDate = (m <= 9 ? '0' + m : m) + '/' + (d <= 9 ? '0' + d : d) + '/' + y; //console.log('New Date is '+newDate); if (trip == 1) { // Two Way if (direction == 1) { $('#jq-clone-intlSerach').find('input[name="depaturedate"]').prop('value', newDate); $('#jq-clone-intlSerach').find('input[name="returndate"]').prop('value', $.trim( dateParts[1])); } else { $('#jq-clone-intlSerach').find('input[name="depaturedate"]').prop('value', $.trim( dateParts[0])); $('#jq-clone-intlSerach').find('input[name="returndate"]').prop('value', newDate); } } else { $('#jq-clone-intlSerach').find('input[name="depaturedate"]').prop('value', newDate); } var formData = $('#jq-clone-intlSerach').serialize(); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': travelcore.token } }) $.ajax({ type: 'GET', url: "https://meroflight.com/flight/intl/search", data: formData, dataType: 'json', beforeSend: function(xhr) { $('.bd-modify-search-modal-lg').modal('hide'); if (trip == 1) var _trip = 'roundtrip'; else if (trip == 2) var _trip = 'oneway'; else var _trip = 'multicity'; $('#searchingModal').find('p').text($('#searchingModal').find('p') .text().replace(":trip", _trip)); $('#searchingModal').modal('show'); }, success: function(data) { if (data.success) { succUrl = travelcore.flight_intl_list_url.replace('TOKEN', data .token); window.location = succUrl; } else { $('#searchingModal').modal('hide'); var $html = '
    ' + '' + data.message + '
    '; $('.intl-alert').html($html).show(); //alert(data.message); } }, error: function(data) { console.log('Error:', data); } }); }); if (travelcore.trip != 3) { // var cloneForm = $('#jq-intlSerach').clone(); if ($('#intlflightForm').length != 0) { var cloneForm = $('#intlflightForm').clone(); } cloneForm.prop('name', 'intlCloneSeach'); cloneForm.prop('id', 'jq-clone-intlSerach'); cloneForm.find('#jq-caleran-intl').prop('id', 'jq-clone-caleran-intl'); $('.navSerachFromWrapper').append(cloneForm); $('#jq-clone-intlSerach').find('input[name="depaturedate"]').removeAttr('id'); $('#jq-clone-intlSerach').find('input[name="returndate"]').removeAttr('id'); } }); // Dcoument Ready Ends $(document).on('keypress', '.jq-calendar-multi', function(e) { e.preventDefault(); }); $(document).on('keydown', '.jq-calendar-multi', function(e) { e.preventDefault(); }); $(document).on('focus', '.jq-calendar-multi', function() { var currentCaleranIndex = $('.jq-calendar-multi').index($(this)); var date = new Date(); var timestamp = date.getTime(); var myid = makeid(5) + timestamp + currentCaleranIndex; $(this).prop('id', myid); var previousCaleran = getPrevious(currentCaleranIndex - 1); if (currentCaleranIndex == 0) { if ($(this).prop('value') != '') { new TinyPicker({ firstBox: document.getElementById(myid), elemtId: $(this), startDate: new Date($(this).prop('value')), success: function(a, elem) { $('.jq-calendar-multi').each(function(index) { var currentCaleranIndex = $('.jq-calendar-multi').index(elem); if (index > currentCaleranIndex) { $('.jq-calendar-multi').eq(index).prop('value', ''); } }); } }).init(); } else { new TinyPicker({ firstBox: document.getElementById(myid), elemtId: $(this), success: function(a, elem) { $('.jq-calendar-multi').each(function(index) { var currentCaleranIndex = $('.jq-calendar-multi').index(elem); if (index > currentCaleranIndex) { $('.jq-calendar-multi').eq(index).prop('value', ''); } }); } }).init(); } } else if (previousCaleran && previousCaleran.prop('value') != '') { console.log(previousCaleran); var prevdate = new Date(previousCaleran.prop('value')); if ($(this).prop('value') != '') { new TinyPicker({ firstBox: document.getElementById(myid), elemtId: $(this), showFrom: prevdate, startDate: new Date($(this).prop('value')), success: function(a, elem) { $('.jq-calendar-multi').each(function(index) { var currentCaleranIndex = $('.jq-calendar-multi').index(elem); if (index > currentCaleranIndex) { $('.jq-calendar-multi').eq(index).prop('value', ''); } }); } }).init(); } else { new TinyPicker({ firstBox: document.getElementById(myid), elemtId: $(this), showFrom: prevdate, success: function(a, elem) { $('.jq-calendar-multi').each(function(index) { var currentCaleranIndex = $('.jq-calendar-multi').index(elem); if (index > currentCaleranIndex) { $('.jq-calendar-multi').eq(index).prop('value', ''); } }); } }).init(); } } }); function getPrevious(index) { if (index >= 0) { var previousCaleran = $('.jq-calendar-multi').eq(index); if (previousCaleran.length > 0) { if (previousCaleran.prop('value') != '') { return previousCaleran; } else { return getPrevious(index - 1); } } else { return getPrevious(index - 1); } } else { return false; } } function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for (var i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } $(document).on('keydown', 'input[name="origin_lbl[]"]', function(e) { var key = event.keyCode || event.charCode; if (key == 8 || key == 46) { $(this).parent('div').find('input[name="origin[]"]').prop('value', ''); } }); $(document).on('keydown', 'input[name="destination_lbl[]"]', function(e) { var key = event.keyCode || event.charCode; if (key == 8 || key == 46) { $(this).parent('div').find('input[name="destination[]"]').prop('value', ''); } }); $(document).on('click', '.jq-remove-cities', function(e) { e.preventDefault(); $(this).parents('.jq-cities').remove(); travelcore.multicity--; if (travelcore.multicity < 6) { $('.jq-more-cities').show(); } }); $(document).on('focusout', '.active day', function() { $('.jq-passangers-input').trigger('focus'); }); $(window).click(function(e) { if (caleransuccess == false) $('.jq-intl-pax').hide(); caleransuccess = false; }); $('.jq-passangers-input').click(function(event) { $('.cal').remove(); caleransuccess = false; event.stopPropagation(); }); $('.jq-intl-pax').on('click', function(e) { e.preventDefault(); e.stopPropagation(); }); function toggling(element) { $("." + element).toggle(); } var displayPassangerI = function(me) { var total = 0; console.log(me); me.parents('form').find('.jq-input-number').map(function() { var count = parseInt($(this).prop('value')); if (!isNaN(count)) total += parseInt($(this).prop('value')); }); if (total > 9) { //console.log(me.data('oldValue')); me.val(me.val() - 1); alert('Can not exceed maximum 9 Pax'); return false; } nati = me.parents('form').find('.jq-nationality').prop('value'); clsi = me.parents('form').find('.jq-classi').prop('value'); avali = ''; if (nati != '' && nati != 'undefined') { avali = avali + " ," + nati; } if (clsi != '' && clsi != 'undefined') { avali = avali + " ," + clsi; } me.parents('form').find('#jq-passangers').prop('value', total + (total == 1 ? " Pax" : " Pax") + avali); } var displayModifyPassangerI = function(me) { var total = 0; //console.log(me); me.parents('form').find('.jq-modify-input-number').map(function() { var count = parseInt($(this).prop('value')); if (!isNaN(count)) total += parseInt($(this).prop('value')); }); if (total > 9) { //console.log(me.data('oldValue')); me.val(me.val() - 1); alert('Can not exceed maximum 9 Pax'); return false; } nati = me.parents('form').find('.jq-nationality').prop('value'); clsi = me.parents('form').find('.jq-classi').prop('value'); avali = ''; if (nati != '' && nati != 'undefined') { avali = avali + " ," + nati; } if (clsi != '' && clsi != 'undefined') { avali = avali + " ," + clsi; } //me.parents('form').find('#jq-passangers').prop('value', total + (total == 1 ? " Pax" : " Pax") + avali); me.parents('form').find('.jq-passangers-input').prop('value', total + (total == 1 ? " Pax" : " Pax") + avali); } var submitSearchForm1 = function() { var origin = $('#intlflightForm').find('input[name="origin"]').prop('value'); var destination = $('#intlflightForm').find('input[name="destination"]').prop('value'); var depatureDate = $('#intlflightForm').find('input[name="depaturedate"]').prop('value'); var returnDate = $('#intlflightForm').find('input[name="returndate"]').prop('value'); var trip = $('#intlflightForm').find('input[name="trip"]:checked').prop('value'); var currency = $('#intlflightForm').find('input[name="currency"]').prop('value'); var error = false; var message = []; origin = $.trim(origin); destination = $.trim(destination); depatureDate = $.trim(depatureDate); returnDate = $.trim(returnDate); if (origin == '' || origin.length == 0) { $('#intlflightForm').find('input[name^="origin"]').addClass('error'); message[message.length] = 'From field is missing'; error = true; } else if (origin.length < 3 || origin.length > 3) { $('#intlflightForm').find('input[name^="origin"]').addClass('error'); message[message.length] = '
    Invalid Origin'; error = true; } if (destination == '' || destination.length == 0) { $('#intlflightForm').find('input[name^="destination"]').addClass('error'); message[message.length] = 'To field is missing'; error = true; } else if (destination.length < 3 || destination.length > 3) { $('#intlflightForm').find('input[name^="destination"]').addClass('error'); message[message.length] = '
    Invalid Destintion'; error = true; } if ((origin != '' && origin.length != 0) && (destination != '' && destination.length != 0)) { if (origin == destination) { error = true; message[message.length] = 'Please enter different from and to city.'; } } if (depatureDate == '' || depatureDate.length == 0) { $('#intlflightForm').find('input[name^="depaturedate"]').addClass('error'); message[message.length] = 'Departure date is missing'; error = true; } if (trip == 1 && (returnDate == '' || returnDate.length == 0)) { $('#intlflightForm').find('input[name^="returnedate"]').addClass('error'); message[message.length] = 'Return date is missing'; error = true; } if (error) { var $element = '
    ' + '' + message.join('
    ') + '
    '; $('.intl-alert').html($element).show(); //$('.ncs-intl-alert').html(message).show(); return false; } $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': travelcore.token } }) var formData = $('#intlflightForm').serialize(); $.ajax({ type: 'GET', url: "https://meroflight.com/flight/intl/search", data: formData, dataType: 'json', beforeSend: function(xhr) { $('#ModifySearchPopup').modal('hide'); if (trip == 1) var _trip = 'roundtrip'; else if (trip == 2) var _trip = 'oneway'; else var _trip = 'multicity'; $('#searchingModal').find('p').text($('#searchingModal').find('p').text().replace( ":trip", _trip)); $('#searchingModal').modal('show'); }, success: function(data) { if (data.success) { succUrl = travelcore.flight_intl_list_url.replace('TOKEN', data.token); window.location = succUrl; } else { $('#searchingModal').modal('hide'); alert(data.message); } }, error: function(data) { console.log('Error:', data); } }); } var submitSearchForm = function(e) { $("#intlflightForm *").filter(':input').each(function() { $(this).removeClass('error'); }); $('.intl-alert').html(' '); var origin = $('#intlflightForm').find('input[name="origin"]').prop('value'); var destination = $('#intlflightForm').find('input[name="destination"]').prop('value'); var depatureDate = $('#intlflightForm').find('input[name="depaturedate"]').prop('value'); var returnDate = $('#intlflightForm').find('input[name="returndate"]').prop('value'); var trip = $('#intlflightForm').find('input[name="trip"]:checked').prop('value'); var nationality = $('#intlflightForm').find('select[name="nationality"]').prop('value'); var pax1 = $('#intlflightForm').find('input[name="adults"]').prop('value'); var pax2 = $('#intlflightForm').find('input[name="studnets"]').prop('value'); var pax = pax1 + pax2; var error = false; var message = []; origin = $.trim(origin); destination = $.trim(destination); depatureDate = $.trim(depatureDate); returnDate = $.trim(returnDate); if (origin == '' || origin.length == 0) { $('#intlflightForm').find('input[name^="origin_lbl"]').focus(); return false; } if (destination == '' || destination.length == 0) { $('#intlflightForm').find('input[name^="destination_lbl"]').focus(); return false; } if (depatureDate == '' || depatureDate.length == 0) { $('#intlflightForm').find('input[name="depaturedate"]').focus(); return false; } if (trip == 1 && (returnDate == '' || returnDate.length == 0)) { $('#intlflightForm').find('input[name="returndate"]').focus(); return false; } if ((origin != '' && origin.length != 0) && (destination != '' && destination.length != 0)) { if (origin == destination) { error = true; message[message.length] = 'Please enter different from and to city.'; $('#intlflightForm').find('input[name^="origin"]').addClass('error'); $('#intlflightForm').find('input[name^="destination"]').addClass('error'); } } //if (pax == '' || pax == 0 || pax == undefined || pax == null) { // console.log(pax); // message[message.length] = 'Please Make Sure At least one pax.'; // $('#intlflightForm').find('input[name^="adults"]').addClass('error'); // error = true; //} if (nationality == '' || nationality.length == 0) { message[message.length] = 'Please choose nationality.'; $('#intlflightForm').find('select[name^="nationality"]').addClass('error'); error = true; } e.preventDefault(); if (error) { var $element = '
    ' + '' + message.join('
    ') + '
    '; $('.intl-alert').html($element).show(); //$('.ncs-intl-alert').html(message).show(); return false; } $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': travelcore.token } }) var formData = $('#intlflightForm').serialize(); $.ajax({ type: 'GET', url: "https://meroflight.com/flight/intl/search", data: formData, dataType: 'json', beforeSend: function(xhr) { $('#ModifySearchPopup').modal('hide'); if (trip == 1) var _trip = 'roundtrip'; else if (trip == 2) var _trip = 'oneway'; else var _trip = 'multicity'; $('#searchingModal').find('p').text($('#searchingModal').find('p').text().replace( ":trip", _trip)); $('#searchingModal').modal('show'); }, success: function(data) { if (data.success) { if (data.domestic == true) { var succUrl = travelcore.flight_domsetic_list_url.replace('TOKEN', data.token); console.log(succUrl); window.location.href = succUrl; return; } succUrl = travelcore.flight_intl_list_url.replace('TOKEN', data.token); window.location.href = succUrl; } else { $('#searchingModal').modal('hide'); var $html = '
    ' + '' + data.message + '
    '; $('.intl-alert').html($html).show(); //alert(data.message); } }, error: function(data) { console.log('Error:', data); } }); } travelcore.autocomplete = function() { $('input[name="origin_lbl[]"]').each(function(index) { var me = $(this); //console.log(index); me.autocomplete({ source: function(request, response) { var term = request.term; autocompleteSelected = false; //console.log(cache); if (term in cache) { response(cache[term]); } else { $.ajax({ url: "https://meroflight.com/flight/intl/locations", dataType: "json", data: { term: request.term }, success: function(data) { response(data); } }); } }, minLength: 0, select: function(event, ui) { event.preventDefault(); event.stopPropagation(); $('input[name="origin[]"]').eq(index).val(ui.item.value); me.val(ui.item.display); autocompleteSelected = true; if (!event.keyCode || event.keyCode === 13) { if ($(this).val() != '') { let indexCount = $(this).data('index') ?? 1; if (indexCount >= 2) { if ($(this).parents('.intl-row').find( 'input[name="destination_lbl[]"]').val() === '') { setTimeout(() => { $(this).parents('.intl-row').find( 'input[name="destination_lbl[]"]') .focus(); }, 5); } else if ($(this).parents('.intl-row').find( 'input[name="depaturedate[]"]').val() === '') { setTimeout(() => { $(this).parents('.intl-row').find( 'input[name="depaturedate[]"]').focus(); }, 0); } else if (!paxselected) { setTimeout(() => { $(this).parents('.intl-row').find( '#jq-multi-passangers').focus(); }, 0); } } else { if ($(this).parents('.wrap-multisearch').find( 'input[name="destination_lbl[]"]').val() === '') { setTimeout(() => { $(this).parents('.wrap-multisearch').find( 'input[name="destination_lbl[]"]') .focus(); }, 5); } else if ($(this).parents('.wrap-multisearch').find( 'input[name="depaturedate[]"]').val() === '') { setTimeout(() => { $(this).parents('.wrap-multisearch').find( 'input[name="depaturedate[]"]').focus(); }, 0); } else if (!paxselected) { setTimeout(() => { $(this).parents('.wrap-multisearch').find( '#jq-multi-passangers').focus(); }, 0); } } } } }, focus: function(event, ui) { event.preventDefault(); // me.val(ui.item.label); } }) .focusout(function(event, ui) { event.stopPropagation(); if (!me.val().trim()) { $(this).val(''); } }) .focus(function() { $('.cal').remove(); if (!me.val().trim()) { $(this).autocomplete("search"); } else { $(this).select(); } }) .autocomplete("instance")._renderItem = function(ul, item) { return $("
  • ") .append("
    " + item.label + item.desc + "
    ") .appendTo(ul); }; }); $('input[name="destination_lbl[]"]').each(function(index) { var me = $(this); me.autocomplete({ source: function(request, response) { var term = request.term; autocompleteSelected = false; //console.log(cache); if (term in cache) { response(cache[term]); } else { $.ajax({ url: "https://meroflight.com/flight/intl/locations", dataType: "json", data: { term: request.term }, success: function(data) { response(data); } }); } }, minLength: 0, select: function(event, ui) { event.preventDefault(); event.stopPropagation(); $('input[name="destination[]"]').eq(index).val(ui.item.value); me.val(ui.item.display); autocompleteSelected = true; if (!event.keyCode || event.keyCode === 13) { if ($(this).val() != '') { let indexCount = $(this).data('index') ?? 1; if (indexCount >= 2) { if ($(this).parents('.intl-row').find( 'input[name="origin_lbl[]"]').val() === '') { setTimeout(() => { $(this).parents('.intl-row').find( 'input[name="origin_lbl[]"]').focus(); }, 0) } else if ($(this).parents('.intl-row').find( 'input[name="depaturedate[]"]').val() === '') { setTimeout(() => { $(this).parents('.intl-row').find( 'input[name="depaturedate[]"]').focus(); }, 0) } else if (!paxselected) { setTimeout(() => { $(this).parents('.intl-row').find( '#jq-multi-passangers').focus(); }, 0) } } else { if ($(this).parents('.wrap-multisearch').find( 'input[name="origin_lbl[]"]').val() === '') { setTimeout(() => { $(this).parents('.wrap-multisearch').find( 'input[name="origin_lbl[]"]').focus(); }, 0) } else if ($(this).parents('.wrap-multisearch').find( 'input[name="depaturedate[]"]').val() === '') { setTimeout(() => { $(this).parents('.wrap-multisearch').find( 'input[name="depaturedate[]"]').focus(); }, 0) } else if (!paxselected) { setTimeout(() => { $(this).parents('.wrap-multisearch').find( '#jq-multi-passangers').focus(); }, 0) } } } } }, focus: function(event, ui) { event.preventDefault(); //me.val(ui.item.label); } }) .focusout(function(event, ui) { //console.log('focusout'); if (!me.val().trim()) { $(this).val(''); } }) .focus(function(event, ui) { $('.cal').remove(); event.preventDefault(); if (!me.val().trim()) { $(this).autocomplete("search"); } else { $(this).select(); } }) .autocomplete("instance")._renderItem = function(ul, item) { return $("
  • ") .append("
    " + item.label + item.desc + "
    ") .appendTo(ul); }; }); }
  • ' ).show(); var formData = $('#tourismcoreloginForm').serialize(); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': travelcore.token } }); $.ajax({ type: 'POST', url: "https://meroflight.com/dispatch/module", data: formData, dataType: 'json', beforeSend: function(xhr) {}, success: function(data) { $('.tourismcoreloginBolck').html(data.html).show(); }, error: function(data) { console.log(data); } }); } } }); $(".owl-carousel").owlCarousel(); $('.cancel-mpbt').click(function() { $.ajax({ type: 'get', url: "https://meroflight.com/flight/intl/endset", data: '', dataType: 'json', beforeSend: function(xhr) {}, success: function(data) { }, error: function(data) { console.log(data); } }); $('.flight-model').hide(); }); }); if ($('#otpphonelogin').length > 0) { var input = document.querySelector("#otpphonelogin"); window.intlTelInput(input, { preferredCountries: ['np'], separateDialCode: true, utilsScript: "https://meroflight.com/siteassets/js/utils.js" }); }