﻿(function () { var a = WebApplications; var b = a.register("WebApplications.SearchWidget"); var c = new google.maps.Geocoder; var d = "dd/mm/yy"; var e = function (a) { return $.datepicker.formatDate(d, a) }; var f = {}; var g = { searchWidget: $("div.WASearchWidget") }; var h = {}; var i = {}; var j = { selectLocationOrCampsite: "* Please select a Location or Campsite", arrivalBeforeDeparture: "* The arrival date must be before the leaving date", arrivalMinimumDate: "* The arrival date cannot be before ", departureAfterArrival: "* The leaving date must be after the arrival date", departureMinimumDate: "* The leaving date cannot be before ", departureMaximumDate: "* The leaving date cannot be after " }; var k = "Eg: Lake district"; b.init = function (a, c, d, e, j, k) { if (a) { g.searchWidget = $(a) } i.bookingWebsiteURL = c; i.membershipLogin = d; f.selectOption = g.searchWidget.find("#WASearchWidgetSelectOptionTemplate"); g.ukSelection = g.searchWidget.find("input#srchDestinationUK"); g.europeSelection = g.searchWidget.find("input#srchDestinationEurope"); g.ukContainer = g.searchWidget.find("li#UK"); g.europeContainer = g.searchWidget.find("li#EUROPE"); g.ukWhere = g.searchWidget.find("input#location"); g.ukWhereLatitude = g.searchWidget.find("input#locationLatitude"); g.ukWhereLongitude = g.searchWidget.find("input#locationLongitude"); g.ukRadius = g.searchWidget.find("select#radius"); g.ukSite = g.searchWidget.find("select#site"); g.europeCountries = g.searchWidget.find("select#country"); g.europeRegions = g.searchWidget.find("select#region2"); g.arrivalDate = g.searchWidget.find("input#srchArriving"); g.departureDate = g.searchWidget.find("input#srchLeaving"); g.equipmentTypeSelectors = g.searchWidget.find(".EquipmentTypeSelection"); g.equipmentTypeDimensions = g.searchWidget.find(".EquipmentTypeDimensions"); g.ukEquipmentTypeContainers = g.searchWidget.find(".EquipmentTypeContainerUK"); g.europeEquipmentTypeContainers = g.searchWidget.find(".EquipmentTypeContainerEurope"); g.searchButton = g.searchWidget.find("input#clickSearch"); h.europeRegions = j; h.ukWhereAutocompleteSites = e; $.extend(i, k); b.setupUKFields(); b.setupEuropeFields(); b.setupGeneralFields(); b.setupValidator(); b.setupSubmission(); g.ukSelection.click(); g.equipmentTypeSelectors.propAttr("checked", false) }; b.setupUKFields = function () { g.ukWhere.add(g.ukRadius).add(g.ukSite).filter("[title]").tooltip({ position: "center right", offset: [22, 0] }); g.ukWhere.val(k).focus(function () { if (g.ukWhere.val() == k) { g.ukWhere.val("") } }).blur(function () { if (!g.ukWhere.val()) { g.ukWhere.val(k) } }); g.ukWhere.change(function () { if (g.ukWhere.val()) { g.ukSite.val("") } }); g.ukRadius.change(function () { var a = g.ukRadius.val(); if (a) { g.ukSite.val(""); if (a == -1) { g.ukWhere.val("").blur() } } }); g.ukSite.change(function () { if (g.ukSite.val()) { g.ukWhere.add(g.ukRadius).val("").blur() } }); var a; $.widget("custom.whereAutocomplete", $.ui.autocomplete, { _renderMenu: function (a, b) { var c = this; var d = ""; $.each(b, function (b, e) { if (e.category != d) { a.append('<li class="ui-autocomplete-category">' + e.category + "</li>"); d = e.category } c._renderItem(a, e) }) }, _renderItem: function (b, c) { var d = c.label.replace(a, '<span class="Bold">$1</span>'); return $("<li></li>").data("item.autocomplete", c).append("<a>" + d + "</a>").appendTo(b) } }); $.ui.menu.prototype.activate = function (a, b) { this.deactivate(); if (this.hasScroll()) { var c = b.offset().top - this.element.offset().top; var d = this.element.scrollTop(); var e = this.element.height(); if (c < 0) { this.element.scrollTop(d + c) } else if (c >= e) { this.element.scrollTop(d + c - e + b.height()) } } this.active = b.eq(0).children("a").addClass("ui-state-hover").end(); this._trigger("focus", a, { item: b }) }; $.ui.menu.prototype.deactivate = function () { if (!this.active) { return } this.active.children("a").removeClass("ui-state-hover"); this._trigger("blur"); this.active = null }; g.ukWhere.whereAutocomplete({ source: $.map(h.ukWhereAutocompleteSites, function (a) { return { label: a.SiteName, category: a.Category} }), open: function () { $(this).children("li.ui-menu-item:odd a").addClass("ui-menu-item-alternate") }, search: function () { a = new RegExp("(" + $.ui.autocomplete.escapeRegex(g.ukWhere.val()) + ")", "ig") } }).bind("change", function () { g.ukWhereLatitude.val(""); g.ukWhereLongitude.val("") }) }; b.setupEuropeFields = function () { g.europeCountries.change(function () { g.europeRegions.empty(); var a = g.europeCountries.val(); if (!a) { g.europeRegions.propAttr("disabled", true); return } var b = h.europeRegions[a]; if (!b) { g.europeRegions.propAttr("disabled", true); return } f.selectOption.tmpl({ Value: "", Text: "All of " + b.Name }).appendTo(g.europeRegions); if (!b.Children.length) { g.europeRegions.propAttr("disabled", true).val(""); return } f.selectOption.tmpl($.map(b.Children, function (a) { return { Value: a.UniqueName, Text: a.Name} })).appendTo(g.europeRegions); g.europeRegions.propAttr("disabled", false) }).change() }; b.setupGeneralFields = function () { g.ukSelection.click(function () { g.europeContainer.removeClass("showElement").addClass("hideElement"); g.ukContainer.removeClass("hideElement").addClass("showElement"); g.europeEquipmentTypeContainers.removeClass("showElement").addClass("hideElement"); g.ukEquipmentTypeContainers.removeClass("hideElement").addClass("showElement"); g.equipmentTypeSelectors.propAttr("checked", false); g.equipmentTypeDimensions.removeClass("showElement").addClass("hideElement"); b.setDatepickerConstraints("UK"); g.searchWidget.validationEngine("hideAll") }); g.europeSelection.click(function () { g.ukContainer.removeClass("showElement").addClass("hideElement"); g.europeContainer.removeClass("hideElement").addClass("showElement"); g.ukEquipmentTypeContainers.removeClass("showElement").addClass("hideElement"); g.europeEquipmentTypeContainers.removeClass("hideElement").addClass("showElement"); g.equipmentTypeSelectors.propAttr("checked", false); g.equipmentTypeDimensions.removeClass("showElement").addClass("hideElement"); b.setDatepickerConstraints("Europe"); g.searchWidget.validationEngine("hideAll") }); g.arrivalDate.datepicker({ dateFormat: d }).siblings(".icon").click(function () { g.arrivalDate.datepicker("show") }); g.departureDate.datepicker({ dateFormat: d }).siblings(".icon").click(function () { g.departureDate.datepicker("show") }); g.equipmentTypeSelectors.click(function () { var a = $(this); var b = a.propAttr("id"); g.equipmentTypeDimensions.filter(":not(#" + b + "Dimensions)").removeClass("showElement").addClass("hideElement").end().filter("#" + b + "Dimensions").removeClass("hideElement").addClass("showElement"); g.searchWidget.validationEngine("hideAll") }) }; b.setDatepickerConstraints = function (a) { var c = 1; var f = 8; var h = 1; var j = 8; var k = 30; switch (a) { case "Europe": c = parseInt(i.EuropeArrivalLeadTime, 10); f = parseInt(i.EuropeDepartureLeadTime, 10); h = parseInt(i.EuropeDefaultArrivalDate, 10); j = parseInt(i.EuropeDefaultDepartureDate, 10); k = parseInt(i.EuropeMaximumDuration, 10); break; case "UK": c = parseInt(i.UKArrivalLeadTime, 10); f = parseInt(i.UKDepartureLeadTime, 10); h = parseInt(i.UKDefaultArrivalDate, 10); j = parseInt(i.UKDefaultDepartureDate, 10); k = parseInt(i.UKMaximumDuration, 10); break } if (f <= c) { f = c + 1 } if (h < c) { h = c } if (j < f) { j = f } var l = function (a) { var c = $.datepicker.parseDate(d, a); var e = new Date(Math.max(b.daysToDate(f).getTime(), c.addDays(1).getTime())); g.departureDate.datepicker("option", "minDate", e).datepicker("option", "maxDate", c.addDays(k)) }; g.arrivalDate.datepicker("option", "minDate", c).datepicker("option", "defaultDate", h).datepicker("option", "onSelect", l); g.departureDate.datepicker("option", "minDate", f).datepicker("option", "defaultDate", j); if (!g.arrivalDate.val()) { g.arrivalDate.val(e(b.daysToDate(h))) } if (!g.departureDate.val()) { g.departureDate.val(e(b.daysToDate(j))) } l(g.arrivalDate.val()) }; b.setupValidator = function () { g.searchWidget.validationEngine({ customValidatorObject: b.validatorMethods, promptPosition: "centerRight" }) }; b.setupSubmission = function () { g.searchButton.click(function (a) { a.preventDefault(); if (!g.searchWidget.validationEngine("validate")) { return } g.searchWidget.validationEngine("hideAll"); var d = g.ukSelection.add(g.europeSelection).filter(":checked:first"); if (d.length < 1) { return } var e = function () { var a = b.buildSubmissionURL(d.val()); if (!a) { return } window.location = a }; if (d.val() == "UK") { var f = g.ukWhere.val(); if (!f || f == k) { e(); return } var i = $.grep(h.ukWhereAutocompleteSites, function (a) { return a.SiteName == f }); if (i.length > 0) { i = i[0]; g.ukWhereLatitude.val(i.Latitude); g.ukWhereLongitude.val(i.Longitude); e(); return } var j = function (a, b) { switch (b) { case "REQUEST_DENIED": alert("The GeoLocation request was denied, error code: REQUEST_DENIED"); break; case "OVER_QUERY_LIMIT": alert("The GeoLocation API is currently over its request limit for the day from this IP address, error code: OVER_QUERY_LIMIT"); break; case "ZERO_RESULTS": alert('The location was not found based on "Where?" field - Please try a different location'); break; case "OK": var c = a[0]; if (c && c.geometry && c.geometry.location) { g.ukWhere.val(c.formatted_address); g.ukWhereLatitude.val(c.geometry.location.lat()); g.ukWhereLongitude.val(c.geometry.location.lng()); e() } break; default: alert("An error occurred processing the GeoLocation, error code: INVALID_REQUEST"); break } }; c.geocode({ address: f, region: "gb" }, j) } else { e() } }) }; b.buildSubmissionURL = function (a) { var b = i.bookingWebsiteURL; switch (a) { case "Europe": b += "EUROPE/"; b += encodeURIComponent(g.europeCountries.val()) + "/"; b += encodeURIComponent(g.europeRegions.val()) + "/"; b += g.arrivalDate.val() + "/?"; b += "CheckAvailability=true"; break; case "UK": if (g.ukSite.val()) { b += "SelectSite/?"; b += "WorldRegionName=UNITED%20KINGDOM"; b += "&Country=UNITED%20KINGDOM"; b += "&ArrivalDate=" + encodeURIComponent(g.arrivalDate.val()) + "&" } else { b += "EUROPE/"; b += "UNITED%20KINGDOM/"; b += g.arrivalDate.val() + "/?" } b += "CheckAvailability=true"; if (g.ukWhere.val()) { b += "&Where=" + encodeURIComponent(g.ukWhere.val()) } if (g.ukWhereLatitude.val()) { b += "&Latitude=" + g.ukWhereLatitude.val() } if (g.ukWhereLongitude.val()) { b += "&Longitude=" + g.ukWhereLongitude.val() } if (g.ukRadius.val()) { b += "&Distance=" + g.ukRadius.val() } if (g.ukSite.val()) { b += "&UKSiteSelection=" + g.ukSite.val() } break; default: return "" } b += "&LeavingDate=" + encodeURIComponent(g.departureDate.val()); b += "&EquipmentType=" + g.equipmentTypeSelectors.filter(":checked:first").val(); var c = g.equipmentTypeDimensions.filter(":visible"); b += "&EquipmentLength=" + c.find('input[name="EquipmentTypeLength"]').val(); b += "&EquipmentLengthUnit=" + c.find('select[name="EquipmentTypeLengthUnit"]').val(); b += "&EquipmentWidth=" + c.find('input[name="EquipmentTypeWidth"]').val(); b += "&EquipmentWidthUnit=" + c.find('select[name="EquipmentTypeWidthUnit"]').val(); if (i.membershipLogin) { b += "&i=" + i.membershipLogin } return b }; b.daysToDate = function (a) { if (typeof a == "number") { var b = (new Date).clearTime(); return b.addDays(a) } return a }; b.validatorMethods = { requiredUKLocation: function (a) { if (g.ukRadius.val() != -1 && !g.ukSite.val()) { var b = a.val(); if (!b || b == k) { return j.selectLocationOrCampsite } } }, requiredUKRadius: function (a) { var b = g.ukSite.val(); if (!b) { var c = a.val(); if (!c) { return j.selectLocationOrCampsite } } }, requiredUKCampsite: function (a) { var b = g.ukWhere.val(); var c = !b || b == k; if (g.ukRadius.val() != -1 && (c || !g.ukRadius.val())) { var d = a.val(); if (!d) { return j.selectLocationOrCampsite } } }, arrivalDate: function (a) { try { var c = $.datepicker.parseDate(d, a.val()); var f = $.datepicker.parseDate(d, g.departureDate.val()); if (c >= f) { return j.arrivalBeforeDeparture } var h = b.daysToDate(a.datepicker("option", "minDate")); if (h && c < h) { return j.arrivalMinimumDate + e(h) } } catch (i) { var k = new RegExp($.validationEngineLanguage.allRules.dateUK.regex); if (k.test(a.val())) { return $.validationEngineLanguage.allRules.dateUK.alertText } } }, departureDate: function (a) { try { var c = $.datepicker.parseDate(d, a.val()); var f = $.datepicker.parseDate(d, g.arrivalDate.val()); if (c <= f) { return j.departureAfterArrival } var h = b.daysToDate(a.datepicker("option", "minDate")); if (h && c < h) { return j.departureMinimumDate + e(h) } var i = b.daysToDate(a.datepicker("option", "maxDate")); if (i && c > i) { return j.departureMaximumDate + e(i) } } catch (k) { var l = new RegExp($.validationEngineLanguage.allRules.dateUK.regex); if (l.test(a.val())) { return $.validationEngineLanguage.allRules.dateUK.alertText } } }, positive: function (a) { try { var b = new Number(a.val()); if (b <= 0) { return "* Must be a positive number" } } catch (c) { return $.validationEngineLanguage.allRules.number.alertText } } } })()
