var xmlHttp; var hidManageVal = ""; var inputAutocomplete = []; inputAutocomplete["txtFrom"] = "From..."; inputAutocomplete["txtTo"] = "To..."; var stopValue; function GetXmlHttpObject() { try { /* * Firefox, Opera 8.0+, Safari */ xmlHttp = new XMLHttpRequest(); } catch(e) { /* * Internet Explorer */ try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert("Your browser does not support AJAX!"); return false; } } } } $(function(){ if($(window).width() < 768){ $(".ui-autocomplete-input").each(function(){ $(this).autocomplete({ open: function(event, ui) { $('.ui-autocomplete').off('menufocus hover mouseover mouseenter'); var autoWidth = $(this).outerWidth(); $(this).autocomplete("widget").width(autoWidth - 10); } }) }); } $('.passcustommenu .dropdown-menu').click(function(e) { e.stopPropagation(); }); $(".passcustommenu").mouseleave(function(){ $(".passcustommenu.dropdown").removeClass("open"); }); }); $(".ui-autocomplete-input").on({ select : function() { var val = $(this).attr("id") + ":@@:" + $(this).val(); hidManageVal = val; }, focus : function() { $(this).select(); if($.trim($(this).val()) == 'To...' || $.trim($(this).val()) == 'From...'){$(this).val('');} if($.trim($(this).val()) != "") { autoDisplayLocation($(this).attr("id")); } }, blur : function() { var inputValue = $.trim($(this).val()); var inputId = $(this).attr("id"); if(inputAutocomplete.indexOf(inputValue) && inputValue == ''){ $(this).val(inputAutocomplete[inputId]); } if($.trim($(this).val()) != "") { autoDisplayLocation($(this).attr("id")); } }, keyup : function(e) { /** * check if the field is selected */ var arrHidManageVal = hidManageVal.split(":@@:"); if($(this).attr("id") == arrHidManageVal[0] && $(this).val() != arrHidManageVal[1]) { $(this).next("input:hidden").attr("value", ""); hidManageVal = ""; } if(e.keyCode == 8 || e.keyCode == 46) { $(this).next("input:hidden").attr("value", ""); } autoDisplayLocation($(this).attr("id")); } }); /* * Function for auto loading site user */ function autoDisplayLocation(eleId, hdPlaceId, hdCountryId, hdCityId, hdCountryName) { //alert(eleId); var elementID = "#" + eleId; var demomod = $('#DEMOMOD').val(); $(elementID).autocomplete({ source: function( request, response ) { $(elementID + "Loader").css("display", "block"); var strUrl = absPath + "Autocomplete.php?setAction=getAirports&term=" + $(elementID).val(); if(demomod == 1) { var strUrl=absPath+"Autocomplete.php?setAction=getAirports&DEMOMOD=1&term="+$(elementID).val(); } else { var strUrl=absPath+"Autocomplete.php?setAction=getAirports&term="+$(elementID).val(); } $.ajax({ url: strUrl, data: request, dataType: "json", type: "POST", /*success: function(data) { response(data); }*/ success: function( data ) { if (data == false) { response( $.map( data, function( item ) { return{ label: "No results found", value: "No results found", PlaceId: "", PlaceName: "", CountryId: "", CityId: "", CountryName: "" } })); } else{ response( $.map( data, function( item ) { //When typing in an airport code make it autoaccept if the code entered matches the list if((item.PlaceId.substr(0, 3).toString() == request.term.toUpperCase().toString().trim()) && data.length == 1 ){ $(this).val($('
').html(decodeURIComponent(item.value)).text()); if($("#" + eleId).next("input:hidden").length > 0) { $("#" + eleId).next("input:hidden").attr("value", item.PlaceId); var nextId = $("#" + eleId).next("input:hidden").attr("id"); } if($("#" + nextId).next("input:hidden").length > 0) { $("#" + nextId).next("input:hidden").attr("value", item.CountryId); var nextId = $("#" + nextId).next("input:hidden").attr("id"); } if($("#" + nextId).next("input:hidden").length > 0) { $("#" + nextId).next("input:hidden").attr("value", item.CityId); var nextId = $("#" + nextId).next("input:hidden").attr("id"); } if($("#" + nextId).next("input:hidden").length > 0) { $("#" + nextId).next("input:hidden").attr("value", item.CountryName); } if(item.PlaceId != ''){ if(document.getElementById(eleId)) { document.getElementById(eleId).value = decodeURIComponent(item.PlaceName + ", " + item.CountryName + " [" + item.PlaceId.substr(0, 3) + "]"); } checkFocusBlurEvent(eleId); } else{ if(document.getElementById(eleId)) { document.getElementById(eleId).value = item.PlaceName; $("#" + eleId).attr("value", ""); $("#" + eleId).next("input:hidden").attr("value", ""); } } } if(item.PlaceId != ''){ return{ label: (item.PlaceName + ", " + item.CountryName + " [" + item.PlaceId.substr(0, 3) + "]"), value: item.PlaceName, PlaceId: item.PlaceId, PlaceName: item.PlaceName, CountryId: item.CountryId, CityId: item.CityId, CountryName: item.CountryName } } else{ return{ label: item.PlaceName, value: item.PlaceName, PlaceId: item.PlaceId, PlaceName: item.PlaceName, CountryId: item.CountryId, CityId: item.CityId, CountryName: item.CountryName } } })); } $(elementID + "Loader").css("display", "none"); } }); }, minLength: 3, select: function (event, ui) { event.preventDefault(); $(this).val($('
').html(decodeURIComponent(ui.item.value)).text()); if($("#" + eleId).next("input:hidden").length > 0) { $("#" + eleId).next("input:hidden").attr("value", ui.item.PlaceId); var nextId = $("#" + eleId).next("input:hidden").attr("id"); } if($("#" + nextId).next("input:hidden").length > 0) { $("#" + nextId).next("input:hidden").attr("value", ui.item.CountryId); var nextId = $("#" + nextId).next("input:hidden").attr("id"); } if($("#" + nextId).next("input:hidden").length > 0) { $("#" + nextId).next("input:hidden").attr("value", ui.item.CityId); var nextId = $("#" + nextId).next("input:hidden").attr("id"); } if($("#" + nextId).next("input:hidden").length > 0) { $("#" + nextId).next("input:hidden").attr("value", ui.item.CountryName); } if(ui.item.PlaceId != ''){ if(document.getElementById(eleId)) { document.getElementById(eleId).value = decodeURIComponent(ui.item.PlaceName + ", " + ui.item.CountryName + " [" + ui.item.PlaceId.substr(0, 3) + "]"); } checkFocusBlurEvent(eleId); } else{ if(document.getElementById(eleId)) { document.getElementById(eleId).value = ui.item.PlaceName; $("#" + eleId).attr("value", ""); $("#" + eleId).next("input:hidden").attr("value", ""); } } } }); } function changeRoutes(){ if((document.getElementById('txtFrom').value != '' && document.getElementById('txtTo').value != '') && (document.getElementById('txtFrom').value != 'From...' && document.getElementById('txtTo').value != 'To...')){ var swaptxtFrom = document.getElementById('txtFrom').value; var swaphdPlaceId = document.getElementById('hdPlaceId').value; var swaphdCountryId = document.getElementById('hdCountryId').value; var swaphdCityId = document.getElementById('hdCityId').value; var swaphdCountryName = document.getElementById('hdCountryName').value; document.getElementById('txtFrom').value = document.getElementById('txtTo').value; document.getElementById('hdPlaceId').value = document.getElementById('hdToPlaceId').value; document.getElementById('hdCountryId').value = document.getElementById('hdToCountryId').value; document.getElementById('hdCityId').value = document.getElementById('hdToCityId').value; document.getElementById('hdCountryName').value = document.getElementById('hdToCountryName').value; document.getElementById('txtTo').value = swaptxtFrom; document.getElementById('hdToPlaceId').value = swaphdPlaceId; document.getElementById('hdToCountryId').value = swaphdCountryId; document.getElementById('hdToCityId').value = swaphdCityId; document.getElementById('hdToCountryName').value = swaphdCountryName; setBackgroundImage(); } } function checkFocusBlurEvent(elementID){ if(elementID == 'txtFrom'){ $("#txtTo").focus(); } if(elementID == 'txtTo'){ $("#flights_calendar_depart_inp_org").focus(); setBackgroundImage(); } } /* * Function to validate flight search criteria */ function flightSearchValidation(){ var departure = document.getElementById('txtFrom'); var destination = document.getElementById('txtTo'); var departureH = document.getElementById('hdPlaceId'); var destinationH = document.getElementById('hdToPlaceId'); var travelType = document.getElementById('hdTripType'); /* * Departure */ if(!notEmpty(departure, null, false, true) || departure.value == 'From...') { alert("Please select From"); departure.focus(); return false; } /* * Destination */ if(!notEmpty(destination, null, false, true) || destination.value == 'To...') { alert("Please select To"); destination.focus(); return false; } if(!notEmpty(departureH, null, false, true)) { alert("From is not valid"); departure.focus(); return false; } if(!notEmpty(destinationH, null, false, true)) { alert("To is not valid"); destination.focus(); return false; } if(departureH.value == destinationH.value) { alert("From and To should be different"); destination.focus(); return false; } /* * Date validation */ var departArr = document.getElementById('flights_calendar_depart_inp').value; if(!notEmpty(document.getElementById('flights_calendar_depart_inp'), null, false, true)) { alert("Please select Depart Date"); document.getElementById('flights_calendar_depart_inp_org').focus(); return false; } if(departArr == 'Depart Date'){ alert("Please select Depart Date"); document.getElementById('flights_calendar_depart_inp_org').focus(); return false; } /* * To get Today date in timestamp */ objToday = getCurrentDate("DD/MM/YYYY"); var todayDay = objToday.substring(0, 2); var todayMon = objToday.substring(3, 5); var todayYear = objToday.substring(6); var todayTime = new Date(todayYear, todayMon - 1, todayDay).getTime(); /* * To get Departure date in timestamp */ var departDay = departArr.substring(0, 2); var departMon = departArr.substring(3, 5); var departYear = departArr.substring(6); var depTime = new Date(departYear, departMon - 1, departDay).getTime(); /* * Check for Depart time greater than today time */ if(depTime < todayTime){ alert("Depart Date should be greater than Today Date"); return false; } //var travelType = 'R'; /* * If there is Roundtrip then validate Return date */ if(travelType.value == 2) { var returnArr = document.getElementById('flights_calendar_return_inp').value; var returnArr_org = document.getElementById('flights_calendar_return_inp_org').value; if(!notEmpty(document.getElementById('flights_calendar_return_inp_org'), null, false, true)) { alert("Please select Return Date"); document.getElementById('flights_calendar_return_inp_org').focus(); return false; } if(returnArr_org == 'Return Date') { alert("Please select Return Date"); document.getElementById('flights_calendar_return_inp_org').focus(); return false; } /* * To get Return date in timestamp */ var returnDay = returnArr.substring(0, 2); var returnMon = returnArr.substring(3, 5); var returnYear = returnArr.substring(6); var retTime = new Date(returnYear, returnMon - 1, returnDay).getTime(); /* * Check for Return time greater than today time */ if(retTime < todayTime){ alert("Return Date should be greater than Today Date"); return false; } /* * Check for Return time greater than Depart time */ if(depTime > retTime) { alert("Depart Date should not be greater than Return Date"); return false; } } /* * Check that searched page is home page or not */ if(deviceType == 'C' && (typeof flagHomePagePopup != 'undefined')){ //leaveBehindPopup(); } /* * Used to maintain stop information when clicking of update button in graph section. */ if((typeof flagMapSearch != 'undefined') && flagMapSearch == true){ if(document.getElementById('hidStrStop')){ stopValue = document.getElementById('hidStrStop').value; document.getElementById('hidStop').value = stopValue; } } /* * Get current form data */ var curr_data = $('#frmSearch').serializeArray().reduce(function(obj, item) { obj[item.name] = item.value; return obj; }, {}); $("#frmSearch").submit(); } /* * Function for leave behind. */ function leaveBehindPopup(){ var urlClickTripz = absPath + 'compareflightsearchppc.php?dep=' + $('#hdPlaceId').val().substr(0, 3) + '&dest=' + $('#hdToPlaceId').val().substr(0, 3) + '&depDate=' + $('#departureDateCT').val() + '&retDate=' + $('#returnDateCT').val() + '&adt=' + $('#hdAdults').val() + '&chl=' + $('#hdChildren').val() + '&inf=' + $('#hdInfants').val() + '&cabin=e&trip=' + $('#hdTripType').val() + 'code=PPCCMP&bncode=DIRFLT&chfcode=DIRFLT&affId=' + document.getElementById("affId").value; var screenHeight = screen.height; var screenWidth = screen.width; var topPos = (screenHeight / 3) * 2; var flBrowser = 'Other'; if(window.chrome && window.chrome != "undefined") { var flBrowser = 'Crome'; var topPos = (screenHeight / 2.15); } if(navigator.userAgent.indexOf("Firefox")!=-1) { var flBrowser = 'Firefox'; var topPos = (screenHeight / 3) * 2; } if(flBrowser == 'Other') { var popupWindow = window.open(urlClickTripz, "", "width=" + (screenWidth / 2) + ",height=" + screenHeight + ",scrollbars=yes,resizable=yes,left=" + (screenWidth / 2)); } else if(flBrowser == 'Crome') { var popupWindow = window.open(urlClickTripz, "", "width=" + (screenWidth / 4) + ",height=" + (screenHeight / 4) + ",scrollbars=yes,resizable=yes,left="+ screenWidth + ",top=" + ((screenHeight / 4) * 2.5)); } else { var popupWindow = window.open(urlClickTripz, "", "width=" + (screenWidth / 2.5) + ",height=" + (screenHeight / 2.5) + ",scrollbars=yes,resizable=yes,left=" + (screenWidth) + ",top=" + topPos); popupWindow.window.open('about:blank').close(); popupWindow.blur(); window.focus(); } } function setCabinClass(cabinClass, cabinClassName){ $("#hdCabinClass").val(cabinClass); $("#cabinClassName").html(cabinClassName); } function setTripType(tripType, tripName){ $("#hdTripType").val(tripType); $("#tripName").html(tripName); if(tripType == '1'){ $("#flights_calendar_return_inp_org").attr("disabled", "disabled"); $("#returndatecross").hide(); } else{ $("#flights_calendar_return_inp_org").removeAttr("disabled"); $("#returndatecross").show(); } } /* * Function for Adult child drop down */ function changePassenger(field, action){ var str; var count = $("#" + field).val(); switch(action) { case "removeAdult": if(count > 1){ $("#adultCounts").html(parseInt(count) - 1); $("#hdAdults").val(parseInt(count) - 1); } total = parseInt($("#adultCounts").html()) + parseInt($("#childCounts").html()); if(total > 1){ str = total + " Passengers"; } else{ str = total + " Passenger"; } $("#passengerCounts").html(str); break; case "addAdult": var demomod = $('#DEMOMOD').val(); if(demomod == 1) { var max_adult = 6; } else { var max_adult = 9; } if(count < max_adult){ $("#adultCounts").html(parseInt(count) + 1); $("#hdAdults").val(parseInt(count) + 1); } total = parseInt($("#adultCounts").html()) + parseInt($("#childCounts").html()); if(total > 1){ str = total + " Passengers"; } else{ str = total + " Passenger"; } $("#passengerCounts").html(str); break; case "removeChild": if(count > 0){ $("#childCounts").html(parseInt(count) - 1); $("#hdChildren").val(parseInt(count) - 1); } total = parseInt($("#adultCounts").html()) + parseInt($("#childCounts").html()); if(total > 1){ str = total + " Passengers"; } else{ str = total + " Passenger"; } $("#passengerCounts").html(str); break; case "addChild": if(count < 9){ $("#childCounts").html(parseInt(count) + 1); $("#hdChildren").val(parseInt(count) + 1); } total = parseInt($("#adultCounts").html()) + parseInt($("#childCounts").html()); if(total > 1){ str = total + " Passengers"; } else{ str = total + " Passenger"; } $("#passengerCounts").html(str); break; } } function setBackgroundImage(){ var countryName = $("#hdToPlaceId").val(); var strBackgroundUrl = absPath + "Autocomplete.php"; $.ajax({ url: strBackgroundUrl, type: 'GET', data: "setAction=getBackgroundURL&strCountryName=" + countryName, success: function(data) { //called when successful if($("#backgroundvideo").length > 0 && ($.trim(data) != absPath + 'images/main_bg.jpg')){ $("#backgroundvideo").hide(); } $('.mainpage-content').css('background-image', 'url(' + data + ')'); } }); }