function verifForm(form)  
{
	var messaggio="";
  if(form.richiesta.value == "")   	
	{  		
		alert('Inserisci la richiesta da effettuare!');   		
		form.richiesta.focus();  		
		return false;   	
	}
	if (!form.accetto.checked)
	{
		messaggio="Consentire il trattamento dei dati è necessario per inviare il modulo";
	}
	if (messaggio	!="")
	{
		alert(messaggio);
		return false;
	}
	//controlla che la e-mail non sia vuota
	if (form.email.value == "")
	{
		alert("Indirizzo E-mail non valido!\n (Inserisci un indirizzo nella forma utente@dominio.it)");
		form.email.focus();
		return false;
 }
 // controllo della presenza del carattere '@'
 var index     = form.email.value.indexOf('@', 0);
 var address   = "";
 var ok = true;   
 if (index == -1)
 {
	 ok = false;
 }
 else
 {
		var size = form.email.value.length;
		address = form.email.value.substring(size + 1, index + 1);
		userid =  form.email.value.substring(0, index);
		// controlla: l'unicità del carattere "@";
		// - la presenza del "." nella parte DX dell'indirizzo;
		// - l'assenza di spazi e
		// - che la stringa non sia del tipo userid@.address o userid.@address
		if (isValidEmail(form.email.value) == false)
		{
			ok=false;
		}
		else
		{
			ok=true;
		}
		/*
		if ((address.indexOf('@') != -1) || (userid.indexOf('@') != -1) ||
				(address.indexOf('.') == -1) || (!nospace(form.email.value)) ||
				(form.email.charAt(index - 1) == '.') || (form.email.charAt(index + 1) == '.'))
		{
			ok = false;
		}    */
		
		
	}
	if (ok == false)
	{
		alert("Indirizzo E-mail non valido!\n (Inserisci un indirizzo nella forma utente@dominio.it)");
		form.email.focus();
		return false;
	}
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
