$(function () { $('input.animate, select.animate').on('input', function () { if (this.value == "") { $(this).parent().removeClass('active'); } else { $(this).parent().addClass('active'); } }); $(".dates_filter input").datepicker({ changeMonth: true, changeYear: true, maxDate: "+2y", minDate: "-1y", dateFormat: "DD, d MM yy", firstDay: 1, hideIfNoPrevNext: true, onSelect: function (date) { $(this).parent().addClass('active'); } }); if ($('.dates_filter input').attr('value') != "") { $(".dates_filter input").datepicker('setDate', new Date($('.dates_filter input').attr('value'))); } else { $(".dates_filter input").datepicker('setDate', null); } if ($('#search_cruise_all_dates').size()) { selectableDates = $('#search_cruise_all_dates').val().split(","); $(".dates_filter input").datepicker('option', 'beforeShowDay', availableDates); } $('.tt-radio, .filter select').change(UpdateSearch); // Process languages $('.tourBox').each(function () { langs_available = typeof $(this).attr('alllangs') == "undefined" ? [] : $(this).attr('alllangs').split(","); for (x in langs_available) { $('.filter #lang-' + langs_available[x]).addClass('keep-lang'); } }); $('.filter-langs:not(.keep-lang)').next('label').remove().end().next('br').remove().end().remove(); if ($('.filter-langs').size() == 0) { $('.filter.filter-languages').remove(); } $('.filter-langs').prop('checked', false); if (location.search.indexOf("langs=") != -1) { selectedLangs = location.search.substr(location.search.indexOf("langs=")).split("&")[0].split("=")[1]; if (selectedLangs != "") { $.each(selectedLangs.split(","), function () { $('#lang-' + this).prop('checked', true); }); } } // Extras $('.filter-extras').prop('checked', false); if (location.search.indexOf("extras=") != -1) { selectedExtras = location.search.substr(location.search.indexOf("extras=")).split("&")[0].split("=")[1].split(","); $.each(selectedExtras, function () { $('.filter-extras[value="' + this + '"]').prop('checked', true); }); } $('.filter-cruiseday').prop('checked', false); if (location.search.indexOf("cruise=") != -1) { selectedValue = rtrim(location.pathname.split("/s/")[1], "/") + "###" + location.search.substr(location.search.indexOf("date=")).split("&")[0].split("=")[1]; $('.filter-cruiseday[value="'+selectedValue+'"]').prop('checked', true); } $('#filter-groupsize option').prop('selected', false); if (location.search.indexOf("groupsize=") != -1) { selectedSize = location.search.substr(location.search.indexOf("groupsize=")).split("&")[0].split("=")[1]; if (selectedSize != "") { $('#filter-groupsize').parent('.filter').addClass('active'); $('#filter-groupsize option[value="'+selectedSize+'"]').prop('selected', true); } } $('#filter_timestart option').prop('selected', false); if (location.search.indexOf("starttime=") != -1) { selectedSize = location.search.substr(location.search.indexOf("starttime=")).split("&")[0].split("=")[1]; $('#filter_timestart').parent('.sub-filter').addClass('active'); $('#filter_timestart option[value="'+selectedSize+'"]').prop('selected', true); } $('#filter_timeend option').prop('selected', false); if (location.search.indexOf("endtime=") != -1) { selectedSize = location.search.substr(location.search.indexOf("endtime=")).split("&")[0].split("=")[1]; $('#filter_timeend').parent('.sub-filter').addClass('active'); $('#filter_timeend option[value="'+selectedSize+'"]').prop('selected', true); } $('#filter_maxprice').keyup(function (event) { if (event.keyCode == 13) { UpdateSearch(); } if (!$(this).parents('.filter').find('button').size()) { $(this).parents('.filter').append('Update'); } }); $('#tourResults a.continuesearch').each(function () { if ($(this).attr('href').indexOf("/?") !== -1) { qs = ltrim(location.search, "?").split("&"); for (x in qs) { key_patt = qs[x].split("=")[0] + "="; if ($(this).attr('href').indexOf(key_patt) == -1 && key_patt != "end=") { $(this).attr('href', $(this).attr('href') + "&" + qs[x]); } } } else { $(this).attr('href', $(this).attr('href') + "/" + location.search); } }); }); function availableDates(date) { fDate = formatDate(date, "%YYYY-%MM-%dd"); if (jQuery.inArray(fDate, selectableDates) != -1) return [true, "", ""]; else return [false, "", ""]; } function RemoveCruiseItinerary() { $('#filter_cruise').remove(); UpdateSearch(); } function UpdateSearch() { q = encodeURIComponent($('#tourInfo .title').html()).replace(/%20/g, '+'); string = ''; if ($('.filter-cruiseday:checked').size()) { itinerary_parts = $('.filter-cruiseday:checked').val().split("###"); q = itinerary_parts[0]; $('#filter_date').val(new Date(itinerary_parts[1])); string += '&date=' + itinerary_parts[1]; } else if ($('#filter_date').size() && $('#filter_date').val() != "") { string += '&date=' + formatDate(new Date($('#filter_date').val() + " 00:00:00"), "%YYYY-%MM-%dd"); } if ($('#filter_monthyear').size() && $('#filter_monthyear').val() != "") { string += '&monthyear=' + $('#filter_monthyear').val(); } langs = $.makeArray($('.filter-langs:checked').map(function () { return $(this).val(); })).join(","); if (langs != "") { string += '&langs=' + langs; } extras = $.makeArray($('.filter-extras:checked').map(function () { return $(this).val(); })).join(","); if (extras != "") { string += '&extras=' + extras; } if ($('#filter_cruise').size() && $('#filter_date').val() != "") { string += '&cruise=' + $('#filter_cruise').val(); } if ($('#filter-groupsize').val() != "") { string += '&groupsize=' + parseInt($('#filter-groupsize').val()); } if ($('#filter_maxprice').val() != "" && !isNaN(parseInt($('#filter_maxprice').val()))) { string += '&maxprice=' + parseInt($('#filter_maxprice').val()); } if ($('#filter_timestart').val() != "") { string += '&starttime=' + $('#filter_timestart').val(); } if ($('#filter_timeend').val() != "") { string += '&endtime=' + $('#filter_timeend').val(); } if (string != "") { string = "/s/" + q + "/?" + ltrim(string, "&"); } else { string = "/s/" + q; } location.href = string; } function ltrim(str, charlist) { charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1'); var re = new RegExp('^[' + charlist + ']+', 'g'); return (str + '').replace(re, ''); } function rtrim(str, charlist) { charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\\$1'); var re = new RegExp('[' + charlist + ']+$', 'g'); return (str + '').replace(re, ''); } function MoreResults() { if (history) { // Change the history state var end_used = false; var params = ltrim(location.search, "?&").split("&").map(function (el, num) { if (el.indexOf('end=') != -1) { parts = el.split("="); parts[1] = ($('.tourBox').size() + 10).toString(); end_used = true; return parts.join("="); } else { return el; } }).join("&"); if (!end_used) { params += "&end=" + ($('.tourBox').size() + 10).toString(); } params = ltrim(params, "&"); var new_url = "/s/" + $('#tourInfo .title').html().replace(/\s/, "+") + "/?" + params; history.replaceState(null, null, new_url); } // Loading $('button.more_results').attr('disabled', 'disabled'); $('button.more_results').html('Loading more results...'); if ($('#search_type').val() == "port") { $.post("/Search@PerformSearch", "type=port&" + ltrim(ltrim(location.search, "?&") + "&port=" + $('#search_id').val() + "&start=" + $('.tourBox').size() + "&max=10", "&"), function (results) { $('button.more_results').removeAttr('disabled'); $('button.more_results').html('Show more results'); if (results.charAt(0) == "0") { results = results.substr(1); $('button.more_results').attr('disabled', 'disabled'); $('button.more_results').attr('onclick', ''); $('button.more_results').html('No more results'); } data = JSON.parse(results); for (i=0; i' + (data[i]["spacesLeft"] ? 'Remaining Capacity ' + data[i]["spacesLeft"] + ' spacesMin Team Size ' + data[i]["minSize"] + ' Max Team Size ' + data[i]["size"] + ' peopleDuration ' + data[i]["length"] + ' hours' : '') + '' + data[i]["img"] + '' + data[i]["name"] + '' + data[i]["description"] + 'Currently' + data[i]["higherPricePerPerson"] + ' pp-' + data[i]["discount_val"] + '%Our best price' + data[i]["lowestPerPerson"][0] + ',' + data[i]["lowestPerPerson"][1] + ' pp'); } }); } else if ($('#search_type').val() == "line") { $.post("/Search@PerformSearch", "type=line&line=" + $('#search_id').val() + "&start=" + $('.tourBox').size() + "&max=10", function (results) { $('button.more_results').removeAttr('disabled'); $('button.more_results').html('Show more results'); if (results.charAt(0) == "0") { results = results.substr(1); $('button.more_results').attr('disabled', 'disabled'); $('button.more_results').attr('onclick', ''); $('button.more_results').html('No more results'); } data = JSON.parse(results); for (i=0; i' + data[i]["img"] + '' + data[i]["name"] + '' + data[i]["description"] + '' + data[i]["title"] + '' + data[i]["largeText"] + '' + data[i]["smallText"] + '' + data[i]["sub"] + ''); } }); } else if ($('#search_type').val() == "ship") { $.post("/Search@PerformSearch", "type=cruise&shipName=" + $('h1 .title').text() + "&ship=" + $('#search_id').val() + "&start=" + $('.tourBox').size() + "&max=10", function (results) { $('button.more_results').removeAttr('disabled'); $('button.more_results').html('Show more results'); if (results.charAt(0) == "0") { results = results.substr(1); $('button.more_results').attr('disabled', 'disabled'); $('button.more_results').attr('onclick', ''); $('button.more_results').html('No more results'); } data = JSON.parse(results); for (i=0; i' + data[i]["img"] + '' + data[i]["name"] + '' + data[i]["description"] + '' + data[i]["title"] + '' + data[i]["largeText"] + '' + data[i]["smallText"] + '' + data[i]["sub"] + ''); } }); } else if ($('#search_type').val() == "itinerary") { $.post("/Search@PerformSearch", "type=itinerary&cruise=" + $('#search_id').val() + "&start=" + $('.tourBox').size() + "&max=10", function (results) { $('button.more_results').removeAttr('disabled'); $('button.more_results').html('Show more results'); if (results.charAt(0) == "0") { results = results.substr(1); $('button.more_results').attr('disabled', 'disabled'); $('button.more_results').attr('onclick', ''); $('button.more_results').html('No more results'); } data = JSON.parse(results); for (i=0; i' + data[i]["img"] + '' + data[i]["name"] + '' + data[i]["description"] + '' + data[i]["title"] + '' + data[i]["largeText"] + '' + data[i]["smallText"] + '' + data[i]["sub"] + ''); } }); } else if ($('#search_type').val() == "guide") { $.post("/Search@PerformSearch", "type=guide&" + ltrim(ltrim(location.search, "?&") + "&guide=" + $('#search_id').val() + "&start=" + $('.tourBox').size() + "&max=10", "&"), function (results) { $('button.more_results').removeAttr('disabled'); $('button.more_results').html('Show more results'); if (results.charAt(0) == "0") { results = results.substr(1); $('button.more_results').attr('disabled', 'disabled'); $('button.more_results').attr('onclick', ''); $('button.more_results').html('No more results'); } data = JSON.parse(results); for (i=0; i' + (data[i]["spacesLeft"] ? 'Remaining Capacity ' + data[i]["spacesLeft"] + ' spacesMin Team Size ' + data[i]["minSize"] + ' Max Team Size ' + data[i]["size"] + ' peopleDuration ' + data[i]["length"] + ' hours' : '') + '' + data[i]["img"] + '' + data[i]["name"] + '' + data[i]["description"] + 'Currently' + data[i]["higherPricePerPerson"] + ' pp-' + data[i]["discount_val"] + '%Our best price' + data[i]["lowestPerPerson"][0] + ',' + data[i]["lowestPerPerson"][1] + ' pp'); } }); } }