// Controllo lunghezza campi
function MaxCaratteri(Object,MaxLen)
{return (Object.value.length<=MaxLen);}

// Controllo campi obbligatori
function formCheck(formobj){
	//1) Inserisci il nome che hai assegnato ai tuoi campi con name
	var fieldRequired = Array("tipostruttura","nomecognome", "provincia", "citta","mail", "nomeazienda",  "tel", "email", "descrizione", "testo","email1","captcha");
	//2) Inserisci la descrizione del campo da riempire che appare nel messaggio a video
	var fieldDescription = Array("Tipologia Struttura","Nome e Cognome", "Provincia", "Citta","E-mail", "Nome dell'azienda",  "Telefono", "Email", "Descrizione", "Messaggio","Email","Codice di Verifica");
	//3) Inserisci il messagio che deve precedere l'elenco dei campi non inseriti.
	var alertMsg = "Per favore, riempi i seguenti campi:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

// Controllo email corretta
function ControllaMail(){
   EmailAddr = document.modulo.email.value;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return true;
   else
      {
		  if(EmailAddr != ""){
			  alert("Indirizzo e-mail non valido!");
			  document.modulo.email.focus();
			  return false;
		}
      }
}

// Menù select dinamico - homepag (googlemap)
function changeLocationHome(menuObj) {
  var i = menuObj.selectedIndex;
  if(i > 0) {
    window.location.href = "index.php?page=0&select="+menuObj.options[i].value;
  }
}
// Menù select dinamico - Ricerca su mappa
function changeLocationricerca(menuObj) {
  var i = menuObj.selectedIndex;
  if(i > 0) {
    window.location.href = "index.php?page=22&select="+menuObj.options[i].value;
  }
}

//Popup a centro pagina
function centerPopUp( url, name, width, height, scrollbars ) {
if( scrollbars == null ) scrollbars = "0"
str = "";
str += "resizable=1,";
str += "scrollbars=" + scrollbars + ",";
str += "width=" + width + ",";
str += "height=" + height + ",";
if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;
var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;
str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}
window.open( url, name, str );
}


//Popup a centro pagina
function centerPopUp1( url, name, width, height, scrollbars ) {
if( scrollbars == null ) scrollbars = "1"
str = "";
str += "resizable=1,";
str += "scrollbars=" + scrollbars + ",";
str += "width=" + width + ",";
str += "height=" + height + ",";
if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;
var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;
str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}
window.open( url, name, str );
}
// Menù select dinamico - homepag (googlemap)
function changeLocationHome(menuObj) {
  var i = menuObj.selectedIndex;
  if(i > 0) {
    window.location.href = "index.php?page=0&select="+menuObj.options[i].value;
  }
}