﻿if(typeof(velir)=="undefined")
	velir = {}; neverReZoom = false; extend = false; centerLat = 0; centerLong = 0; compare = false; velir.googleMaps = { createMapSimple: function (containerId, latitude, longitude, zoomLevel, controlType, showRating) { mapMarkers = new Array(); compare = showRating; lastInfoWindow = new google.maps.InfoWindow({ content: "" }); var latlng = new google.maps.LatLng(latitude, longitude); var myOptions = { zoom: zoomLevel, center: latlng, mapTypeId: controlType }; map = new google.maps.Map(document.getElementById(containerId), myOptions); checkZoom = true; zoomListener = google.maps.event.addListener(map, 'zoom_changed', function () { if (map.getZoom() > 14 && checkZoom) { map.setZoom(14); checkZoom = false; } }); google.maps.event.addListener(map, 'dragend', function () { $(".updateMap").prop("disabled", false); }); mapTypeListener = google.maps.event.addListener(map, 'maptypeid_changed', function () { $(".mapType").val(map.getMapTypeId()); setTimeout("__doPostBack('" + $(".nolink").attr("name") + "','')", 0); }); bounds = null; isWindowOpen = false; lastAcNum = ""; textField = ""; }, createMap: function (containerId, latitude, longitude, zoomLevel, controlType, buttonId, textId, sortById, sortDirId, showRating) {
	mapMarkers = new Array(); button = buttonId; textField = textId; sortByField = sortById; sortDirField = sortDirId; compare = showRating; lastInfoWindow = new google.maps.InfoWindow({ content: "" }); var latlng = new google.maps.LatLng(latitude, longitude); var myOptions = { zoom: zoomLevel, center: latlng, mapTypeId: controlType }; map = new google.maps.Map(document.getElementById(containerId), myOptions); bounds = null; isWindowOpen = false; lastAcNum = ""; secondaryMarkersListener = google.maps.event.addListener(map, 'bounds_changed', velir.googleMaps.getSecondaryMarkers); mapBoundsListener = google.maps.event.addListener(map, 'bounds_changed', velir.googleMaps.saveBoundCoords); checkZoom = true; zoomListener = google.maps.event.addListener(map, 'zoom_changed', function () {
		if (map.getZoom() > 14 && !neverReZoom && checkZoom) { map.setZoom(14); checkZoom = false; }
		if (extend) { extend = false; var latlng = new google.maps.LatLng(latitude, longitude); map.setCenter(latlng); map.setZoom(map.getZoom() - 1); }
	}); mapTypeListener = google.maps.event.addListener(map, 'maptypeid_changed', function () { $(".mapType").val(map.getMapTypeId()); setTimeout("__doPostBack('" + $(".nolink").attr("name") + "','')", 0); }); google.maps.event.addListener(map, 'dragend', function () {   $(".updateMap").prop("disabled", false); });
}, createMap1: function (containerId, swLat, swLng, neLat, neLng, zoomLevel, controlType, buttonId, textId, sortById, sortDirId, showRating) { var swPoint = new google.maps.LatLng(swLat, swLng); var nePoint = new google.maps.LatLng(neLat, neLng); var tempBounds = new google.maps.LatLngBounds(swPoint, nePoint); var centerPoint = tempBounds.getCenter(); document.title = "Custom Search - " + document.title; neverReZoom = true; velir.googleMaps.createMap(containerId, centerPoint.lat(), centerPoint.lng(), zoomLevel, controlType, buttonId, textId, sortById, sortDirId, showRating); }, removeMarkers: function () {
	for (var i in mapMarkers) { mapMarkers[i].setMap(null); }
	mapMarkers = new Array();
}, saveBoundCoords: function () { var tempBounds = map.getBounds(); var neLat = tempBounds.getNorthEast().lat(); var neLong = tempBounds.getNorthEast().lng(); var swLat = tempBounds.getSouthWest().lat(); var swLong = tempBounds.getSouthWest().lng(); var centerLat = map.getCenter().lat(); var centerLong = map.getCenter().lng(); $("input.southwest").val(swLat + "," + swLong); $("input.northeast").val(neLat + "," + neLong); $("input.centerCoord").val(centerLat + "," + centerLong); $("input.zoom").val(map.getZoom()); }, getSecondaryMarkers: function () {
	var tempBounds = map.getBounds(); var neLat = tempBounds.getNorthEast().lat(); var neLong = tempBounds.getNorthEast().lng(); var swLat = tempBounds.getSouthWest().lat(); var swLong = tempBounds.getSouthWest().lng(); var page = 1; var sortBy = "Distance"; var sortDir = "ASC"; var querystring = window.location.search.substring(1); if (document.getElementById(textField).value != null && document.getElementById(textField).value != undefined)
		page = document.getElementById(textField).value; if (document.getElementById(sortByField).value != null && document.getElementById(sortByField).value != undefined)
		sortBy = document.getElementById(sortByField).value; if (document.getElementById(sortDirField).value != null && document.getElementById(sortDirField).value != undefined)
		sortDir = document.getElementById(sortDirField).value; if (querystring != null && querystring != undefined && querystring != "") { $.ajax({ type: "POST", url: "/Services/Search.aspx/GetSecondaryMarkers", data: "{'querystring': '" + querystring + "', 'page': '" + page + "', 'sortBy':'" + sortBy + "', 'sortDir': '" + sortDir + "', 'minLat': '" + swLat + "', 'maxLat': '" + neLat + "', 'minLng': '" + swLong + "', 'maxLng': '" + neLong + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { var commands = data.d.split("\n"); for (var i = 0; i < commands.length; i++) { eval(commands[i]); } } }); }
	google.maps.event.removeListener(secondaryMarkersListener);
}, showMarker: function (ac_num, page, showRating) {
	$.ajax({ type: "POST",
		url: "/Services/Search.aspx/GetInfoWindow",
		data: "{'ac_num': '" + ac_num + "', 'show_rating': '" + showRating + "'}",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function (data) {
			var infowindow = new google.maps.InfoWindow({ content: data.d });
			lastInfoWindow.close();
			lastInfoWindow = infowindow;
			isWindowOpen = true;
			lastAcNum = ac_num;
			if (document.getElementById(textField) == null || document.getElementById(textField).value == page) { infowindow.open(map, mapMarkers[ac_num]); }

			$("acronym").tooltip({ bodyHandler: function () { return $("div." + $(this).parent().attr("class")).html(); }, showURL: false });
			if (document.getElementById(textField) != null && document.getElementById(textField).value != page) { document.getElementById(textField).value = page; setTimeout("__doPostBack('" + button + "','')", 0); }
		}
	});
}, addMarkerByJSON: function (marker) { velir.googleMaps.addMarker(marker["ac_num"], marker["title"], marker["latitude"], marker["longitude"], marker["iconUrl"], marker["iconWidth"], marker["iconHeight"], marker["shadowUrl"], marker["shadowWidth"], marker["shadowHeight"], marker["page"], marker["zIndex"]); }, addMarker: function (ac_num, title, latitude, longitude, iconUrl, iconWidth, iconHeight, shadowUrl, shadowWidth, shadowHeight, page, zIndex) {
	iconUrl = iconUrl.replace(/ /g, "%20"); var latlng = new google.maps.LatLng(latitude, longitude); var index = 0; for (var i in mapMarkers) { if (latlng.equals(mapMarkers[i].getPosition())) { index++; } }
	if (zIndex > 0) {
		if (bounds == null) { bounds = new google.maps.LatLngBounds(); }
		bounds.extend(latlng);
	}
	var image = new google.maps.MarkerImage(iconUrl, new google.maps.Size(iconWidth, iconHeight), new google.maps.Point(0, 0), new google.maps.Point((iconWidth - (5 * index)), (iconHeight - (5 * index)))); var shape = { coord: [1, 1, 1, 20, 18, 20, 18, 1], type: 'poly' }; var marker = new google.maps.Marker({ position: latlng, map: map, icon: image, title: title, zIndex: zIndex }); mapMarkers[ac_num] = marker; google.maps.event.addListener(marker, 'click', function () { velir.googleMaps.showMarker(ac_num, page, compare); });
}, closeOpenWindow: function () { isWindowOpen = false; lastInfoWindow.close(); }, setNewZoomLevel: function () {
	if (bounds != null && !neverReZoom) { checkZoom = true; map.fitBounds(bounds); }
	if (isWindowOpen) { lastInfoWindow.open(map, mapMarkers[lastAcNum]); }
}, clearBounds: function () { bounds = new google.maps.LatLngBounds(); }, closeInfoWindow: function (postBackElementId) {
	var buttonId = button; var matchIndex = buttonId.indexOf("$"); while (matchIndex != -1) { buttonId = buttonId.replace("$", "_"); matchIndex = buttonId.indexOf("$"); }
	if (buttonId != postBackElementId) { velir.googleMaps.closeOpenWindow(); }
}, centerZoomMap: function (latitude, longitude, zoomLevel) { var latlng = new google.maps.LatLng(latitude, longitude); map.setCenter(latlng); map.setZoom(zoomLevel); }, resetBounds: function (latitude, longitude) {
	if (bounds != null) { map.fitBounds(bounds); }
	centerLat = latitude; centerLong = longitude; extend = true;
}
}
