
﻿var jNetMapInitLat="[INIT_LAT]";var jNetMapInitLong="[INIT_LONG]";var jNetMapInitZoom="[INIT_ZOOM]";var jNetMapWidth="[WIDTH]";var jNetMapHeight="[HEIGHT]";var jNetMapID="[MAP_ID]";var jNetActiveCategories="[MAP_ACTIVE_CATEGORIES]";var jNetMapContainerID="MapContainer";var jNetMapDirectionsID="DrivingDirections";var jNetMap=new VEMap(jNetMapID+"_"+jNetMapContainerID);var jNetMapDirectionsPlotted=false;$(document).ready(function(){initializeMap();window.onunload=function(){disposeMap();};});function initializeMap(){var initialPosition=new VELatLong(jNetMapInitLat,jNetMapInitLong);jNetMap.LoadMap(initialPosition,1,'r',false,VEMapMode.Mode2D,false);jNetMap.AttachEvent("onendzoom",plotLocations);jNetMap.AttachEvent("onendpan",plotLocations);jNetMap.SetCenterAndZoom(initialPosition,jNetMapInitZoom);$("#"+jNetMapID+"_"+jNetMapDirectionsID).hide();}
function plotLocations(){if(!jNetMapDirectionsPlotted){var topLeft=jNetMap.PixelToLatLong(new VEPixel(0,0));var bottomRight=jNetMap.PixelToLatLong(new VEPixel(jNetMapWidth,jNetMapHeight));var zoomLevel=jNetMap.GetZoomLevel();jNetMapPinUrl="jNetMapPins.axd?mid="+jNetMapID+"&lattl="+topLeft.Latitude+"&longtl="+topLeft.Longitude+"&latbr="+bottomRight.Latitude+"&longbr="+bottomRight.Longitude+"&zoom="+zoomLevel;if(jNetActiveCategories.length>0)
jNetMapPinUrl+="&cids="+jNetActiveCategories;$.ajax({type:"GET",url:jNetMapPinUrl,success:plotLocations_callback,dataType:"xml"});}}
function plotLocations_callback(xml){var iconDirectory=$(xml).find("MapPins").attr("IconDirectory");jNetMap.Clear();$(xml).find("MapPin").each(function(){var pinLat=$(this).find("View").attr("Latitude");var pinLong=$(this).find("View").attr("Longitude");var pinIcon=$(this).find("Icon").attr("Src");var shape=new VEShape(VEShapeType.Pushpin,new VELatLong(pinLat,pinLong));var description="";$(this).find("Location").each(function(){var iconSrc=iconDirectory+$(this).find("Icon").attr("ImageFilename")+"."+$(this).find("Icon").attr("ImageExtension");var phoneNum=$(this).attr("PhoneNumber");var website=$(this).attr("WebsiteUrl");description+="<div class='jNetMapLocationHeader'>";description+="<img src='"+iconSrc+"' alt='"+$(this).find("Icon").attr("Description")+"' />";description+="<h3>"+$(this).attr("Name")+"</h3>";description+="</div>";description+="<p>";description+="<span>"+$(this).find("Address").attr("Street")+"</span>";description+="<span>"+$(this).find("Address").attr("City")+", "+$(this).find("Address").attr("State")+" "+$(this).find("Address").attr("ZipCode")+"</span>";if(phoneNum!=null&&phoneNum.length>0)
description+="<span>Phone: "+phoneNum+"</span>";if(website!=null&&website.length>0)
description+="<a href='"+website+"' target='_blank'>Visit their website</a>";description+="<a href='#' onclick='toggleDirectionsInput("+$(this).attr("ID")+")'>Get Directions</a>";description+="</p>";description+="<div id='"+jNetMapID+"_"+jNetMapDirectionsID+"_"+$(this).attr("ID")+"' class='jNetMapDirections' style='display: none;'>";description+="<input type='text' />";description+="<a href='#' onclick='showDirections("+$(this).attr("ID")+","+$(this).find("View").attr("Latitude")+","+$(this).find("View").attr("Longitude")+")'>Go</a>";description+="</div>";});shape.SetDescription(description);shape.SetCustomIcon(iconDirectory+pinIcon);jNetMap.AddShape(shape);});}
function toggleDirectionsInput(locationId){$("#"+jNetMapID+"_"+jNetMapDirectionsID+"_"+locationId).toggle();}
function clearDirections(){$("#"+jNetMapID+"_"+jNetMapDirectionsID+" h6").show();jNetMapDirectionsPlotted=false;plotLocations();$("#"+jNetMapID+"_"+jNetMapDirectionsID).html("");$("#"+jNetMapID+"_"+jNetMapDirectionsID).hide();}
function showDirections(locationId,latitude,longitude){var fromAddress=$("#"+jNetMapID+"_"+jNetMapDirectionsID+"_"+locationId+" input").val();if(fromAddress!=null&&fromAddress!=''){$("#"+jNetMapID+"_"+jNetMapDirectionsID).show();var toLocation=new VELatLong(latitude,longitude);var options=new VERouteOptions();options.RouteCallback=searchCallback;options.DrawRoute=true;options.SetBestMapView=true;options.ShowDisambiguation=true;jNetMapDirectionsPlotted=true;jNetMap.GetDirections([fromAddress,toLocation],options);}}
function searchCallback(route){var legs=route.RouteLegs;if(legs.length>0){var directionsDiv=$("#"+jNetMapID+"_"+jNetMapDirectionsID);var header=$("<h3></h3>").html("Total distance: "+route.Distance.toFixed(1)+" Mi");var routeList=$("<ol></ol>");directionsDiv.append(header);var numTurns=0;var leg=null;for(var i=0;i<legs.length;i++){leg=legs[i];var turn=null;for(var j=0;j<leg.Itinerary.Items.length;j++){turn=leg.Itinerary.Items[j];numTurns++;var listItem=$("<li></li>").html(turn.Text+" ("+turn.Distance.toFixed(1)+" mi)");routeList.append(listItem);}}
directionsDiv.append(routeList);var clearDirections=$("<a></a>").attr("href","#").attr("onclick","clearDirections()").html("Clear Directions");directionsDiv.append(clearDirections);$("#"+jNetMapID+"_"+jNetMapDirectionsID+" h6").hide();}else
$("#"+jNetMapID+"_"+jNetMapDirectionsID).html("No Results");}
function disposeMap()
{if(jNetMap!=null)
jNetMap.Dispose();}