// JavaScript Document $(document).ready(function () { // Clear the signature on focus and put enter name back on blur if empty $("#email").focus(function() { if($('#email').val() == 'Please enter your email'){ $("#email").val(""); } }); $("#email").blur(function() { if($('#email').val() == ''){ $("#email").val("Please enter your email"); } }); // Initialize validation dialog $("#validationDialog").dialog({ autoOpen: false, bgiframe: true, modal: true, buttons: { Ok: function() { $(this).dialog('close'); } } }); // Pop up validation dialog when email fails $("#newsletterForm").submit(function (){ var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = $("#email").val(); if ($("#email").val() == 'Please enter your email'){ $("#validationDialog").dialog('open'); return false; }else if(reg.test(address) == false) { $("#validationDialog").dialog('open'); return false; }else{ return true; } }); // Initialize changing city dialog $("#changeCityDialog").dialog({ autoOpen: false, bgiframe: true, modal: true, buttons: { Change: function() { $("#changeCityForm").submit(); } } }); // Open changing city dialog when link is clicked $("#changeCity").click(function(){ $("#changeCityDialog").dialog('open'); }); // Default date picker $(".date").datepicker({ showOn: 'both', buttonImageOnly: true, buttonImage: 'css/images/calendar-sm.gif', buttonText: 'Select date' }); // Flight date range var flight_dates = $('#flight_date_dep, #flight_date_ret').datepicker({ showOn: 'both', buttonImageOnly: true, buttonImage: 'css/images/calendar-sm.gif', buttonText: 'Select date', changeMonth: true, changeYear:true, numberOfMonths: 1, onSelect: function(selectedDate) { var option = this.id == "flight_date_dep" ? "minDate" : "maxDate"; var instance = $(this).data("datepicker"); var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings); flight_dates.not(this).datepicker("option", option, date); } }); // Hotel date range var hotel_dates = $('#hotel_date_dep, #hotel_date_ret').datepicker({ showOn: 'both', buttonImageOnly: true, buttonImage: 'css/images/calendar-sm.gif', buttonText: 'Select date', changeMonth: true, changeYear:true, numberOfMonths: 1, onSelect: function(selectedDate) { var option = this.id == "hotel_date_dep" ? "minDate" : "maxDate"; var instance = $(this).data("datepicker"); var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings); hotel_dates.not(this).datepicker("option", option, date); } }); // Car date range var car_dates = $('#car_date_dep, #car_date_ret').datepicker({ showOn: 'both', buttonImageOnly: true, buttonImage: 'css/images/calendar-sm.gif', buttonText: 'Select date', changeMonth: true, changeYear:true, numberOfMonths: 1, onSelect: function(selectedDate) { var option = this.id == "car_date_dep" ? "minDate" : "maxDate"; var instance = $(this).data("datepicker"); var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings); car_dates.not(this).datepicker("option", option, date); } }); $("#gateway_dep").keyup(function(){ processSuggest($(this),$("#fromSuggest")); }); $("#gateway_dep").blur(function(){ $(this).css({"border" : "1px solid #7f9db9"}); setTimeout(function(){$('#fromSuggest').html('')},500); }); $("#dest_dep").keyup(function(){ processSuggest($(this),$("#toSuggest")); }); $("#dest_dep").blur(function(){ $(this).css({"border" : "1px solid #7f9db9"}); setTimeout(function(){$('#toSuggest').html('')},500); }); function processSuggest(element,suggestDiv) { if(element.val().length >= 3){ element.css({ "background" : "white url(images/indicator.gif) no-repeat right", "padding" : "1px" }); $.getJSON("ajax/qry_getAirport.cfm",{keyword: element.val()}, function(j){ element.css({ "background" : "white", "padding" : "1px", "border" : "1px solid #7f9db9" }); var result = ''; for (var i = 0; i < j.length; i++) { if(i % 2 == 0){ result += '
  • ' }else{ result += '
  • ' } result += '' + j[i].CODE + ', ' + j[i].NAME + ',
    ' + j[i].AIR_NAME + '
  • '; } suggestDiv.html(result); $(".suggestElement").click(function(){ element.val($(this).text()); suggestDiv.html(''); }); } ); } else { suggestDiv.html(''); } } // Prepopulate the destination dropdown for vacations search $.getJSON("ajax/softvoyage/departures.js", function(j){ for (var i = 0; i < j.length; i++) { $(".departure").append(''); } } ); // Define outside variable for destinations JSON response for use in Hotels generation var destinations_json; // Vacation search departure -> destination -> hotels population $("#departure_package").change(function(){ $("#destination_load").html(''); // Get destinations for picked departure $.getJSON("ajax/softvoyage/" + $(this).val() + ".js", function(destinations){ destinations_json = destinations; $(".destination").html(''); $("#no_hotel").html(''); // Populate dropdown of destinations separated by regions for (var i = 0; i < destinations.length; i++) { if(destinations[i].TYPE == "section"){ $(".destination").append(''); } else { $(".destination").append(''); } } $("#destination_load").html(''); } ); }); // When clicked on the destination get the hotels for it $(".destination").change(function(){ $("#hotel_load").html(''); var codesArray = new Array(); // Only sub sections can have hotels, so create array of hotel codes for picked destination for (var i = 0; i < destinations_json.length; i++) { if(destinations_json[i].TYPE == "sub_section" && destinations_json[i].CODE == $(this).val()){ var codes = destinations_json[i].HOTELS + ""; codesArray = codes.split(","); } } $("#no_hotel").html(''); // Now go to hotels.js file to match hotel codes with names $.getJSON("ajax/softvoyage/hotels.js", function(hotels){ // Loop through hotels in hotels.js file for (var i = 0; i < hotels.length; i++) { // Match with the ones that are currently in the array for (var j = 0; j < codesArray.length; j++) { if (codesArray[j] == hotels[i].CODE) { $("#no_hotel").append('