function initializeAutocomplete(id) { var element = document.getElementById(id); var currentLocation = window.location.pathname; if (element) { var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] }); google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChanged); } } function onPlaceChanged() { var current_url = window.location.href; var substring = "/en/"; var lang = 'fr' if (current_url.indexOf(substring) !== -1) { var lang = 'en' }; var place = this.getPlace(); var lat=place.geometry.location.lat(); var lng=place.geometry.location.lng(); document.getElementById('lat').value= lat; document.getElementById('lng').value= lng; var currentLocation = window.location.pathname; if (currentLocation.indexOf("availabilities")!== -1) { document.location.href = lang+"/results-availabilities.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else if (currentLocation.indexOf("list")!== -1) { document.location.href = lang+"/results-list.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else if (currentLocation.indexOf("map")!== -1) { document.location.href = lang+"/results-map.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else { document.location.href = lang+"/results-availabilities.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } } function initializeAutocompleteList(id) { var element = document.getElementById(id); var currentLocation = window.location.pathname; if (element) { var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] }); google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChangedList); } } function onPlaceChangedList() { var current_url = window.location.href; var substring = "/en/"; var lang = 'fr' if (current_url.indexOf(substring) !== -1) { var lang = 'en' }; var place = this.getPlace(); var lat=place.geometry.location.lat(); var lng=place.geometry.location.lng(); document.getElementById('lat').value= lat; document.getElementById('lng').value= lng; var currentLocation = window.location.pathname; if (currentLocation.indexOf("availabilities")!== -1) { document.location.href = lang+"/results-availabilities.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else if (currentLocation.indexOf("list")!== -1) { document.location.href = lang+"/results-list.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else if (currentLocation.indexOf("map")!== -1) { document.location.href = lang+"/results-map.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else { document.location.href = lang+"/results-list.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } } function initializeAutocompleteMap(id) { var element = document.getElementById(id); var currentLocation = window.location.pathname; if (element) { var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] }); google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChangedMap); } } function onPlaceChangedMap() { var current_url = window.location.href; var substring = "/en/"; var lang = 'fr' if (current_url.indexOf(substring) !== -1) { var lang = 'en' }; var place = this.getPlace(); var lat=place.geometry.location.lat(); var lng=place.geometry.location.lng(); document.getElementById('lat').value= lat; document.getElementById('lng').value= lng; var currentLocation = window.location.pathname; if (currentLocation.indexOf("availabilities")!== -1) { document.location.href = lang+"/results-availabilities.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else if (currentLocation.indexOf("list")!== -1) { document.location.href = lang+"/results-list.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else if (currentLocation.indexOf("map")!== -1) { document.location.href = lang+"/results-map.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } else { document.location.href = lang+"/results-map.php?lat="+lat+"&lng="+lng+"&address="+place.formatted_address; } } google.maps.event.addDomListener(window, 'load', function() { initializeAutocompleteMap('address5'); initializeAutocompleteList('address4'); initializeAutocomplete('address3'); initializeAutocomplete('address2'); initializeAutocomplete('address'); });