
function MapManager()
{var mapElement=null;this.MapElement=null;var isCategorySearch=null;var wayPointLetters=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");var mapStyleList=new Array(null,VEMapStyle.Road,VEMapStyle.Aerial,VEMapStyle.Hybrid);var SelectedMapId=null;var SelectedMapInfo={mapID:SelectedMapId,Latitude:null,Longitude:null,ZoomLevel:null,MapStyle:null};this.GetWayPointLetter=function(index)
{return wayPointLetters[index];}
this.GetIsCategorySearch=function()
{return isCategorySearch;}
this.SetCategorySearch=function(value)
{isCategorySearch=value;}
this.SetSelectedMap=function(value)
{SelectedMapInfo=value;}
this.GetSelectedMap=function()
{return SelectedMapInfo;}
this.SetSelectedMapId=function(value)
{SelectedMapId=value;}
this.GetSelectedMapId=function()
{return SelectedMapId;}
this.GetMapStyle=function(mapStyleInt)
{return mapStyleList[mapStyleInt];}
this.GetMapStyleIndex=function(mapStyle)
{var ctr="";for(var i=0;i<mapStyleList.length;i++)
{if(mapStyleList[i]==mapStyle)
{return i;}}
return ctr;}
this.keyDownOnMap=function(e)
{var keyIsBirdsEyeShortcut=(e.keyCode==66||e.keyCode==79);return keyIsBirdsEyeShortcut;}
var map=null;this.Map=map;this.GetPrintMap=function(mapDivElement)
{map=new VEMap(mapDivElement);this.Map=map;map.LoadMap();map.HideDashboard();map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);}
this.PrepareForMapPointGeocoding=function(address){var postalCode=address.match(/([a-z])(\d)([a-z])\s?(\d[a-z]\d)?/i);var firstFSALetter='';var FSA='';if(postalCode!=null){firstFSALetter=postalCode[1];FSA=(postalCode[1]!=undefined?postalCode[1]:'')+(postalCode[2]!=undefined?postalCode[2]:'')+(postalCode[3]!=undefined?postalCode[3]:'');if(address==postalCode[0])
return(postalCode[1]+postalCode[2]+postalCode[3]+' '+postalCode[4]);else
address=address.replace(postalCode[0],"");}
address=address.replace(/(\d)([a-zA-Z])/g,"$1 $2");address=address.replace(/^[uUsS]\d+[\-\s]+(\d)/,"$1");address=address.replace(/^\d+\s*\-\s*(\d+)[\s,]/,"$1 ");address=address.replace(/\b(unite?|u|bureau|suite|app(artement)?|apartment|apt)\s*\d+[a-z]*(\s*&\s*\d+[a-z]*)?/i," ");address=address.replace(/\b\d+(st|nd|rd|th)?\s*(fl|floor)\b/i," ");address=address.replace(/\bfirst floor\b/i,"");address=address.replace(/\b\d+\s*(er?|i[èe]me?|eme)\s[eé]tage\b/i,"");address=address.replace(/\bE(st)?\b/i,"East");address=address.replace(/\bS(ud)?\b/i,"South");address=address.replace(/\b(Ouest|O|W)\b/i,"West");address=address.replace(/\bN(ord)?\b/i,"North");address=address.replace(/\b(po|p\.o\.) box [a-z0-9]+/gi,"");address=address.replace(/^box [a-z0-9]+/i,"");address=address.replace(/\b(stn|station) (main|[a-z])\b/i,"");address=address.replace(/\b(at)\b/i,"and");return(address+FSA);}
this.GetMapWidthHeight=function(){var myWidth=0
var myHeight=(browserManager.BrowserName=='msie'?(0-1):(browserManager.BrowserName=='safari'?(0-7):0));if(typeof(window.innerWidth)=='number'){myWidth+=window.innerWidth;myHeight+=window.innerHeight;}
else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth+=document.documentElement.clientWidth;myHeight+=document.documentElement.clientHeight;}
else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth+=document.body.clientWidth;myHeight+=document.body.clientHeight;}
var mapHeight=parseInt(myHeight-118);mapHeight=mapHeight<200?200:mapHeight;var mapWidth=myWidth-282;mapWidth=mapWidth<200?200:mapWidth;var widthHeight=new Array();widthHeight.push(mapWidth);widthHeight.push(mapHeight);return widthHeight;}
this.GetMap=function(mapDivElement,centerLatitude,centerLongitude,zoom){mapElement=mapDivElement;this.MapElement=document.getElementById(mapElement);document.getElementById(mapElement).style.width=this.GetMapWidthHeight()[0]+"px";document.getElementById(mapElement).style.height=(this.GetMapWidthHeight()[1]-1)+"px";map=new VEMap(mapDivElement);this.Map=map;paneNumber=-1;map.LoadMap(new VELatLong(centerLatitude,centerLongitude),zoom);map.HideDashboard();map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);AddNavControl();AddMiniControl();AddMyLocationControl();AddMaplevelAlertMessageControl();AddTrafficAlertMessageControl();AddTrafficBrandingControl();map.AttachEvent('onresize',this.OnMapResize);map.AttachEvent('onclick',MouseHandler);map.AttachEvent('onstartpan',HideCurrentEro);map.AttachEvent('onstartzoom',HideCurrentEro);map.AttachEvent('onendpan',ShowCurrentEro);map.AttachEvent('onendpan',this.updateClientCacheCenter);map.AttachEvent('onendzoom',this.updateClientCacheZoom);map.AttachEvent("onchangemapstyle",this.updateClientCacheStyle);CarouselManager.DisplayCarousel();window.onresize=this.MapResize;if(browserManager.BrowserName!='msie')
MapControl.Features.ScaleBarKilometers=true;document.getElementById('CloseMini').style.display="none";document.getElementById('footerdiv').style.top=document.getElementById(mapElement).offsetHeight+167-(document.getElementById('PanelWhatsNearby').style.display=="none"?78:0)+"px";document.getElementById('div_traffic_branding').style.top=document.getElementById(mapElement).offsetHeight+167-(document.getElementById('PanelWhatsNearby').style.display=="none"?78:0)+"px";browserManager.GetWindowHeight();}
function AddMaplevelAlertMessageControl(){var div_zoom_alert=document.getElementById('div_maplevel_alert_message');map.AddControl(div_zoom_alert);}
function AddTrafficAlertMessageControl(){var div_traffic_alert=document.getElementById('div_traffic_alert_message');map.AddControl(div_traffic_alert);}
function AddTrafficBrandingControl(){var div_traffic_branding=document.getElementById('div_traffic_branding');map.AddControl(div_traffic_branding);}
this.validateFindInput=function(clientCacheId,value,fieldId){var returnValue=value;if(returnValue==undefined||returnValue==null){returnValue=ClientCache.Retrieve(clientCacheId);if(returnValue==undefined||returnValue==null){returnValue=document.getElementById(fieldId).value;}}
ClientCache.Save(clientCacheId,returnValue);document.getElementById('ErrHeaderTxt').style.visibility=returnValue.trim()==""?"visible":"hidden";document.getElementById(fieldId).style.border=returnValue.trim()==""?"1px solid red":"1px solid black";returnValue=returnValue.trim()==""?null:returnValue;document.getElementById(fieldId).value=returnValue;return returnValue;}
this.PerformSelectedSearch=function(selectedPane,newPane){paneNumber=selectedPane==null?ClientCache.Retrieve('selected_pane_num'):selectedPane;if(paneNumber!=-1)
this.Find((newPane==null?false:newPane),ClientCache.Retrieve('lastSearch'));}
this.Find=function(newFind,searchType,first,second){FindNearbyClick(true);var validatedInputs=this.PrepareForFindLookup(newFind,searchType,first,second);this.FindLookup(validatedInputs[0],validatedInputs[1]);this.resizeLeftDiv();ClientCache.Save('lastSearchFailed','false');HideLoading();}
this.NewFindLookup=function(txtFind){txtFind=(txtFind==undefined?document.getElementById('txtFind').value:txtFind);TopNav('FindMap');this.Find(true,'fm',txtFind);}
this.PrepareForNewFindLookup=function(txtFind){TopNav('FindMap');this.PrepareForFindLookup(true,'fm',txtFind);}
this.NewFindBusiness=function(latLongMode,SkipHistory,keyword,location){location=(location==undefined?document.getElementById('txtBusLocation').value:location);keyword=(keyword==undefined?document.getElementById('txtBusName').value:keyword);if(location==undefined||location==null||location=='')
location=this.Map.GetCenter().Latitude+','+this.Map.GetCenter().Longitude;TopNav('FindBusiness');paneNumber=paneNumber+1;ClientCache.Save('pane_'+paneNumber+'_LocationInput',location);ClientCache.Save('pane_'+paneNumber+'_NameInput',keyword);ClientCache.Save('pane_'+paneNumber+'_inputTypeToValidate','BusLoc');map.Find(null,this.PrepareForMapPointGeocoding(location),null,null,null,null,null,null,false,false,mapManager.FindInputValidatorCallback);}
this.PrepareForNewFindBusiness=function(location,keyword){TopNav('FindBusiness');this.PrepareForFindLookup(true,'bus',location,keyword);}
this.NewFindPerson=function(latLongMode,SkipHistory,keyword,location){location=(location==undefined?document.getElementById('txtPersonLocation').value:location);keyword=(keyword==undefined?document.getElementById('txtPersonName').value:keyword);if(location==undefined||location==null||location=='')
location=this.Map.GetCenter().Latitude+','+this.Map.GetCenter().Longitude;TopNav('FindPerson');paneNumber=paneNumber+1;ClientCache.Save('pane_'+paneNumber+'_LocationInput',location);ClientCache.Save('pane_'+paneNumber+'_NameInput',keyword);ClientCache.Save('pane_'+paneNumber+'_inputTypeToValidate','PerLoc');map.Find(null,this.PrepareForMapPointGeocoding(location),null,null,null,null,null,null,false,false,mapManager.FindInputValidatorCallback);}
this.PrepareForNewFindPerson=function(location,keyword){TopNav('FindBusiness');this.PrepareForFindLookup(true,'per',location,keyword);}
this.GetNewDirections=function(origin,destination){origin=(origin==undefined?document.getElementById('txtFrom').value:origin);destination=(destination==undefined?document.getElementById('txtTo').value:destination);if(origin==undefined||origin==null||origin=='')
origin=this.Map.GetCenter().Latitude+','+this.Map.GetCenter().Longitude;else if(destination==undefined||destination==null||destination=='')
destination=this.Map.GetCenter().Latitude+','+this.Map.GetCenter().Longitude;TopNav('DrivingDirections');paneNumber=paneNumber+1;ClientCache.Save('pane_'+paneNumber+'_FromInput',origin);ClientCache.Save('pane_'+paneNumber+'_ToInput',destination);ClientCache.Save('pane_'+paneNumber+'_inputTypeToValidate','From');map.Find(null,this.PrepareForMapPointGeocoding(origin),null,null,null,null,null,null,false,false,mapManager.FindInputValidatorCallback);}
this.PrepareForGetNewDirections=function(origin,destination){TopNav('DrivingDirections');this.PrepareForFindLookup(true,'dd',origin,destination);}
this.AddWaypoint=function(location){var numWaypoints=(ClientCache.Retrieve('pane_'+paneNumber+'_NumWaypoints'));location=((location==undefined)?document.getElementById('txtWaypoint'+paneNumber).value:location);numWaypoints=(numWaypoints==undefined?0:numWaypoints);ClientCache.Save('pane_'+paneNumber+'_WaypointInput'+numWaypoints,location);ClientCache.Save('pane_'+paneNumber+'_NumWaypoints',numWaypoints);ClientCache.Save('pane_'+paneNumber+'_inputTypeToValidate','Waypoint');map.Find(null,this.PrepareForMapPointGeocoding(location),null,null,null,null,null,null,false,false,mapManager.FindInputValidatorCallback);}
this.FindInputValidatorCallback=function(shapeLayer,findResultArray,placeArray){if(placeArray==null){mapManager.onFailedSearch();}else{var validatedInputType=ClientCache.Retrieve('pane_'+paneNumber+'_inputTypeToValidate');if(validatedInputType=='Waypoint'){ClientCache.Save('pane_'+paneNumber+'_NumWaypoints',ClientCache.Retrieve('pane_'+paneNumber+'_NumWaypoints')+1);mapManager.Find(false,'dd');}else if(validatedInputType=='From'){ClientCache.Save('pane_'+paneNumber+'_inputTypeToValidate','To');mapManager.Map.Find(null,mapManager.PrepareForMapPointGeocoding(ClientCache.Retrieve('pane_'+paneNumber+'_ToInput')),null,null,null,null,null,null,false,false,mapManager.FindInputValidatorCallback);}else if(validatedInputType=='To'){mapManager.Find(true,'dd',ClientCache.Retrieve('pane_'+paneNumber+'_FromInput'),ClientCache.Retrieve('pane_'+paneNumber+'_ToInput'));}else if(validatedInputType=='PerLoc'){mapManager.Find(true,'per',ClientCache.Retrieve('pane_'+paneNumber+'_LocationInput'),ClientCache.Retrieve('pane_'+paneNumber+'_NameInput'));}else if(validatedInputType=='BusLoc'){mapManager.Find(true,'bus',ClientCache.Retrieve('pane_'+paneNumber+'_LocationInput'),ClientCache.Retrieve('pane_'+paneNumber+'_NameInput'));}}}
this.PrepareForFindLookup=function(newFind,searchType,first,second){newFind=(ClientCache.Retrieve('lastSearchFailed')=='true'?false:newFind);if(newFind)
AjaxControlManager.openLeftNavPane(5);var nextPaneNumber=(newFind?AjaxControlManager.getNextPaneNumber():paneNumber);var lastSearchType=ClientCache.Retrieve('lastSearch');ClientCache.Save('lastSearch',searchType);var validatedFirst='';var validatedSecond='';if(searchType=='fm'){validatedFirst=this.validateFindInput('pane_'+nextPaneNumber+'_FindInput',first,'txtFind');validatedSecond=null;}
else if(searchType=='dd'){validatedFirst=this.validateFindInput('pane_'+nextPaneNumber+'_FromInput',first,'txtFrom');validatedSecond=this.validateFindInput('pane_'+nextPaneNumber+'_ToInput',second,'txtTo');if(ClientCache.Retrieve('pane_'+nextPaneNumber+'_NumWaypoints')==undefined)
ClientCache.Save('pane_'+nextPaneNumber+'_NumWaypoints',0);}
else{validatedFirst=this.validateFindInput('pane_'+nextPaneNumber+'_LocationInput',first,searchType=='bus'?'txtBusLocation':'txtPersonLocation');validatedSecond=this.validateFindInput('pane_'+nextPaneNumber+'_NameInput',second,searchType=='bus'?'txtBusName':'txtPersonName');}
var divIdPrefix='';var paneTitle='';if(searchType=='fm'){divIdPrefix='yp_FindOnMap';paneTitle=validatedFirst;}
else if(searchType=='dd'){divIdPrefix='yp_DrivingDirections';paneTitle=resourceFrom+": "+(validatedFirst.indexOf("@")!=-1?validatedFirst.split("@")[0]:validatedFirst)+" "+resourceTo+": "+(validatedSecond.indexOf("@")!=-1?validatedSecond.split("@")[0]:validatedSecond);}
else if(searchType=='bus'){divIdPrefix='yp_FindBusiness';paneTitle='';}
else{divIdPrefix='yp_FindPerson';paneTitle='';}
if(newFind){paneNumber=AjaxControlManager.addPaneToBusinessDirectionFind(paneTitle,divIdPrefix,validatedSecond,validatedFirst);}
else if(ClientCache.Retrieve('lastSearchFailed')=='true'){if(lastSearchType=='dd'){var previousNumWaypoints=ClientCache.Retrieve('pane_'+paneNumber+'_NumWaypoints');if(previousNumWaypoints>0){ClientCache.Save('pane_'+paneNumber+'_Waypoint'+previousNumWaypoints,undefined);}
else{ClientCache.Save('pane_'+paneNumber+'_From',undefined);ClientCache.Save('pane_'+paneNumber+'_To',undefined);}}
else if(lastSearchType=='fm'){ClientCache.Save('pane_'+paneNumber+'_Find',undefined);}
AjaxControlManager.setBusinessDirectionFindHeader(paneNumber,paneTitle,divIdPrefix,validatedSecond,validatedFirst);AjaxControlManager.setBusinessDirectionFindContent(paneNumber,divIdPrefix);}
AjaxControlManager.OpenAccordionPane(AjaxControlManager.getBusinessDirectionFindAccordion(),paneNumber);ClientCache.Save('pane_'+paneNumber+'_type',searchType);if(searchType=='fm'){findOnMap=document.getElementById(divIdPrefix+paneNumber);findOnMap.innerHTML='';AmbiguityDiv=document.createElement("div");findOnMap.appendChild(AmbiguityDiv);findOnMapFindAmbiguity=document.createElement("div");AmbiguityDiv.appendChild(findOnMapFindAmbiguity);findOnMapResultDiv=document.createElement("div");findOnMapResultDiv.id="firstResultDiv"+paneNumber;findOnMapResultDiv.style.overflow="hidden";findOnMap.appendChild(findOnMapResultDiv);findOnMapResultDiv.innerHTML='<div class="DefaultLocation"><img style="margin-top: 15px; margin-left: 15px;" src="Images/dartblue.gif"/><span class="Arial12" style="margin-left: 6px;">'+validatedFirst+'</span></div>';}
else if(searchType=='dd'){var paneContentDiv=document.getElementById(divIdPrefix+paneNumber);paneContentDiv.innerHTML='';var ambiguityDiv=document.createElement("div");ambiguityDiv.id="outerAmbiguityDiv"+paneNumber;paneContentDiv.appendChild(ambiguityDiv);var innerAmbiguityDiv=document.createElement("div");innerAmbiguityDiv.id="firstAmbiguityDiv"+paneNumber;innerAmbiguityDiv.style.display='none';ambiguityDiv.appendChild(innerAmbiguityDiv);var innerAmbiguityDiv=document.createElement("div");innerAmbiguityDiv.id="secondAmbiguityDiv"+paneNumber;innerAmbiguityDiv.style.display='none';ambiguityDiv.appendChild(innerAmbiguityDiv);var resultDiv=document.createElement("div");resultDiv.id="firstResultDiv"+paneNumber;resultDiv.style.overflow="auto";document.getElementById('yp_DrivingDirections'+paneNumber).style.width="100%";paneContentDiv.appendChild(resultDiv);resultDiv=document.createElement("div");resultDiv.id="secondResultDiv"+paneNumber;paneContentDiv.appendChild(resultDiv);resultDiv=document.createElement("div");resultDiv.id="thirdResultDiv"+paneNumber;disclaimer="<div style='margin-left:15px; overflow:auto;'>"+resourceDDDisclaimer+"</div>";addDestination="<div style='font:12px Arial; margin-left:15px;'><span>"+resourceDDAddDestination+"</span><span style='left:96px;'><img id='addLocationArrow"+paneNumber+"' alt='RightArrow' src='Images/rightarrow.gif' onclick='mapManager.toggleAddLocation("+paneNumber+")'/></span></div><div id='addDestinationPanel"+paneNumber+"'><div style='font:11px Arial; margin-left:15px; margin-top:5px;'>"+resourceDDAddressPlace+"</div><form><input id='txtWaypoint"+paneNumber+"' style='margin-left:15px; float:left;' type='text' onkeydown='ExecuteFindFromInput(\"addDestinationButton\", event);' /><img id='addDestinationButton' style='margin-left:10px;' class='handicon' src='"+images+"addButton.gif' onclick='mapManager.AddWaypoint()'/></form><div style='margin-left:15px;' class='ExampleText'>"+resourceDDExampleAddress+"</div>";greyLine="<div class='grey_line_div' style='top:0px;margin-top:5px;margin-bottom:5px;' id='grey_line_div'></div>";resultDiv.innerHTML=disclaimer+greyLine+addDestination;paneContentDiv.appendChild(resultDiv);}
var validatedInputs=new Array();validatedInputs.push(validatedFirst);validatedInputs.push(validatedSecond);return validatedInputs;}
this.FindLookup=function(txtFrom,txtTo){mapManager.clearRoute();mapManager.ClearSearchRelatedShapes();var searchType=ClientCache.Retrieve('pane_'+paneNumber+'_type');ClientCache.Save('selected_pane_num',paneNumber);var searchInput=txtFrom;waypointsArray=new Array();ShowLoading();AjaxControlManager.findDisplayed(true);mapManager.FindOnMap(true,searchInput);HideLoading();}
this.FindOnMap=function(searchCanada,searchInput){if(searchInput==undefined){mapManager.onFailedSearch();return;}
var latLongLocation=false;if(this.IsLatLong(searchInput)){latLongLocation=true;}
if(searchInput.indexOf("@")!=-1){mapManager.FindCallback(null,null,this.LatLongToPlaceArray(searchInput.split("@")[1],this.PrepareForMapPointGeocoding(searchInput.split("@")[0])));}
else if(latLongLocation){mapManager.FindCallback(null,null,this.LatLongToPlaceArray(searchInput));}
else{if(ClientCache.Retrieve('pane_'+paneNumber+'_type')=='per'||ClientCache.Retrieve('pane_'+paneNumber+'_type')=='bus'){map.Find(null,this.PrepareForMapPointGeocoding(searchInput)+', Canada',null,null,null,null,null,null,false,false,mapManager.FindBusPerCallback);}else{if(searchCanada){map.Find(null,this.PrepareForMapPointGeocoding(searchInput)+', Canada',null,null,null,null,null,null,false,false,mapManager.FindInCanadaCallback);}
else{map.Find(null,this.PrepareForMapPointGeocoding(searchInput),null,null,null,null,null,null,false,false,mapManager.FindCallback);}}}}
this.FindInCanadaCallback=function(shapeLayer,findResultArray,placeArray){var numWaypoints=ClientCache.Retrieve('pane_'+paneNumber+'_NumWaypoints');var searchType=ClientCache.Retrieve('pane_'+paneNumber+'_type');if(placeArray!=null&&placeArray[0].Name!='Canada'){if(searchType=='fm'){mapManager.DisambiguateFindResults(placeArray,'FindInput','Find');HideLoading();mapManager.ReadWaypointsArray(searchType);}
else if(searchType=='dd'){if(waypointsArray.length==0){mapManager.DisambiguateFindResults(placeArray,'FromInput','From');mapManager.FindOnMap(true,ClientCache.Retrieve('pane_'+paneNumber+'_ToInput'));return;}
else if(waypointsArray.length==1){mapManager.DisambiguateFindResults(placeArray,'ToInput','To');if((waypointsArray.length-2)<numWaypoints){mapManager.FindOnMap(true,ClientCache.Retrieve('pane_'+paneNumber+'_WaypointInput'+(waypointsArray.length-2)));return;}
mapManager.ReadWaypointsArray(searchType);return;}
else{mapManager.DisambiguateFindResults(placeArray,'WaypointInput'+(waypointsArray.length-2),'Waypoint'+(waypointsArray.length-1));if((waypointsArray.length-2)<numWaypoints){mapManager.FindOnMap(true,ClientCache.Retrieve('pane_'+paneNumber+'_WaypointInput'+(waypointsArray.length-2)));return;}
mapManager.ReadWaypointsArray(searchType);return;}}
else{mapManager.FindBusPerCallback(shapeLayer,findResultArray,placeArray);}
return;}
else{var searchInput;if(searchType=='fm'){searchInput=ClientCache.Retrieve('pane_'+paneNumber+'_FindInput');mapManager.FindOnMap(false,searchInput);HideLoading();}
else if(searchType=='dd'){if(waypointsArray.length==0)
searchInput=ClientCache.Retrieve('pane_'+paneNumber+'_FromInput');else if(waypointsArray.length==1)
searchInput=ClientCache.Retrieve('pane_'+paneNumber+'_ToInput');else if((waypointsArray.length-2)<numWaypoints)
searchInput=ClientCache.Retrieve('pane_'+paneNumber+'_WaypointInput'+(waypointsArray.length-2));mapManager.FindOnMap(false,searchInput);HideLoading();}
else{searchInput=ClientCache.Retrieve('pane_'+paneNumber+'_NameInput');mapManager.FindOnMap(false,searchInput);}}}
this.onFailedSearch=function(inputType,invalidInputFieldID){ClientCache.Save('lastSearchFailed','true');var searchInputField=document.getElementById(invalidInputFieldID);document.getElementById('ErrHeaderTxt').style.visibility="visible";if(searchInputField!=undefined)
document.getElementById(invalidInputFieldID).style.border="1px solid red";var searchInput=searchInputField!=undefined?searchInputField.value:ClientCache.Retrieve('pane_'+paneNumber+'_'+inputType+'Input');search=inputType+searchInput;if(searchInput!=''&&(inputType!=null||invalidInputFieldID!=null))
YPSearchManager.HBXSearch('map',0,null,search);HideLoading();if(searchInput==undefined){var error='';var divIdPrefix='';switch(ClientCache.Retrieve('lastSearch')){case'fm':error=resourceErrorFOM;divIdPrefix='yp_FindOnMap';break;case'bus':error=resourceErrorFAB;divIdPrefix='yp_DrivingDirections';break;case'per':error=resourceErrorFAB;divIdPrefix='yp_FindBusiness';break;case'dd':error=resourceErrorGDD;divIdPrefix='yp_FindPerson';break;}
document.getElementById('ErrHeaderTxt').innerHTML=error;AjaxControlManager.setBusinessDirectionFindHeader(paneNumber,error,divIdPrefix,searchInput);document.getElementById(divIdPrefix+paneNumber).innerHTML='<div class="TopErrorText" style="visibility:visible">'+error+'</div>';}
return;}
this.FindCallback=function(shapeLayer,findResultArray,placeArray){var numWaypoints=ClientCache.Retrieve('pane_'+paneNumber+'_NumWaypoints');var searchType=ClientCache.Retrieve('pane_'+paneNumber+'_type');if(placeArray==null){mapManager.onFailedSearch('Find','txtFind');return;}
else{if(searchType=='fm'){mapManager.DisambiguateFindResults(placeArray,'FindInput','Find');mapManager.ReadWaypointsArray(searchType);}
else if(searchType=='dd'){if(waypointsArray.length==0){mapManager.DisambiguateFindResults(placeArray,'FromInput','From');mapManager.FindOnMap(true,ClientCache.Retrieve('pane_'+paneNumber+'_ToInput'));}
else if(waypointsArray.length==1){mapManager.DisambiguateFindResults(placeArray,'ToInput','To');if((waypointsArray.length-2)<numWaypoints){mapManager.FindOnMap(true,ClientCache.Retrieve('pane_'+paneNumber+'_WaypointInput'+(waypointsArray.length-2)));return;}
mapManager.ReadWaypointsArray(ClientCache.Retrieve('pane_'+paneNumber+'_type'));return;}
else{mapManager.DisambiguateFindResults(placeArray,'WaypointInput'+(waypointsArray.length-2),'Waypoint'+(waypointsArray.length)-1);if((waypointsArray.length-2)<numWaypoints){mapManager.FindOnMap(true,ClientCache.Retrieve('pane_'+paneNumber+'_WaypointInput'+(waypointsArray.length-2)));return;}
mapManager.ReadWaypointsArray(ClientCache.Retrieve('pane_'+paneNumber+'_type'));return;}}
else{mapManager.FindBusPerCallback(shapeLayer,findResultArray,placeArray);}}}
this.DisambiguateFindResults=function(placeArray,searchInputId,searchId){var search=ClientCache.Retrieve('pane_'+paneNumber+'_'+searchId);if(search!=undefined){waypointsArray.push(search);}
else{var disambiguationText=mapManager.getDisambiguationText(searchId,placeArray,ClientCache.Retrieve('pane_'+paneNumber+'_'+searchInputId));if(searchId=='Find'){findOnMapFindAmbiguity.innerHTML=disambiguationText;mapManager.resizeLeftDiv();}
else if(disambiguationText!=''){if(searchId=='From'){document.getElementById("firstAmbiguityDiv"+paneNumber).style.display='block';document.getElementById("firstAmbiguityDiv"+paneNumber).innerHTML=disambiguationText;}
else if(searchId=='To'){document.getElementById("secondAmbiguityDiv"+paneNumber).style.display='block';document.getElementById("secondAmbiguityDiv"+paneNumber).innerHTML=disambiguationText;}
else{var innerAmbiguityDiv=document.createElement("div");innerAmbiguityDiv.id="Waypoint"+(waypointsArray.length-2)+"AmbiguityDiv"+paneNumber;innerAmbiguityDiv.innerHTML=disambiguationText
document.getElementById("outerAmbiguityDiv"+paneNumber).appendChild(innerAmbiguityDiv);}}}}
this.EmulateSelectedPaneFind=function(paneClicked,first,second,sbn){HideLoading();FindNearbyClick(true);paneNumber=paneClicked;switch(ClientCache.Retrieve('pane_'+paneClicked+'_type')){case'fm':TopNav('FindMap');findOnMap=document.getElementById('yp_FindOnMap'+paneClicked);AmbiguityDiv=findOnMap.childNodes[0];findOnMapResultDiv=findOnMap.childNodes[1];first=ClientCache.Retrieve('pane_'+paneClicked+'_FindInput');second=null;center=this.Map.GetCenter();zoomLevel=this.Map.GetZoomLevel();this.Map.SetCenterAndZoom(center,zoomLevel);this.Map.SetCenterAndZoom(center,5);this.Map.SetCenterAndZoom(center,zoomLevel);break;case'bus':TopNav('FindBusiness');paneNumber=paneClicked;break;case'per':TopNav('FindPerson');paneNumber=paneClicked;break;case'dd':TopNav('DrivingDirections');drivingDirections=document.getElementById('yp_DrivingDirections'+paneNumber);AmbiguityDiv=drivingDirections.childNodes[0];drivingDirectionsFromAmbiguity=AmbiguityDiv.childNodes[0];drivingDirectionsToAmbiguity=AmbiguityDiv.childNodes[1];drivingDirectionResultDiv=drivingDirections.childNodes[1];drivingDirectionDistanceDiv=drivingDirections.childNodes[2];HideLoading();break;}
AjaxControlManager.openLeftNavPane(5);this.FindLookup(first,second);}
this.ClearFind=function(){this.clearRoute();this.ClearSearchRelatedShapes();document.getElementById('txtFind').value='';document.getElementById('txtBusLocation').value='';document.getElementById('txtBusName').value='';document.getElementById('txtPersonLocation').value='';document.getElementById('txtPersonName').value='';document.getElementById('txtFrom').value='';document.getElementById('txtTo').value='';}
this.CategorySearch=function()
{document.getElementById('txtBusName').value=document.getElementById('txtCategorySearch').value;var center=mapManager.Map.GetCenter();document.getElementById('txtBusLocation').value=(Math.round(center.Latitude*100)/100)+', '+(Math.round(center.Longitude*100)/100);TopNav("FindBusiness");this.SetCategorySearch(true);this.NewFindBusiness(true);}
this.FindBusPerCallback=function(shapeLayer,findResultArray,placeArray){if(placeArray){if(placeArray.length>0)
YPSearchManager.Search(ClientCache.Retrieve('lastSearch'),false,placeArray);}
else{YPSearchManager.Search(ClientCache.Retrieve('lastSearch'));}
findBusinessResultsPaneNumber=-1;}
this.clearRoute=function()
{var map=mapManager.Map;var shapeLayerCount=map.GetShapeLayerCount();map.DeleteRoute();for(var i=0;i<shapeLayerCount;i++)
{var shapeLayer=map.GetShapeLayerByIndex(i);if(shapeLayer==null)
{break;}
var shapeCount=shapeLayer.GetShapeCount();for(var j=0;j<shapeCount;j++)
{var shape=shapeLayer.GetShapeByIndex(j);var icon=shape.GetCustomIcon();if(!(typeof icon=="string")){break;}
else if(icon.search('A_Icon.gif')>0)
{map.DeleteShapeLayer(shapeLayer);break;}}}}
this.SwitchDirections=function()
{var txtFrom=document.getElementById('txtFrom').value;document.getElementById('txtFrom').value=document.getElementById('txtTo').value
document.getElementById('txtTo').value=txtFrom;}
this.getDisambiguationText=function(id,placeArray,input){var name;var postal;var lat;var lon;var display='block';var ambiguationText="";var index=0;var ambiguityArray=new Array;var ambiguityTextArray=new Array;for(var i=0;i<placeArray.length;i++){ambiguityArray[i]=new Array;name=placeArray[i].Name;if(name.match((/([a-zA-Z][0-9][a-zA-Z])(\s*[0-9][a-zA-Z][0-9])?/))||name.match(/,\s(AB|BC|MB|NB|NL|NS|NT|NU|ON|PE|QC|SK|YT)/)){index=placeArray[i].MatchConfidence<placeArray[index].MatchConfidence?i:index;}
ambiguityTextArray.push(name+";"+"new VELatLong("+placeArray[i].LatLong.Latitude+","+placeArray[i].LatLong.Longitude+")',\'"+id+"\');\">"+name);}
if(ambiguityArray.length>1){ambiguationText+="<span class='DisambiguationText'>"+resourceYourSearchOf+" </span><span class='DisambiguationLocation'>"+input+"</span>";if(ambiguityArray.length>3){display='none';ambiguationText+='returned multiple results <a id="'+id+'AmbiguationExpand" style="cursor:pointer" onclick="mapManager.changeDisplay(\''+id+paneNumber+'AmbiguationTable\');">+</a>';}else ambiguationText+="<span class='DisambiguationText'> "+resourceReturnedMultiple+":"+"</span>";ambiguationText+="<table id='"+id+paneNumber+"AmbiguationTable' style='display:"+display+"'><tr><td><div class='handicon locationunderlined' onclick=\"mapManager.disambiguateWaypoint('"+placeArray[index].Name+"','"+ambiguityTextArray.join("</div><div class='handicon locationunderlined' onclick=\"mapManager.disambiguateWaypoint('"+placeArray[index].Name+"','")+"</div></td></tr></table>";ambiguationText+="<div class='lines'></div>";}
var defaultLocation=placeArray[index].Name+";"+"new VELatLong("+placeArray[index].LatLong.Latitude+","+placeArray[index].LatLong.Longitude+")";waypointsArray.push(defaultLocation);ClientCache.Save('pane_'+paneNumber+'_'+id,defaultLocation);return ambiguationText;}
this.disambiguateWaypoint=function(toRemoveName,toAdd,id){var waypoint;var waypointName;var index=0;for(var i=0;i<waypointsArray.length;i++){waypoint=waypointsArray[i].split(';');waypointName=waypoint[0];if(waypointName==toRemoveName){waypointsArray[i]=toAdd;index=i;break;}}
if(ClientCache.Retrieve('pane_'+paneNumber+'_type')=='dd')
AmbiguityDiv=document.getElementById('outerAmbiguityDiv'+paneNumber);var ambiguationDivs=AmbiguityDiv.childNodes;ambiguationDivs[index].innerHTML="";ambiguationDivs[index].style.display="none";if(toRemoveName!=toAdd){ClientCache.Save('pane_'+paneNumber+'_'+id,waypointsArray[index]);if(waypointsArray.length>1){this.ReadWaypointsArray('dd');}
else{ClientCache.Save('lastSearchFailed','true');this.PrepareForFindLookup(false,'fm',this.extractPlaceValues(false,0),null);ClientCache.Save('lastSearchFailed','false');mapManager.ClearSearchRelatedShapes();this.ReadWaypointsArray('fm');ClientCache.Save('selected_pane_num',paneNumber);}}}
this.ClearSearchRelatedShapes=function(){mapManager.Map.DeleteAllShapes();POIManager.HidePOIs();}
this.ReadWaypointsArray=function(type){ShowLoading();var waypointsLLArray=new Array();for(var i=0;i<waypointsArray.length;i++){waypointsLLArray.push(eval(this.extractPlaceValues(true,i)));}
if(type=='dd'){var options=new VERouteOptions();options.RouteColor=new VEColor(0,73,134,0.5);options.RouteWeight=6;options.RouteCallback=this.onGotRoute;options.ShowDisambiguation=false;options.ShowErrorMessages=false;options.DistanceUnit=VERouteDistanceUnit.Kilometer;map.GetDirections(waypointsLLArray,options);var query=YPSearchManager.CreateSearchQuery('route',null,null,null,ClientCache.Retrieve('pane_'+paneNumber+'_FromInput'),ClientCache.Retrieve('pane_'+paneNumber+'_ToInput'));YPSearchManager.PersistQuery(query,'route');var origin=ClientCache.Retrieve('pane_'+paneNumber+'_FromInput');var destination=ClientCache.Retrieve('pane_'+paneNumber+'_ToInput');ClientCache.Save('origin',origin);ClientCache.Save('destination',destination);ClientCache.Save('lastSearch','dd');YPSearchManager.HBXSearch('directions',1,null,"From "+origin+" To "+destination);}
else{waypoint=waypointsArray[0].split(';');var waypointName=waypoint[0];var waypointVELatLon=waypoint[1].split('(');var waypointLatLon=waypointVELatLon[1].split(',');var waypointLat=waypointLatLon[0];var waypointLon=waypointLatLon[1].substring(0,waypointLatLon[1].length-1);YPSearchManager.includePlaces(this.LatLongToPlaceArray(waypointLat+','+waypointLon,waypoint[0]));this.findOnMap(0,waypointName,waypointLat,waypointLon);var query=YPSearchManager.CreateSearchQuery('map',null,waypointName,new VELatLong(waypointLat,waypointLon),null,null);YPSearchManager.PersistQuery(query,'map');POIManager.RefreshPOIs();var location=document.getElementById('txtFind').value;ClientCache.Save('location',location);ClientCache.Save('lastSearch','fm');YPSearchManager.HBXSearch('map',1,null,location);}
mapManager.resizeLeftDiv();}
this.extractPlaceValues=function(getLatLong,index){var itemArray=waypointsArray[index].split(';');if(getLatLong){return itemArray[1];}
else{return itemArray[0];}}
this.changeDisplay=function(id){var element=document.getElementById(id);var display=element.style.display;if(display=='block')
element.style.display='none';else
element.style.display='block';}
this.findOnMap=function(index,location,latitude,longitude){ShowLoading();var divHeight="170px";var topMargin="8px";var dartImg="dartblue.gif";var description='<div style="height: '+divHeight+';margin-top:'+topMargin+';"><div class="popupTop"><div class="popupTopLeft"><div style="display:block; margin-top:5px; margin-bottom:5px;"><img src="Images/dartblue.gif"></img></div><div style="font-weight: bold; font: 12px/14px Arial;"><strong>'+location+'</strong></div></div><div class="popupTopRight"><div id=\"AL_ACTION_'+index+'\" class="popupActionArea" style="top:10px;"><div id=\"AL_EMPTY_'+index+'\" style="height:130px; width:100px;"></div><div id=\"AL_TO_'+index+'\" style="height:130px; display:none; margin-left:5px;"><div class="popupHeader"><strong>'+resourceDD+':</strong></div><br/><div><img src="Images/tohereicon.gif">'+resourceToHere+':</img></div><input type="text" id="l_toAddress'+index+'" style="width:158px;" onkeydown="ExecuteFindFromInput(\'l_imgTo'+(index)+'\', event);"/><br/><div class="popupLink" onclick="YPSearchManager.ShowActionDiv(\'AL_\', '+index+', \'FROM\');">'+resourceFromHere+'<img src="images/fromhereicon.gif"></div><div><img id="l_imgTo'+index+'" src="'+images+'GetDD.gif" class="popupLink" style="left:100px; float: right;" onclick="YPSearchManager.GDDForLocationPopup(\'TO\');" /></div></div><div id=\"AL_FROM_'+index+'\" style="height:130px; display:none; margin-left:5px;"><div class="popupHeader"><strong>'+resourceDD+': </strong></div><br/><div><img src="Images/fromhereicon.gif">'+resourceFromHere+':</img></div><input type="text" id="l_fromAddress'+index+'" style="width:158px;" onkeydown="ExecuteFindFromInput(\'l_imgFrom'+(index)+'\', event);"/><br/><div class="popupLink" onclick="YPSearchManager.ShowActionDiv(\'AL_\', '+(index)+', \'TO\');">'+resourceToHere+'<img src="images/tohereicon.gif"></div><div><img id="l_imgFrom'+(index)+'" src="'+images+'GetDD.gif" class="popupLink" style="left:100px; float: right;" onclick="YPSearchManager.GDDForLocationPopup(\'FROM\');"/></div></div><div id=\"AL_NEAR_'+index+'\" style="height:130px;display:none;"><div class="popupHeader"><strong>'+resourceWhatsNearby+': </strong></div><br/><div class="popupSubheader">'+resourceSearchForCategory+':<br/></div><input type="text" id="l_nearby'+index+'" style="width:158px;" onkeydown="ExecuteFindFromInput(\'l_imgNear'+(index)+'\', event);"/><br/><div style="float:left; width:110px">'+resourceWhatsNearbyExample+'</div><div><img id="l_imgNear'+(index)+'" src="'+images+'GetDD.gif" class="popupLink" style="margin-top:11px; left:100px; float: right;" onclick="YPSearchManager.GNBForLocationPopup();"/></div></div><div id=\"AL_MAP_'+index+'\" style="height:130px;display:none;"><div id=\"AL_MAP_SAVE_'+index+'\" style="display:none"><div style="float:left;"><div class="popupHeader" style="width:110px"><strong>'+resourceSaveToAMap+': </strong></div><br /><div style="width:110px">'+resourceSaveToAMapPrompt+'</div></div><div><img src="Images/'+dartImg+'" class="popupLink" style="margin-right:10px; margin-top:10px; float: right; border: 1px solid black;" /></div><div style="margin-top:10px;"><select id="mapSelect" style="width:158px;""></select><br/></div><div><img id="l_imgAdd'+(index)+'" src="'+images+'doneButton.gif" class="popupLink" style="left:100px; float: right;" onclick="YPSearchManager.SaveLocationToCustomMap();"/></div></div><div id=\"AL_MAP_WARN_'+index+'\" style="float:left;display:none"><div class="popupHeader" style="width:110px"><strong>'+resourceSaveToAMap+': </strong></div><br /><div style="width:180px">'+resourceLoginNeeded+'</div></div></div></div></div></div><div class="popupBottom"><table><tr><td><table><td><img src="images/drivingicon.gif" align="left" style="margin-right:3px;margin-left:3px"></img></td><td>'+resourceDD.toUpperCase()+'<div></div><span class="popupLink popupDrivingFunctionTo" onclick="YPSearchManager.ShowActionDiv(\'AL_\', '+(index)+', \'TO\');"><img src="images/tohereicon.gif"><span>'+resourceToHere.toUpperCase()+'</span></img></span><span> | </span><span class="popupLink popupDrivingFunctionFrom" onclick="YPSearchManager.ShowActionDiv(\'AL_\', '+(index)+', \'FROM\');"><img src="images/fromhereicon.gif"><span>'+resourceFromHere.toUpperCase()+'</span></img></span></td><td style="width:60px;margin-right:3px;"><span class="popupLink" onclick="YPSearchManager.ShowActionDiv(\'AL_\', '+(index)+', \'NEAR\');"><img src="images/nearbyicon.gif" align="left" style="margin-right:3px"></img><span class="popupLink">'+resourceWhatsNearby.toUpperCase()+'</div></span></td><td style="margin-right:3px; width:70px;"><span class="popupLink" onclick="YPSearchManager.ShowActionDiv(\'AL_\', '+(index)+', \'MAP\');"><img src="images/savemapicon.gif" align="left" style="margin-right:3px;margin-left:3px"></img>'+resourceAddToAMap.toUpperCase()+'</span></td></tr></table></div></div>';description='(S)'+description;var shape=new VEShape(VEShapeType.Pushpin,new VELatLong(latitude,longitude));shape.SetTitle("");shape.SetDescription('fom||'+index);shape.SetCustomIcon("<div class='pin_blue'></div>");map.AddShape(shape);InfoBoxManager.StoreDescription('fom',index,description);this.ZoomToLocation(location,latitude,longitude);HideLoading();}
this.ZoomToLocation=function(name,latitude,longitude)
{var numSpaces=name.match(/\s/g);var zoomFactor=numSpaces!=null?numSpaces.length:0;var latLon=new VELatLong(latitude,longitude);map.SetCenterAndZoom(latLon,12+zoomFactor);}
this.onGotRoute=function(route){if(route.RouteLegs.length==0){document.getElementById('ErrHeaderTxt').innerHTML=resourceDDGenerateError;document.getElementById('ErrHeaderTxt').style.visibility="visible";document.getElementById('txtFrom').style.border="1px solid red";document.getElementById('txtTo').style.border="1px solid red";HideLoading();YPSearchManager.HBXSearch('directions',0,null,"From "+document.getElementById('txtFrom').value+" To "+document.getElementById('txtTo').value);return;}
document.getElementById('ErrHeaderTxt').style.visibility="hidden";document.getElementById('txtFind').style.border="1px solid black";ShowLoading();mapManager.ClearSearchRelatedShapes();var legs=route.RouteLegs;var numTurns=0;var leg=null;var shape=null;var wayPointCount=0;var legsArray=new Array;var prevPrevLatLons=legs[0].Itinerary.Items[0].LatLong;var prevLatLons=legs[0].Itinerary.Items[0].LatLong;var curLatLons=legs[0].Itinerary.Items[0].LatLong;var nextLatLons=legs[0].Itinerary.Items[0].LatLong;var nextNextLatLons=legs[0].Itinerary.Items[1].LatLong;var prevShape=new VEShape(VEShapeType.Pushpin,prevLatLons);var curShape;var nextShape=new VEShape(VEShapeType.Pushpin,nextLatLons);var shapeIds=new Array();var prevPrevText="";var prevText="";var curText=legs[0].Itinerary.Items[0].Text;var nextText=legs[0].Itinerary.Items[0].Text;var prevStep=resourceStart;var curStep=resourceStart;var nextStep="";var prevDist="";var curDist=legs[0].Itinerary.Items[0].Distance;var nextDist=legs[0].Itinerary.Items[0].Distance;var totalDist=0;var prevTime="";var curTime=legs[0].Itinerary.Items[0].Time;var nextTime=legs[0].Itinerary.Items[0].Time;var totalTime=0;for(var i=0;i<legs.length;i++){leg=legs[i];curLatLons=nextLatLons;curShape=nextShape;nextLatLons=nextNextLatLons;nextShape=new VEShape(VEShapeType.Pushpin,nextLatLons);nextText=leg.Itinerary.Items[1].Text;nextStep=resourceStep+" "+(numTurns+1);nextDist=leg.Itinerary.Items[1].Distance;nextTime=leg.Itinerary.Items[1].Time;if(leg.Itinerary.Items.length>=3){nextNextLatLons=leg.Itinerary.Items[2].LatLong;}
else if(leg.Itinerary.Items.length==2){if(i<legs.length-1)
nextNextLatLons=legs[i+1].Itinerary.Items[0].LatLong;else
nextStep=resourceFinalDestination;}
else{if(i==(legs.length-1)){nextStep=resourceFinalDestination;}
else{nextText=legs[i+1].Itinerary.Items[0].Text;nextStep=resourceStep+" &#"+(i+66)+";";nextNextLatLons=legs[i+1].Itinerary.Items[1].LatLong;}}
var latLons=curLatLons+","+prevLatLons;var shapeCustomIconImage="Images/GreyIcons/"+iconArray[incrementWayPointCount(i)]+".gif";var shapeDescriptionTitle=prevText;var shapeDescriptionItems=new Array();var shapeDescriptionCurrentItemTopRow="<tr class='DDEroTextCurrentSeperator DDEroTextSeperatorCurrentTop DDEroTextCurrent'><td></td><td></td><td class='popupLink DDEroUpArrow' onclick='mapManager.ShowInfoBoxp;'></td></tr>";var wayPointLinks=new Array();var waypointType='(DDI)';shapeDescriptionItems.push("<tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr>"+"<tr class='DDEroTextPrevious'><td class='DDEroTextStepNum'>"+prevStep+"</td><td class='DDEroTextStepText'>"+prevText+"</td><td class='waypointDescriptionDistance'>"+mapManager.getDistTime(prevDist,prevTime)+"</td></tr>"+"<tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr>");wayPointLinks.push(prevLatLons+","+prevPrevLatLons+","+curLatLons+");'>prev");if(i==0){shapeCustomIconImage="Images/A_Icon.gif";mapManager.extractPlaceValues(false,0);latLons=curLatLons;shapeDescriptionTitle=resourceStart;shapeDescriptionItems.pop();wayPointLinks.pop();curText=mapManager.extractPlaceValues(false,i);shapeDescriptionCurrentItemTopRow="<tr class='DDEroTextSeperator DDEroTextSeperatorCurrentTop DDEroTextCurrent'><td></td><td></td><td></td></tr>";waypointType='(DDF)';}
shapeDescriptionItems.push(shapeDescriptionCurrentItemTopRow+"<tr class='DDEroTextCurrent DDEroTextStepText'><td class='DDEroTextStepNum DDEroTextStepNumSelected'>"+curStep+"</td><td class='DDEroTextStepText'>"+curText+"</td><td></td></tr>"+"<tr class='DDEroTextCurrentSeperator DDEroTextSeperatorCurrentBottom DDEroTextCurrent'><td></td><td></td><td class='popupLink DDEroDownArrow' onclick='mapManager.ShowInfoBoxn;'></td></tr>");wayPointLinks.push(curLatLons+","+prevLatLons+","+nextLatLons+");'>zoom in");shapeDescriptionItems.push("<tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr>"+"<tr class='DDEroTextNext'><td class='DDEroTextStepNum'>"+nextStep+"</td><td class='DDEroTextStepText'>"+nextText+"</td><td class='waypointDescriptionDistance'>+"+mapManager.getDistTime(nextDist,nextTime)+"</td></tr>"+"<tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr>");wayPointLinks.push(nextLatLons+","+prevLatLons+","+nextNextLatLons+");'>next");latLons+=","+nextLatLons;legsArray.push("<table class='directionsList' id='leg_"+i+"_title'><tr><td onclick='mapManager.CenterAndZoom("+latLons+")'><div class='drivingDirectionsWaypointIcon drivingDirectionsWaypointListIcon' style='background-image:url(\""+shapeCustomIconImage+"\")'><b></b></div></td><td style='width:10px'></td><td><div class='drivingDirectionsListDetails'>"+curText+(i!=0?"</div><div>"+mapManager.getDistTime(totalDist,totalTime):'')+"</div></td><td><a id='waypoint_"+i+"_Expand' style='cursor:pointer' onclick='mapManager.changeDisplay(\"leg_"+i+"_table\");'>+</a></td></tr></table><table style='display:block' class='directionsList' id='leg_"+i+"_table'>");shape=curShape;shape.SetDescription(waypointType+"<table id='turnpoint"+numTurns+"_table' class='DDEroText'>"+
shapeDescriptionItems.join("")+"<tr style='height:14px; background:#66676a'><td></td><td></td><td></td></tr>"+"</table>");shape.SetCustomIcon("<div class='drivingDirectionsWaypointMapIcon drivingDirectionsWaypointIcon' style='background-image:url(\""+shapeCustomIconImage+"\")'></div>");map.AddShape(shape);shapeIds.push(shape.GetID());for(var k=1;k<leg.Itinerary.Items.length-1;k++){numTurns++;prevPrevLatLons=prevLatLons;prevLatLons=curLatLons;prevShape=curShape;curLatLons=nextLatLons;curShape=nextShape;nextLatLons=nextNextLatLons;nextShape=new VEShape(VEShapeType.Pushpin,nextLatLons);prevStep=curStep;curStep=nextStep;nextStep=resourceStep+" "+(numTurns+1);prevDist=curDist;curDist=nextDist;nextDist=leg.Itinerary.Items[k+1].Distance;prevTime=curTime;curTime=nextTime;nextTime=leg.Itinerary.Items[k+1].Time;prevText=curText;curText=nextText;nextText=leg.Itinerary.Items[k+1].Text;if((k+1)==(leg.Itinerary.Items.length-1)){if(i<(legs.length-1)){nextText=legs[i+1].Itinerary.Items[0].Text;nextStep=resourceStep+" &#"+(i+66)+";";}
else{nextStep=resourceFinalDestination;}}
if(leg.Itinerary.Items.length>=k+3)
nextNextLatLons=leg.Itinerary.Items[k+2].LatLong;else{if(i<legs.length-1)
nextNextLatLons=legs[i+1].Itinerary.Items[1].LatLong;}
shapeDescriptionItems=new Array();wayPointLinks=new Array();shapeDescriptionItems.push("<td class='DDEroTextStepNum'>"+prevStep+"</td><td class='DDEroTextStepText'>"+prevText+"</td><td class='waypointDescriptionDistance'>"+mapManager.getDistTime(prevDist,prevTime)+"</td>");shapeDescriptionItems.push("<td class='DDEroTextStepNum DDEroTextStepNumSelected'>"+curStep+"</td><td class='DDEroTextStepText'>"+curText+"</td><td></td>");shapeDescriptionItems.push("<td class='DDEroTextStepNum'>"+nextStep+"</td><td class='DDEroTextStepText'>"+nextText+"</td><td class='waypointDescriptionDistance'>+"+mapManager.getDistTime(nextDist,nextTime)+"</td>");wayPointLinks.push(prevLatLons+","+prevPrevLatLons+","+curLatLons+");'>prev");wayPointLinks.push(curLatLons+","+prevLatLons+","+nextLatLons+");'>zoom in");wayPointLinks.push(nextLatLons+","+prevLatLons+","+nextNextLatLons+");'>next");legsArray.push("<tr><td style='width:27px' onclick='mapManager.CenterAndZoom("+curLatLons+","+prevLatLons+","+nextLatLons+")'><div class='drivingDirectionsTurnIcon drivingDirectionsTurnListIcon' style='background-image:url(\"Images/turnpointPushpin.png\")'><div class='drivingDirectionsTurnIconText'>"+numTurns+"</div></div></td><td style='width:10px'></td><td><div class='drivingDirectionsListDetails'><span>"+leg.Itinerary.Items[k].Text+"</span></div></td></tr>");shape=curShape;shape.SetDescription("(DDI)<table id='turnpoint"+numTurns+"_table' class='DDEroText'><tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr><tr class='DDEroTextPrevious'>"+shapeDescriptionItems[0]+"</tr><tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr><tr class='DDEroTextCurrentSeperator DDEroTextSeperatorCurrentTop DDEroTextCurrent'><td></td><td></td><td class='popupLink DDEroUpArrow' onclick='mapManager.ShowInfoBoxp;'></td></tr><tr class='DDEroTextCurrent DDEroTextStepText'>"+shapeDescriptionItems[1]+"</tr><tr class='DDEroTextCurrentSeperator DDEroTextSeperatorCurrentBottom DDEroTextCurrent'><td></td><td></td><td class='popupLink DDEroDownArrow' onclick='mapManager.ShowInfoBoxn;'></td></tr><tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr><tr class='DDEroTextNext'>"+shapeDescriptionItems[2]+"</tr><tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr><tr style='height:14px; background:#66676a'><td></td><td></td><td></td></tr></table>");shape.SetCustomIcon("<div class='drivingDirectionsTurnMapIcon drivingDirectionsTurnIcon' style='background-image:url(\"Images/turnpointPushpin.png\")'><div class='drivingDirectionsTurnIconText'>"+numTurns+"</div></div>");map.AddShape(shape);shapeIds.push(shape.GetID());}
prevPrevLatLons=prevLatLons;prevLatLons=curLatLons;prevShape=curShape;prevPrevText=prevText;prevText=curText;curText=nextText;prevStep=curStep;curStep=nextStep;curDist=nextDist;curTime=legs[0].Itinerary.Items[0].Time;totalDist+=leg.Distance;totalTime+=leg.Time;legsArray.push("</table>");}
curLatLons=nextLatLons;curShape=nextShape;curText=nextText;curStep=nextStep;var shapeDescriptionItems=new Array();var wayPointLinks=new Array();shapeDescriptionItems.push("<td class='DDEroTextStepNum'>"+prevStep+"</td><td class='DDEroTextStepText'>"+prevText+"</td><td class='waypointDescriptionDistance'>"+mapManager.getDistTime(prevDist,prevTime)+"</td>");shapeDescriptionItems.push("<td class='DDEroTextStepNum DDEroTextStepNumSelected'>"+resourceFinalDestination+"</td><td class='DDEroTextStepText'>"+curText+"</td><td></td>");legsArray.push("<table class='directionsList' id='last_waypoint'><tr><td onclick='mapManager.CenterAndZoom("+curLatLons+","+prevLatLons+")'><div class='drivingDirectionsWaypointIcon drivingDirectionsWaypointListIcon' style='background-image:url(\"Images/GreenIcons/"+iconArray[legs.length]+".gif\")'><b></b></div></td><td style='width:10px'></td><td><div class='drivingDirectionsListDetails'>"+mapManager.extractPlaceValues(false,waypointsArray.length-1)+"</div><div>"+mapManager.getDistTime(totalDist,totalTime)+"</div></td></tr>");shape=curShape;shape.SetDescription("(DDL)<table id='turnpoint"+numTurns+"_table' class='DDEroText'><tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr><tr class='DDEroTextPrevious'>"+shapeDescriptionItems[0]+"</tr><tr class='DDEroTextSeperator'><td></td><td></td><td></td></tr><tr class='DDEroTextCurrentSeperator DDEroTextSeperatorCurrentTop DDEroTextCurrent'><td></td><td></td><td class='popupLink DDEroUpArrow' onclick='mapManager.ShowInfoBoxp;'></td></tr><tr class='DDEroTextCurrent DDEroTextStepText'>"+shapeDescriptionItems[1]+"</tr><tr class='DDEroTextSeperator DDEroTextSeperatorCurrentBottom DDEroTextCurrent'><td></td><td></td><td></td></tr><tr style='height:14px; background:#66676a'><td></td><td></td><td></td></tr></table>");shape.SetCustomIcon("<div class='drivingDirectionsWaypointMapIcon drivingDirectionsWaypointIcon' style='background-image:url(\"Images/GreenIcons/"+iconArray[legs.length]+".gif\")'></div>");map.AddShape(shape);shapeIds.push(shape.GetID());ClientCache.Save('pane_'+paneNumber+'_turnpointIds',shapeIds.join('|'));document.getElementById("firstResultDiv"+paneNumber).innerHTML=legsArray.join("");mapManager.resizeLeftDiv();POIManager.RefreshPOIs();HideLoading();}
this.CenterAndZoom=function(centerLat,centerLon,secondLat,secondLon,thirdLat,thirdLon){var includePredAndSuc=false;var latLon=new VELatLong(centerLat,centerLon);map.SetCenterAndZoom(latLon,15);if(includePredAndSuc){if(!(typeof secondLat=="undefined")){latLon=new VELatLong(secondLat,secondLon);map.IncludePointInView(latLon);}
if(!(typeof thirdLat=="undefined")){latLon=new VELatLong(thirdLat,thirdLon);map.IncludePointInView(latLon);}
if(map.GetZoomLevel()<18){map.SetCenterAndZoom(latLon,15);}}}
this.ShowInfoBox=function(shapeID){nextEro=new PushpinERO(shapeID,map);nextEro.Show();}
this.getDistTime=function(dist,time){var dist=Math.round(dist*10)/10+" km";var time="("+Math.round(time/60)+" min)";return dist+'<div>'+time+'</div>';}
function incrementWayPointCount(wayPointCount)
{if(wayPointCount==25)
return wayPointCount;else
return wayPointCount+1;}
this.toggleAddLocation=function(index)
{var addLocationElement=document.getElementById("addDestinationPanel"+index);var addLocationArrow=document.getElementById("addLocationArrow"+index);if(addLocationElement.style.display=="none")
{addLocationElement.style.display="block";addLocationArrow.src="Images/downarrow.gif";}
else
{addLocationElement.style.display="none";addLocationArrow.src="Images/rightarrow.gif";}}
this.MapResize=function(){MapControl.Features.ScaleBarKilometers=true;OldMapCenter=map.GetCenter();OldMapZoomLevel=map.GetZoomLevel();if(onPanEnd==false){closeMiniDisplay=document.getElementById('CloseMini').style.display;openMiniDisplay=document.getElementById('ClosePanel').style.display;closePanelDisplay=document.getElementById('OpenMini').style.display;onPanEnd=true;}
var mapWidthHeight=mapManager.GetMapWidthHeight();var mapWidth=mapWidthHeight[0];var mapHeight=mapWidthHeight[1]-(document.getElementById('PanelWhatsNearby').style.display=="none"?(browserManager.BrowserName=='msie'?(0-6):0):(browserManager.BrowserName=='msie'?79:79));map.Resize(parseInt(mapWidth),mapHeight);map.SetCenterAndZoom(OldMapCenter,OldMapZoomLevel);browserManager.GetWindowHeight();}
this.OnMapResize=function(e){map.HideMiniMap();setTimeout(function(){document.getElementById('OpenMini').style.display=closePanelDisplay;document.getElementById('CloseMini').style.display=closeMiniDisplay;document.getElementById('ClosePanel').style.display=openMiniDisplay;onPanEnd=false;document.getElementById('OpenMini').style.left=map.GetLeft()+map.GetWidth()-105+"px";document.getElementById('navcontrol').style.top=map.GetTop()+"px";document.getElementById('CloseMini').style.left=map.GetLeft()+map.GetWidth()-152+"px";if(document.getElementById('CloseMini').style.display=="none"){if(images=="Images/"){document.getElementById('ClosePanel').style.left=map.GetLeft()+map.GetWidth()-161+"px";}
else{document.getElementById('ClosePanel').style.left=map.GetLeft()+map.GetWidth()-181+"px";}}
else{map.ShowMiniMap(map.GetWidth()-154,0);document.getElementById('ClosePanel').style.left=map.GetLeft()+map.GetWidth()-209+"px";}
mapManager.resizeLeftDiv();document.getElementById('footerdiv').style.top=document.getElementById(mapElement).offsetHeight+152-(document.getElementById('PanelWhatsNearby').style.display=="none"?78:0)+"px";document.getElementById('div_traffic_branding').style.top=document.getElementById(mapElement).offsetHeight+152-(document.getElementById('PanelWhatsNearby').style.display=="none"?78:0)+"px";document.getElementById('div_traffic_branding').style.left=map.GetWidth()-(browserManager.BrowserName=='msie'?712:710)+'px';},300);}
this.resizeLeftDiv=function(){if(paneNumber!=-1){var numPanes=AjaxControlManager.getNextPaneNumber();var headerHeightSum=(browserManager.BrowserName=='msie'?39:(browserManager.BrowserName=='safari'?17:10));for(var i=0;i<numPanes;i++){headerHeightSum+=document.getElementById('header'+i).offsetHeight;}
if(numPanes==1&&browserManager.BrowserName=='msie')
headerHeightSum+=15;if(ClientCache.Retrieve('pane_'+paneNumber+'_type')=='per'||ClientCache.Retrieve('pane_'+paneNumber+'_type')=='bus'){document.getElementById("content"+paneNumber).style.height=document.getElementById(mapElement).offsetHeight-15-(browserManager.BrowserName=='msie'?118:(browserManager.BrowserName=='safari'?157:65))-headerHeightSum+(document.getElementById('PanelWhatsNearby').style.display=="none"?0:67)+"px";}
else if(ClientCache.Retrieve('pane_'+paneNumber+'_type')=='dd'){document.getElementById("content"+paneNumber).style.height=document.getElementById(mapElement).offsetHeight+7-headerHeightSum-(document.getElementById('PanelWhatsNearby').style.display=="none"?(browserManager.BrowserName=='msie'?120:80):0)+"px";document.getElementById('yp_DrivingDirections'+paneNumber).style.width='93%';}
else{document.getElementById("yp_FindOnMap"+paneNumber).style.height=document.getElementById(mapElement).offsetHeight+5+(browserManager.BrowserName=='msie'?38:(browserManager.BrowserName=='safari'?16:8))-headerHeightSum-(document.getElementById('PanelWhatsNearby').style.display=="none"?80:0)+"px";document.getElementById("firstResultDiv"+paneNumber).style.width="100%";document.getElementById("firstResultDiv"+paneNumber).style.overflow="hidden";}}}
this.updateClientCacheCenter=function(e){var center=map.GetCenter();ClientCache.Save('center',center.Latitude+'|'+center.Longitude);}
this.updateClientCacheZoom=function(e){var center=map.GetCenter();ClientCache.Save('center',center.Latitude+'|'+center.Longitude);ClientCache.Save('zoom',map.GetZoomLevel());}
this.updateClientCacheStyle=function(e){ClientCache.Save('style',map.GetMapStyle());}
this.GetTrafficToronto=function(){map.SetCenterAndZoom(new VELatLong(43.673334930320145,-79.420166015625),11);ToggleTraffic();if(document.getElementById('PanelWhatsNearby').style.display=="none")
{FindNearbyShow();ShowTrafficTab();}}
this.IsLatLong=function(input)
{var result=false;if(/^[-]?[\d]{1,3}[\.]?[\d]*[,][\s]?[-]?[\d]{1,3}[\.]?[\d]*$/.test(input))
{var coords=input.replace(/[\s]/g,"").split(',');if(coords.length==2)
{var lat=coords[0];var lon=coords[1];if(lat>=-90&&lat<=90&&lon>=-180&&lon<=180)
{result=true;}}}
return result;}
this.LatLongToPlaceArray=function(input,placeName){var latLong=null;var result=null;if(typeof(input)=="string"){var coords=input.replace(/[\s]/g,"").split(',');latLong=new VELatLong(coords[0],coords[1]);}
else if(typeof(input)=="object"){latLong=input;}
if(latLong!=null){if(placeName==null){result=new Array(new VEPlace(latLong.toString(),latLong,null,0,0,1));}
else{result=new Array(new VEPlace(placeName,latLong,null,0,0,1));}}
return result;}}