﻿var map=null;var mapElement=null;var mapDirElement=null;var mapErrorElement=null;var icon='<div style="position:relative; top:-28px;"><img src="'+cdnURL+'/StoreLoc/081118_CWC_marker.gif" /></div>';var useLatLong=false;var storeLat="";var storeLong="";var eAddressLine="";var eStoreName="";var storeDescription="";var fromAddress="";var mapScripts;function SetMapVariables(f,q,o,a,g,h){var e=(o.indexOf("#")>0)?o.replace(o.substring(o.indexOf("#"),o.length),""):o;e=e.replace(/^\s*/,"").replace(/\s*$/,"").replace(/,$/,"").replace(/\s*$/,"");var i=document.getElementById("myMap");var k=document.getElementById("mapDirs");var b=document.getElementById("mapDirs");var m=false;var l="";var c="";switch(f){case 108:m=true;l="33.56162711864402";c="-117.66891358024625";break;case 340:m=true;l="47.04451405870334";c="-122.92682468891145";break;case 445:m=true;l="28.185669491525367";c="-82.35362962962897";break;case 447:m=true;l="38.292198";c="-77.509448";break;case 462:m=true;l="33.131833";c="-96.65397";break;case 466:m=true;l="26.2529";c="-81.7992";break;case 484:m=true;l="33.678046";c="-111.964508";break;case 9139:m=true;l="39.20612027345347";c="-81.52726113796236";break;default:break}var j=e+", "+h;var n=q;var d='<span class="pushPinDesc">'+e+"<br />"+a+", "+g+"&#160;&#160;"+h+"</span>";var p=document.getElementById("myMap");SetVariablesAndRun(i,k,b,m,l,c,j,n,d)}function SetVariablesAndRun(c,b,h,g,i,e,d,f,a){mapElement=c;mapDirElement=b;mapErrorElement=h;useLatLong=g;storeLat=i;storeLong=e;eAddressLine=d;eStoreName=f;storeDescription=a;GetMap()}function GetMap(){map=new VEMap("myMap");map.SetDashboardSize(VEDashboardSize.Small);map.LoadMap();try{if(useLatLong){var a=new VELatLong(storeLat,storeLong);SetPinAndZoom(a)}else{map.Find(null,eAddressLine,null,null,null,null,null,null,null,null,Find_Callback)}}catch(b){OnCatchError(b.message,"There was an error initializing the map.")}}function Find_Callback(a,b,d,c,e){SetPinAndZoom(map.GetCenter())}function SetPinAndZoom(b){try{var a=new VEShape(VEShapeType.Pushpin,b);a.SetCustomIcon(icon);a.SetTitle(eStoreName);a.SetDescription(storeDescription);a.SetZIndex(null,99999);map.AddShape(a);map.SetCenterAndZoom(b,"15");mapElement.style.visibility="visible"}catch(c){OnCatchError(c.message,"There was an issue setting up the map.")}}function SetVarsGetDir(a){fromAddress=a;GetStoreDirs()}function GetStoreDirs(){try{DoUponGetStoreDirs();map.DeleteAllShapes();var b=new VERouteOptions();b.RouteCallback=OnGotRoute;b.ShowDisambiguation=false;b.ShowErrorMessages=false;if(useLatLong){var a=new VELatLong(storeLat,storeLong);map.GetDirections([fromAddress,a],b)}else{map.GetDirections([fromAddress,eAddressLine],b)}}catch(c){OnCatchError(c.message,"There was an error retrieving directions from the address provided."+c.message)}}function OnGotRoute(e){DoUponOnGotRoute();try{var n=e.RouteLegs;var g="<div>Total distance: "+e.Distance.toFixed(1)+" miles</div>";var f=0;var h=null;for(var a=0;a<n.length;a++){h=n[a];h.Itinerary.Items[(h.Itinerary.Items.length)-1].Shape.SetCustomIcon(icon);var o=null;for(var b=0;b<h.Itinerary.Items.length;b++){o=h.Itinerary.Items[b];f++;g+='<div class="mapDir_turns">'+f+". "+o.Text+" ("+o.Distance.toFixed(1)+" mi)</div>";var d=o.Hints;var m=null;if(d){for(var c=0;c<d.length;c++){m=d[c];g+='<div class="mapDir_hints">'+m.Text+"</div>"}}}}mapDirElement.innerHTML=g}catch(l){OnCatchError(l.message,"There was an error retrieving directions from the address provided.")}}function OnCatchError(a,b){if(mapErrorElement){mapErrorElement.innerHTML="Error: "+b;mapErrorElement.style.visibility="visible"}}function getDirsEnterKey(c,a){var b;if(window.event){b=c.keyCode}else{b=c.which}if(b==13){a();return false}else{return true}}function GetMapDirs(){var a="";a+=(document.getElementById("_txtFromAddress").value!="")?document.getElementById("_txtFromAddress").value+", ":"";a+=(document.getElementById("_txtFromCity").value!="")?document.getElementById("_txtFromCity").value+", ":"";a+=document.getElementById("_ddlFromState").value;a+=(document.getElementById("_txtFromZip").value!="")?", "+document.getElementById("_txtFromZip").value:"";SetVarsGetDir(a)}function DoUponGetStoreDirs(){document.getElementById("mapDirsWrapper").style.display="block";ShowStoreAvailabilityLoadingModal()}function DoUponOnGotRoute(){document.getElementById("_divStoreLoadingContent").style.display="none";document.getElementById("_divStoreMainContent").style.display="block";$find("_storeAvailabilityPopupBehavior").show()};
