
var PersistenceManager=new PersistenceManagerClass();function PersistenceManagerClass()
{var MapDescriptionIdPrefix="MapDescription_";var MapTitleIdPrefix="MapTitle_";var popupDelay=900;this.ShowPopup=m_ShowPopup;this.LoadUserMaps=function(alternateHandler)
{m_GetUserMaps(alternateHandler);}
function m_GetUserMaps(alternateHandler)
{var HiddenUserId=document.getElementById("HiddenUserId");if(!HiddenUserId.value)
{return;}
userid=HiddenUserId.value;var date=new Date();var qString="?userid="+userid+"&ptime="+date.getTime();if(alternateHandler==undefined)
{var request=new AjaxRequest("Handlers/MapGet.ashx"+qString,m_GetMapDone);request.Execute();}
else
{var request=new AjaxRequest("Handlers/MapGet.ashx"+qString,alternateHandler);request.Execute();}}
this.LoadUserFriends=function(alternateHandler)
{m_GetFriendsMaps(alternateHandler);}
function m_GetFriendsMaps(alternateHandler)
{var HiddenFriendsMaps=document.getElementById("HiddenFriendsMaps").value;if(HiddenFriendsMaps=="")
{return;}
var friendArray=HiddenFriendsMaps.split(";");for(var i=0;i<friendArray.length-1;i++)
{var date=new Date();var qString="?username="+friendArray[i].split(":")[0]+"&userid="+friendArray[i].split(":")[1]+"&ptime="+date.getTime();;var request=new AjaxRequest("Handlers/MapGet.ashx"+qString,m_GetMapFriendsDone);request.Execute();}}
function m_GetMapFriendsDone(responseText)
{var mapList=eval('('+responseText+')');mapListingDiv=document.getElementById(friendMapsListingId);var mapsDivContent="";mapsDivContent+=m_GetMapListingContent(mapList,true,"FriendListingPanel",mapList.UserName).html;if(mapsDivContent!="")
{mapListingDiv.innerHTML+=mapsDivContent;}}
function m_GetMapDone(responseText)
{try
{var mapList=eval('('+responseText+')');mapListingDiv=document.getElementById(myMapsListingId);removeAllChild(mapListingDiv);var mapList=m_GetMapListingContent(mapList,false,"MyMapListingPanel","");var mapsDivContent=mapList.html;if(mapsDivContent!="")
{mapListingDiv.innerHTML=mapsDivContent;}
else
{PersistenceManager.SaveMap({title:MyMaps,description:' '});}
PersistenceManager.SelectMap("MyMapListingPanel",currMapID,false,MapTitleIdPrefix+currMapID,MapDescriptionIdPrefix+currMapID,mapList.lat,mapList.lon,mapList.zoom,mapList.style);}
catch(e)
{}}
function m_GetMapListingContent(mapList,readOnly,mapContainerID,userName)
{var mapsDivContent="";var mapId="";var currLat="";var currLon="";var currZoom="";var currStyle="";if(mapList!=undefined&&mapList.DataList!=null&&mapList.DataList.length>0)
{for(var x=0;x<mapList.DataList.length;x++)
{mapId=mapList.DataList[x].MapID;if(mapId==currMapID)
{currLat=mapList.DataList[x].Latitude;currLon=mapList.DataList[x].Longitude;currZoom=mapList.DataList[x].ZoomLevel;currStyle=mapList.DataList[x].MapStyle;}
mapDescriptionId=MapDescriptionIdPrefix+mapId;mapTitleId=MapTitleIdPrefix+mapId;mapsDivContent+="<div id='"+mapTitleId+"' class='mySingleMap' onclick=PersistenceManager.SelectMap('"
+mapContainerID
+"','"+mapId
+"',"+readOnly
+",'"+mapTitleId
+"','"+mapDescriptionId
+"',"+mapList.DataList[x].Latitude
+","+mapList.DataList[x].Longitude
+","+mapList.DataList[x].ZoomLevel
+","+mapList.DataList[x].MapStyle
+")>";mapsDivContent+=mapList.DataList[x].Title;if(!readOnly)
{var filteredTitle=mapList.DataList[x].Title.replace("'","%27").replace("\"","%28");var filteredDescription=mapList.DataList[x].Description.replace("'","%27").replace("\"","%28");mapsDivContent+="  ";mapsDivContent+="<span id='editButton' class='editButton' onclick='PersistenceManager.EditMap(\""+mapId+"\",\""+filteredTitle+"\",\""+filteredDescription+"\")'> "+editText+"</span>";mapsDivContent+="  ";mapsDivContent+="<span id='editButton' class='editButton' onclick='PersistenceManager.DeleteMap(\""+mapId+"\")'> "+resourceRemove+"</span>";}
else
{mapsDivContent+="<span id='copyButton' class='editButton' onclick='PersistenceManager.CopyMap(\""+mapId+"\")'> "+copyThisMapText+"</span>";}
mapsDivContent+="</div>";mapsDivContent+="<div id='"+mapDescriptionId+"' class='mySingleMapDescription hidden'>"+mapList.DataList[x].Description+"</div>";if(userName!=undefined&&userName!="")
{mapsDivContent+="<div class='createdBy'>   "+createdBy+" ";mapsDivContent+=userName+"<br/></div>";}}}
var result={html:mapsDivContent,lat:currLat,lon:currLon,zoom:currZoom,style:currStyle};return result;}
function m_GetUserMapLocations(mapID)
{if(!mapID)
{return;}
var date=new Date();var qString="?mapID="+mapID+"&ptime="+date.getTime();var request=new AjaxRequest("Handlers/MapLocationGet.ashx"+qString,m_GetMapLocationDone);request.Execute();}
function m_GetMapLocationDone(responseText)
{try
{var mapList=eval('('+responseText+')');var locationPoints=new Array();var locationsDivContent="";var locationId="";var mapid=currMapID;var mapLocationDivID=myMapLocationsListingIdPrefix+mapid;var holder;if(isCurrMapFriends)
holder=document.getElementById(friendLocationListingID);else
holder=document.getElementById(myLocationListingID);var mapListingDiv=document.createElement('div');mapListingDiv.setAttribute('id',mapLocationDivID);mapListingDiv.setAttribute('class','myMapLocation');removeAllChild(holder);holder.appendChild(mapListingDiv);var layer=mapManager.Map.GetShapeLayerByIndex(0);if(layer)
{layer.DeleteAllShapes();}
if(mapList!=undefined&&mapList.DataList!=null&&mapList.DataList.length!=0)
{locationsDivContent+="<div>"+locationIntroText+"</div>";locationsDivContent+="<table class='myLocation' cell-padding='10px'>";for(var x=0;x<mapList.DataList.length;x++)
{locationId=mapList.DataList[x].LocationID;var title=mapList.DataList[x].Title;var des=mapList.DataList[x].Description;var lat=mapList.DataList[x].Latitude;var lon=mapList.DataList[x].Longitude;var lastUpdated=mapList.DataList[x].LastUpdated;var iconURL=mapList.DataList[x].IconURL;if(!iconURL||iconURL=="")iconURL="Images/MyLocationPin.gif";locationPoints[x]=new VELatLong(lat,lon);var shape=new VEShape(VEShapeType.Pushpin,new VELatLong(lat,lon));shape.SetCustomIcon("<div class='pin_personal' style='background:url("+iconURL+") no-repeat 0 0; '></div>");mapManager.Map.AddShape(shape);var locationContent={title:title,description:des,latitude:lat,longitude:lon,lastUpdated:lastUpdated,shapeID:shape.GetID(),iconURL:iconURL};var shapeContent=GenerateLocationDescription(locationId,locationContent);var key=InfoBoxManager.StoreDescription('Personal',x,shapeContent);shape.SetDescription(key);locationId=mapList.DataList[x].LocationID;locationTitleId=locationId+x+"title";locationDescriptionId=locationId+x+"description";locationsDivContent+="<tr><td rowspan='2' align='top'><img src=' "+iconURL+"'/></td>";locationsDivContent+="<td style='width: 190px'><div id='"+locationTitleId+"' class='mySingleMapLocationTitle' ";var title=locationContent.title.replace("'","%27").replace("\"","%28");var des=locationContent.description.replace("'","%27").replace("\"","%28");locationsDivContent+="onclick='PersistenceManager.SelectMapLocation(\""+locationId+"\",\""
+locationContent.shapeID+"\",\""
+title+"\",\""
+des+"\","
+locationContent.latitude+","
+locationContent.longitude+",\""
+locationContent.lastUpdated+"\",\""
+locationContent.iconURL+"\")'";locationsDivContent+=">"+mapList.DataList[x].Title+"</div></td>";locationsDivContent+="<td style='width: 15px'></td>";locationsDivContent+="<td valign='middle'><img src='Images/WaypointDelete.gif' onclick='PersistenceManager.DeleteMyLocation(\""+shape.GetID()+"\", \""+locationId+"\")'/></td>";locationsDivContent+="<tr><td><div id='"+locationDescriptionId+"' class='mySingleMapLocationDescription'>"+mapList.DataList[x].Description+"</div>";locationsDivContent+="</td></tr>";}
locationsDivContent+="</table>";totalPersonalPins+=mapList.DataList.length;mapListingDiv.innerHTML=locationsDivContent;}
if(locationPoints.length==0)
{var currMap=mapManager.GetSelectedMap();mapManager.Map.SetCenterAndZoom(new VELatLong(currMap.Latitude,currMap.Longitude),currMap.ZoomLevel);}
else
{mapManager.Map.SetMapView(locationPoints);}}
catch(e)
{}}
this.SelectMapLocation=function(locationID,shapeID,title,des,lat,lon,lastUpdated,iconURL)
{title=title.replace("%27","'").replace("%28","\"");des=des.replace("%27","'").replace("%28","\"");var locationContent={title:title,description:des,latitude:lat,longitude:lon,lastUpdated:lastUpdated,shapeID:shapeID,iconURL:iconURL};HideCurrentEro(null);var shape=mapManager.Map.GetShapeByID(locationContent.shapeID);if(!shape)
{var shape=new VEShape(VEShapeType.Pushpin,new VELatLong(locationContent.latitude,locationContent.longitude));shape.SetCustomIcon("<div class='pin_personal' style='background:url("+locationContent.iconURL+") no-repeat 0 0; '></div>");mapManager.Map.AddShape(shape);}
var des=GenerateLocationDescription(locationID,locationContent);shape.SetDescription(des);mapManager.Map.SetCenter(new VELatLong(lat,lon));setTimeout('PersistenceManager.ShowPopup("'+shape.GetID()+'")',popupDelay);}
function m_ShowPopup(shapeID)
{activeEro=new PushpinERO(shapeID,mapManager.Map);activeEro.Show();}
this.SaveMapLocation=function(locationID,mapID,lat,lon,shapeID,iconURL)
{if(!mapID)
{return;}
var titleElement=document.getElementById("myLocTitle_"+shapeID);var title=titleElement.value;var description=document.getElementById("myLocDescription_"+shapeID).value;var qString="?locationID="+locationID
+"&mapID="+mapID
+"&title="+title
+"&description="+description
+"&latitude="+lat
+"&longitude="+lon
+"&iconURL="+iconURL;var request=new AjaxRequest("Handlers/MapLocationSave.ashx"+qString,m_SaveMapLocationDone);request.Execute();HideCurrentEro(null);isAddingNewLocation=false;}
this.SaveMapLocationDetailed=function(mapID,lat,lon,title,description,imageURL)
{if(!mapID)
{return;}
var qString="?mapID="+mapID+"&title="+title+"&description="+description+"&latitude="+lat+"&longitude="+lon+"&iconURL="+imageURL;var request=new AjaxRequest("Handlers/MapLocationSave.ashx"+qString,m_SaveMapLocationDone);request.Execute();HideCurrentEro(null);isAddingNewLocation=false;}
function m_SaveMapLocationDone(responseText)
{try
{m_GetUserMapLocations(currMapID);}
catch(e)
{}}
this.DeleteMyLocation=function(shapeID,locationID)
{if(!locationID||locationID=="")
{return;}
var answer=confirm(resourceLocationDeleteConfirm);if(answer)
{var qString="?locationID="+locationID+"&shapeID="+shapeID;var request=new AjaxRequest("Handlers/MapLocationDelete.ashx"+qString,m_DeleteMapLocationDone);request.Execute();HideCurrentEro(null);isAddingNewLocation=false;}}
function m_DeleteMapLocationDone(responseText)
{try
{totalPersonalPins--;m_GetUserMapLocations(currMapID);var layer=mapManager.Map.GetShapeLayerByIndex(0);var shape=layer.GetShapeByID(responseText);if(shape)
{layer.DeleteShape(shape);}}
catch(e)
{}}
this.SelectMap=function(mapContainerID,mapId,readOnly,mapTitleDivId,mapDescriptionDivId,currLat,currLon,currZoom,currStyle)
{mapManager.SetSelectedMapId(mapId);mapManager.SetSelectedMap({mapID:mapId,Latitude:currLat,Longitude:currLon,ZoomLevel:currZoom,MapStyle:currStyle});if(mapId=="")
return;isCurrMapFriends=readOnly;if(currStyle&&currStyle!="")
mapManager.Map.SetMapStyle(mapManager.GetMapStyle(currStyle));var myMapListContainer=document.getElementById(mapContainerID).childNodes;var myMapList;var index=0;for(index=0;index<myMapListContainer.length;index++)
{myMapList=myMapListContainer[index];if(myMapList&&myMapList.nodeType==1&&myMapList.id.indexOf("MapListing")>0)
{break;}}
if(myMapList.firstChild)
{var oChild=myMapList.firstChild;while(oChild)
{if(oChild.nodeType!=1)
{oChild=oChild.nextSibling;continue;}
var array=oChild.id.split("_");if(array[0]+"_"==MapTitleIdPrefix)
{if(array[array.length-1]==mapId)
{oChild.setAttribute("className","mySingleMapSelected");oChild.setAttribute("class","mySingleMapSelected");currMapID=mapId;}
else
{oChild.setAttribute("className","mySingleMap");oChild.setAttribute("class","mySingleMap");}}
else if(array[0]+"_"==MapDescriptionIdPrefix)
{if(array[array.length-1]==mapId)
{oChild.setAttribute("className","mySingleMapDescription shown");oChild.setAttribute("class","mySingleMapDescription shown");}
else
{oChild.setAttribute("className","mySingleMapDescription hidden");oChild.setAttribute("class","mySingleMapDescription hidden");}}
oChild=oChild.nextSibling;}}
m_GetUserMapLocations(mapId);if(!readOnly)
{var myLocationIcon=document.getElementById("MyLocationIcon");myLocationIcon.style.display="block";myLocationIcon.onmousedown=new Function("AddMyLocation('"+mapId+"')");}
else
{var myLocationIcon=document.getElementById("MyLocationIcon");myLocationIcon.style.display="none";}}
this.SaveMap=function(map)
{if(map==null){if(document.getElementById("SaveMapTitle")==null)return;if(document.getElementById("SaveMapDescription")==null)return;var SaveMapTitle=document.getElementById("SaveMapTitle").value;var SaveMapDescription=document.getElementById("SaveMapDescription").value;}
else{var SaveMapTitle=map.title;var SaveMapDescription=map.description;}
if(document.getElementById("HiddenUserId")==null)return;var HiddenUserId=document.getElementById("HiddenUserId").value;var mapID=currMapID;userid=HiddenUserId;title=SaveMapTitle;description=SaveMapDescription;latitude=mapManager.Map.GetCenter().Latitude;longitude=mapManager.Map.GetCenter().Longitude;mapstyle=mapManager.GetMapStyleIndex(mapManager.Map.GetMapStyle());zoomlevel=mapManager.Map.GetZoomLevel();var qString="?userid="+userid+"&mapid="+mapID+"&latitude="+latitude+"&longitude="+longitude+"&zoomlevel="+zoomlevel+"&mapstyle="+mapstyle+"&title="+title+"&description="+
description;var request=new AjaxRequest("Handlers/MapSave.ashx"+qString,m_SaveMapDone);request.Execute();}
function m_SaveMapDone(responseText)
{try
{if(responseText!="0")
{m_GetUserMaps();currMapID=responseText;}}
catch(e)
{}}
this.CreateMap=function()
{currMapID="";document.getElementById("SaveMapTitle").value="";document.getElementById("SaveMapDescription").value="";}
this.EditMap=function(mapID,title,description)
{var EditMapTitle=document.getElementById("SaveMapTitle");var EditMapDescription=document.getElementById("SaveMapDescription");EditMapTitle.value=title.replace("%27","'").replace("%28","\"");EditMapDescription.value=description.replace("%27","'").replace("%28","\"");var editMapPanel=$find("EditMapPanel");if(editMapPanel)
{editMapPanel._doOpen();currMapID=editMapPanel;}}
this.DeleteMap=function(mapID)
{var answer=confirm(resourceMapDeleteConfirm);if(answer)
{var qString="?mapid="+mapID;var request=new AjaxRequest("Handlers/MapDelete.ashx"+qString,m_DeleteMapDone);request.Execute();}}
this.ClearPushpins=function()
{if(mapManager==null)return;if(mapManager.Map==null)return;mapManager.Map.DeleteAllShapes();mapManager.Map.DeleteRoute();}
this.CopyMap=function(mapID)
{var HiddenUserId=document.getElementById("HiddenUserId");if((!HiddenUserId.value)||(!mapID))
{return;}
userid=HiddenUserId.value;var qString="?mapid="+mapID+"&userid="+userid;var request=new AjaxRequest("Handlers/MapCopy.ashx"+qString,m_CopyMapDone);request.Execute();}
function m_DeleteMapDone(responseText)
{try
{if(responseText=="1")
{m_GetUserMaps();currMapID="";}}
catch(e)
{}}
function m_CopyMapDone(responseText)
{try
{if(responseText!="0")
{m_GetUserMaps();currMapID=responseText;}}
catch(e)
{}}
this.SaveIconSelection=function(locationID)
{var starIconURL=document.getElementById("customStarIcon").src;starIconURL=starIconURL.substring(starIconURL.indexOf("Images"));var qString="?locationid="+locationID+"&iconURL="+starIconURL;var request=new AjaxRequest("Handlers/MapLocationSave.ashx"+qString,m_SaveIconDone);request.Execute();}
function m_SaveIconDone(responseText)
{HideCurrentEro(null);m_GetUserMapLocations(currMapID);}
this.GDDForPopup=function(mode,locationID,lat,lon){var startAddress;var endAddress;if(mode=='TO'){startAddress=new VELatLong(lat,lon).toString();if(startAddress.trim()=='')
return;endAddress=document.getElementById('p_toAddress'+locationID).value;document.getElementById("txtFrom").value=startAddress;document.getElementById("txtTo").value=endAddress;drivingDirectionTo=endAddress;drivingDirectionFrom=startAddress;fromPlaceArray=mapManager.LatLongToPlaceArray(startAddress);}
else{endAddress=new VELatLong(lat,lon).toString();if(endAddress.trim()=='')
return;startAddress=document.getElementById('p_fromAddress'+locationID).value;document.getElementById("txtFrom").value=startAddress;document.getElementById("txtTo").value=endAddress;drivingDirectionTo=endAddress;drivingDirectionFrom=startAddress;}
mapManager.GetNewDirections(startAddress,endAddress);TopNav('DrivingDirections');HideCurrentEro(null);}
this.GNBForPOIPopup=function(index,lat,lon)
{var txtNB=document.getElementById('p_nearby'+index).value;if(txtNB.trim()=='')
{return;}
if(typeof(g_POIs)=='undefined'&&lat!=null&&lon!=null)
{document.getElementById('txtBusLocation').value=(Math.round(lat*100)/100)+", "+(Math.round(lon*100)/100);}
else
{if(g_POIs.length-1<=index)
{return;}
var currentPOI=g_POIs.DataList[index];document.getElementById('txtBusLocation').value=(Math.round(currentPOI.Latitude*100)/100)+", "+(Math.round(currentPOI.Longitude*100)/100);}
document.getElementById('txtBusName').value=txtNB;TopNav("FindBusiness");mapManager.NewFindBusiness(true);}}