var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):$jscomp.arrayIterator(a)};$jscomp.arrayFromIterator=function(a){for(var b,c=[];!(b=a.next()).done;)c.push(b.value);return c};
$jscomp.arrayFromIterable=function(a){return a instanceof Array?a:$jscomp.arrayFromIterator($jscomp.makeIterator(a))};var tdbLocationFinder={};jQuery().ready(function(){tdbLocationFinder.init()});
(function(){tdbLocationFinder={items:[],item:function(){this.blockObj=this.uid="";this.APIService="google";this.mapMarker=this.map=void 0;this.defLong=this.defLat=0;this.defZoom=3;this.defAddress="";this.bingSearchManager=this.bingAutosuggestManager=this.errorContainer=void 0;this._is_initialized=this._in_composer=!1},init:function(){tdbLocationFinder.items=[];this._is_running=!1},_initialize_item:function(a){!0!==a._is_initialized&&(a.errorContainer=a.blockObj.find(".tdb-s-notif"),tdbLocationFinder.initMap(a),
a._in_composer||tdbLocationFinder.currentLocation(a),a._is_initialized=!0)},addItem:function(a){if("undefined"===typeof a.uid)throw"item.uid is not defined";tdbLocationFinder.items.push(a);tdbLocationFinder._initialize_item(a)},initMap:function(a){var b=document.querySelector("."+a.uid+" .tdb-lf-map"),c={lat:a.defLat,lng:a.defLong};switch(a.APIService){case "google":a.map=new google.maps.Map(b,{center:c,zoom:a.defZoom});a.mapMarker=new google.maps.Marker({position:c,map:a.map});tdbLocationFinder._locationSearchGoogle(a);
""!==a.defAddress&&tdbLocationFinder.displayLocationByAddress(a,a.defAddress);break;case "bing":a.map=new Microsoft.Maps.Map(b,{center:new Microsoft.Maps.Location(a.defLat,a.defLong),zoom:a.defZoom,showLocateMeButton:!1}),Microsoft.Maps.loadModule(["Microsoft.Maps.AutoSuggest","Microsoft.Maps.Search"],function(){a.bingAutosuggestManager=new Microsoft.Maps.AutosuggestManager({map:a.map});a.bingSearchManager=new Microsoft.Maps.Search.SearchManager(a.map);tdbLocationFinder._locationSearchBing(a);""!==
a.defAddress&&tdbLocationFinder.displayLocationByAddress(a,a.defAddress)})}},displayLocationByAddress:function(a,b){switch(a.APIService){case "google":(new google.maps.Geocoder).geocode({address:b},function(b,d){"OK"===d&&(b=b[0].geometry.location,tdbLocationFinder.updateMap(a,b.lat(),b.lng(),15))});break;case "bing":a.bingSearchManager.geocode({where:b,callback:function(b){b&&b.results&&0<b.results.length&&setTimeout(function(){tdbLocationFinder.updateMap(a,b.results[0].location.latitude,b.results[0].location.longitude,
15)},400)}})}},currentLocation:function(a){var b=a.blockObj.find(".tdb-lf-curr-loc"),c=a.blockObj.find("#tdb-lf-search-"+a.uid);b.on("click",function(){c.addClass("loading").prop("disabled",!0);tdbLocationFinder._updateError(a,"",!1);navigator.geolocation.getCurrentPosition(function(b){var d=b.coords.latitude,f=b.coords.longitude;switch(a.APIService){case "google":b=new google.maps.LatLng(d,f);(new google.maps.Geocoder).geocode({location:b},function(b,d){if("OK"===d){d=$jscomp.makeIterator(tdbLocationFinder._retrieveAddressComponents(a,
b[0].address_components));var e=d.next().value,k=d.next().value,f=d.next().value,g=d.next().value,h=d.next().value,n=d.next().value,p=d.next().value,t=b[0].geometry.location;setTimeout(function(){c.val(p);tdbLocationFinder.updateLocationInputs(a,e,k,f,g,h,n);tdbLocationFinder.updateMap(a,t.lat(),t.lng(),15);c.removeClass("loading").prop("disabled",!1)},400)}else tdbLocationFinder._updateError(a,"Unable to retrieve your current location. Please try again.",!0),c.removeClass("loading").prop("disabled",
!1)});break;case "bing":a.bingSearchManager.reverseGeocode({location:new Microsoft.Maps.Location(d,f),callback:function(b){b=$jscomp.makeIterator(tdbLocationFinder._retrieveAddressComponents(a,b.address));var g=b.next().value,e=b.next().value,k=b.next().value,h=b.next().value,l=b.next().value,r=b.next().value,n=b.next().value;setTimeout(function(){c.val(n);tdbLocationFinder.updateLocationInputs(a,g,e,k,h,l,r);tdbLocationFinder.updateMap(a,d,f,15);c.removeClass("loading").prop("disabled",!1)},400)},
error_callback:function(b){tdbLocationFinder._updateError(a,"Unable to retrieve your current location. Please try again.",!0);c.removeClass("loading").prop("disabled",!1)}})}},function(){tdbLocationFinder._updateError(a,"Unable to retrieve your current location. Please activate the location setting, then refresh the page.",!0);c.removeClass("loading").prop("disabled",!1)})})},updateMap:function(a,b,c,d){switch(a.APIService){case "google":b=new google.maps.LatLng(b,c);a.map.setCenter(b);a.map.setZoom(d);
a.mapMarker.setPosition(b);break;case "bing":a.map.setView({mapTypeId:Microsoft.Maps.MapTypeId.road,center:new Microsoft.Maps.Location(b,c),zoom:d}),a.map.entities.clear(),a.map.entities.push(new Microsoft.Maps.Pushpin({altitude:0,altitudeReference:-1,latitude:b,longitude:c}))}},updateLocationInputs:function(a,b,c,d,h,f,k){var g=jQuery("#tdb-lf-address-"+a.uid),e=jQuery("#tdb-lf-postal-code-"+a.uid),m=jQuery("#tdb-lf-city-"+a.uid),q=jQuery("#tdb-lf-state-"+a.uid);a=jQuery("#tdb-lf-country-"+a.uid);
g.val(b+(""!==c?" "+c:""));e.val(d);m.val(h);q.val(f);a.val(k)},_locationSearchGoogle:function(a){var b=document.querySelector("#tdb-lf-search-"+a.uid),c=new google.maps.places.Autocomplete(b,{types:["address"],fields:["address_components","geometry"]});c.addListener("place_changed",function(){var d=c.getPlace();b.classList.add("loading");b.disabled=!0;tdbLocationFinder._updateError(a,"",!1);if(d.geometry){var h=$jscomp.makeIterator(tdbLocationFinder._retrieveAddressComponents(a,d.address_components)),
f=h.next().value,k=h.next().value,g=h.next().value,e=h.next().value,m=h.next().value,q=h.next().value;h.next();var l=d.geometry.location;""===m&&(m=e);setTimeout(function(){tdbLocationFinder.updateLocationInputs(a,f,k,g,e,m,q);tdbLocationFinder.updateMap(a,l.lat(),l.lng(),15);b.classList.remove("loading");b.disabled=!1},400)}else setTimeout(function(){b.value="";tdbLocationFinder.updateLocationInputs(a,"","","","","","");tdbLocationFinder.updateMap(a,0,0,3);b.classList.remove("loading");b.disabled=
!1},400)})},_locationSearchBing:function(a){var b=a.blockObj.find("#tdb-lf-search-"+a.uid);b.on("click",function(){a.blockObj.find(".tdb-lf-search-results").length&&a.blockObj.find(".tdb-lf-search-results").show()});jQuery(document).on("click",function(b){a.blockObj.find(".tdb-lf-search-results *").find(b.target).length||jQuery(b.target).is("#tdb-lf-search-"+a.uid)||a.blockObj.find(".tdb-lf-search-results").hide()});b.on("keyup",tdbLocationFinder._keyupDelay(function(){var c=b.val(),d=a.blockObj.find(".tdb-lf-search-results");
""===c?d.length&&d.remove():(d.length||(d=jQuery('<div class="tdb-lf-search-results" style="display:none;top:'+b.outerHeight()+'px"></div>'),b.before(d)),3>c.length?(d.html('<div class="tdb-lf-sr-txt">Please type in 2 or more letters to perform a search.</div>'),d.show()):a.bingAutosuggestManager.getSuggestions(c,function(c){d.show();if(c.length){d.html('<div class="tdb-lf-sr-txt">Please be more specific in your search.</div>');var f=!1;c.forEach(function(c){if("PostalAddress"===c.entityType||"Address"===
c.entitySubType&&"Road"===c.entitySubType){f||(f=!0,d.html(""));var g=$jscomp.makeIterator(tdbLocationFinder._retrieveAddressComponents(a,c.address)),e=g.next().value,h=g.next().value,k=g.next().value,l=g.next().value,r=g.next().value,n=g.next().value,p=g.next().value;g=jQuery('<div class="tdb-lf-search-result">'+p+"</div>");g.on("click",function(){b.addClass("loading");b.prop("disabled",!0);tdbLocationFinder._updateError(a,"",!1);b.val(p);d.hide();a.bingSearchManager.geocode({where:c.formattedSuggestion,
callback:function(c){c&&c.results&&0<c.results.length&&setTimeout(function(){tdbLocationFinder.updateLocationInputs(a,e,h,k,l,r,n);tdbLocationFinder.updateMap(a,c.results[0].location.latitude,c.results[0].location.longitude,15);b.removeClass("loading").prop("disabled",!1)},400)}})});d.append(g)}})}else d.html('<div class="tdb-lf-sr-txt">No results were found for the selected address.</div>')}))},300))},_retrieveAddressComponents:function(a,b){var c="",d="",h="",f="",k="",g="",e="";switch(a.APIService){case "google":for(a=
0;a<b.length;a++)for(e=0;e<b[a].types.length;e++){"route"===b[a].types[e]&&(c=b[a].long_name);"street_number"===b[a].types[e]&&(d=b[a].long_name);"postal_code"===b[a].types[e]&&(h=b[a].long_name);if(""===f&&"locality"===b[a].types[e]||""===f&&"postal_town"===b[a].types[e])f=b[a].long_name;"administrative_area_level_1"===b[a].types[e]&&(k=b[a].long_name);"country"===b[a].types[e]&&(g=b[a].long_name)}""===k&&""!==f&&(k=f);e=c;e+=""!==d?(""!==e?" ":"")+d:"";e+=""!==f?(""!==e?", ":"")+f:"";e+=""!==k?
(""!==e?", ":"")+k:"";e+=""!==g?(""!==e?", ":"")+g:"";break;case "bing":"undefined"!==typeof b.addressLine&&(c+=e=b.addressLine.replace(",","")),"undefined"!==typeof b.postalCode&&(h=b.postalCode),"undefined"!==typeof b.locality&&(f=b.locality,e+=(""!==e?", ":"")+f),"undefined"!==typeof b.adminDistrict&&(k=b.adminDistrict),""===k&&""!==f&&(k=f),e+=""!==k?(""!==e?", ":"")+k:"","undefined"!==typeof b.countryRegion&&(g=b.countryRegion,e+=(""!==e?", ":"")+g)}return[c,d,h,f,k,g,e]},_updateError:function(a,
b,c){c=void 0===c?!0:c;a=a.errorContainer;a.find(".tdb-s-notif-descr").html(b);c?a.show():a.hide()},_keyupDelay:function(a,b){var c=0;return function(d){for(var h=[],f=0;f<arguments.length;++f)h[f-0]=arguments[f];clearTimeout(c);c=setTimeout(a.bind.apply(a,[this].concat($jscomp.arrayFromIterable(h))),b||0)}},deleteItem:function(a){for(var b=0;b<tdbLocationFinder.items.length;b++)if(tdbLocationFinder.items[b].uid===a)return tdbLocationFinder.items.splice(b,1),!0;return!1},resetItems:function(){tdbLocationFinder.items=
[]}}})();
