diff --git a/_header.php b/_header.php
index 979c5f7..16f4695 100644
--- a/_header.php
+++ b/_header.php
@@ -10,7 +10,7 @@ session_start();
-
+
-
+
-
diff --git a/assets/js/main.js b/assets/js/main.js
index e6d207e..d561629 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -1 +1,53 @@
// Main javascript file
+
+document.addEventListener('DOMContentLoaded', function() {
+ const locationInputs = document.querySelectorAll('input[name="location"]');
+ if (locationInputs.length === 0) {
+ return;
+ }
+
+ const COMUNI_URL = 'https://raw.githubusercontent.com/matteocontrini/comuni-json/master/comuni.json';
+ const IP_GEOLOCATION_URL = 'http://ip-api.com/json';
+
+ // Create a datalist for suggestions
+ const datalist = document.createElement('datalist');
+ datalist.id = 'comuni-list';
+ document.body.appendChild(datalist);
+
+ // Attach the datalist to the input fields
+ locationInputs.forEach(input => {
+ input.setAttribute('list', datalist.id);
+ input.setAttribute('autocomplete', 'off'); // Disable browser's own autocomplete
+ });
+
+ // Fetch comuni and populate datalist
+ fetch(COMUNI_URL)
+ .then(response => response.json())
+ .then(data => {
+ data.forEach(comune => {
+ const option = document.createElement('option');
+ option.value = comune.nome;
+ datalist.appendChild(option);
+ });
+ })
+ .catch(error => {
+ console.error('Error fetching Italian municipalities:', error);
+ });
+
+ // Fetch IP-based geolocation and pre-fill the input
+ fetch(IP_GEOLOCATION_URL)
+ .then(response => response.json())
+ .then(data => {
+ if (data && data.city) {
+ locationInputs.forEach(input => {
+ // Only set the value if the input is currently empty
+ if (input.value.trim() === '') {
+ input.value = data.city;
+ }
+ });
+ }
+ })
+ .catch(error => {
+ console.error('Error fetching IP geolocation:', error);
+ });
+});
\ No newline at end of file