function initAutoComplete(){const t=document.getElementById("changeLocation");!t;const n=locName!=undefined,i=n?locName.value:null;if(i==null){let t=getLocation();t!=null?(appendToLinks(t),n&&(locName.innerText=t.name,locLat.value=t.lat,locLng.value=t.lng,submitFormIfNoQuery(),initMap())):getUserGeoLocation()}if(n)autocomplete=new google.maps.places.Autocomplete(t,{fields:["address_components","geometry","icon","name"],strictBounds:!1,types:["(regions)"]}),autocomplete.addListener("place_changed",getSelectedPlaced)}function appendToLinks(n){const t=document.querySelectorAll("a[href]");t.forEach(function(t){const i=t.getAttribute("href");if(i.indexOf("/jobs/")>-1||i.indexOf("/trabajos/")>-1){let r=new URL(i,document.baseURI);r.searchParams.set("lat",n.lat);r.searchParams.set("lng",n.lng);t.setAttribute("href",r.href)}});let i=document.getElementById("joboard-modal-form");i&&(document.getElementById("modal-lat").value=n.lat,document.getElementById("modal-lng").value=n.lng)}function getSelectedPlaced(){const n=autocomplete.getPlace(),t=n.address_components[0];setUserLocation(n.geometry.location.lat(),n.geometry.location.lng(),t.long_name);document.getElementById("job-filter").submit()}function getUserGeoLocation(){navigator.geolocation?navigator.geolocation.getCurrentPosition(geolocationSuccess,geolocationError):showLocationInput()}function setUserLocation(n,t,i){n=parseFloat(n);t=parseFloat(t);(n<-90||n>90)&&(n=42.28);(t<-180||t>180)&&(t=-83.73);i&&i.length!=0||(i="Current location");const r={name:i,lat:n,lng:t};return locLat&&locLng&&(locLat.value=r.lat,locLng.value=r.lng,locName.innerText=r.name),storeLocation(r),r}function getLocation(){let n;const t=sessionStorage.getItem(sessionKey);if(n=t?JSON.parse(t):null,n==null){const t=new URLSearchParams(window.location.search);t.has("lat")&&t.has("lng")&&(n=setUserLocation(t.get("lat"),t.get("lng")),reverseGeocode(new google.maps.LatLng(n.lat,n.lng)))}return n}function storeLocation(n){const t=JSON.stringify(n);sessionStorage.setItem(sessionKey,t)}function showLocationInput(){document.getElementById("collapseChangeLocation").classList.add("show")}function geolocationSuccess(n){if(n){const t=new google.maps.LatLng(n.coords.latitude,n.coords.longitude);reverseGeocode(t,!0)}}function reverseGeocode(n,t){geocoder=new google.maps.Geocoder;geocoder.geocode({location:n},function(i,r){if(r=="OK"){const r=i[0];let u=r.address_components[2].short_name?r.address_components[2].short_name:r.address_components[2].long_name;r.address_components[3]&&(u+=", ",u+=r.address_components[3].short_name?r.address_components[3].short_name:r.address_components[3].long_name);setUserLocation(n.lat().toFixed(5),n.lng().toFixed(5),u);t&&submitFormIfNoQuery()}else console.log("Geocode was not successful for the following reason: "+r)})}function geolocationError(){console.log("Unable to get user location so reverting to default location...");showLocationInput();setUserLocation(42.279594,-83.732124,"Ann Arbor, MI");submitFormIfNoQuery()}function submitFormIfNoQuery(){const n=new URLSearchParams(window.location.search);n.has("lat")&&n.has("lng")&&n.get("lat")==locLat.value&&n.get("lng")==locLng.value||document.getElementById("job-filter").submit()}function insertUrlParam(n,t){if(history.pushState){let i=new URLSearchParams(window.location.search);i.set(n,t);let r=window.location.protocol+"//"+window.location.host+window.location.pathname+"?"+i.toString();window.history.pushState({path:r},"",r)}}function calcDistance(n,t){return(google.maps.geometry.spherical.computeDistanceBetween(n,t)/1e3).toFixed(2)}function initMap(){let f=new google.maps.LatLngBounds,i=document.getElementById("map");if(i){const e=document.getElementById("js-map-elements");if(e){const o=getLocation();let n=new google.maps.LatLng(o.lat,o.lng);const a=new google.maps.Marker({position:n,map:gMap}),s=e.children,h=s.length,l=new URLSearchParams(window.location.search);let u=parseInt(l.get("zoom"));if(u||(u=8),gMap=new google.maps.Map(i,{zoom:u,maxZoom:11,minZoom:7,streetViewControl:!1,center:n}),gMap.addListener("dragend",()=>{const t=gMap.getCenter();let i=(15-gMap.getZoom())*12;calcDistance(n,t)>i&&(n=t,reverseGeocode(gMap.getCenter(),!0))}),gMap.addListener("zoom_changed",()=>{insertUrlParam("zoom",gMap.getZoom())}),h==0){gMap.setZoom(6);return}const c=document.getElementById("js-job-results").lastElementChild;if(c){const t=parseInt(c.getAttribute("data-radius")),i=new google.maps.Circle({strokeColor:"#e31837",strokeOpacity:.4,strokeWeight:1,fillColor:"#006491",fillOpacity:.1,gMap,center:n,radius:t+1e4});i.setMap(gMap)}let t,r;for(infoWindow=new google.maps.InfoWindow,t=0;t<h;t++){const n=s[t],u=n.getAttribute("data-bu"),i=new google.maps.LatLng(n.getAttribute("data-lat"),n.getAttribute("data-lng"));f.extend(i);r=new google.maps.Marker({position:i,map:gMap,icon:"/images/marker-instore.png",title:n.getAttribute("data-name")});gMarkers[u]=r;google.maps.event.addListener(r,"click",function(n,t,i){return function(){infoWindow.setContent(i.innerHTML);infoWindow.open(gMap,n)}}(r,t,n))}gMap.fitBounds(f);insertUrlParam("zoom",gMap.getZoom());document.querySelectorAll(".js-job-link").forEach(n=>{n.classList.remove("invisible"),n.addEventListener("click",t=>{if(t.preventDefault(),i){i.scrollIntoView();const t=gMarkers[n.dataset.address];google.maps.event.trigger(t,"click")}return!1})})}}}let autocomplete;const locLat=document.getElementById("loc-lat"),locLng=document.getElementById("loc-lng"),locName=document.getElementById("loc-name"),sessionKey="dominos.location",getUserLocation=document.getElementById("js-getUserLocation");getUserLocation&&getUserLocation.addEventListener("click",function(){getUserGeoLocation()});let gMap,gMarkers={},infoWindow