﻿var IsMapLoaded = true; checkinDateVar = new Date(); checkoutDateVar = new Date(); function setElementVisibility(eobj, ShowIt, KeepPlace) { if (ShowIt == true) { try { eobj.style.display = "inline" } catch (e) { } try { eobj.style.visibility = "visible" } catch (e) { } } else { if (KeepPlace == true) { try { eobj.style.display = "inline" } catch (e) { } try { eobj.style.visibility = "hidden" } catch (e) { } } else { try { eobj.style.visibility = "hidden" } catch (e) { } try { eobj.style.display = "none" } catch (e) { } } } } function AdvancedValidation() { } function isDefined(type) { return type != 'undefined' && type != 'unknown' && type != '' } function getById(id) { if (isDefined(typeof document.getElementById)) { return document.getElementById(id) } else if (isDefined(typeof document.all)) { return document.all[id] } else { return null } } function HideMap() { var objMap = getById('myMap'); setElementVisibility(objMap, false, false); IsMapLoaded = false } var map = null; function CreateMap() { map = new VEMap('myMap'); map.SetCredentials("Attoj3gzd8J9uboPN-1Jm256kvqZ_YoefVf-lqTPDqlRlnH0UXL9GiswFiFj1ajB"); map.LoadMap(new VELatLong(-33.959444, 18.607222), 7, VEMapStyle.Road); map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers); map.ClearInfoBoxStyles(); map.AttachEvent("onendzoom", ShowGroupedPushPins); IsMapLoaded = true; $('#progress').hide() } function GetMore(id) { var oManager = GetRadWindowManager(); var oWnd = oManager.GetWindowByName("rwDetails"); if (selectedDateIn == null) { selectedDateIn = '' } if (selectedDateOut == null) { selectedDateOut = '' } oWnd.SetUrl("/PortalModules/DirectoryModule/DirectoryItem.aspx?ID=" + id + "&checkindate=" + selectedDateIn + "&checkoutdate=" + selectedDateOut + "&adultcount=" + varAdultCount.value + "&childcount=" + varChildCount.value + "&roomcount=" + varRoomCount.value); oWnd.Show() } function Window_OnClientshow(sender, args) { cursor_wait() } function Window_OnClientPageLoad(sender, args) { } function Window_OnClientClose(sender, args) { sender.SetUrl(""); sender.Reload(); $(sender).find("body").css("cursor", "wait") } function ToggleLayerVisibility(title, obj) { if (IsMapLoaded == true) { var layer = FindLayer(title); if (layer.GetVisibility() == true) { layer.Hide() } else { layer.Show() } } if (obj.checked == false) { $("div").each(function () { if ($(this).hasClass('GeoType' + title)) { $(this).hide() } }) } else { $("div").each(function () { if ($(this).hasClass('GeoType' + title)) { $(this).show() } }) } } function FindLayer(title) { var layer = null; for (var i = 0; i < map.GetShapeLayerCount(); i++) { layer = map.GetShapeLayerByIndex(i); if (layer.GetTitle() == title) break; layer = null } return layer } function bookHotel(checkinDate, checkoutDate, adultCount, childCount, roomCount, id) { var dateIn = new Date(checkinDate); var dateOut = new Date(checkoutDate); getById('shs_HotelId').value = id; var day1Option = document.createElement("OPTION"); day1Option.value = dateIn.format('dd'); getById('shs_ddDay1').options.add(day1Option); var month1Option = document.createElement("OPTION"); month1Option.value = dateIn.format('MM') + ' ' + dateIn.format('yyyy'); getById('shs_ddMonth1').options.add(month1Option); var day2Option = document.createElement("OPTION"); day2Option.value = dateOut.format('dd'); getById('shs_ddDay2').options.add(day2Option); var month2Option = document.createElement("OPTION"); month2Option.value = dateOut.format('MM') + ' ' + dateOut.format('yyyy'); getById('shs_ddMonth2').options.add(month2Option); var roomsOption = document.createElement("OPTION"); roomsOption.value = roomCount; getById('shs_ddlRooms').options.add(roomsOption); var adultsOption = document.createElement("OPTION"); adultsOption.value = adultCount; getById('shs_ddlAdults').options.add(adultsOption); var childrenOption = document.createElement("OPTION"); childrenOption.value = childCount; getById('shs_ddlChildren').options.add(childrenOption); $('#txtURL[value]').val('http://comair/page/SearchResults?region=' + varRegion + '&keywords=' + keywords + '&adultcount=' + adultCount + '&childcount=' + childCount + '&roomcount=' + roomCount + '&checkindate=' + dateIn.format('yyyy/MM/dd') + '&checkoutdate=' + dateOut.format('yyyy/MM/dd') + '&accommodationtypes=63'); getById('fHtlSgl').submit() } $(function () { window.onerror = WriteLogEntry; init() }); $(function () { $("#form1").validate({ invalidHandler: function (form, validator) { ShowValidationDialog() }, errorLabelContainer: '#errorList', wrapper: 'li', errorClass: "invalid", rules: { fullSearchRegion: { regions: true }, datepickerIn: { date: true, required: true }, datepickerOut: { date: true, required: true, futuredate: true} }, messages: { datepickerIn: { required: "Checkin date required", date: "Please enter a valid checkin date" }, datepickerOut: { required: "Checkout date required", date: "Please enter a valid checkout date"}} }) }); function CheckoutDateValidation(value, element) { return $('#datepickerOut').datepicker('getDate') > $('#datepickerIn').datepicker('getDate') } function RegionValidation(value, element) { return true } $(function () { $.validator.addMethod('futuredate', CheckoutDateValidation, 'Please select a checkout date after the checkin date'); $.validator.addMethod('regions', RegionValidation, 'Please select at least one region') }); $(function () { $("#dateRequiredDialog").dialog({ autoOpen: false, closeText: '', modal: true, overlay: { opacity: 0.5, background: 'black' }, buttons: { OK: function () { $(this).dialog('close') } } }) }); function ShowValidationDialog() { $("#dateRequiredDialog").dialog('open') } var tabLinks = new Array(); var contentDivs = new Array(); function init() { var i = 0; for (var id in tabLinks) { tabLinks[id].onclick = showTab; tabLinks[id].onfocus = function () { this.blur() }; if (i == 0) tabLinks[id].className = 'selected'; i++ } var i = 0; for (var id in contentDivs) { if (i != 0) contentDivs[id].className = 'tabContent hide'; i++ } } function showTab() { var selectedId = getHash(this.getAttribute('href')); switch (selectedId) { case 'advanced': AdvancedValidation(); break } for (var id in contentDivs) { if (id == selectedId) { tabLinks[id].className = 'selected'; contentDivs[id].className = 'tabContent' } else { tabLinks[id].className = ''; contentDivs[id].className = 'tabContent hide' } } return false } function getFirstChildWithTagName(element, tagName) { for (var i = 0; i < element.childNodes.length; i++) { if (element.childNodes[i].nodeName == tagName) return element.childNodes[i] } } function getHash(url) { var hashPos = url.lastIndexOf('#'); return url.substring(hashPos + 1) } $(document).ready(function () { $("#RegionLinkHolder div.trigger").toggle(function () { $(this).addClass("active") }, function () { $(this).removeClass("active") }); $("#RegionLinkHolder div.trigger").click(function () { $("div.search_content").slideToggle("slow") }) }); $(function () { ParseQueryString(); SetDatePickers(); SetDefaultDates() }); function ClearDates() { varCheckinDate = ''; varCheckoutDate = ''; $('#checkindate').datepicker('destroy').val(''); $('#checkoutdate').datepicker('destroy').val(''); SetDatePickers(); $('#ClearDatesLink').hide() } function SetDatePickers() { $('#checkindate').datepicker({ changeMonth: true, changeYear: true, dateFormat: 'yy/mm/dd', minDate: 'null', showOn: 'both', buttonImage: '/Content/dev-mtbeds/Skins/Default/Img/calendar_blank.gif', buttonImageOnly: true, onClose: function (selectedDate) { if (selectedDate != '') { var dt = new Date(selectedDate); varCheckinDate = selectedDate; $('#checkoutdate').datepicker('option', 'minDate', DateAdd('d', 1, dt)); $('#ClearDatesLink').show() } } }); $('#checkoutdate').datepicker({ changeMonth: true, changeYear: true, dateFormat: 'yy/mm/dd', showOn: 'both', buttonImage: '/Content/dev-mtbeds/Skins/Default/Img/calendar_blank.gif', buttonImageOnly: true, onClose: function (selectedDate) { if (selectedDate != '') { var dt = new Date(selectedDate); varCheckoutDate = selectedDate; $('#checkindate').datepicker('option', 'maxDate', DateAdd('d', -1, dt)); $('#ClearDatesLink').show() } } }); if (isDefined(varCheckinDate)) { $("#checkindate").datepicker({ defaultDate: new Date(varCheckinDate), maxDate: new Date(varCheckoutDate) }); $('#checkoutdate').datepicker('option', 'minDate', DateAdd('d', 1, new Date(varCheckinDate))) } if (isDefined(varCheckoutDate)) { $("#checkoutdate").datepicker({ defaultDate: new Date(varCheckoutDate) }); $('#checkindate').datepicker('option', 'maxDate', DateAdd('d', -1, new Date(varCheckoutDate))) } } function SetDefaultDates() { if (isDefined(varCheckinDate)) { $("#checkindate").datepicker('setDate', new Date(varCheckinDate)) } if (isDefined(varCheckoutDate)) { $("#checkoutdate").datepicker('setDate', new Date(varCheckoutDate)) } if ($("#checkindate").val() != '' || $("#checkoutdate").val()) { $('#ClearDatesLink').show() } } $(function () { $get('AdultCount').value = varAdultCount.value; $get('ChildCount').value = varChildCount.value; $get('RoomCount').value = varRoomCount.value; $.post('/PortalModules/DirectoryModule/TripSelectorServices/AccommodationService.svc/GetRegions', null, BuildRegionDropdown, "json"); $('#searchResults').listview({ itemsToDisplay: 5, listLoadedFn: ShowMap, imagePath: '/Content/dev-mtbeds/Skins/Default/Img/', templateId: 'ItemTemplate', listType: 'hotel' }); $('#AccommodationTypes').checkboxlist({ data: 'Hotel,2;Boutique Hotel/Manor,1;Bush/Game Lodge,16;Bed & Breakfast,4;Guest House,32;Apartment/Self Catering,8' }); var selectedAccommodationTypes = parseInt(accommodationtypes); $('#AccommodationTypes .checkboxList .checkboxItem input').each(function (index) { var currentvalue = parseInt(this.tag); if ((currentvalue & selectedAccommodationTypes) === currentvalue) { $(this).attr('checked', 'checked') } }) }); function ShowMap() { CreateMap(); BuildMapLayers() } function BuildRegionDropdown(result) { $('#RegionSelect').autocomplete(result.d) } $(function () { }); function GetHotels() { var hotelproxy = new AAjaxProxy.POSAccommodationService(); var inDate = null; var outDate = null; if (isDefined(varCheckinDate)) { inDate = new Date(selectedDateIn) } if (isDefined(varCheckoutDate)) { outDate = new Date(selectedDateOut) } var searchString = document.location.search; searchString = searchString.substring(1); var nvPairs = searchString.split("&"); var resultstring = new Object(); for (i = 0; i < nvPairs.length; i++) { var nvPair = nvPairs[i].split("="); resultstring[nvPair[0]] = nvPair[1] } var siteId = CMS_SiteId; hotelproxy.GetHotels(siteId, searchString, EndGetHotelResults, FailGetSearchResults) } function GetPromos() { BuildPromosFromSession() } var regionName; var keywords; var selectedDateIn; var selectedDateOut; function ParseQueryString() { var searchString = document.location.search; searchString = searchString.substring(1); var nvPairs = searchString.split("&"); var results = new Object(); for (i = 0; i < nvPairs.length; i++) { var nvPair = nvPairs[i].split("="); results[nvPair[0]] = nvPair[1] } if (results['adultcount']) { varAdultCount.value = results['adultcount']; $("#AdultCount").val(varAdultCount.value) } else { varAdultCount.value = 1 } if (results['childcount']) { varChildCount.value = results['childcount']; $("#ChildCount").val(varChildCount.value) } else { varChildCount.value = 0 } if (results['roomcount']) { varRoomCount.value = results['roomcount']; $("#RoomCount").val(varRoomCount.value) } else { varRoomCount.value = 1 } if (results['checkindate']) { varCheckinDate = results['checkindate']; $("#checkindate").val(varCheckinDate); selectedDateIn = varCheckinDate } if (results['checkoutdate']) { varCheckoutDate = results['checkoutdate']; $("#checkoutdate").val(varCheckoutDate); selectedDateOut = varCheckoutDate } if (results['region']) { varRegion = results['region'].replace(/%20/gi, ' ').replace(/%26/gi, '&'); var url = '/PortalModules/DirectoryModule/TripSelectorServices/AccommodationService.svc/GetRegionId'; $.ajax({ url: url, data: '{"RegionName": "' + varRegion + '"}', type: "POST", processData: true, contentType: "application/json", timeout: 30000, dataType: "json", success: SetRegionId, error: handleError }); $("#fullSearchRegion").val(varRegion); $("#RegionSelect").val(varRegion) } if (results['keywords']) { keywords = results['keywords'].replace(/%20/gi, ' '); $("#fullKeywords").val(keywords); $("#KeywordInput").val(keywords) } if (results['errDesc']) { var errMsg = results['errDesc'] } if (results['accommodationtypes']) { accommodationtypes = results['accommodationtypes'] } } var accommodationtypes; function handleError(XMLHttpRequest, textStatus, errorThrown) { } var RegionId = 0; function SetRegionId(result) { RegionId = result.d; if (RegionId > 0) { $('#RegionLink a').attr('href', 'javascript:GetMore(' + RegionId + ')').text(varRegion).show() } else { $('.RegionLinkLeft').hide(); $('.RegionLinkMiddle').hide(); $('.RegionLinkRight').hide() } } function EndGetHotelResults(results) { if (results.length > 0) { CreateMap(); BuildMapLayers(); $('#searchResults').listview.ResultCallback(results); GetPromos() } else { $('#NoResults').show() } } function FailGetSearchResults() { alert('Failed to get accommodations') } function EndGetPromotions(results) { $('#promoResults').listview.ResultCallback(results) } function FailGetPromotions() { alert("Failed to get promotions") } function SetRegion() { varCheckinDate = $get('checkindate').value; varCheckoutDate = $get('checkoutdate').value } function SetHiddenFields() { varCheckinDateControl.value = $get('checkindate').value; varCheckoutDateControl.value = $get('checkoutdate').value; varAdultCount.value = $get('AdultCount').selectedIndex; varChildCount.value = $get('ChildCount').value; varRoomCount.value = $get('RoomCount').value; SetRegion() } function BuildMapLayers() { if (map != null) { var proxy = new AAjaxProxy.POSAccommodationService(); proxy.GetLayeredIcons(GetLayersComplete, GetLayersFailed) } } function BuildPromoLayers() { var proxy = new AAjaxProxy.POSAccommodationService(); proxy.GetPromoIcons(GetLayersComplete, GetPromosFailed) } function GetPromosFailed() { alert('get promos failed') } var shapes = []; function GetLayersComplete(results) { map.DeleteAllShapeLayers(); shapes = []; for (var i = 0; i < results.length; i++) { var layer = new VEShapeLayer(); layer.SetTitle(results[i].Key); for (var j = 0; j < results[i].Value.length; j++) { var pin = new VEShape(VEShapeType.Pushpin, new VELatLong(results[i].Value[j].Lattitude, results[i].Value[j].Longitude)); pin.SetCustomIcon("<div class='" + results[i].Key + 'Pushpin' + "'></div>"); pin.SetDescription(results[i].Value[j].InfoHtml); shapes[results[i].Value[j].Id] = pin; layer.AddShape(pin) } var rect = layer.GetBoundingRectangle(); var options = new VEClusteringOptions(); var customIcon = new VECustomIconSpecification(); customIcon.Image = "/Content/dev-mtbeds/Images/mapicon_group.gif"; options.Icon = customIcon; options.Callback = clusteringCallback; if (map.GetZoomLevel() > 14) { layer.SetClusteringConfiguration(VEClusteringType.None, options) } else { layer.SetClusteringConfiguration(VEClusteringType.Grid, options) } map.AddShapeLayer(layer) } if (rect != null) { map.SetMapView(rect) } } function clusteringCallback(clusters) { for (var i = 0; i < clusters.length; ++i) { var cluster = clusters[i]; var clusterShape = cluster.GetClusterShape(); clusterShape.SetTitle(""); clusterShape.SetDescription("There are " + cluster.Shapes.length + " hotels around here. Double-click to zoom in.") } } function GetLayersFailed() { alert('get layers failed') } function ShowGroupedPushPins(e) { var zoomLevel = map.GetZoomLevel(); var options = new VEClusteringOptions(); var customIcon = new VECustomIconSpecification(); customIcon.Image = "/Content/dev-mtbeds/Images/mapicon_group.gif"; options.Icon = customIcon; options.Callback = clusteringCallback; if (zoomLevel > 14) { var layer = map.GetShapeLayerByIndex(1); layer.SetClusteringConfiguration(VEClusteringType.None, options) } else { var layer = map.GetShapeLayerByIndex(1); layer.SetClusteringConfiguration(VEClusteringType.Grid, options) } } function GetFlyoutHtmlComplete(result, e) { var shape = map.GetShapeByID(e.elementID); shape.SetDescription(result); shape.SetTitle("") } function GetFlyoutHtmlFailed(e) { var shape = map.GetShapeByID(e.elementID); shape.SetDescription("Unexpected error while getting information") } function TogglePromos() { var promocheckbox = $('#chkPromos'); switch (promocheckbox[0].checked) { case true: BuildPromoLayers(); break; case false: BuildMapLayers(); break } } function _utf8_decode(utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++ } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2 } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3 } } return string } function SubmitAccommodationData() { var region = UrlEncode($('#RegionSelect').val()); var keywords = UrlEncode($('#KeywordInput').val()); var checkindate = varCheckinDate; var checkoutdate = varCheckoutDate; var roomcount = $('#RoomCount').find('option:selected').val(); var adultcount = $('#AdultCount').find('option:selected').val(); var childcount = $('#ChildCount').find('option:selected').val(); var accommodationtypes = 63; if ($('#AccommodationTypes').checkboxlist('getValue') > 0) { accommodationtypes = $('#AccommodationTypes').checkboxlist('getValue') } var url = "/page/SearchResults?region=" + region + "&keywords=" + keywords + "&adultcount=" + adultcount + "&childcount=" + childcount + "&roomcount=" + roomcount + "&accommodationtypes=" + accommodationtypes; if (checkindate != "" && checkoutdate != "") { url = url + "&checkindate=" + checkindate + "&checkoutdate=" + checkoutdate } if (ValidateInputs()) { window.location.replace(url) } } function ValidateInputs() { if ($('#RegionSelect').val() == "") { $('#RegionSelect').after($('#ValidationMessage').html("<p>Please select a region</p>").fadeIn().animate({ opacity: 1.0 }, 1000).fadeOut()); return false } return true } function UrlEncode(s) { return s.replace(/&/gi, '%26').replace(/ /gi, '%20') } function WriteLogEntry(errorMessage, url, lineNumber) { var url = '/PortalModules/DirectoryModule/AjaxProxy/POSAccommodationService.svc/WriteErrorLogEntry'; $.ajax({ url: url, data: '{"errorMessage": "' + errorMessage + '", "url":"' + url + '", "lineNumber":"' + lineNumber + '"}', type: "POST", processData: true, timeout: 30000, success: AfterWriteLogEntry, error: FailedWriteLogEntry }); return true } function AfterWriteLogEntry(result) { alert("An unexpected error has occurred. We have logged it and will investigate."); window.location.replace("\\") } function FailedWriteLogEntry(error) { var stackTrace = error.get_stackTrace(); var message = error.get_message(); var statusCode = error.get_statusCode(); var exceptionType = error.get_exceptionType(); var timedout = error.get_timedOut(); alert("Stack Trace: " + stackTrace + "nr" + "Service Error: " + message + "nr" + "Status Code: " + statusCode + "nr" + "Exception Type: " + exceptionType + "nr" + "Timedout: " + timedout) }
