function selectComuni() {
	var prov = document.cerca.prov.value;
  if (prov != "") {
      var ajax = assegnaXMLHttpRequest();
      usaLink = true;
      dataChiamata = new Date();
      inizioChiamata = dataChiamata.getTime();
      massimaAttesa = 90;
      var verificaTempoTrascorso;
      if (ajax) {
          usaLink = false;
          ajax.open("get", "ComuniServlet?metodo=comune&prov=" + prov, true);
          ajax.onreadystatechange = function() {
              if (ajax.readyState == 4) {
                  verificaTempoTrascorso = function(){};
                  if (ajax.status == 200 && ajax.responseXML) {
                      document.getElementById("comusearch").innerHTML = parseXML(ajax.responseXML) + "<br>COMUNE";
                  } else {
                      alert("Problemi nel reperire l'elenco dei comuni! -" + ajax.status);
                  }
              } else
              if(massimaAttesa < 1000) {
                  massimaAttesa = massimaAttesa * 1000;
                  verificaTempoTrascorso = function() {
                      dataChiamata = new Date();
                      if((dataChiamata.getTime() - inizioChiamata) > massimaAttesa) {
                          ajax.onreadystatechange = function(){
                              return;
                          };
                          ajax.abort();
                      } else {
                          setTimeout(verificaTempoTrascorso, 150);
                      }
                  };
                  verificaTempoTrascorso();
              }
          };
          ajax.send(null);
      } else {
          alert("Il browser con cui stai navigando non supporta la tecnologia usata in questo programma!\nOppure controlla le sue impostazioni!");
      }
  } else {
      document.getElementById("comusearch").innerHTML = "<select name=\"comune\" class=\"fieldform\"><option value=\"\"></option></select>";
  }

  return usaLink;
}

function assegnaXMLHttpRequest() {
	var jx = null;
  if (window.XMLHttpRequest) {
      jx = new XMLHttpRequest();
  } else
  if (window.ActiveXObject) {
      if (navigator.appName == "Microsoft Internet Explorer") {
          if (navigator.appVersion.indexOf("MSIE 6.0") > 0) {
              jx = new ActiveXObject("Msxml2.XMLHTTP");
          } else {
              jx = new ActiveXObject("Microsoft.XMLHTTP");
          }
      }
  }

  return jx;
}

function parseXML(xml) {
  var risultato = "<select name=\"comune\" class=\"fieldform\"><option selected value=\"\"></option>";
  var items = xml.getElementsByTagName("comune");
  if (items.length == 1 && items[0].firstChild.nodeValue.charAt(0) == '-') {
      risultato += "</select>";
  } else {
      for (var i = 0; i < items.length; i++) {
          risultato += "<option value=\"" + items[i].firstChild.nodeValue + "\">" + items[i].firstChild.nodeValue + "</option>";
      }
      risultato += "</select>";
  }

  return risultato;
}

function cerca() {
  if (document.cerca.damq.value == "") {
      document.cerca.damq.value = "0";
  }
  for (i = 0; i < document.cerca.damq.value.length; i++) {
      if (document.cerca.damq.value.charCodeAt(i) < 48 || document.cerca.damq.value.charCodeAt(i) > 57) {
          alert("La dimesione deve essere composta da soli numeri");
          return;
      }
  }
  if (document.cerca.amq.value == "") {
      document.cerca.amq.value = "0";
  }
  for (i = 0; i < document.cerca.amq.value.length; i++) {
      if (document.cerca.amq.value.charCodeAt(i) < 48 || document.cerca.amq.value.charCodeAt(i) > 57) {
          alert("La dimesione deve essere composta da soli numeri");
          return;
      }
  }
  if (document.cerca.davani.value == "") {
      document.cerca.davani.value = "0";
  }
  for (i = 0; i < document.cerca.davani.value.length; i++) {
      if (document.cerca.davani.value.charCodeAt(i) < 48 || document.cerca.davani.value.charCodeAt(i) > 57) {
          alert("I vani devono essere composti da soli numeri");
          return;
      }
  }
  if (document.cerca.avani.value == "") {
      document.cerca.avani.value = "0";
  }
  for (i = 0; i < document.cerca.avani.value.length; i++) {
      if (document.cerca.avani.value.charCodeAt(i) < 48 || document.cerca.avani.value.charCodeAt(i) > 57) {
          alert("I vani devono essere composti da soli numeri");
          return;
      }
  }
  if (document.cerca.daprezzo.value == "") {
      document.cerca.daprezzo.value = "0";
  }
  for (i = 0; i < document.cerca.daprezzo.value.length; i++) {
      if (document.cerca.daprezzo.value.charCodeAt(i) < 48 || document.cerca.daprezzo.value.charCodeAt(i) > 57) {
          alert("Il prezzo deve essere composto da soli numeri!");
          return;
      }
  }
  if (document.cerca.aprezzo.value == "") {
      document.cerca.aprezzo.value = "0";
  }
  for (i = 0; i < document.cerca.aprezzo.value.length; i++) {
      if (document.cerca.aprezzo.value.charCodeAt(i) < 48 || document.cerca.aprezzo.value.charCodeAt(i) > 57) {
          alert("Il prezzo deve essere composto da soli numeri!");
          return;
      }
  }
  if (document.cerca.lingua.value == "ITA")  {
  	document.cerca.action = "elenco.jsp";
  } else {
  	document.cerca.action = "list.jsp";
  }
  document.cerca.submit();
}

function invia() {
  if (document.contatto.nome.value == "") {
      alert("Inserire il nome!");
      return;
  }
  if (document.contatto.citta.value == "") {
      alert("Inserire il città !");
      return;
  }
  if (document.contatto.telefono.value == "") {
      alert("Inserire il telefono!");
      return;
  }
  if (document.contatto.email.value == "") {
      alert("Inserire l'e-mail!");
      return;
  }
	if (document.contatto.email.value != "" && (document.contatto.email.value.indexOf("@") == -1 || document.contatto.email.value.indexOf(".") == -1)) {
		alert("Il formato dell'e-mail non è corretto!");
		return;
	}
  if (document.contatto.consenso.checked == true) {
		document.contatto.cons.value="1";
	}
  document.contatto.action = "SendMailServlet";
  document.contatto.submit();
}

function viewBig(foto, wdth, hght) {
	if (foto == "images/FotoVuota.jpg") {
		return;
	}
	document.getElementById("fotoprinc").innerHTML = "<a href=\"javascript:void(0);\"><img src=\"" + foto + "\" style=\"border-color: #000000;\" width=" + wdth + " height=" + hght + " border=1 onMouseDown=\"javascript:zoomFoto('" + foto + "');\"></a>";
}

function zoomFoto(nfoto) {
	window.open(nfoto, "new", "resizable=yes,scrollbars=yes,status=yes,left=0,top=0");
}

function gotoElenco() {
	document.immobile.target = "";
	if (document.immobile.lingua.value == "ITA")  {
  	document.immobile.action = "elenco.jsp";
  } else {
  	document.immobile.action = "list.jsp";
  }
  document.immobile.submit();
}

function loadImmobile(sid) {
  document.immobili.sid.value = sid;
  if (document.immobili.lingua.value == "ITA")  {
  	document.immobili.action = "dettaglio.jsp";
  } else {
  	document.immobili.action = "details.jsp";
  }
  document.immobili.submit();
}

function loadImmobile2(sid, lingua) {
	if (lingua == "ITA")  {
		window.location.href = "dettaglio.jsp?sid=" + sid;
	} else {
		window.location.href = "details.jsp?sid=" + sid + "&lingua=ENG";
	}
}

function prevPage() {
	if (document.immobili.totpag.value == 0) {
		return;
	}
	var i = parseInt(document.immobili.curpag.value) - 1;
	if ((document.immobili.totpag.value > 0 && i < 1) || (document.immobili.totpag.value == 0 && i < 0)) {
		return;
	}
  document.immobili.curpag.value = i;
  if (document.immobili.lingua.value == "ITA")  {
  	document.immobili.action = "elenco.jsp";
  } else {
  	document.immobili.action = "list.jsp";
  }
  document.immobili.submit();
}

function nextPage() {
	if (document.immobili.totpag.value == 0) {
		return;
	}
	var i = parseInt(document.immobili.curpag.value) + 1;
	if (i > document.immobili.totpag.value) {
		return;
	}
  document.immobili.curpag.value = i;
  if (document.immobili.lingua.value == "ITA")  {
  	document.immobili.action = "elenco.jsp";
  } else {
  	document.immobili.action = "list.jsp";
  }
  document.immobili.submit();
}

function sendEmail() {
  document.location.href = "mailto:info@euro3immobiliare.it";
}

function readInformativa(lingua) {
	window.open("InformativaPrivacy.pdf", "new", "");
}

function stampa() {
	document.immobile.target = "new";
	document.immobile.action = "StampaServlet";
	document.immobile.submit();
}

function loadFoto() {
  immagini = new Array("1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg", "7.jpg", "8.jpg", "9.jpg", "10.jpg", "11.jpg", "12.jpg", "13.jpg");
  var qs = location.search;
  var nr = qs.substring(4);
  var len = immagini.length;
  document.getElementById("id_foto").innerHTML = "<img src=\"rotation/" + immagini[nr] + "\" border=0 width=1024 heigth=450/></a>";
  nr++;
  if (nr == len) {
      nr = 0;
  }
  setTimeout("refresh('" + nr + "')", 5000);
}

function refresh(nr) {
  window.location.href = "rotofoto.html?nr=" + nr;
}

