﻿Type.registerNamespace("Audley.Maps");

Audley.Maps.AccordianControl = function(element) {
	this._accordian = null;
	this._popplacesid = 0;
	this._countryid = null; 
	this._places = null; 
	this._popplacescount = 0; 
	this._selectedcat = -1; 
	this._ajaxaccordian = null;
	
	Audley.Maps.AccordianControl.initializeBase(this, [element]) }; 
	Audley.Maps.AccordianControl.prototype = { initialize: function() { 
		this._setupAjaxAccordian()
		},
		
		_setupAjaxAccordian: function() {
			
			Sys.Application.initialize(); 
			
			var el = this.get_element(); 
			
			Sys.Application.add_init(new Function.createDelegate(this, function() { 
				
				this._ajaxaccordian = $create(AjaxControlToolkit.AccordionBehavior, { 
											  "FramesPerSecond": 40, 
											  "HeaderCssClass": "accordianbar", 
											  "HeaderSelectedCssClass": 
											  "accordianbar_selected", 
											  "id": "toolbaraccordian_AccordionExtender", 
											  "requireOpenedPane": false, 
											  "suppressHeaderPostbacks": true
											  },
											  null, 
											  null, 
											  el);
				
				this._ajaxaccordian.set_SelectedIndex(0); 
				this._ajaxaccordian.add_selectedIndexChanging(new Function.createDelegate(this, this._ajaxAccordianSelectedIndexChanging)) })) }, setCategories: function(cats, catcounts) { var gfl = $get("goodforlist"); gfl.innerHTML = ""; var sl = $get("showlist"); sl.innerHTML = ""; var result = ""; var li = document.createElement("li"); var txt = document.createTextNode("All places"); var radio; try { radio = document.createElement('<input type="radio" name="goodfor" id="c_-1">') } catch (e) { radio = document.createElement("input"); radio.name = "cats"; radio.type = "radio"; radio.id = "c_-1" } radio.checked = true; $addHandler(radio, "click", new Function.createDelegate(this, this._catClicked)); li.appendChild(radio); li.appendChild(txt); sl.appendChild(li); for (var i = 0; i < cats.length; i++) { var count = this._findCategoryCountById(cats[i][1], catcounts); if (cats[i][1] == this._popplacesid || count > 0) { var li = document.createElement("li"); var txt = ""; if (cats[i][1] == this._popplacesid) { txt = document.createTextNode(cats[i][0]) } else { txt = document.createTextNode(cats[i][0] + " (" + count + ")") } var radio; try { radio = document.createElement('<input type="radio" name="goodfor" id="c_' + cats[i][1] + '">') } catch (e) { radio = document.createElement("input"); radio.name = "cats"; radio.type = "radio"; radio.id = "c_" + cats[i][1] } if (this._selectedcat == cats[i][1]) radio.checked = true; $addHandler(radio, "click", new Function.createDelegate(this, this._catClicked)); li.appendChild(radio); li.appendChild(txt); if (cats[i][1] == this._popplacesid) { sl.appendChild(li) } else { gfl.appendChild(li) } } } }, _replaceBraces: function(text) { return text.replace(/\{|\}/gi, "") }, _findCategoryCountById: function(id, catcounts) { if (id != "0") { for (var i = 0; i < catcounts.length; i++) { if (this._replaceBraces(catcounts[i].CategoryId) == id) return catcounts[i].Total } } else { return this._popplacescount } }, setRegions: function(regs) { if (regs.length > 0) { var regl = $get("regionlist"); regl.innerHTML = ""; /*var link = document.createElement("a"); link.innerHTML = "Region Name"; link.id = "r_0"; $addHandler(link, "click", new Function.createDelegate(this, this._regionClicked));*/var li = document.createElement("li"); /*li.appendChild(link);*/regl.appendChild(li); for (var i = 0; i < regs.length; i++) { var link = document.createElement("a"); link.innerHTML = regs[i].Name; link.id = "r_" + regs[i].Id; link.value = regs[i].Latitude + "," + regs[i].Longitude; $addHandler(link, "click", new Function.createDelegate(this, this._regionClicked)); var li = document.createElement("li"); li.appendChild(link); regl.appendChild(li) } } else { var regpane = this._ajaxaccordian.get_Pane(2); regpane.content.style.display = "none"; regpane.header.style.display = "none" } }, setPlaces: function(ps) { var pl = $get("placeslist"); pl.innerHTML = ""; this._places = ps; var currentalpha = " "; ps.sort(compareNames); for (var i = 0; i < ps.length; i++) { if (!ps[i].Name.startsWith(currentalpha)) { if (i > 0) { pl.lastChild.lastChild.parentNode.removeChild(pl.lastChild.lastChild) } var ali = document.createElement("li"); currentalpha = ps[i].Name.substring(0, 1); ali.innerHTML = currentalpha; ali.className = "alpha"; pl.appendChild(ali) } var link = document.createElement("a"); link.innerHTML = ps[i].Name; link.id = "pl_" + ps[i].Id; link.value = ps[i].Latitude + "," + ps[i].Longitude; $addHandler(link, "click", new Function.createDelegate(this, this._placeClicked)); var li = document.createElement("li"); li.appendChild(link); var comma = document.createTextNode("\n"); li.appendChild(comma); pl.appendChild(li) } if (pl.lastChild.lastChild.nodeValue != null && pl.lastChild.lastChild.nodeValue == ", ") { pl.lastChild.lastChild.parentNode.removeChild(pl.lastChild.lastChild) } }, _catClicked: function(e) { this._selectedcat = e.target.id.replace("c_", ""); this._raiseEvent('selectedCategoryChanged', new Audley.Maps.SelectionChangedEventArgs(this._selectedcat)) }, _placeClicked: function(e) { var coords = e.target.value.split(","); this._raiseEvent('placeClicked', new Audley.Maps.MapPointChangedEventArgs(e.target.id.replace("pl_", ""), coords[0], coords[1])) }, _regionClicked: function(e) { var coords = e.target.value.split(","); this._raiseEvent('regionClicked', new Audley.Maps.MapPointChangedEventArgs(e.target.id.replace("r_", ""), coords[0], coords[1])) }, _ajaxAccordianSelectedIndexChanging: function(s, e) { switch (e.get_selectedIndex()) { case 2: this._raiseEvent('regionsOpening', Sys.EventArgs.Empty); break; case 3: this._raiseEvent('placesOpening', Sys.EventArgs.Empty); break } }, get_CountryId: function(c) { return this._countryid }, set_CountryId: function(c) { this._countryid = c }, get_PopularPlacesCount: function(c) { return this._popplacescount }, set_PopularPlacesCount: function(c) { this._popplacescount = c }, get_SelectedCategoryId: function() { return this._selectedcat }, set_SelectedCategoryId: function(c) { this._selectedcat = c; $get("c_" + c).checked = true; this._raiseEvent('selectedCategoryChanged', new Audley.Maps.SelectionChangedEventArgs(this._selectedcat)) }, add_selectedCategoryChanged: function(handler) { this.get_events().addHandler('selectedCategoryChanged', handler) }, remove_selectedCategoryChanged: function(handler) { this.get_events().removeHandler('selectedCategoryChanged', handler) }, add_regionClicked: function(handler) { this.get_events().addHandler('regionClicked', handler) }, remove_regionClicked: function(handler) { this.get_events().removeHandler('regionClicked', handler) }, add_placeClicked: function(handler) { this.get_events().addHandler('placeClicked', handler) }, remove_placeClicked: function(handler) { this.get_events().removeHandler('placeClicked', handler) }, add_placeClicked: function(handler) { this.get_events().addHandler('placeClicked', handler) }, remove_placeClicked: function(handler) { this.get_events().removeHandler('placeClicked', handler) }, add_regionsOpening: function(handler) { this.get_events().addHandler('regionsOpening', handler) }, remove_regionsOpening: function(handler) { this.get_events().removeHandler('regionsOpening', handler) }, add_placesOpening: function(handler) { this.get_events().addHandler('placesOpening', handler) }, remove_placesOpening: function(handler) { this.get_events().removeHandler('placesOpening', handler) }, _raiseEvent: function(eventName, eventArgs) { var handler = this.get_events().getHandler(eventName); if (handler) { if (!eventArgs) { eventArgs = Sys.EventArgs.Empty } handler(this, eventArgs) } }, dispose: function() { this._places = null; this._accordian = null } }; Audley.Maps.AccordianControl.registerClass('Audley.Maps.AccordianControl', Sys.UI.Control); if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); function compareNames(a, b) { var nameA = a.Name.toLowerCase(); var nameB = b.Name.toLowerCase(); if (nameA < nameB) { return -1 } if (nameA > nameB) { return 1 } return 0 } Type.registerNamespace("Audley.Maps"); var _self; var _atozplaceclicked; Audley.Maps.LocationMap = function(element) { this._gmap = null; this._accordian = null; this._countryid; this._placeid; this._isminimap; this._bounds = null; this._ds = AudleyTravel.Maps.IMapping; this._baseIcon = null; this._clusterman = null; this._originalwidth = 0; this._originalheight = 0; this._originalleft = 0; this._originaltop = 0; this._poplaces = null; this._allplaces = null; this._regions = null; _self = this; Audley.Maps.LocationMap.initializeBase(this, [element]) }; Audley.Maps.LocationMap.prototype = { initialize: function() { this._createMapControl(); if (this._placeid == null) { this._accordian = $create(Audley.Maps.AccordianControl, { "CountryId": this._countryid }, null, null, $get("toolbaraccordian")) } else { document.getElementById("toolbaraccordian").style.display = "none"; document.getElementById("btnResetMap").style.display = "none"; if (this._isminimap == "1") { document.getElementById("btnMapView").style.display = "none"; document.getElementById("btnSatelliteView").style.display = "none"; document.getElementById("btnTerrainView").style.display = "none"; document.getElementById("msgZoomIn").style.display = "none" } } this._attachControlEvents(); this._loadInitialData() }, _createMapControl: function() { var bb = Earthware.GMaps.Utils.parseBoundingBox(this._bounds); 
			this._gmap = new GMap2(this.get_element()); 
			this._gmap.setCenter(bb.getCenter(), 
			this._gmap.getBoundsZoomLevel(bb)); 
			this._gmap.setMapType(G_PHYSICAL_MAP);
			
			var ui = this._gmap.getDefaultUI(); 
			
			ui.controls.maptypecontrol = false; 
			ui.controls.menumaptypecontrol = false; 
			ui.controls.scalecontrol = false; 
			ui.controls.hierarchicalmaptypecontrol = false; 
			
			this._gmap.setUI(ui); 
			this._gmap.disableScrollWheelZoom(); 
			
			this._baseIcon = new GIcon(G_DEFAULT_ICON); this._baseIcon.shadow = ""; this._baseIcon.iconSize = new GSize(16, 16); this._baseIcon.iconAnchor = new GPoint(8, 8); this._baseIcon.infoWindowAnchor = new GPoint(5, -2); this._setupClustering() }, _setupClustering: function() { var styles = [{ url: '/images/maps/icons/m1.png', height: 52, width: 53, opt_anchor: [0, 0], opt_textColor: '#fff' }, { url: '/images/maps/icons/m1.png', height: 53, width: 52, opt_anchor: [0, 0], opt_textColor: '#fff' }, { url: '/images/maps/icons/m1.png', height: 53, width: 52, opt_anchor: [0, 0] }, { url: '/images/maps/icons/m1.png', height: 53, width: 52, opt_anchor: [0, 0] }, { url: '/images/maps/icons/m1.png', height: 52, width: 53, opt_anchor: [0, 0]}]; var clustopts = { gridSize: 34, styles: styles }; this._clusterman = new MarkerClusterer(this._gmap, [], clustopts) }, _attachControlEvents: function() { if (this._accordian != null) { this._accordian.add_selectedCategoryChanged(new Function.createDelegate(this, this._selectedCategoryChanged)); this._accordian.add_regionClicked(new Function.createDelegate(this, this._regionClicked)); this._accordian.add_placeClicked(new Function.createDelegate(this, this._placeClicked)); this._accordian.add_regionsOpening(new Function.createDelegate(this, this._regionsOpening)); this._accordian.add_placesOpening(new Function.createDelegate(this, this._placesOpening)) } $addHandler($get("btnFullscreen"), "click", new Function.createDelegate(this, this._togleFullscreen)); $addHandler($get("btnExitFullscreen"), "click", new Function.createDelegate(this, this._togleFullscreen)); $addHandler($get("btnMapView"), "click", new Function.createDelegate(this, this._setmapviewtype)); $addHandler($get("btnSatelliteView"), "click", new Function.createDelegate(this, this._setmapviewtype)); $addHandler($get("btnTerrainView"), "click", new Function.createDelegate(this, this._setmapviewtype)); $addHandler($get("btnResetMap"), "click", new Function.createDelegate(this, this._resetmap)) }, _attachMapevents: function() { }, _loadInitialData: function() { if (this._countryid != null) { if (this._placeid == null) { this._ds.GetCountryCategoryCounts(this._countryid, new Function.createDelegate(this, this._getCountryCategoryCountsCompleted), Earthware.Ajax.PageUtils.onFailed) } this._ds.GetCountryMapPoints(this._countryid, new Function.createDelegate(this, this._getCountryMapPointsCompletedAndAddToMap), Earthware.Ajax.PageUtils.onFailed); if (this._placeid == null) { this._ds.GetCountryRegions(this._countryid, new Function.createDelegate(this, this._getCountryRegionsCompleted), Earthware.Ajax.PageUtils.onFailed) } } if (this._isminimap == "1") { setTimeout(new Function.createDelegate(this, this._doAnimationZoom), 5000) } }, _doAnimationZoom: function() { var currentZoomLevel = this._gmap.getZoom(); if (currentZoomLevel < 8) { _self._gmap.setZoom(currentZoomLevel + 1); setTimeout(new Function.createDelegate(this, this._doAnimationZoom), 1000) } }, _addMapPoints: function(mps, catid) { if (catid < 0) catid = 0; this._gmap.closeExtInfoWindow(); var markers = []; for (var i = 0; i < mps.length; i++) { var point = new GLatLng(mps[i].Latitude, mps[i].Longitude); var iconfile; if (this._placeid == null || this._placeid != mps[i].Id) { iconfile = '/images/maps/icons/icon-c0.png' } else { iconfile = '/images/maps/icons/icon-place.png'; this._gmap.setCenter(point); if (this._isminimap != "1") { this._gmap.setZoom(8) } } var icon = new GIcon(this._baseIcon, iconfile); var markerOptions = { icon: icon }; var marker = new GMarker(point, markerOptions); marker.ref = mps[i].Id; marker.tooltip = mps[i].Name; GEvent.addListener(marker, 'click', new Function.createCallback(this._markerClicked, { marker: marker, context: this })); GEvent.addListener(marker, 'mouseover', new Function.createCallback(this._markerOver, { marker: marker, context: this })); GEvent.addListener(marker, 'mouseout', new Function.createCallback(this._markerOut, { marker: marker, context: this })); markers.push(marker) } this._clusterman.clearMarkers(); this._clusterman.addMarkers(markers); if (this._isminimap != "1") { if (this._clusterman.getTotalClusters() > 0) this._showZoomInMessage() } }, _zoomToRegionMapPoints: function(mps) { var bounds = new GLatLngBounds(); for (var i = 0; i < mps.length; i++) { var point = new GLatLng(mps[i].Latitude, mps[i].Longitude); bounds.extend(point); } this._gmap.setZoom(this._gmap.getBoundsZoomLevel(bounds)); this._gmap.setCenter(bounds.getCenter()); }, _showZoomInMessage: function() { if (this._gmap.getZoom() < 8) { $get("msgZoomIn").style.display = "block"; setTimeout('$get("msgZoomIn").style.display = "none";', 6000) } }, _hideZoomInMessage: function() { $get("msgZoomIn").style.display = "none" }, _openInfoWindow: function(a) { var mkr = _self._clusterman.getMarkerByRef(atozplaceclicked); if (mkr != null) { _self._ds.GetPlace(mkr.ref, new Function.createDelegate(_self, _self._getPlaceCompleted), Earthware.Ajax.PageUtils.onFailed); mkr.openExtInfoWindow(_self._gmap, "details_window", "Loading please wait.", { beakOffset: 3 }) } }, get_Bounds: function() { return this._bounds }, set_Bounds: function(b) { this._bounds = b }, get_CountryId: function(c) { return this._countryid }, set_CountryId: function(c) { this._countryid = c }, get_PlaceId: function(r) { return this._placeid }, set_PlaceId: function(r) { this._placeid = r }, get_IsMiniMap: function(r) { return this._isminimap }, set_IsMiniMap: function(r) { this._isminimap = r }, _selectedCategoryChanged: function(s, args) { var catid = args.get_newSelection(); if (catid != "0" && catid != "-1") { this._ds.GetCountryMapPointsCategories(this._countryid, "{" + catid + "}", new Function.createDelegate(this, this._getCategoryMapPointsCompletedAndAddToMap), Earthware.Ajax.PageUtils.onFailed) } else { if (catid == "0") { if (this._poplaces == null) { this._ds.GetIconicCountryMapPoints(this._countryid, new Function.createDelegate(this, this._getPopularPlacesCompleted), Earthware.Ajax.PageUtils.onFailed) } else { this._addMapPoints(this._poplaces, 0) } } else { if (this._allplaces == null) { this._ds.GetCountryMapPoints(this._countryid, new Function.createDelegate(this, this._getCountryMapPointsCompletedAndAddToMap), Earthware.Ajax.PageUtils.onFailed) } else { this._addMapPoints(this._allplaces, -1) } } } var bb = Earthware.GMaps.Utils.parseBoundingBox(this._bounds); this._gmap.setCenter(bb.getCenter(), this._gmap.getBoundsZoomLevel(bb)) }, _regionClicked: function(s, args) { if (this._accordian.get_SelectedCategoryId() != "-1") { this._accordian.set_SelectedCategoryId(-1) } this._gmap.closeExtInfoWindow(); var regionId = args.get_newId(); this._ds.GetRegionMapPoints(regionId, new Function.createDelegate(this, this._getRegionMapPointsCompleted), Earthware.Ajax.PageUtils.onFailed); this._hideZoomInMessage() }, _placeClicked: function(s, args) { if (this._accordian.get_SelectedCategoryId() != "-1") { this._accordian.set_SelectedCategoryId(-1) } this._gmap.closeExtInfoWindow(); this._gmap.setCenter(new GLatLng(args.get_newLatitude(), args.get_newLongitude())); this._gmap.setZoom(9); this._hideZoomInMessage(); atozplaceclicked = args.get_newId().replace("pl_", ""); this._openInfoWindow(_self) }, _regionsOpening: function(s, args) { if (this._regions == null) { this._ds.GetCountryRegions(this._countryid, new Function.createDelegate(this, this._getCountryRegionsCompleted), Earthware.Ajax.PageUtils.onFailed) } }, _placesOpening: function(s, args) { if (this._allplaces == null) { this._ds.GetCountryMapPoints(this._countryid, new Function.createDelegate(this, this._getCountryMapPointsCompleted), Earthware.Ajax.PageUtils.onFailed) } }, _togleFullscreen: function(s, e) { var containerdiv = $get("map_container"); var mapcenter = this._gmap.getCenter(); var mapdiv = this._gmap.getContainer(); if (containerdiv.style.top == "0px" || containerdiv.style.top == "0") { containerdiv.style.position = "relative"; containerdiv.style.width = this._originalwidth; containerdiv.style.height = this._originalheight; containerdiv.style.top = this._originalleft; containerdiv.style.left = this._originaltop; mapdiv.style.width = this._originalwidth; mapdiv.style.height = this._originalheight; $get("btnFullscreen").style.display = "block"; $get("btnExitFullscreen").style.display = "none" } else { this._originalwidth = containerdiv.style.width; this._originalheight = containerdiv.style.height; this._originalleft = containerdiv.style.top; this._originaltop = containerdiv.style.left; containerdiv.style.position = "absolute"; containerdiv.style.top = "0px"; containerdiv.style.left = "0px"; containerdiv.style.width = Earthware.Ajax.PageUtils.getScreenWidth() + "px"; containerdiv.style.height = Earthware.Ajax.PageUtils.getScreenHeight() + "px"; mapdiv.style.width = "100%"; mapdiv.style.height = "100%"; $get("btnFullscreen").style.display = "none"; $get("btnExitFullscreen").style.display = "block" } this._gmap.checkResize(); this._gmap.setCenter(mapcenter) }, _maptypechanged: function() { switch ($get("ddlMapStyles").selectedIndex) { case 0: this._gmap.setMapType(G_PHYSICAL_MAP); break; case 1: this._gmap.setMapType(G_SATELLITE_MAP); break; case 2: this._gmap.setMapType(G_HYBRID_MAP); break; case 3: this._gmap.setMapType(G_NORMAL_MAP); break } }, _setmapviewtype: function(e) { switch (e.target.id) { case "btnMapView": this._gmap.setMapType(G_NORMAL_MAP); break; case "btnSatelliteView": this._gmap.setMapType(G_HYBRID_MAP); break; case "btnTerrainView": this._gmap.setMapType(G_PHYSICAL_MAP); break } document.getElementById("btnMapView").setAttribute("class", "view_unselected"); document.getElementById("btnSatelliteView").setAttribute("class", "view_unselected"); document.getElementById("btnTerrainView").setAttribute("class", "view_unselected"); e.target.setAttribute("class", "") }, _resetmap: function(e) { var bb = Earthware.GMaps.Utils.parseBoundingBox(this._bounds); this._gmap.setCenter(bb.getCenter(), this._gmap.getBoundsZoomLevel(bb)); this._gmap.setMapType(G_PHYSICAL_MAP); document.getElementById("btnMapView").setAttribute("class", "view_unselected"); document.getElementById("btnSatelliteView").setAttribute("class", "view_unselected"); document.getElementById("btnTerrainView").setAttribute("class", ""); this._accordian.set_SelectedCategoryId(-1) }, _markerClicked: function(e, p) { p.context._ds.GetPlace(p.marker.ref, new Function.createDelegate(p.context, p.context._getPlaceCompleted), Earthware.Ajax.PageUtils.onFailed); p.context._gmap.setCenter(p.marker.getLatLng()); p.marker.openExtInfoWindow(p.context._gmap, "details_window", "Loading please wait.", { beakOffset: 3 }) }, _markerOver: function(e, p) { if (p.context._gmap.getExtInfoWindow() == null) { p.marker.openExtInfoWindow(p.context._gmap, "hover_window", "<div>" + p.marker.tooltip + "</div>", { beakOffset: 3 }) } }, _markerOut: function(e, p) { var iw = p.context._gmap.getExtInfoWindow(); if (iw != null) { if (iw.infoWindowId == "hover_window") p.marker.closeExtInfoWindow(p.context._gmap) } }, _getCountryCategoryCountsCompleted: function(r) { this._accordian.setCategories(Audley.Maps.StaticData.getCategories(), r) }, _getCountryRegionsCompleted: function(r) { this._regions = r; this._accordian.setRegions(r) }, _getRegionMapPointsCompleted: function(r) { this._zoomToRegionMapPoints(r); }, _getCountryMapPointsCompleted: function(r) { this._allplaces = r; this._accordian.setPlaces(r) }, _getCountryMapPointsCompletedAndAddToMap: function(r) { this._allplaces = r; if (this._accordian != null) { this._accordian.setPlaces(r); this._addMapPoints(r, this._accordian.get_SelectedCategoryId()) } else { this._addMapPoints(r, -1) } }, _getCategoryMapPointsCompletedAndAddToMap: function(r) { this._addMapPoints(r, this._accordian.get_SelectedCategoryId()) }, _getPopularPlacesCompleted: function(r) { this._poplaces = r; if (this._placeid == null) { this._accordian.set_PopularPlacesCount(r.length); this._addMapPoints(r, this._accordian.get_SelectedCategoryId()) } else { this._addMapPoints(r, -1) } }, _getPlaceCompleted: function(r) { var iw = this._gmap.getExtInfoWindow(); if (iw != null) { var formatter = new Audley.Maps.PlaceFormatter(); iw.setContentNode(formatter.format(r, this._gmap)) } }, dispose: function() { this._gmap = null; this._controls = null; this._baseIcon = null; this._clusterman = null; this._poplaces = null; this._allplaces = null; this._regions = null } }; Audley.Maps.LocationMap.registerClass('Audley.Maps.LocationMap', Sys.UI.Control); if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
