ALKMaps.Util.addEventHelper=function(e,t,s){return e.attachEvent?e.attachEvent("on"+t,s):e.addEventListener(t,s,!1)},ALKMaps.Util.toggleClass=function(e,t){return e=e.className.indexOf(t)<0?ALKMaps.Util.addClassHelper(e,t):ALKMaps.Util.removeClassHelper(e,t)},ALKMaps.Util.addClassHelper=function(e,t){return e.className.indexOf(t)<0&&(e.className+=" "+t),e},ALKMaps.Util.removeClassHelper=function(e,t){return e.className=e.className.replace(t,""),e.className=e.className.replace(/^\s+|\s+$/g,""),e},ALKMaps.Util.showElement=function(e){return e=ALKMaps.Util.removeClassHelper(e,"hide"),e=ALKMaps.Util.addClassHelper(e,"show")},ALKMaps.Util.hideElement=function(e){return e=ALKMaps.Util.removeClassHelper(e,"show"),e=ALKMaps.Util.addClassHelper(e,"hide")},ALKMaps.Control.Geocoding=ALKMaps.Class(ALKMaps.Control,{div:null,componentLocation:"topright",componentWidth:"normal",buttonText:"Go",listSize:10,showMarker:!0,markerStyle:null,marker:null,callback:null,region:"NA",displayInLayerSwitcher:!1,isDivExternal:!1,isMovingWithinList:!1,allowClickGeocoding:!1,clickGeocodingCallback:null,clickGeocodingMarker:null,setMap:function(){if(ALKMaps.Control.prototype.setMap.apply(this,arguments),null==this.geocodingLayer){var e=ALKMaps.Util.createUniqueID("ALKMaps.Layer.VectorMarkers");this.geocodingLayer=new ALKMaps.Layer.VectorMarkers(e,{displayInLayerSwitcher:this.displayInLayerSwitcher})}this.map.addLayers([this.geocodingLayer]);for(var t=0;t1){this.resultsListElement.innerHTML="",this.resultsResponse=e;for(var t=0;t0&&null==e[0].Coords?(this.errorMessageBox=ALKMaps.Util.showElement(this.errorMessageBox),this.errorMessage.innerHTML=e[0].Errors[0].Description):(this.clearFields(),this.processResponseItem(e[0]))},createResultElement:function(e){var t=document.createElement("li"),s=document.createElement("a");s.href="#",s.setAttribute("tabindex","0"),s.innerHTML=this.formatAddressString(e.Address);var i=this;return ALKMaps.Util.addEventHelper(s,"keydown",function(t){i.isMovingWithinList=!0,40===t.keyCode&&null!=t.target.parentElement.nextSibling&&t.target.parentElement.nextSibling.children[0].focus(),38===t.keyCode&&null!=t.target.parentElement.previousSibling&&t.target.parentElement.previousSibling.children[0].focus(),13===t.keyCode&&(i.processResponseItem(e),i.clearFields(),t.preventDefault()),27===t.keyCode&&(i.resultsListElement=ALKMaps.Util.hideElement(i.resultsListElement))}),ALKMaps.Util.addEventHelper(s,"blur",function(){i.isMovingWithinList||(i.resultsListElement=ALKMaps.Util.hideElement(i.resultsListElement))}),ALKMaps.Util.addEventHelper(s,"focus",function(){i.isMovingWithinList&&(i.isMovingWithinList=!1)}),ALKMaps.Util.addEventHelper(s,"mousedown",function(t){i.processResponseItem(e),i.clearFields(),t.preventDefault()}),t.appendChild(s),t},clearFields:function(){this.updateFields({StreetAddress:"",City:"",State:"",Zip:""}),this.resultsListElement=ALKMaps.Util.hideElement(this.resultsListElement),this.errorMessageBox=ALKMaps.Util.hideElement(this.errorMessageBox)},updateFields:function(e){this.addressText=e.StreetAddress,this.cityText=e.City,this.stateText=e.State,this.postalCodeText=e.Zip,this.refreshBindings()},refreshBindings:function(){this.addressElement.value=this.addressText,this.cityElement.value=this.cityText,this.stateElement.value=this.stateText,this.postalCodeElement.value=this.postalCodeText},processResponseItem:function(e){this.geocodingResponse=e,null!=this.callback&&this.callback(e),this.removeMarker(),this.marker=this.drawPoint(e.Coords.Lon,e.Coords.Lat,this.formatAddressString(e.Address,!0),!0)},processClickGeocodingResponse:function(e){var t=new ALKMaps.LonLat(e.Coords.Lon,e.Coords.Lat);t.transform(this.map.getProjectionObject(),new ALKMaps.Projection("EPSG:4326")),e.Coords.Lon=t.lon,e.Coords.Lat=t.lat,null!=this.clickGeocodingCallback&&this.clickGeocodingCallback(e),this.removeClickGeocodingMarker(),this.clickGeocodingMarker=this.drawPoint(e.Coords.Lon,e.Coords.Lat,this.formatAddressString(e.Address,!0),!0)},drawPoint:function(e,t,s,i){var o=null;if(this.showMarker){var n=new ALKMaps.LonLat(e,t).transform(new ALKMaps.Projection("EPSG:4326"),this.map.getProjectionObject());o=this.geocodingLayer.createMarker(n,{markerType:this.markerStyle?"custom":"blue",popupSize:new ALKMaps.Size(200,80),popupContentHTML:s,anchor:{size:new ALKMaps.Size(21,25),offset:new ALKMaps.Pixel(-5,-30)},overflow:"auto"},this.markerStyle),i&&(this.markerPopup&&this.map.removePopup(this.markerPopup),this.markerPopup=o.createPopup(!0),this.map.addPopup(this.markerPopup)),this.map.setCenter(n,12)}return o},setAddressText:function(e){this.addressText=e},setCityText:function(e){this.cityText=e},setStateText:function(e){this.stateText=e},setPostalCodeText:function(e){this.postalCodeText=e},createTextboxInput:function(e,t,s,i){var o=document.createElement("input");ALKMaps.Util.extend(o,{name:e+"Textbox",type:"text",className:"form-control input-sm alkmaps-geo-input alkmaps-geo-"+e,placeholder:t,value:s}),o.events=new ALKMaps.Events(this,o,null,!0,{}),o.events.on({click:function(){o.focus()}});var n=this;return ALKMaps.Util.addEventHelper(o,"keyup",function(){i.call(n,o.value)}),o},clearMarkers:function(){this.geocodingLayer.clearMarkers(),this.marker=null,this.clickGeocodingMarker=null},removeMarker:function(){this.marker&&this.geocodingLayer.removeMarker(this.marker)},removeClickGeocodingMarker:function(){this.clickGeocodingMarker&&this.geocodingLayer.removeMarker(this.clickGeocodingMarker)},formatAddressString:function(e,t){var s="";return null!=e.StreetAddress&&""!==e.StreetAddress&&(s+=e.StreetAddress+", ",s+=t?"
":""),null!=e.City&&""!==e.City&&(s+=e.City+", "),s+=e.State+" "+e.Zip},CLASS_NAME:"ALKMaps.Control.Geocoding"}),ALKMaps.Control.Routing=ALKMaps.Class(ALKMaps.Control,{div:null,componentLocation:"topright",componentWidth:"normal",routeId:"Route 1",routeStyle:{strokeOpacity:.4,strokeColor:"#0000FF"},routeOptions:{},allowPickStop:!1,totalDistance:0,region:"NA",geocodingControl:null,stops:[],_currentStopId:0,setMap:function(){if(ALKMaps.Control.prototype.setMap.apply(this,arguments),null==this.routingLayer){var e=ALKMaps.Util.createUniqueID("ALKMaps.Layer.Routing");this.routingLayer=new ALKMaps.Layer.Routing(e)}-1===this.map.getLayerIndex(this.routingLayer)&&this.map.addLayer(this.routingLayer)},draw:function(){ALKMaps.Control.prototype.draw.apply(this);var e=this;this.geocodingDiv=document.createElement("div"),this.div.className="alkmaps-routing-panel alkmaps-routing-panel-position panel panel-default container-fluid",this.div.className+=" alkmaps-"+this.componentLocation,this.div.className+=" alkmaps-routing-"+this.componentWidth;var t=document.createElement("div");t.className="panel-heading",t.innerHTML="Route";var s=document.createElement("button");s.className="btn btn-link btn-xs pull-right",s.innerHTML="Clear Route",s.onclick=function(t){e.clearRoute(),e.geocodingControl.clearMarkers(),t.preventDefault(),t.cancelBubble=!0,t.stopPropagation&&t.stopPropagation()},t.appendChild(s);var i=document.createElement("div");i.className="panel-body",t.onclick=function(e){ALKMaps.Util.toggleClass(i,"hide"),ALKMaps.Util.toggleClass(s,"hide"),e.preventDefault()},this.stopListPanel=document.createElement("div"),this.stopListPanel.className="alkmaps-routing-stopListContainer panel panel-default hide",this.stopList=document.createElement("ul"),this.stopList.className="alkmaps-routing-stopList list-group",this.stopListPanel.appendChild(this.stopList),i.appendChild(this.stopListPanel),this.geocodingControl=new ALKMaps.Control.Geocoding({div:this.geocodingDiv,region:this.region,callback:function(t){e.addStop(t)},markerStyle:{externalGraphic:ALKMaps.IMAGE.FLAG_START,graphicHeight:26,graphicWidth:26,graphicXOffset:-12,graphicYOffset:-26},buttonText:"Add Stop",allowClickGeocoding:this.allowPickStop,clickGeocodingCallback:function(t){e.addStop(t)}}),this.geocodingControl.setMap(this.map),this.geocodingControl.draw(),this.allowPickStop===!0&&(this.div.onmouseover=function(){null!=e.geocodingControl.clickGeocodingHandler&&e.geocodingControl.clickGeoActive===!0&&e.geocodingControl.disableClickGeocoding()},this.div.onmouseout=function(){null!=e.geocodingControl.clickGeocodingHandler&&e.geocodingControl.clickGeoActive===!0&&e.geocodingControl.enableClickGeocoding(e.geocodingControl.clickGeocodingCallback)});var o=document.createElement("div");o.className="clearfix",this.totalElement=document.createElement("div"),this.totalElement.className="pull-right",o.appendChild(this.totalElement),i.appendChild(o);var n=document.createElement("div"),a=document.createElement("div");a.className="alkmaps-routing-optionspanel panel panel-default hide";var l=document.createElement("button");l.className="close",l.innerHTML="x",l.onclick=function(t){a=ALKMaps.Util.toggleClass(a,"hide"),e.geocodingDiv=ALKMaps.Util.toggleClass(e.geocodingDiv,"hide"),t.preventDefault()},a.appendChild(l),a.appendChild(this.generateDropdown("Vehicle Type",this._VEHICLE_TYPES,function(e){this.routeOptions.vehicleType=e.value,this.runRoute()},this.routeOptions.vehicleType)),a.appendChild(this.generateDropdown("Route Type",this._ROUTE_TYPES,function(e){this.routeOptions.routingType=e.value,this.runRoute()},this.routeOptions.routingType)),a.appendChild(this.generateCheckbox("Avoid Toll Roads",function(e){this.routeOptions.tollDiscourage=e.checked,this.runRoute()})),a.appendChild(this.generateCheckbox("Only Use Highways",function(e){this.routeOptions.highwayOnly=e.checked,this.runRoute()}));var r=document.createElement("button");return r.className="btn btn-link btn-xs",r.innerHTML="Route Options",r.onclick=function(t){a=ALKMaps.Util.toggleClass(a,"hide"),e.geocodingDiv=ALKMaps.Util.toggleClass(e.geocodingDiv,"hide"),t.preventDefault()},n.appendChild(r),n.appendChild(a),i.appendChild(n),i.appendChild(this.geocodingDiv),this.div.appendChild(t),this.div.appendChild(i),this.div},addStop:function(e){var t=this;0===this.stops.length&&ALKMaps.Util.showElement(this.stopListPanel),e.id=this._currentStopId,this._currentStopId++,this.stops.push(e);var s=document.createElement("li");s.className="list-group-item",s.innerHTML=this.geocodingControl.formatAddressString(e.Address,!0),s.onclick=function(){var s=new ALKMaps.LonLat(e.Coords.Lon,e.Coords.Lat).transform(new ALKMaps.Projection("EPSG:4326"),t.map.getProjectionObject());t.map.setCenter(s,14)};var i=document.createElement("button");i.className="close",i.innerHTML="x",i.onclick=function(s){t.removeStop(e.id),t.runRoute(),s.preventDefault(),s.cancelBubble=!0,s.stopPropagation&&s.stopPropagation()},s.appendChild(i),this.stopList.appendChild(s),this.runRoute()},removeStop:function(e){for(var t=-1,s=0;s0?this.routingLayer.updateRoute({stops:this.getStops(),functionOptions:{routeId:this.routeId,style:this.routeStyle,callback:function(t){if(null!=t.report&&t.report.length>0){var s=t.report[0].ReportLines.length-1;e.totalDistance=t.report[0].ReportLines[s].TMiles,e.totalElement.innerHTML="Route Distance: "+e.totalDistance+" miles",e.geocodingControl.clearMarkers(),e.geocodingControl.showMarker=e.allowPickStop}}},routeOptions:this.routeOptions,reportOptions:{type:"Mileage",format:"json"}}):this.routingLayer.addRoute({stops:this.getStops(),functionOptions:{routeId:this.routeId,style:this.routeStyle,callback:function(){}},routeOptions:this.routeOptions,reportOptions:{type:"Mileage",format:"json"}}))},clearRoute:function(){this.stops=[],this.stopList.innerHTML="",this.routingLayer.removeRoute(this.routeId),ALKMaps.Util.hideElement(this.stopListPanel),this.totalElement.innerHTML="",this.totalDistance=0},getStops:function(){for(var e=[],t=0;t