var hotelmap = { overlayElement : null, properties : {} } ; /** * ------------------------------------------------------------------------- * HotelMap WorldWide 1.0 * Copyright (C) 2012 - All Rights Reserved - HotelMap.com * ------------------------------------------------------------------------- * Base ID: Hotelmap|Library|Utility Functions * Description: Generic Util functions for use within HM * ------------------------------------------------------------------------- * Version : $Id$ * Author : James Holden * Contact : james@hotelmap.com * ------------------------------------------------------------------------- * Notes : Yay! * ------------------------------------------------------------------------- */ var debug_enabled = false; var location_path = false; var has_calendar_hash = false; function getLingualDate(date, options) { try { var options = (options) ? options : { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric' }; var final_str = date.toLocaleDateString(attributes.language.replace("_", "-"), options); return final_str; } catch (noDateValidException) { console.log("error"); console.dir(noDateValidException); return false; } } /** * Instructs browser to make hash uri change. * * @param newHash * @param details */ function makeHashChange(newHash, details) { try { if (newHash != "calendar" || !has_calendar_hash) { if (!location_path) { location_path = location.href.replace(location.hash, ""); if (newHash == "calendar") { has_calendar_hash = true; } } history.pushState(details, document.title, location_path + "#" + newHash); } } catch (pushStateException) { // Empty. } } /** * Switch the language of the map when selected from the map drop down. * This intercepts urls found in the shortcodes area which map to the index * project. * * @param destination * @param languagecode */ function switchLanguageFromCalendarDropDown(destination, languagecode) { // Allow for shortcodes and always default the base option of // adding the languages to end of the url - old style! try { if (shortcodes && shortcodes[languagecode]) { location.href = shortcodes[languagecode].destination; } else { location.href = destination; } } catch (switchCalendarException) { location.href = destination; } } function clearViewFromHashChange(remCal, remTray, remDetail) { //cal try { if (remCal) { hotelmap.library.utility.overlay(80, '#000', false, 154); hotelmap.calendar.panel.parentNode.removeChild(hotelmap.calendar.panel); } } catch (e_1) {} try { if (remDetail) { hotelmap.detail_panel.parentNode.removeChild(hotelmap.detail_panel); } } catch (e_2) {} try { if (remTray) { hotelmap.infopanel.container.parentNode.removeChild(hotelmap.infopanel.container); hotelmap.infopanel.isClosed = true; } } catch (e_3) {} } /** * Create a new hash event * * @param event */ function makeHashEventActive(event) { if (event && event.state && event.state.model) { switch (event.state.model) { case "calendar": clearViewFromHashChange(false, true, true); // Make sure we haven't already got one of thse. if ($("#caldhad").length == 0) { hotelmap.calendar.init(); } break; case "tray": clearViewFromHashChange(true, false, true); break; case "search": clearViewFromHashChange(true, true, true); break; } } } window.onpopstate = function(event) { makeHashEventActive(event); }; function debugMessage(message) { if (debug_enabled == true) console.log("debug: " + message); } function runRoutingDistance(dataBindElement, mode) { try { $(".walk_dis_" + hotelmap.infopanel.hmid).html(""); hotelmap.walking_times_data[hotelmap.infopanel.hmid] = ""; hotelmap.infopanel.process_height(); } catch (infProcHeightException) {} } // Processing Session Request. function processSessionRequest(data) { if (data && data.responseText) { var postloadSessionData = JSON.parse(data.responseText); if (postloadSessionData.session > '') { attributes.session = postloadSessionData.session; } if (postloadSessionData.auth > '') { attributes.authcode = postloadSessionData.auth; } } } var language_fields = {}; function doAddLang() { $.each($("[langid]"), function() { var langid = $(this).attr("langid"); var langreset = $(this).attr("allowreset"); var langtarget = $(this).attr("langtarget"); if (!language_fields[langid] || langreset) { language_fields[langid] = true; if (langtarget) { $(this).attr(langtarget, translations["LNG_" + langid]); // + " (TR)"); } else { $(this).html(translations["LNG_" + langid]); //+ " (TR)"); } if (langid == "FRMATEN") { var sentence = translations["LNG_" + langid]; //[ATTENDEES] attendees are expected at [EVENT] this [MONTH] at [VENUE]. These visitors are staying in hotels mainly in [COUNT] hotel hubs, all with easy access to the venue. var countPoint = (!attributes.pointers) ? "popular" : (attributes.pointers.length + 1); sentence = sentence.replace("[ATTENDEES]", attributes.eventAttendees); sentence = sentence.replace("[EVENT]", attributes.pagedata.title); sentence = sentence.replace("[MONTH]", translations["LNG_AUTOLONGMONTHS" + attributes.event.date_start.month]); sentence = sentence.replace("[VENUE]", attributes.pagedata.subtitle); try { sentence = sentence.replace("[COUNT]", countPoint); } catch (e123) {} $(this).html(sentence); } } }); } /** * This is a temporary work around to disable distances for specific hotels * whilst we implement a better routing option */ function canRunDistanceCheck(mapid, hmid) { try { if (attributes.disable_distance_checks[mapid][hmid]) { return false; } } catch (invalidAttributeReferenceException) { // Empty. } return true; } /** * Post calendar runner */ var doCustomFramePostCalendarHasBeenRun = false; function doCustomFramePostCalendar() { if (attributes.custom_frames && attributes.custom_frames.enabled == true && !doCustomFramePostCalendarHasBeenRun) { if (!$("div").hasClass("hubframeshown")) { $.ajax( "frames/custom_frames/loader?mapReference=" + attributes.map_identity + "&auth=" + attributes.authcode + "&target=" + attributes.custom_frames.source, { 'complete': function(data) { var d = JSON.parse(data.responseText); //console.dir(d); var p = document.createElement("div"); $(p).addClass("custom_frame hubframeshown"); $(p).append(d.data); $("body").append($(p)); bindPickerWtmEvents(); //hotelmap.library.utility.overlay(80,'#000',true, 999); var closeIcon = hotelmap.library.utility.element( "img", { 'position': 'absolute', 'right': '-10px', 'top': '-10px', 'zIndex': '9999', 'cursor': 'pointer', 'z-index': '999999' }, { 'src': attributes.host + 'resource/images/gfx_v2/close.png', 'id': 'hdhjd' } ); $(".shadowyman").append(closeIcon); $(closeIcon).click(function() { doCustomFramePostCalendarHasBeenRun = true; setTimeout(function() { $(".custom_frame").fadeOut( 300, function() { $(this).remove() } ); hotelmap.library.utility.overlay(80, '#000', false, 154); }, 50); }); doAddLang(); $(".hub_title").html(attributes.pagedata.title); $(".hub_sub_title").html($("#prim_subtitle").html()); } } ); } } } function bindPickerWtmEvents() { $(".inner[hm-type='jump']").click(function() { doCustomFramePostCalendarHasBeenRun = true; var latlon = $(this).attr("hm-latlon").split(","); hotelmap.maps.zoomToPoint(latlon[0], latlon[1], parseInt(latlon[2]) + 1); $(".custom_frame").fadeOut(300, function() { $(this).remove() }); hotelmap.library.utility.overlay(80, '#000', false, 154); /* Server Automation mode, send through cal set */ if (attributes.automation_mode == "server") { hotelmap.auto_demo.server.send_notify("doWTMClose", latlon[0] + "," + latlon[1] + "," + (parseInt(latlon[2]) + 1)); } }); } function inIframe() { try { return window.self !== window.top } catch (a) { return true; } } function userdata(field, value) { var session = attributes.session; var mapsession = attributes.mapsession; var mapid = attributes.map_identity; var zoom = attributes.zoomlevel; var lat = attributes.latitude; var lon = attributes.longitude; if (!window.isbot) { $.ajax("/map/services/reporting/userdata?auth=" + attributes.authcode + "&id=" + mapid + "&lat=" + lat + "&lon=" + lon + "&zoom=" + zoom + "&session=" + session + "&mapsession=" + mapsession + "&f=" + field + "&v=" + escape(value), { 'complete': function(data) { processSessionRequest(data); } }); } } function usermetadata(type, data) { var session = attributes.session; var mapsession = attributes.mapsession; var mapid = attributes.map_identity; if (!window.isbot) { $.ajax("/map/services/reporting/userdata?auth=" + attributes.authcode + "&mode=meta&id=" + mapid + "&type=" + type + "&v=" + escape(data) + "&session=" + session + "&mapsession=" + mapsession, { 'complete': function(data) { processSessionRequest(data); } }); } } /** * NEW RUNTIMES */ hotelmap.runtime = { applyHeaders: function(title, subtitle) { hotelmap.heading_items.title.innerHTML = "HotelMapTM " + translations.LNG_HMFOR + " " + title; hotelmap.heading_items.subtitle.innerHTML = subtitle; try { document.title = "HotelMap " + translations.LNG_HMFOR + " " + title; } catch (titleSettingException) {} hotelmap.calendar.title = title; hotelmap.calendar.subtitle = (subtitle.length > 57) ? subtitle.substr(0, 57) + ".." : subtitle; } }; String.prototype.rtrim = function(s) { return this.replace(new RegExp(s + "*$"), ''); }; function capitaliseFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } if (!hotelmap.library) hotelmap.library = {}; /* define: hotelmap.library.utility */ function id_check_input(obj, dest) { if (obj.value.length == 1) { document.getElementById(dest).focus(); try { document.getElementById(dest).select(); } catch (ekl) {} } } function similarity(s1, s2) { var longer = s1; var shorter = s2; if (s1.length < s2.length) { longer = s2; shorter = s1; } var longerLength = longer.length; if (longerLength == 0) { return 1.0; } return (longerLength - editDistance(longer, shorter)) / parseFloat(longerLength); } function editDistance(s1, s2) { s1 = s1.toLowerCase(); s2 = s2.toLowerCase(); var costs = new Array(); for (var i = 0; i <= s1.length; i++) { var lastValue = i; for (var j = 0; j <= s2.length; j++) { if (i == 0) costs[j] = j; else { if (j > 0) { var newValue = costs[j - 1]; if (s1.charAt(i - 1) != s2.charAt(j - 1)) newValue = Math.min(Math.min(newValue, lastValue), costs[j]) + 1; costs[j - 1] = lastValue; lastValue = newValue; } } } if (i > 0) costs[s2.length] = lastValue; } return costs[s2.length]; } function deg2rad(deg) { return deg * (Math.PI / 180) } function translate(i) { try { var j = "LNG_" + i; if (translations[j]) document.getElementById(j).innerHTML = translations[j]; } catch (e) {} } /* public functions available externally */ function frameClose() { hotelmap.library.utility.close(); } var iterations = 0; var transparency = 100; function closeInformationWindow() { hotelmap.detail_panel_id = ""; //hotelmap.rhp.push_to_packet("CLICK_CLOSEINFWINDOW","1"); iterations = 0; transparency = 100; runGradientClose(); hotelmap.library.json.get("resource/script/hmww-tap?point=INFO_PANEL&tid=" + attributes.ref_codal_tid + "&"); } function getRandomArbitrary(min, max) { return Math.round(Math.random() * (max - min) + min); } function isWithin(lat, lon) { lat = parseFloat(lat); lon = parseFloat(lon); var boundary = hotelmap.maps.getQueryPosition(); //console.log("LL: " + lat + ", " + lon); //console.dir(boundary); return (lat > boundary[0] && lat < boundary[2] && lon > boundary[3] && lon < boundary[1]) ? true : false; } function runGradientClose() { if (attributes.isIE) { hotelmap.library.utility.overlay(90, '#000', false, 154); hotelmap.detail_panel.parentNode.removeChild(hotelmap.detail_panel); } else { if (iterations < 20) { transparency = transparency - 5; iterations++; hotelmap.library.utility.setTrans(hotelmap.detail_panel, transparency); hotelmap.library.utility.setTrans(hotelmap.overlayElement, transparency - 10); setTimeout(function() { runGradientClose(); }, 20); } else { iterations = 0; transparency = 100; hotelmap.library.utility.overlay(90, '#000', false, 154); hotelmap.detail_panel.parentNode.removeChild(hotelmap.detail_panel); } } } function removeUpdatingRatesLayer() { /* Remove any remaining rate progress elements from the screen */ try { hotelmap.calendar.preload.parentNode.removeChild(hotelmap.calendar.preload); } catch (e1) {} } function infoPanelFocus(hotelId, setter) { window.tagging.setHotelPopup(); makeHashChange("hotel", { model: 'hotel', hmid: hotelId, setter: setter }); /* Remove any remaining rate progress elements from the screen */ removeUpdatingRatesLayer(); //hotelmap.rhp.push_to_packet("CLICK_INFOPANELFOCUS",hotelId+"|"+setter); hotelmap.graphics.zoomInScreen(null, 920, 634, '#FFFFFF', function() { var user_string = ""; if (attributes.additional_params) { for (var i = 0; i < attributes.additional_params.length; i++) { var param = attributes.additional_params[i]; user_string += "" + param.parameter_name + "=" + param.parameter_value + "&"; } } if (hotelmap.calendar.postLoadHotel) { user_string += "&waitNode=true"; hotelmap.calendar.initialiseHotelId = ""; hotelmap.calendar.postLoadHotel = false; user_string += "&panel=" + hotelmap.calendar.panelPush; } else { user_string += "&panel=summary"; } hotelmap.userstatistics.pop_panels++; userdata("countHotelsPopup", hotelmap.userstatistics.pop_panels); usermetadata("FULL_INFO_POPUP", hotelId); //console.log("user_stirng: " + user_string); //console.log("Processing HMID " + hotelId + " with SearchID: " + hotelmap.modules.feedprocess.search_id_reference[hotelId]); var iframe = hotelmap.library.utility.element( "iframe", { 'width': '920px', 'height': '634px', 'overflow': 'hidden', 'zIndex': '997' }, { 'allowtransparency': 'yes', 'wmode': 'Opaque', 'width': '920px', 'height': '634px', 'scrolling': 'no', 'frameBorder': 'no', 'id': 'frame', 'src': 'frames/details/landing?dir=' + attributes.direction + '&agentID=' + attributes.agentID + '&displayRates=' + hotelmap.modules.feedprocess.payViewType + '&' + user_string + '&affiliateCode=' + attributes.affiliateCode + '&searchID=' + hotelmap.modules.feedprocess.search_id_reference[hotelId] + '&hmid=' + hotelId + '&mapProCode=' + attributes.map_identity + '&host=' + attributes.remote + '&' //' } //attributes.searchid ); hotelmap.detail_panel_id = hotelId + "|" + setter; hotelmap.detail_panel.innerHTML = ""; hotelmap.detail_panel.appendChild(iframe); }, setter); } function closeAndShowCal(hotelID, panel) { if (!hotelID) { hotelmap.library.utility.overlay(60, '#000', false, 154); } hotelmap.detail_panel.parentNode.removeChild(hotelmap.detail_panel); hotelmap.detail_panel_id = ""; //hotelmap.library.utility.overlay(90,'#000',false, 174); hotelmap.calendar.init(); if (hotelID) { hotelmap.calendar.panelPush = panel; hotelmap.calendar.initialiseHotelId = hotelID; hotelmap.calendar.hasShownElement = false; hotelmap.calendar.postLoadHotel = true; } } /* utility functions */ hotelmap.library.utility = { applyAttributes: function(o, styles) { if (o && styles) { for (var i in styles) { o[i] = styles[i]; } } }, applyStyles: function(o, styles) { if (o && styles) { for (var i in styles) { o.style[i] = styles[i]; } } }, focusMoments: {}, focusOnZone: function(plat, plon, latmin, latmax, lonmin, lonmax, ID) { if (latmax && lonmax && latmax != 0 && lonmax != 0) // Is it an area? { hotelmap.disable = true; if (hotelmap.library.utility.focusMoments[ID]) { hotelmap.maps.zoomToPoint(plat, plon, hotelmap.library.utility.focusMoments[ID]); } else { hotelmap.maps.zoomToPoint(plat, plon, 5); var proceed = false; var start = 5; var zoomInModeInterval = setInterval( function() { //latmin, lonmin, latmax, lonmax if (hotelmap.maps.isInZone(latmin, lonmin, latmax, lonmax)) { start++; hotelmap.maps.zoomToPoint(plat, plon, start); } else { // hotelmap.disable=false; // hotelmap.maps.zoomToPoint( plat, plon, start-1 ) ; setTimeout(function() { hotelmap.modules.feedprocess.get_new_hotel_listing(); }, 500); clearInterval(zoomInModeInterval); // hotelmap.library.utility.focusMoments[ID] = start-1; } }, 100 ); } } }, isIEResizeEvent: function() { if (attributes.isIpad == true) return false; return true; if (!attributes.isIE || attributes.isLowIE) return true; // All other browsers behave correctly. var dims = hotelmap.library.utility.getDimensions(); if (dims[0] != hotelmap.IEDIMS[0] || dims[1] != hotelmap.IEDIMS[1]) { hotelmap.IEDIMS = dims; return true; } else { return false; } }, /** * Frame closer * @returns */ close: function() { if (hotelmap.detail_panel) { try { hotelmap.detail_panel.parentNode.removeChild(hotelmap.detail_panel); hotelmap.library.utility.overlay(90, '#000', false, 154); } catch (e) {} } }, /** * Transparency setter * @param obj * @param level * @returns */ setTrans: function(obj, level) { level = parseInt(level); if (obj && level >= 0 && level <= 100) { obj.hidOpac = level; obj.style.MozOpacity = level / 100; obj.style.opacity = level / 100; obj.style.filter = "alpha(opacity=" + level + ")"; try { if (attributes.isLowIE && obj.allowSubSet && obj.childNodes && obj.childNodes.length > 0) { for (var i = 0; i < obj.childNodes.length; i++) { hotelmap.library.utility.setTrans(obj.childNodes[i], level); } } } catch (e) {} } }, /** * Quick DIV * @param id * @param text * @returns */ quickdiv: function(id, text) { return hotelmap.library.utility.element("div", {}, { 'innerHTML': text, 'id': id }); }, /** * Quick DIV * @param id * @param text * @returns */ makediv: function(id, text) { return hotelmap.library.utility.element("div", {}, { 'innerHTML': text, 'className': id }); }, /** * deflect * Stops hotel collision so much. Note that 1 degree is 112.12KM */ deflect: function(lat, lon, distanceInMetres, direction) { //Earth�s radius, sphere var R = 6378137; //offsets in meters var dn = 0; var de = 0; if (direction == "lat") { dn = distanceInMetres; } else { de = distanceInMetres; } //Coordinate offsets in radians var dLat = dn / R; var dLon = de / (R * Math.cos(Math.PI * lat / 180)); //OffsetPosition, decimal degrees var latO = lat + dLat * 180 / Math.PI; var lonO = lon + dLon * 180 / Math.PI; /* var k1 = 1/112; // 1000M var m1 = k1/1000; var result = m1 * distanceInMetres ; var outcome = parseFloat(coordinate) + parseFloat(result); console.log("Current: " + coordinate ); console.log("Outcome: " + outcome); */ return [latO, lonO]; }, grabImageBase: function(imageObject) { console.log(imageObject); console.log("Dimensions: " + imageObject.width + " x " + imageObject.height); var canvas = document.getElementById("cn"); //document.createElement("canvas"); canvas.width = imageObject.width; canvas.height = imageObject.height; var context = canvas.getContext("2d"); context.drawImage(imageObject, 0, 0); boxBlurCanvasRGB("cn", 0, 0, 256, 256, 23, 2); //canvas.style.webkitFilter = "blur(10px)"; /* code that actually blurs the image goes here */ //var dataURI = canvas.toDataUrl("image/png"); //console.log(dataURI); }, /** * overlay * Creates [or uses existing] overlay. * @param color string (hex) * @param $doShow boolean */ overlay: function(transparency, color, doShow, zIndex) { if (!hotelmap.calendar.postLoadHotel) { hotelmap.ui = (hotelmap.ui) ? hotelmap.ui : _("ui"); if (hotelmap.overlayElement != null) { hotelmap.overlayElement.style.backgroundColor = color; hotelmap.library.utility.setTrans(hotelmap.overlayElement, transparency); hotelmap.overlayElement.style.display = (doShow) ? '' : 'none'; } else { var dimensions = hotelmap.library.utility.getDimensions(); hotelmap.overlayElement = hotelmap.library.utility.element("div", { 'zIndex': zIndex, 'position': 'fixed', 'left': '0px', 'top': '0px', 'width': '100%', 'height': '100%' }, {}); hotelmap.library.utility.setTrans(hotelmap.overlayElement, transparency); hotelmap.ui.appendChild(hotelmap.overlayElement); hotelmap.library.utility.overlay(transparency, color, doShow); } } }, /** * getDimensions * Returns the current browser dimensions * @return array[w,h] */ getDimensions: function() { var viewportwidth; var viewportheight; if (typeof window.innerWidth != 'undefined') { viewportwidth = window.innerWidth, viewportheight = window.innerHeight } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) { viewportwidth = document.documentElement.clientWidth, viewportheight = document.documentElement.clientHeight } else { viewportwidth = document.getElementsByTagName('body')[0].clientWidth, viewportheight = document.getElementsByTagName('body')[0].clientHeight } //if ( attributes.dvid == "MOB_SAFARI_TAB" || attributes.dvid == "MOB_SAFARI") // { // viewportwidth = screen.width; // viewportheight = screen.height; // } // alert( viewportwidth +", " + viewportheight); return new Array(viewportwidth, viewportheight); }, /** * pushFullScreenMap * Redundant? */ pushFullScreenMap: function(objectName) { var dimensions = hotelmap.library.utility.getDimensions(); hotelmap.object_map = (hotelmap.object_map) ? hotelmap.object_map : document.getElementById(objectName); hotelmap.object_map.style.position = 'absolute'; hotelmap.object_map.style.left = '0px'; hotelmap.object_map.style.top = '0px'; hotelmap.object_map.style.width = dimensions[0] + 'px'; hotelmap.object_map.style.height = dimensions[1] + 'px'; if (hotelmap.engine_map) setTimeout(function() { hotelmap.engine_map.resize(); }, 100); //hotelmap.object_map.style.width = "200px"; //hotelmap.object_map.style.height = "300px"; }, pushSpecificScreenMap: function(objectName, left, top, width, height) { var dimensions = hotelmap.library.utility.getDimensions(); hotelmap.object_map = (hotelmap.object_map) ? hotelmap.object_map : document.getElementById(objectName); hotelmap.object_map.style.position = 'absolute'; hotelmap.object_map.style.left = left + 'px'; hotelmap.object_map.style.top = top + 'px'; hotelmap.object_map.style.width = width + 'px'; hotelmap.object_map.style.height = height + 'px'; //if ( hotelmap.engine_map ) setTimeout(function(){ hotelmap.engine_map.resize(); }, 100 ); //hotelmap.object_map.style.width = "200px"; //hotelmap.object_map.style.height = "300px"; }, /** * styles * Apply styling elements to an object * @param obj DOM * @param attributes JSON attribute array */ styles: function(obj, attributes) { if (attributes) for (var a in attributes) if (a && attributes[a]) try { obj.style[a] = attributes[a]; } catch (e) {} }, /** * attributes * Apply styling elements to an object * @param obj DOM Node * @param attributes JSON attribute array */ attributes: function(obj, attributes) { if (attributes) for (var a in attributes) if (a && attributes[a]) try { obj[a] = attributes[a]; } catch (e) {} }, /** * element * Creates a new DOM element * @param name - DOM name * @param styles - JSON styles * @param attributes - JSON attr * @return Returns a new DOM element node. */ element: function(name, styles, attributes) { var element = document.createElement(name); hotelmap.library.utility.styles(element, styles); hotelmap.library.utility.attributes(element, attributes); //element.die=function(){ this.parentNode.removeChild(this); } //element.ping=function(){ console.log("Element PING: Alive");} return element; }, /** * rn * Round a number to N dec * @param num - the number * @param dec - decimal places * @return double */ rn: function(num, dec) { var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec); return result; }, generateID: function(length) { var sequence = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; var preSequence = "NID_"; var id = preSequence; for (var i = 0; i < length; i++) id += sequence[hotelmap.library.utility.rnd1random(0, sequence.length)]; return id; }, rnd1random: function(from, to) { return from + Math.floor(Math.random() * (to + 1)); }, calculateSecondsBetweenDates: function(date1) { var t1 = date1; var t2 = new Date(); var dif = t1.getTime() - t2.getTime() var Seconds_from_T1_to_T2 = dif / 1000; var Seconds_Between_Dates = Math.abs(Seconds_from_T1_to_T2); return Seconds_Between_Dates; } }; /** * * Base64 encode / decode * http://www.webtoolkit.info/ * **/ var Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function(input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function(input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode: function(string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode: function(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 _(id) { return document.getElementById(id); } /** * ------------------------------------------------------------------------- * HotelMap WorldWide 1.0 * Copyright (C) 2012 - All Rights Reserved - HotelMap.com * ------------------------------------------------------------------------- * Base ID: Hotelmap|Core|Library|Events * Description: Event based routines for the hotelmap core * ------------------------------------------------------------------------- * Version : $Id$ * Author : James Holden * Contact : james@hotelmap.com * ------------------------------------------------------------------------- * Notes : Ensure that only event based routines go in here. * ------------------------------------------------------------------------- */ if ( !hotelmap.library ) hotelmap.library = {} ; /* define: hotelmap.library.events */ hotelmap.library.events = { triggers : {}, /** * add_window_event * Add a browser based event handler * @param eventType [load,click etc] * @param func [the function to run] */ initialiseEvent : function( eventType, func ) { if (window.addEventListener) { window.addEventListener(eventType, func, false); } else if (window.attachEvent) { window.attachEvent('on'+eventType, func); } }, /** * preventLoadEvent * Prevents the loading of hotel information for a specific event */ preventLoadEvent : function() { clearInterval( hotelmap.properties['new_hotel_listing_interval'] ) ; }, /** * addTriggerEvent * */ addTriggerEvent : function( triggerID, funcAction ) { if ( !hotelmap.library.events.triggers[triggerID] ) hotelmap.library.events.triggers[triggerID] = []; hotelmap.library.events.triggers[triggerID].push(funcAction); }, callTriggerEvent : function( triggerID ) { if ( hotelmap.library.events.triggers[triggerID] ) { for ( var i = 0 ; i < hotelmap.library.events.triggers[triggerID].length ; i++ ) { try { hotelmap.library.events.triggers[triggerID][i]; } catch ( triggerException ) { alert("triggerException: " + triggerException.message); } } } } } ; /** * ------------------------------------------------------------------------- * HotelMap WorldWide 1.0 * Copyright (C) 2012 - All Rights Reserved - HotelMap.com * ------------------------------------------------------------------------- * Base ID: Hotelmap|Core|Library|JSON * Description: HTTP XML Request / JSON Handler * ------------------------------------------------------------------------- * Version : $Id$ * Author : James Holden * Contact : james@hotelmap.com * ------------------------------------------------------------------------- * Notes : Don't edit this - it should be pretty static code. * ------------------------------------------------------------------------- */ if (!hotelmap.library) hotelmap.library = {}; /* define: hotelmap.library.json */ hotelmap.library.json = { counter: 0, /** * get_handle * Obtain a valid AJAX handler * @return AJAX Handler Object */ get_handle: function() { var ajaxHandle = null; if (window.XMLHttpRequest) { ajaxHandle = new XMLHttpRequest(); } else if (window.ActiveXObject) { _msxml_progid = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP']; for (var i = 0; i < _msxml_progid.length; i++) { try { ajaxHandle = new ActiveXObject(this._msxml_progid[i]); break; } catch (ajaxHandleException) { /* Null Value */ } } if (ajaxHandle == null) { ajaxHandle = new ActiveXObject('Microsoft.XMLHTTP'); } } return ajaxHandle; }, staggered_get: function(url) { if (hotelmap.library.json.counter < 20) { hotelmap.library.json.counter++; var delta_url = ("" + Math.random()).split(".")[1].substring(0, 7); url = url + "verification=" + attributes.verification + "&pdr=" + delta_url + "&auth=" + attributes.authcode; var ajaxHandle = hotelmap.library.json.get_handle(); if (ajaxHandle != null) { ajaxHandle.onreadystatechange = function() { hotelmap.library.json.parse_staggered(ajaxHandle); }; ajaxHandle.open("GET", url, true); ajaxHandle.send(null); } } else { setTimeout(function() { hotelmap.library.json.staggered_get(url); }, 1000); } }, /** * parse * Process an incoming handler on the correct state * @param handle */ parse_staggered: function(handle) { if (handle.readyState == 4 && handle.status == 200) { if (handle.responseText) { var response = handle.responseText; if (response) { hotelmap.library.json.counter--; try { eval(response); } catch (e) { hotelmap.library.json.post( "services/reporting/jserror", "error=" + e.message + "&block=" + response + "&verification=" + attributes.verification + "&auth=" + attributes.authcode ); console.error("Error Report: " + e.message); } response = null; } } } }, /** * get * @param url string * @param doEval boolean [do evaluation of return] */ get: function(url, doEval) { if (!window.isbot) { var delta_url = ("" + Math.random()).split(".")[1].substring(0, 7); var destination = url + "&auth=" + attributes.authcode + "&pdr=" + delta_url; $.ajax(destination, { 'complete': function(data) { if (data && data.responseText) { $responseSet = data.responseText; try { eval($responseSet); } catch (parseException) { hotelmap.library.json.post( "services/reporting/jserror", "error=" + parseException.message + "&block=" + $responseSet + "&verification=" + attributes.verification + "&auth=" + attributes.authcode ); response = null; } } } }); } }, post: function(url, post) { var ajaxHandle = hotelmap.library.json.get_handle(); if (ajaxHandle) { ajaxHandle.onreadystatechange = function() {}; ajaxHandle.open("POST", url, true); ajaxHandle.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // ajaxHandle.setRequestHeader("Content-length", post.length); // ajaxHandle.setRequestHeader("Connection", "close"); ajaxHandle.send(post); } }, postRun: function(url, post) { var ajaxHandle = hotelmap.library.json.get_handle(); if (ajaxHandle) { ajaxHandle.onreadystatechange = function() { hotelmap.library.json.parse(ajaxHandle); }; ajaxHandle.open("POST", url, true); ajaxHandle.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // ajaxHandle.setRequestHeader("Content-length", post.length); // ajaxHandle.setRequestHeader("Connection", "close"); ajaxHandle.send(post); } }, /** * parse * Process an incoming handler on the correct state * @param handle */ parse: function(handle) { if (handle.readyState == 4 && handle.status == 200) { if (handle.responseText) { var response = handle.responseText; if (response) { try { eval(response); } catch (e) { hotelmap.library.json.post( "services/reporting/jserror", "error=" + e.message + "&block=" + response + "&verification=" + attributes.verification + "&auth=" + attributes.authcode ); response = null; } } } } } }/** * ------------------------------------------------------------------------- * HotelMap WorldWide 1.0 * Copyright (C) 2012 - All Rights Reserved - HotelMap.com * ------------------------------------------------------------------------- * Base ID: Hotelmap|Modules|Process Hotel Feeds * Description: Process the incomign hotel feeds for display. * ------------------------------------------------------------------------- * Version : $Id$ * Author : James Holden * Contact : james@hotelmap.com * ------------------------------------------------------------------------- * Notes : CORE interface for searching hotels. * ------------------------------------------------------------------------- */ if (!hotelmap.modules) hotelmap.modules = {}; /* define: hotelmap.modules.feedprocess */ hotelmap.modules.feedprocess = { zoom_level: null, hotels: {}, pixel_sets: {}, pins: [], base_to_search: [], base_timeout: null, cached_rates: {}, rate_icons: {}, base_searcher: {}, has_searched: false, hotel_length: 0, resetCoordinates: true, hasDoneHotels: false, isZoomMode: false, payViewType: false, loop_pop: '', pop_done: false, doPaymentTypeProcess: function() { var showall = ((attributes.filtering.showPayLater && attributes.filtering.showPayNow) || (!attributes.filtering.showPayLater && !attributes.filtering.showPayNow)) ? true : false; if (showall) { hotelmap.modules.feedprocess.payViewType = false; } else { if (attributes.filtering.showPayLater) { hotelmap.modules.feedprocess.payViewType = "PAY_LATER"; } else { hotelmap.modules.feedprocess.payViewType = "PAY_NOW"; } } // Search the hotelmap based on the new settings. hotelmap.calendar.search(); }, get_new_hotel_listing_by_zoom: function() { hotelmap.modules.feedprocess.get_new_hotel_listing(); hotelmap.modules.feedprocess.isZoomMode = true; }, /** * get_new_hotel_listing * On each movement this will get the local host listings nearby */ get_new_hotel_listing: function() { try { hotelmap.maps.zoomer.maintainOrder(); } catch (maintainOrderException) { console.log("Maintain: " + e1.message); } if (hmwwas && hmwwas.HOTEL_AREAS_ALLOWED == "ON" && hotelmap.calendar.searched) { if (!hotelmap.modules.feedprocess.hasDoneHotels) { hotelmap.library.json.get("resource/script/hmww-tap?point=VIEWING_HOTELS&tid=" + attributes.ref_codal_tid + "&"); hotelmap.modules.feedprocess.hasDoneHotels = true; } var zoom = hotelmap.maps.getZoom(); var current_center_coordinates = hotelmap.maps.getCenter(); attributes.latitude = current_center_coordinates.lat; attributes.longitude = current_center_coordinates.lon; attributes.zoomlevel = zoom; if (zoom > 6 && hotelmap.search_data.dates.arrival && !window.isbot) { clearTimeout(hotelmap.modules.feedprocess.base_timeout); clearInterval(hotelmap.properties['new_hotel_listing_interval']); hotelmap.properties['new_hotel_listing_interval'] = setInterval( function() { var recommended = 0; if (attributes.isRecommendedHotelAutoSet == 1 && (attributes.isRecommendedHotelSender == 1 || attributes.dvid != 'DESKTOP')) { recommended = 1; } clearInterval(hotelmap.properties['new_hotel_listing_interval']); var coords = hotelmap.maps.getQueryPosition(); var center = hotelmap.maps.getCenter(); var destination_url = "services/hotels/local_hotel_feed?rec=" + recommended + "&mcode=" + attributes.request_uri + "&starRank=" + attributes.star_rankings + "&hotel_requirements=" + attributes.hotel_requirements + "&zt=hotelmap.maps.getZoom&class=" + attributes.hotel_class + "&query=" + coords[0] + "," + coords[1] + "," + coords[2] + "," + coords[3] + "&zoom_level=" + zoom + "&cb=hotelmap.modules.feedprocess.process_result_set&originSet=" + attributes.initial_lat + "," + attributes.initial_lon + "¢er=" + center.lat + "," + center.lon + "&affiliate=" + attributes.affiliateCode + "&"; hotelmap.library.json.get(destination_url); }, 100 ); } else { hotelmap.modules.feedprocess.remove_all_pins(); } } hotelmap.exclusivedeals.process(); }, /** * check_rate * Do we have a valid cached rate? * @param hmid */ check_rate: function(hmid) { return (hotelmap.modules.feedprocess.cached_rates[hmid]) ? true : false; }, search_id_reference: {}, /** * rates * Process an incoming rate feed. * @param rates JSON */ rates: function(rates, searchid) { attributes.total_search_count--; if (attributes.total_search_count <= 0) { attributes.total_search_count = 0; try { $(".connecting").hide(); } catch (conShow) {} } if (rates.length > 0) { for (var i = 0; i < rates.length; i++) { hotelmap.modules.feedprocess.search_id_reference[rates[i].hmid] = searchid; // Create a search reference ID hotelmap.modules.feedprocess.cached_rates[rates[i].hmid] = rates[i]; hotelmap.userstatistics.rates_loaded++; // Exclusive specific.. if (attributes.show_exclusive_specific) { for (var k = 0; k < attributes.show_exclusive_specific.condition_values.length; k++) { if (attributes.show_exclusive_specific.condition_values[k] == rates[i].hmid) { attributes.exclusive_hotels[rates[i].hmid] = true; } } } // Pink Circle - We can auto-dump certain hotels if we want. try { if (attributes.pinkCirclePromos && attributes.pinkCirclePromos.length > 0) { for (var pCount = 0; pCount < attributes.pinkCirclePromos.length; pCount++) { if (rates[i].hmid == attributes.pinkCirclePromos[pCount]) { rates[i].memberRate = 1; } } } } catch (pinkCircleRateException) { // Empty. } /** * Hotel Planner Adjustmet. * This is for testing only and can be removed later. */ try { if (attributes.hpl_circles) { var localFeedsAvailable = JSON.parse(rates[i].feedsAvailable); if (localFeedsAvailable[0] == "HPL") { rates[i].memberRate = 1; } else if (localFeedsAvailable.includes("HPL")) { rates[i].memberRate = 2; } else { rates[i].memberRate = 0; } } } catch (hplCircles) { // console.log("Error in hplCirlces " + hplCircles.message); } if (attributes.runDemoScreenGrab == "NO" && attributes.zoomlevel > 12 && rates[i].memberRate > 0 && rates[i].rate > 0 && rates[i].rate < 9999 && ( attributes.map_identity == "142958" || attributes.map_identity == '145489' || attributes.map_identity == '145171' || attributes.show_member_rates || attributes.show_exclusive_rates)) { if (attributes.hpl_circles) { //console.log(">>>> " . attributes.member_rates_color); var hpl_color = (rates[i].memberRate == 2) ? "#0000FF" : "#FF0000"; attributes.highlighthotels.push({ "color": hpl_color, "hotel": rates[i].hmid, "name": "" }); attributes.promoted_hotels[rates[i].hmid] = true; } else if (!attributes.show_member_rates && !attributes.show_exclusive_rates) { attributes.highlighthotels.push({ "color": attributes.member_rates_color, "hotel": rates[i].hmid, "name": "" }); attributes.promoted_hotels[rates[i].hmid] = true; } else if (attributes.show_member_rates) { var tmpcolor = attributes.member_rates_color; try { if (attributes.show_member_rates.settings == rates[i].hmid) { tmpcolor = "#FF00ED"; } } catch (colorSettingException) { } attributes.highlighthotels.push({ "color": tmpcolor, "hotel": rates[i].hmid, "name": "" }); attributes.promoted_hotels[rates[i].hmid] = true; } else if (attributes.show_exclusive_rates) { attributes.exclusive_hotels[rates[i].hmid] = true; } try { $("div[hm-hmid='" + rates[i].hmid + "']")[0].isAutoActiveNode = true; $("div[hm-hmid='" + rates[i].hmid + "']")[0].runFromRatePoint = true; } catch (e) {} } } } try { if (attributes.resultviewer) { hotelmap.resultviewer.addResults(rates); } } catch (rvException) {} hotelmap.modules.feedprocess.push_rates_to_screen(); attributes.searchid = searchid; hotelmap.hotel_highlight.pushToHotels(); hotelmap.exclusivedeals.process(); setTimeout( function() { hotelmap.sorting.rightpanel.sort( hotelmap.rightpanel.listings.hotelcontainer ); }, 2000 ); }, /** * push_rates_to_screen * Push any and all rates we have obtained to the screen. */ push_rates_to_screen: function() { for (var i in hotelmap.modules.feedprocess.rate_icons) { var ri = hotelmap.modules.feedprocess.rate_icons[i]; var rv = hotelmap.modules.feedprocess.check_rate(i); if (!ri.rate_done && rv) { ri.rate_done = true; hotelmap.hotelicon.create_rate_icon( ri, hotelmap.modules.feedprocess.cached_rates[i] ); ri.hmid = i; try { hotelmap.infopanelisfocused.find(i); } catch (epep) {} } } hotelmap.sorting.rightpanel.sort( hotelmap.rightpanel.listings.hotelcontainer ); try { hotelmap.focushotel.auto_panel_initialiser(); } catch (focusException) {} hotelmap.pushsearchdone = true; }, __do_internal_query: function(url) { if (attributes.searchid && attributes.searchid != 'undefined') { url += "&searchID=" + attributes.searchid + "&"; } url += "&cb=hotelmap.modules.feedprocess.rates&"; url += (hotelmap.modules.feedprocess.has_searched) ? "&newSearch=N&" : "&newSearch=Y&"; url += "&roomConfig=" + hotelmap.criteraJSON + "&"; url += "¤cy=" + hotelmap.search_data.currency; url += "&arrival=" + hotelmap.search_data.dates.arrival.yyyymmdd; url += "&departure=" + hotelmap.search_data.dates.departure.yyyymmdd + "&"; url += "&mapid=" + attributes.map_identity + "&affcode=" + attributes.affiliateCode + "&"; url += "&PIN=" + attributes.pin_number + "&"; url += "&langCode=" + attributes.language + "&"; if (hotelmap.modules.feedprocess.payViewType) { if (hotelmap.modules.feedprocess.payViewType == "PAY_LATER") { url += "&rateType=PHR&"; } else if (hotelmap.modules.feedprocess.payViewType == "PAY_NOW") { url += "&rateType=PNR&"; } } if (attributes.additional_params) { for (var i = 0; i < attributes.additional_params.length; i++) { var param = attributes.additional_params[i]; url += "" + param.parameter_name + "=" + param.parameter_value + "&"; } } attributes.total_search_count++; try { if (!attributes.showOnly) { $(".connecting").fadeIn(); } } catch (conShow) { } hotelmap.library.json.staggered_get(url); }, /** * distance_between_points * Calculates the distance between two sets of latitude and longitude * @param point1 , format = {'lat':0,'lon':0} * @param point2 * @return double * - Added: 15th March 2013 */ distance_between_points: function(point1, point2) { var lat1 = point1.lat; var lon1 = point1.lon; var lat2 = point2.lat; var lon2 = point2.lon; var R = 6371; // Radius of the earth in km var dLat = deg2rad(lat2 - lat1); // deg2rad below var dLon = deg2rad(lon2 - lon1); var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); var d = R * c; // Distance in km return d; }, /** * sort_bases_closet_to_focus * Sort the bases so that those closest to the hotel load first. * @param latitude * @param longitude * - Added: 15th March 2013 */ sort_bases_closet_to_focus: function() { // Obtain the current center point var center = hotelmap.maps.getCenter(); // Ensure that we have some bases to search before we try and sort them. if (hotelmap.modules.feedprocess.base_to_search && hotelmap.modules.feedprocess.base_to_search.length > 0) { // Create our sort method. Use the distance to point as our priority moment. hotelmap.modules.feedprocess.base_to_search.sort( function(a, b) { var centeral_point = { 'lat': center.lat, 'lon': center.lon }; var point_location_1 = { 'lat': hotelmap.modules.feedprocess.rate_icons[a].data.primary_data.latitude, 'lon': hotelmap.modules.feedprocess.rate_icons[a].data.primary_data.longitude }; var point_location_2 = { 'lat': hotelmap.modules.feedprocess.rate_icons[b].data.primary_data.latitude, 'lon': hotelmap.modules.feedprocess.rate_icons[b].data.primary_data.longitude }; var a_distance = hotelmap.modules.feedprocess.distance_between_points(centeral_point, point_location_1); var b_distance = hotelmap.modules.feedprocess.distance_between_points(centeral_point, point_location_2); hotelmap.modules.feedprocess.rate_icons[a].data.primary_data.my_distance = a_distance; hotelmap.modules.feedprocess.rate_icons[b].data.primary_data.my_distance = b_distance; return a_distance - b_distance; } ); } }, // END /** * hotelmap.modules.feedprocess.query * Process any outstanding requests to search for rates. */ query: function() { try { hotelmap.modules.feedprocess.sort_bases_closet_to_focus(); } catch (distanceSortOrderException) { } if (!window.isbot && hmwwas && hmwwas.HOTEL_RATES_ALLOWED == "ON" && hotelmap.search_data.dates.arrival) { var url = "services/hotels/search_hotels?rdsg=" + attributes.runDemoScreenGrab + "&bases="; var base_search_count = 0; var spawn_search = 0; var spawn_temp = attributes.spawn_requests; if (hotelmap.modules.feedprocess.base_to_search.length < 10) { spawn_temp = Math.round(attributes.spawn_requests / 2); } if (hotelmap.modules.feedprocess.base_to_search.length > 0 && !window.isbot) { for (var i = 0; i < hotelmap.modules.feedprocess.base_to_search.length; i++) { if (!hotelmap.modules.feedprocess.check_rate(hotelmap.modules.feedprocess.base_to_search[i]) && !hotelmap.modules.feedprocess.base_searcher[hotelmap.modules.feedprocess.base_to_search[i]]) { attributes.statistics.rate_responses++; base_search_count++; spawn_search++; hotelmap.modules.feedprocess.base_searcher[hotelmap.modules.feedprocess.base_to_search[i]] = 1; url += hotelmap.modules.feedprocess.base_to_search[i] + ","; if (spawn_search == spawn_temp) { hotelmap.modules.feedprocess.__do_internal_query(url); var url = "services/hotels/search_hotels?rdsg=" + attributes.runDemoScreenGrab + "&bases="; var base_search_count = 0; var spawn_search = 0; } } } if (spawn_search > 0) { hotelmap.modules.feedprocess.__do_internal_query(url); } } hotelmap.modules.feedprocess.has_searched = true; hotelmap.modules.feedprocess.push_rates_to_screen(); } }, /** * showCluster * @param filters * Return the count of hotels within a cluster.. */ showCluster: function(filters) { var show = 0; var brand_filtered = false; var reduce = false; //console.dir(filters); // -- // Are we brand filtering? for (var i in hotelmap.brandlinks) { if (hotelmap.brandlinks[i].filtered) brand_filtered = true; } // -- // Brand Filtered: // Only show specific brands and then ensure the star rating is included. if (brand_filtered) { show = 0; for (var i in hotelmap.brandlinks) { if (hotelmap.brandlinks[i].filtered) { if (filters.brands[i]) { if (attributes.filtering.show5star && filters.brands[i].five > 0) show = show + filters.brands[i].five; if (attributes.filtering.show4star && filters.brands[i].four > 0) show = show + filters.brands[i].four; if (attributes.filtering.show3star && filters.brands[i].three > 0) show = show + filters.brands[i].three; if (attributes.filtering.show2star && filters.brands[i].two > 0) show = show + filters.brands[i].two; if (attributes.filtering.show1star && filters.brands[i].one > 0) show = show + filters.brands[i].one; } } } } else // -- // Only process star requirements { show = 0; if (attributes.filtering.show5star && filters.five > 0) show = show + filters.five; if (attributes.filtering.show4star && filters.four > 0) show = show + filters.four; if (attributes.filtering.show3star && filters.three > 0) show = show + filters.three; if (attributes.filtering.show2star && filters.two > 0) show = show + filters.two; if (attributes.filtering.show1star && filters.one > 0) show = show + filters.one; } return (show > 0) ? show : 0; }, processExtendedFilterSystem: function(filter) { var show = 0; }, /** * isBrandFiltered * Single hotel test for showing. */ isBrandFiltered: function(brandid) { show = true; for (var i in hotelmap.brandlinks) { if (hotelmap.brandlinks[i].filtered) { show = false; } } try { if (brandid && hotelmap.brandlinks[brandid].filtered) { show = true; } } catch (brandExceptionPoint) { } return show; }, showHotel: function(hotel) { var show = false; var found = false; if (!attributes.filtering.show3star) { attributes.filtering.show2star = attributes.filtering.show1star = false; } if (attributes.filtering.show5star && hotel.stars >= 5) show = true; if (attributes.filtering.show4star && hotel.stars >= 4 && hotel.stars < 5) show = true; if (attributes.filtering.show3star && hotel.stars >= 3 && hotel.stars < 4) show = true; if (attributes.filtering.show2star && hotel.stars >= 2 && hotel.stars < 3) show = true; if (attributes.filtering.show1star && ((hotel.stars >= 0 && hotel.stars < 2) || hotel.stars == "")) show = true; if (attributes.filtering.internet && hotel.INI != "1") show = false; if (attributes.filtering.restaurant && hotel.RST != "1") show = false; if (attributes.filtering.freeparking && hotel.PRK != "1") show = false; if (attributes.filtering.swimming && hotel.SWM != "1") show = false; if (attributes.filtering.fitness && hotel.FTN != "1") show = false; if (attributes.filtering.rated && (hotel.tripRating < 4)) show = false; // console.log("Filtering element: (rated:"+attributes.filtering.rated+") (val:"+hotel.tripRating+") (show:"+show+")"); if (hotelmap.rightpanel.tabseries == "SHORTLIST" && show == true) { for (var i = 0; i < hotelmap.favorites.container.childNodes.length; i++) { if (hotel.hmid == hotelmap.favorites.container.childNodes[i].hotel_id) { found = true; } } if (!found) show = false; } return show; }, /** * hotelmap.modules.feedprocess.remove_all_pins * Clear all visible pins from the screen. */ remove_all_pins: function() { hotelmap.maps.removeAllLayerContent(); }, /** * This is a post process runner which scans the hotels on the map for * ratings and popularity information so we can promote specific hotels * based on rankings and such */ popularity_scanner: function(data_set) { var map_id = attributes.map_identity; var hmid_stack = ""; for (var i = 0; i < data_set.length; i++) { hmid_stack += "hmids[]=" + data_set[i].hmid + "&"; } $.ajax("services/hotels/popularity?auth=" + attributes.authcode + "&" + hmid_stack + "mapID=" + escape(map_id) + "&auth=" + attributes.authcode, { dataType: "json", 'complete': function(data) { if (data && data.responseText) { var json = JSON.parse(data.responseText); var count = 0; for (var hotel_order in json.popularity_by_map) { if (count == 0) { var hotel = json.popularity_by_map[hotel_order]; var hmid = hotel['hmid']; } count++; } for (var hotel_order in json.popularity_by_area) { if (count == 0) { var hotel = json.popularity_by_area[hotel_order]; var hmid = hotel['hmid']; } count++; } if (count == 0) { hotelmap.library.utility.overlay(80, '#000', false, 154); } else { var element = hotelmap.modules.feedprocess.hotels[hmid]; for (var i in hotelmap.modules.feedprocess.pixel_sets) { // Create a group point (cluster icon) if (hotelmap.modules.feedprocess.pixel_sets[i].length > 3) { if (!hotelmap.maps.disable_zones) { for (var j = 0; j < hotelmap.modules.feedprocess.pixel_sets[i].length; j++) { if (hotelmap.modules.feedprocess.pixel_sets[i][j] == hmid) { $("#BLOCKER_" + i.replace('-', '').replace('%', '')).remove(); hotelmap.modules.feedprocess.pixel_sets[i].splice(j, 1); delete hotelmap.cluster_items[hmid]; hotelmap.modules.feedprocess.new_group_point(i, hotelmap.modules.feedprocess.pixel_sets[i].length, hotelmap.modules.feedprocess.pixel_sets[i]); } } } } } if (!hotelmap.hotelicon.feedpoints[element.hmid]) //if (!$("#map").find("#"+element.hmid).length) { hotelmap.modules.feedprocess.create_new_searching_point(element, 'mostpopular'); } else { hotelmap.modules.feedprocess.run_filter_check(element); } } } } }); }, /** * If a parameter request from the url asks that we only show one * hotel then filter out our hotel data set and only show information * about that hotel. This also has the added benefit of preventing * searches for hotels we don't care about. * * @param dataset */ processSingleHotelRequest: function(dataset) { if (attributes.showOnly > 0 && dataset.length > 0) { return dataset.filter(function(ref) { if (ref.hmid == attributes.showOnly) { return ref; } }); } else { return dataset; } }, /** * hotelmap.modules.feedprocess.process_result_set * Process the incoming data set for the current position * @param data_set - JSON data block * @see services/hotels/hotelfeed for JSON format. */ process_result_set: function(data_set) { var total_length = 0; try { if (data_set && data_set.schedule) attributes.schedule = data_set.extended; } catch (noScheduleAttached) {} try { if (data_set && data_set.listings) { data_set = data_set.listings; total_length = data_set.length; } } catch (noListingAttachedException) {} data_set = hotelmap.modules.feedprocess.processSingleHotelRequest( data_set ); /* Ensure the connecting icon is removed when there are no results */ if (total_length == 0) try { $(".connecting").hide(); } catch (conShow) {} /* Fix the no hotels issues */ hotelmap.modules.feedprocess.HotelListings = { 'total': total_length, 'searched': 0, 'groupings': 0, 'groupSearchPoints': 0 }; hotelmap.active_hotel_icons = []; var zeroCount = false; if (!data_set) zeroCount = true; data_set = (data_set) ? data_set : []; if (!hotelmap.modules.feedprocess.pop_done) { if ($("html").hasClass("mostpopular")) { this.popularity_scanner(data_set); hotelmap.modules.feedprocess.pop_done = true; } } //hotelmap.modules.feedprocess.total_hotel_count = data_set.length ; //console.log("Loading; " + hotelmap.modules.feedprocess.total_hotel_count + " hotels" ) ; hotelmap.modules.feedprocess.zoom_level = hotelmap.maps.getZoom(); hotelmap.hotelicon.process_feed_points(); if (hotelmap.modules.feedprocess.zoom_level != hotelmap.modules.feedprocess.old_zoom) { //hotelmap.rightpanel.listings.hotelcontainer.innerHTML = ""; $(hotelmap.rightpanel.listings.hotelcontainer).find(".rightPanelCoreContainer").remove(); hotelmap.hotelicon.feedpoints = {}; hotelmap.modules.feedprocess.remove_all_pins(); hotelmap.hotelicon.right_panel_elements = {}; } hotelmap.cluster_items = {}; hotelmap.modules.feedprocess.pixel_collider = []; hotelmap.modules.feedprocess.base_to_search = []; hotelmap.modules.feedprocess.old_zoom = hotelmap.maps.getZoom(); hotelmap.modules.feedprocess.hotel_length = data_set.length; hotelmap.modules.feedprocess.get_element_groupings(data_set); hotelmap.counter_groups = 0; hotelmap.counter_standard = 0; // IF zoom is more than 14 OR // IF zoom is more than 8 and the number of hotels is less than the defined limit if ((hotelmap.modules.feedprocess.zoom_level > 15 || (hotelmap.modules.feedprocess.zoom_level > 9 && hotelmap.modules.feedprocess.hotel_length < attributes.hotels.maximum_hotel_limit_in_view)) && hotelmap.modules.feedprocess.hotel_length < attributes.collision.maximum_search_limit) // Now we show rates, if applicable. { // Cycle the points along the route and search them all. for (var i in hotelmap.modules.feedprocess.pixel_sets) { for (var j = 0; j < hotelmap.modules.feedprocess.pixel_sets[i].length; j++) { if (!hotelmap.maps.disable_hotels) { var element = hotelmap.modules.feedprocess.hotels[hotelmap.modules.feedprocess.pixel_sets[i][j]]; if (!hotelmap.hotelicon.feedpoints[element.hmid]) //if (!$("#map").find("#"+element.hmid).length) { hotelmap.modules.feedprocess.create_new_searching_point(element); } else { hotelmap.modules.feedprocess.run_filter_check(element); } } } } } else { // Clusters become available at this point.. var recommended = (attributes.isRecommendedHotelAutoSet == 1 && (attributes.isRecommendedHotelSender == 1 || attributes.dvid != 'DESKTOP')) ? 1 : 0; // Cycle the points along the route for (var i in hotelmap.modules.feedprocess.pixel_sets) { // Create a group point (cluster icon) if (hotelmap.modules.feedprocess.pixel_sets[i].length > 3 && !recommended && attributes.disableClustering == false) { if (!hotelmap.maps.disable_zones) { hotelmap.modules.feedprocess.new_group_point(i, hotelmap.modules.feedprocess.pixel_sets[i].length, hotelmap.modules.feedprocess.pixel_sets[i]); } } else { // Search items, as they are alone in a wilderness. if (!hotelmap.maps.disable_points && hotelmap.modules.feedprocess.zoom_level > 9) { for (var j = 0; j < hotelmap.modules.feedprocess.pixel_sets[i].length; j++) { var element = hotelmap.modules.feedprocess.hotels[hotelmap.modules.feedprocess.pixel_sets[i][j]]; if (!hotelmap.hotelicon.feedpoints[element.hmid]) //if (!$("#map").find("#"+element.hmid).length) { hotelmap.modules.feedprocess.create_new_searching_point(element); } else { hotelmap.modules.feedprocess.run_filter_check(element); } } } } } } hotelmap.modules.feedprocess.query(); try { hotelmap.eventicon.init(); } catch (e1) {} // // This hook allows for multi-venue pointers if (attributes.pointers != null) { for (var i = 0; i < attributes.pointers.length; i++) { pointers.addPointer(attributes.pointers[i]) } } // // This hook allows for saved pointers if (attributes.searchLocations && !attributes.pointers) { for (var i in attributes.searchLocations) { if (attributes.searchLocations[i]) pointers.addLocationPointer(attributes.searchLocations[i]); } } try { clearTimeout(hotelmap.pir); hotelmap.pir = setTimeout(function() { hotelmap.leftpanel.process_icon_requests(); }, 500); } catch (e2) {} hotelmap.sorting.rightpanel.sort(hotelmap.rightpanel.listings.hotelcontainer); hotelmap.hotelicon.remove_from_incoming_data_set(data_set); if (zeroCount) hotelmap.rightpanel.tabReference["onmap"].counterText.innerHTML = "(0)"; hotelmap.modules.feedprocess.HotelListings.searched = hotelmap.modules.feedprocess.HotelListings.total - hotelmap.modules.feedprocess.HotelListings.groupings; hotelmap.modules.feedprocess.HotelListings.percentNotShown = Math.round((hotelmap.modules.feedprocess.HotelListings.groupings / hotelmap.modules.feedprocess.HotelListings.total) * 100) /*BREAK*/ //clearTimeout(hotelmap.dcc); //hotelmap.dcc = setTimeout(function(){ // hotelmap.modules.feedprocess.do_collision_check(); //},200); setTimeout(function() { hotelmap.hotel_highlight.pushToHotels(); }, 1000); // Remove the right side items which you've filtered away. if (attributes.enable_listing_modifications) { $(".rightPanelCoreContainer[hm-active-view='no']").hide(); } // We're missing an sorting element where there are no hotels to search. // Thus, when a user zoomes in and the hotels are already searched the ordering element // is not initialised. try { setTimeout(function() { hotelmap.sorting.rightpanel.sort(hotelmap.rightpanel.listings.hotelcontainer); }, 10); } catch (sortingCallException) { /* we dont care about this. */ } }, create_new_searching_point: function(element, popular) { /* Allows a single show only hotel to appear */ if ((attributes.showOnly > 0 && element.hmid == attributes.showOnly) || attributes.showOnly == 0) { if (element.isRecommendedViewEnabled == 1 && element.isUnRecommendedListing == true) { if (attributes.isRecommendedIconEnabled == true) { var icon_unrec_hotel = document.createElement("div"); $(icon_unrec_hotel).addClass("icon_unrec_hotel"); $(icon_unrec_hotel).attr("hm-set-back-pointer", "true"); var point = hotelmap.modules.feedprocess.new_point(element, icon_unrec_hotel); } } else { var searching_icon = hotelmap.hotelicon.create_hotel_searching_icon(0, Math.round(element.stars), element.numRooms, element, false); var point = hotelmap.modules.feedprocess.new_point(element, searching_icon); point.rate_done = false; point.latitude = element.latitude; point.longitude = element.longitude; hotelmap.modules.feedprocess.base_to_search.push(element.hmid); hotelmap.modules.feedprocess.rate_icons[element.hmid] = point; point.hmid = element.hmid; if (popular == 'mostpopular') { hotelmap.modules.feedprocess.loop_pop = setInterval(function() { if ($("#" + element.hmid).length) { clearInterval(hotelmap.modules.feedprocess.loop_pop); setTimeout(function() { var pin = $("#" + element.hmid).parent().parent().parent().clone(); $(pin).addClass("popular_pin").css({ 'z-index': '999999' }).attr('id', element.hmid); $("body").append(pin); $("body").append(''); $(".mpclose").on('click', function() { $(".popular_pin").fadeOut(function() { $(this).remove(); }); $(".mpclose").fadeOut(function() { $(this).remove(); hotelmap.library.utility.overlay(80, '#000', false, 154); }); }); var lbl = '
'; lbl += 'Most popular hotel'; lbl += '
'; $(pin).append(lbl + '
' + element.hotelName + '
'); setTimeout(function() { var iconpin = $(pin).find("#icon-pin"); $(iconpin).css({ 'left': '-' + (iconpin.width() / 2) + 'px' }); }, 50); setTimeout(function() { $(".popular_pin").fadeOut(function() { $(this).remove(); }); $(".mpclose").fadeOut(function() { $(this).remove(); hotelmap.library.utility.overlay(80, '#000', false, 154); }); }, 10000); }, 50); } }, 250); } } } }, run_filter_check: function(element) { try { if (!hotelmap.modules.feedprocess.showHotel(element) || element.fullybooked) { if (attributes.isLowIE) { //hotelmap.modules.feedprocess.rate_icons[element.hmid].style.display = "none"; [rem change jim] hotelmap.library.utility.setTrans(hotelmap.modules.feedprocess.rate_icons[element.hmid], 40); hotelmap.modules.feedprocess.rate_icons[element.hmid].HMHide = true; } else { hotelmap.library.utility.setTrans(hotelmap.modules.feedprocess.rate_icons[element.hmid], 40); hotelmap.modules.feedprocess.rate_icons[element.hmid].className = 'icon_grey_scale'; hotelmap.modules.feedprocess.rate_icons[element.hmid].HMHide = true; } } else { if (!element.fullybooked) { if (attributes.isLowIE) { //hotelmap.modules.feedprocess.rate_icons[element.hmid].style.display = ""; hotelmap.library.utility.setTrans(hotelmap.modules.feedprocess.rate_icons[element.hmid], 100); hotelmap.modules.feedprocess.rate_icons[element.hmid].HMHide = false; } else { hotelmap.library.utility.setTrans(hotelmap.modules.feedprocess.rate_icons[element.hmid], 100); hotelmap.modules.feedprocess.rate_icons[element.hmid].className = ''; hotelmap.modules.feedprocess.rate_icons[element.hmid].HMHide = false; //console.log("GREY"); } } } /** Show ICON moved from hotelfeed low level remover **/ if (!hotelmap.modules.feedprocess.isBrandFiltered(element.brandID)) { hotelmap.library.utility.setTrans(hotelmap.modules.feedprocess.rate_icons[element.hmid], 40); hotelmap.modules.feedprocess.rate_icons[element.hmid].className = 'icon_grey_scale'; hotelmap.modules.feedprocess.rate_icons[element.hmid].HMHide = true; } // Cross Node Activity Check. hotelmap.modules.feedprocess.runCrossNodeActiveCheck( element.hmid, hotelmap.modules.feedprocess.rate_icons[element.hmid].HMHide ); } catch (eeee) {} }, /** * Process a node and determine if it's active or not. * * @param hmid - HotelMap Hotel ID * @param isHidden - Is the item to be hidden? */ runCrossNodeActiveCheck: function(hmid, isHidden) { try { // Lets obtain the right-side container reference. var rsContainer = $(".rightPanelCoreContainer[hm-ref='" + hmid + "']"); // Determine if we're showing or not. // This was previously set to remove full booked, but this // is perhaps not what was required. For the moment, active-view // is now set to yes by default. $(rsContainer).attr("hm-active-view", "yes"); // Comment above live and add this back in to revert. // if (isHidden == true) { // $(rsContainer).attr("hm-active-view", "yes"); // } else { // $(rsContainer).attr("hm-active-view", "yes"); // } } catch (crossElementDetailsException) { // Empty. } }, /** * addPinSmall * Adds a small ID pin for development * @param x INT map x * @param y INT map y * @param col HEX col string */ addPinSmall: function(x, y, col) { // NULL }, /** * new_group_point * Create a new group area pointer set. * @param points [format=string=XXXX%XXXXX] * @param counter string */ new_group_point: function(points, counter, data) { var clus = { five: 0, four: 0, three: 0, two: 0, one: 0, brands: {}, ini: 0, rst: 0, swm: 0, ftn: 0, prk: 0, s5: { ini: 0, rst: 0, swm: 0, ftn: 0, prk: 0 }, s4: { ini: 0, rst: 0, swm: 0, ftn: 0, prk: 0 }, s3: { ini: 0, rst: 0, swm: 0, ftn: 0, prk: 0 }, s2: { ini: 0, rst: 0, swm: 0, ftn: 0, prk: 0 }, s1: { ini: 0, rst: 0, swm: 0, ftn: 0, prk: 0 } }; var starClusterReferences = { "5": { "ref": "s5", "clus": "five" }, "4": { "ref": "s4", "clus": "four" }, "3": { "ref": "s3", "clus": "three" }, "2": { "ref": "s2", "clus": "two" }, "1": { "ref": "s1", "clus": "one" } }; var counterElements = ["INI", "RST", "SWM", "FTN", "PRK"]; //console.dir(data); var attached_bases = []; for (var j = 0; j < data.length; j++) { var element = hotelmap.modules.feedprocess.hotels[data[j]]; var searched = false; /* Decide if we have a hidden hotel item */ if (hotelmap.distance_checker[element.hmid] < 1.3 || element.likeScore > 0) { hotelmap.modules.feedprocess.base_to_search.push(element.hmid); var point = hotelmap.hotelicon.create_hotel_searching_icon(0, Math.round(element.stars), element.numRooms, element, true); var point = hotelmap.modules.feedprocess.new_point(element, point); point.rate_done = false; point.latitude = element.latitude; point.longitude = element.longitude; hotelmap.modules.feedprocess.base_to_search.push(element.hmid); hotelmap.modules.feedprocess.rate_icons[element.hmid] = point; point.hmid = element.hmid; attached_bases.push(element.hmid); searched = true; hotelmap.modules.feedprocess.HotelListings.groupSearchPoints++; } else { hotelmap.modules.feedprocess.HotelListings.groupings++; } try { if (element.stars > 0 && element.stars < 6) { var starClusterReference = starClusterReferences[element.stars]; clus[starClusterReference.clus]++; for (var scCount = 0; scCount < counterElements.length; scCount++) { if (element[counterElements[scCount]] == "1") { clus[starClusterReference.ref][counterElements[scCount].toLowerCase()]++; } } } } catch (clusterGeneratioNException) { // Error Processing. } if (element.brandID) { if (!clus.brands[element.brandID]) { clus.brands[element.brandID] = { five: 0, four: 0, three: 0, two: 0, one: 0 }; } switch (element.stars) { case 5: clus.brands[element.brandID].five++; break; case 4: clus.brands[element.brandID].four++; break; case 3: clus.brands[element.brandID].three++; break; case 2: clus.brands[element.brandID].two++; break; case 1: clus.brands[element.brandID].one++; break; } } /** * Creating blockers - remove any corresponding hotel ICONS */ for (var i in hotelmap.properties.shapes.objects) { var child = hotelmap.properties.shapes.objects[i]; if (child.identity == element.hmid) { try { hotelmap.properties.shapes.removeObject(child); } catch (e1) { } if (!searched) { try { hotelmap.hotelicon.right_panel_elements[child.identity].parentNode.removeChild(hotelmap.hotelicon.right_panel_elements[child.identity]); hotelmap.hotelicon.right_panel_elements[child.identity] = 0; } catch (e2) { } } } } } /* New Mean Routine for calculating the base for cluster ICONS */ var minCord = hotelmap.modules.feedprocess.min[points]; var maxCord = hotelmap.modules.feedprocess.max[points]; var counter = total_x = total_y = 0; //console.log("------------------------------"); //console.log("points: " + points + "length: " + hotelmap.modules.feedprocess.coordinate_saves[points].length + "minCord: " + minCord + " maxcord:"+ maxCord ); for (var i = 0; i < hotelmap.modules.feedprocess.coordinate_saves[points].length; i++) { var point_node = hotelmap.modules.feedprocess.coordinate_saves[points][i]; //console.log("PointNode: " + point_node.x + ", " + point_node.y); //console.log("CordMeasure: " + minCord.x + ", " + maxCord.x); //console.log("CordMeasure: " + minCord.y + ", "+ maxCord.y); if (point_node.x >= minCord.x && point_node.x <= maxCord.x) { if (point_node.y >= minCord.y && point_node.y <= maxCord.y) { counter++; total_x += point_node.x; total_y += point_node.y; } } } //console.log("Post"); x = total_x / counter; y = total_y / counter; var point = hotelmap.hotelicon.blocker_icon(0, 0, 0, clus); point.base_references = {}; for (var g = 0; g < attached_bases.length; g++) { //console.log(">"); hotelmap.cluster_items[attached_bases[g]] = point; point.base_references[attached_bases[g]] = true; } var useTheselats = false; var worldPosition = hotelmap.maps.mapPixelsToPosition(x, y); if (useTheselats) { worldPosition.lat = attributes.latitude; worldPosition.lon = attributes.longitude; } //console.log(x+","+y+" - "+worldPosition.lat+", "+worldPosition.lon); var ico = hotelmap.maps.addIcon(point, worldPosition.lat, worldPosition.lon, "BLOCKER", points); return ico; }, pixel_collider: [], do_collision_check: function() { if (hotelmap.do_check) return false; hotelmap.do_check = true; //console.log("do_collision_check"); // Obejct copy point. var object_copy = []; for (var i in hotelmap.properties.shapes.objects) object_copy.push(hotelmap.properties.shapes.objects[i]); for (var i = 0; i < object_copy.length; i++) { try { var theNode = object_copy[i].pinImage.parentNode; var nx1 = parseInt(theNode.style.left); var ny1 = parseInt(theNode.style.top); var nx2 = nx1 + 50; var ny2 = ny1 + 27; for (var j in hotelmap.properties.shapes.objects) { try { var negative = false; var testItem = hotelmap.properties.shapes.objects[j].pinImage.parentNode; var tx1 = parseInt(testItem.style.left); var ty1 = parseInt(testItem.style.top); var tx2 = tx1 + 50; var ty2 = ty1 + 27; // The Icon top/left is in the way! if (nx1 > tx1 && nx1 < tx2 && ny1 > ty1 && ny1 < ty2) { //console.log("Batch"); theNode.style.left = (tx2 + 5) + "px"; theNode.style.top = (ty2 + 5) + "px"; // negative = true; } if (nx2 < tx2 && nx2 > tx1 && ny1 > ty1 && ny1 < ty2) { theNode.style.left = (ny1 - 30) + "px"; theNode.style.top = (ny2 + 3) + "px"; } //if ( nx1 == tx1 ) { // theNode.style.left = ( nx1 +5 ) + "px"; // negative = true; //} //if ( ny1 == ty1 ) { // theNode.style.top = ( ny1 +5 ) + "px"; // negative = true; //} //if ( negative ) i--; } catch (noInternalPinException) { console.log("noInternalPinException: " + noInternalPinException.message + " / " + negative); } } } catch (noPinException) { console.log("noPinExceptionL " + noPinException.message); } } hotelmap.do_check = false; }, do_collision_check1: function() { // return false; //console.log("Hello"); var objects = []; var ref = []; for (var i in hotelmap.properties.shapes.objects) objects.push(hotelmap.properties.shapes.objects[i]); for (var i = 0; i < objects.length; i++) { try { var primaryTest = objects[i].pinImage.parentNode; // console.dir(hotelmap.properties.shapes.objects[i]); //console.log("Icon ID: " + i ) ; ref[i]++; if (primaryTest) { var primaryItemX = parseInt(primaryTest.style.left); // Left point var primaryItemY = parseInt(primaryTest.style.top); // Top Point var primaryItemXR = primaryItemX + 30; // Right side point; var primaryItemYR = primaryItemY + 60; // Bottom Point. //console.log("=========================================================="); for (var j in hotelmap.properties.shapes.objects) { try { if (testItem != primaryTest) { try { var testItem = hotelmap.properties.shapes.objects[j].pinImage.parentNode; var testItemX = parseInt(testItem.style.left); var testItemY = parseInt(testItem.style.top); var testItemXR = testItemX + 50; var testItemYR = testItemY + 69; var differenceX = Math.abs(testItemX - primaryItemX); var differenceY = Math.abs(testItemY - primaryItemY); var differenceXR = Math.abs(testItemXR - primaryItemXR); var differenceYR = Math.abs(testItemYR - primaryItemYR); //console.log(">> " + differenceX + " , " + differenceY ) ; var positiveOutCome = ((differenceX < 5 || differenceY < 5) && (differenceX > 0 && differenceY > 0)) ? true : false; var negativeOutCome = ((differenceXR < 5 || differenceYR < 5) && (differenceYR > 0 && differenceYR > 0)) ? true : false; if (positiveOutCome && negativeOutCome) { var n = Math.ceil(Math.random() * 10); var isODD = (n === 0 || !!(n && !(n % 2))); if (isODD) positiveOutCome = false; } if (positiveOutCome || negativeOutCome) { // console.dir(primaryTest); // console.dir(hotelmap.properties.shapes.objects[i].getCenter()); //console.log("Movement of icon pushed.."); if (positiveOutCome) { primaryTest.style.left = (primaryItemX + getRandomArbitrary(25, 45)) + "px"; primaryTest.style.top = (primaryItemY + getRandomArbitrary(25, 45)) + "px"; } else { primaryTest.style.left = (primaryItemX - getRandomArbitrary(25, 45)) + "px"; primaryTest.style.top = (primaryItemY - getRandomArbitrary(25, 45)) + "px"; } if (ref[i] < 20) { i--; } else { console.log("Limite reached.."); } //console.dir(primaryTest); // console.dir(hotelmap.properties.shapes.objects[i].getCenter()); //console.log(primaryTest.getPosition()); } //primaryTest..style.border = '3px solid #FF0000 !important'; } catch (CRT) { //console.log("Exception: " + CRT.message); } } else { console.log("OOps"); } } catch (CarryOnThen) { //console.log("Exception: " + CarryOnThen.message); } } } } catch (e) {} // //console.log("child: x: " + child.domX); //console.log("child: y: " + child.domY); } }, do_collision_provider: function(point, latitude, longitude, count, move_vert, move_horiz) { var pixels = hotelmap.maps.mapPositionToPixels(latitude, longitude); var left = pixels.x; var right = pixels.x + 50; var top = pixels.y; var bottom = pixels.y + 35; attributes.collision.show_collisions = true; var count = 0; // // So how many hotels should be in a view before we consider rearranging them? if (hotelmap.modules.feedprocess.datasetlength > 100 || attributes.collision.isMapCollisionEnabled) { //console.log("Collision enabled.."); //console.log("Number of items in pixel collider: " + hotelmap.modules.feedprocess.pixel_collider.length ) ; // // Cycle the feed and process each element. for (var i = 0; i < hotelmap.modules.feedprocess.pixel_collider.length; i++) { var node = hotelmap.modules.feedprocess.pixel_collider[i]; var distance_differenceX = Math.abs(Math.round(left) - Math.round(node.x)); var distance_differenceY = Math.abs(Math.round(top) - Math.round(node.y)); //console.log("Comparing: X diff: " + Math.abs(Math.round(left)-Math.round(node.x))); ///console.log("Comparing: Y diff: " + Math.abs(Math.round(top)-Math.round(node.y))); //console.log("================================================================="); if (distance_differenceX < 40 && distance_differenceY < 40) { // if ( point ) point.style.border = '1px solid #000'; } var n_left = node.x; var n_right = node.x + 50; var n_top = node.y; var n_bottom = node.y + 35; if (right <= n_right && right > n_left && top > n_top && top <= n_bottom) { //if ( point ) point.style.borderTop = '1px solid #FF0000'; pixels.x += 0 - (25 - Math.floor(Math.random() * 5)); pixels.y += (Math.floor(Math.random() * 35)); left = pixels.x; top = pixels.y; bottom = top + 35; right = left + 50; } if (bottom <= n_bottom && bottom >= n_top && left < n_right && left > n_left) { //if ( point ) point.style.borderLeft = '1px solid #00FF00'; pixels.x += 0 - (25 - Math.floor(Math.random() * 5)); pixels.y = n_top + 2; left = pixels.x; top = pixels.y; bottom = top + 35; right = left + 50; } if (left >= n_left && left <= n_right && top >= n_top && top <= n_bottom) { //if ( point ) point.style.borderRight = '1px solid #000'; //console.log("C!"); if (left >= n_left && left <= n_right) { pixels.x += (25 + Math.floor(Math.random() * 5)); pixels.y += (Math.floor(Math.random() * 5)); left = pixels.x; top = pixels.y; bottom = top + 35; right = left + 50; //if (attributes.collision.show_collisions ) node.style.border = '2px solid #000'; //console.log("Collision A"); // node.style.border = "1px solid #FF0000"; } if (top >= n_top && top <= n_bottom) { pixels.x += (Math.floor(Math.random() * 5)); pixels.y += (20 + Math.floor(Math.random() * 5)); left = pixels.x; top = pixels.y; bottom = top + 35; right = left + 50; //if ( attributes.collision.show_collisions ) node.style.border = '2px solid #000'; //console.log("Collision B"); // node.style.border = "1px solid #00FF00"; // if ( point ) point.style.borderBottom = '1px solid #0000FF'; } } if (right < (node.x + 50) && right > (node.x + 20)) { pixels.x = pixels.x - (25 + Math.floor(Math.random() * 5)); pixels.y += (Math.floor(Math.random() * 5)); left = pixels.x; top = pixels.y; bottom = top + 35; right = left + 50; //point.style.border = '1px solid #00FF00'; //if ( attributes.collision.show_collisions ) node.style.border = '2px solid #000'; //console.log("Collision C"); //node.style.border = "1px solid #0000FF"; // if ( point ) point.style.borderTop = '1px solid #FFFF00'; } if (bottom < n_bottom && (bottom) > n_top) { pixels.x += (Math.floor(Math.random() * 15)); pixels.y += (20 + Math.floor(Math.random() * 5)); left = pixels.x; top = pixels.y; bottom = top + 35; right = left + 50; //point.style.border = '1px solid #FF0000'; //if ( attributes.collision.show_collisions ) node.style.border = '2px solid #000'; //console.log("Collision D"); //node.style.border = "1px solid #FFFF00"; // if ( point ) point.style.borderLeft = '1px solid #00FFFF'; } } } var latlon = hotelmap.maps.mapPixelsToPosition(pixels.x, pixels.y); hotelmap.modules.feedprocess.pixel_collider.push(pixels); return { lat: latlon.lat, lon: latlon.lon }; }, do_collision_provider1: function(point, latitude, longitude, count, move_vert, move_horiz) { /* Defined by the pixels */ var pixels = hotelmap.maps.mapPositionToPixels(latitude, longitude); var dl = pixels.x; var dw = dl + 40 + Math.floor(Math.random() * 10);; var dt = pixels.y; var dh = dt + 26; console.log("Using: " + latitude + ", " + longitude + " width pixels: " + pixels.x + ", " + pixels.y); attributes.collision.show_collisions = true; for (var i = 0; i < hotelmap.modules.feedprocess.pixel_collider.length; i++) { var node = hotelmap.modules.feedprocess.pixel_collider[i]; var ll = hotelmap.maps.mapPixelsToPosition(node.x, node.y); var nl = node.x + 5; //+ 10; var nt = node.y; // - 10; var nw = nl + 40; var nh = nt + 26; var isInZone = false; var left = null; var top = null; if (dl >= nl && dl <= nw && dt >= nt && dt <= nh && !isInZone) { left = dl - 40 - Math.floor(Math.random() * 10); top = dt + Math.floor(Math.random() * 8);; isInZone = true; //console.log("TopLeft: " + dl + " TO " + nw); if (isInZone && attributes.collision.show_collisions) point.style.border = '2px solid #000'; } if (dl >= nl && dl <= nw && dh >= nt && dh <= nh && !isInZone) { top = (nt - (dh - dt)) + Math.floor(Math.random() * 8);; left = left + Math.floor(Math.random() * 10); isInZone = true; //console.log("BottomLeft " + dt + " TO " + top); if (isInZone && attributes.collision.show_collisions) point.style.border = '2px solid #0000FF'; } if (dw > nl && dw < nw && dh > nt && dh < nh && !isInZone) { top = top + Math.floor(Math.random() * 10); left = (nw - 10) + Math.floor(Math.random() * 15); isInZone = true; //console.log("BottomRight " + dl + " TO " + left); if (isInZone && attributes.collision.show_collisions) point.style.border = '2px solid #FF0000'; } if (dw > nl && dw < nw && dt > nt && dt < nh && !isInZone) { left = left - 30 - Math.floor(Math.random() * 10); top = dt + 26; isInZone = true; if (isInZone && attributes.collision.show_collisions) point.style.border = '2px solid #00FF00'; } if (Math.abs(dl - left) > 70) { left = dl + Math.floor(Math.random() * 40); top = top + Math.floor(Math.random() * 10); } if (Math.abs(dt - top) > 70) { top = dt + Math.floor(Math.random() * 40);; left = left + Math.floor(Math.random() * 10); } if (isInZone) { if (left > 0) pixels.x = left; if (top > 0) pixels.y = top; if (count < attributes.collision.recursive_limit) { count++; var latlon = hotelmap.maps.mapPixelsToPosition(pixels.x, pixels.y); latlon = hotelmap.modules.feedprocess.do_collision_provider(point, latlon.lat, latlon.lon, count, move_vert, move_horiz); latitude = latlon.lat; longitude = latlon.lon; } } } hotelmap.modules.feedprocess.pixel_collider.push(pixels); return { lat: latitude, lon: longitude }; }, /** * new_point * New basic point on the screen for a non-searching hotel - too far away! * @param element Hotel Info Node * @param point DOM Element to attach */ new_point: function(element, point) { if (attributes.collision.enabled && hotelmap.modules.feedprocess.hotel_length < attributes.collision.hotel_limit && !element.isMoved) { //console.log("Activiating"); var coords = hotelmap.modules.feedprocess.do_collision_provider(point, element.latitude, element.longitude, 0, null, null); return hotelmap.maps.addIcon(point, coords.lat, coords.lon, element.hmid); } return hotelmap.maps.addIcon(point, element.latitude, element.longitude, element.hmid); }, coordinate_references: {}, do_distance_check: function(hotelid) { }, /** * get_element_groupings * @param data_set [JSON object set] * Obtain the grouping setup for the hotels in question */ get_element_groupings: function(data_set) { // Reset groupings hotelmap.modules.feedprocess.pixel_sets = {}; // Reset the group settings. hotelmap.modules.feedprocess.min = {}; hotelmap.modules.feedprocess.max = {}; hotelmap.modules.feedprocess.coordinate_saves = []; hotelmap.modules.feedprocess.coordinate_references = []; // The distanbce of the groupings. var zoom_levels = { '9': '260', '10': '260', '11': '260', '12': '260', '13': '260', '14': '200', '15': '200', '16': '200', '17': '300', '18': '300', '19': '300', '20': '300', '21': '300' }; hotelmap.modules.feedprocess.datasetlength = data_set.length; // Whats our current zoom; var current_zoom = hotelmap.maps.getZoom(); // Defines the grouping space to actuall use. var col_set = zoom_levels[current_zoom]; // Realtime filtering - allows the cluster counting to work correctly. hotelmap.filter_counter = { one: 0, two: 0, three: 0, four: 0, five: 0 }; hotelmap.distance_checker = []; hotelmap.filter_brands = {}; attributes.filtering.totalRatings = 0; attributes.filtering.internetCount = 0; attributes.filtering.swimmingCount = 0; attributes.filtering.restaurantCount = 0; attributes.filtering.fitnessCount = 0; attributes.filtering.freeparkingCount = 0; var zoom = hotelmap.maps.getZoom(); var wSize = (deCarta.Utilities.tileSizeForZoom(zoom) * Math.pow(2, Math.floor(zoom - 1))); for (var i = 0; i < data_set.length; i++) // Cycle the references coming in. { var element = data_set[i]; // Get the single reference. element.latitude = parseFloat(element.latitude); element.longitude = parseFloat(element.longitude); // Define specific settings for each item sent through element.originalLatitude = element.latitude; element.originalLongitude = element.longitude; element.zoomLevel = current_zoom; // Create the branding quantity counter if (element.brandID) hotelmap.filter_brands[element.brandID] = (!hotelmap.filter_brands[element.brandID]) ? 1 : hotelmap.filter_brands[element.brandID] + 1; /** * DISTANCE CHECKING * This will enable us to search cluster points close to the venues whilst * not searching all clusters on the map. More than likely limited to the * nearest 40 or so hotels. */ var dis_data = { 'hmid': element.hmid, 'distance': element.distance }; hotelmap.distance_checker.push(dis_data); // Count the star counters if (element.stars == 5) hotelmap.filter_counter.five++; if (element.stars == 4) hotelmap.filter_counter.four++; if (element.stars == 3) hotelmap.filter_counter.three++; if (element.stars == 2) hotelmap.filter_counter.two++; if (element.stars == 1) hotelmap.filter_counter.one++; if (element.stars == "") hotelmap.filter_counter.one++; if (element.INI == 1) attributes.filtering.internetCount++; if (element.SWM == 1) attributes.filtering.swimmingCount++; if (element.RST == 1) attributes.filtering.restaurantCount++; if (element.FTN == 1) attributes.filtering.fitnessCount++; if (element.PRK == 1) attributes.filtering.freeparkingCount++; // Star & Liked Data var hotel_data = { stars: element.stars, liked: element.likeScore }; // Ensure total ratings are correctly updated if (element.tripRating >= 4) attributes.filtering.totalRatings++; // Deflect away specific hotels from each other when they are the same actual place. if (!hotelmap.modules.feedprocess.hotels[element.hmid]) { hotelmap.modules.feedprocess.hotels[element.hmid] = element; // Store the element /* Colision */ if (!hotelmap.modules.feedprocess.coordinate_references[element.latitude]) { hotelmap.modules.feedprocess.coordinate_references[element.latitude] = 1; } else { var arc = hotelmap.library.utility.deflect(element.latitude, element.longitude, 30, "lat"); element.latitude = arc[0]; hotelmap.modules.feedprocess.coordinate_references[element.latitude] = 1; } if (!hotelmap.modules.feedprocess.coordinate_references[element.longitude]) { hotelmap.modules.feedprocess.coordinate_references[element.longitude] = 1; } else { var arc = hotelmap.library.utility.deflect(element.latitude, element.longitude, 30, "lon"); element.longitude = arc[1]; hotelmap.modules.feedprocess.coordinate_references[element.longitude] = 1; } /* Colision */ } /** * This determines the average positioning of an element. It allows us * to group together the elements into zones. If we have a zone we can * use it to group. */ //var tmp = pixels ; //var tmp = hotelmap.maps.mapPositionToPixels( element.latitude, element.longitude ) ; // Ensure that the venue in not the hotel . if (attributes.hotel_identity != element.hmid && hotelmap.hotelSearchID != element.hmid) { // Create a generic point place for the X&Y. // e.g. if pixel = 13 and colset = 4 then = 12 // e.g. if pixel = 14 and colset = 4 then = 12 //pixels.x = Math.round( pixels.x /col_set ) * col_set ; //pixels.y = Math.round( pixels.y /col_set ) * col_set ; //key: -3448800%2080400 // Obtain our processed point locations. var element_latitude = parseFloat(element.latitude); var element_longitude = parseFloat(element.longitude); // Process the X&Y coordinates var x = element_longitude * wSize / 180; var y = Math.log(Math.tan((90 + element_latitude) * Math.PI / 360)) / (Math.PI / 180); y = y * wSize / 180; var tmp = { 'x': x, 'y': y }; // Locate them locally. x = Math.ceil(Math.round(x / 150)) * 150; y = Math.ceil(Math.round(y / 150)) * 150; var pixels = { 'x': x, 'y': y }; var key = pixels.x + "%" + pixels.y; } else { var pixels = hotelmap.maps.mapPositionToPixels(element.latitude, element.longitude); var tmp = pixels; var key = pixels.x + "%" + pixels.y; } // Create the groupings with reference to the hotel id if (!hotelmap.modules.feedprocess.pixel_sets[key]) hotelmap.modules.feedprocess.pixel_sets[key] = []; hotelmap.modules.feedprocess.pixel_sets[key].push(element.hmid); // If it doesnt exist yet, create it. if (!hotelmap.modules.feedprocess.min[key]) { hotelmap.modules.feedprocess.min[key] = { 'x': tmp.x, 'y': tmp.y }; hotelmap.modules.feedprocess.max[key] = { 'x': tmp.x, 'y': tmp.y }; // Create the new array for storing all the coordinates. hotelmap.modules.feedprocess.coordinate_saves[key] = []; } else { // Determine the minimum and maximum coordinates currently available. if (hotelmap.modules.feedprocess.min[key].x > tmp.x) hotelmap.modules.feedprocess.min[key].x = tmp.x; if (hotelmap.modules.feedprocess.min[key].y > tmp.y) hotelmap.modules.feedprocess.min[key].y = tmp.y; if (hotelmap.modules.feedprocess.max[key].x < tmp.x) hotelmap.modules.feedprocess.max[key].x = tmp.x; if (hotelmap.modules.feedprocess.max[key].y < tmp.y) hotelmap.modules.feedprocess.max[key].y = tmp.y; } // Create a collective set of the coordinates - this will allow us to weight the position more to the overall position of the hotels. hotelmap.modules.feedprocess.coordinate_saves[key].push(tmp); } // Out of the FOR loop hotelmap.distance_checker = hotelmap.sorting.sort_distance_check(hotelmap.distance_checker); } }/** * ------------------------------------------------------------------------- * HotelMap WorldWide 1.0 * Copyright (C) 2012 - All Rights Reserved - HotelMap.com * ------------------------------------------------------------------------- * Base ID: Reporting * Description: Manages the reporting back to the server. * ------------------------------------------------------------------------- * Version : $Id$ * Author : James Holden * Contact : james@hotelmap.com * ------------------------------------------------------------------------- * Notes : * ------------------------------------------------------------------------- */ hotelmap.reporting = { interval: null, tiles: 0, zooms: 0, inactive: 0, count: 0, /** * firstReport * Called by the initial loader */ firstReport: function() { // Run a first report as the user lands into the system hotelmap.reporting.doReport(true); // Setup the 30 second interval for continual reporting (up to 3 minutes) // hotelmap.reporting.pingReport(); }, /** * doReport * runs the report system back the server * @param runInitial (describes if it's the first call) */ doReport: function(runInitial) { // Ensure we have a last activity date if (attributes.lastActiveDate) { // How long has the user been idles var numberOfSeconds = hotelmap.library.utility.calculateSecondsBetweenDates(attributes.lastActiveDate); // Don't log after three minutes - waste of bandwidth if (numberOfSeconds < (60 * 3) && hotelmap.reporting.count < 1) { hotelmap.reporting++; var location = hotelmap.maps.getCenter(); var zoomlevel = hotelmap.maps.getZoom(); // Send the report out hotelmap.library.json.get("services/reporting/visitor_update?currency=" + attributes.currency_pref + "&runInitial=" + runInitial + "&zoom=" + zoomlevel + "&lat=" + location.lat + "&lon=" + location.lon + "&i=" + attributes.map_identity + "&e=" + attributes.engine[0] + "&ulat=" + attributes.usersession.lat + "&ulon=" + attributes.usersession.lon + "&uloc=" + attributes.usersession.loc + "&data=" + hotelmap.userstatistics.toString() + "&tidID=" + attributes.ref_codal_tid + "&"); userdata("isActiveUser", "YES"); } } }, /** * pingReport * Creates the 30 second interval for reporting */ pingReport: function() { hotelmap.reporting.interval = setInterval( function() { hotelmap.reporting.doReport(false); }, 120000 ); } };