function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value==""||value==undefined) {alert(alerttxt); field.focus(); return false}
		else {return true}
	}
}

function validate_email(field,alerttxt)
{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if ((apos<1||dotpos-apos<2) && value.length!=0) {alert(alerttxt); return false;}
		else return true;
	}
}

function validate_classe(field,alerttxt)
{
        with (field)
        {
		if ( isNaN(value.charAt(0)) || !isNaN(value.charAt(1)) ) {alert(alerttxt); return false;}
        }
}

function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_required(nome,"Il nome è obbligatorio!")==false)  return false;
		else if (validate_required(cognome,"Il cognome è obbligatorio!")==false)  {cognome.focus(); return false}
		else if (validate_required(classe,"La classe è obbligatoria!")==false)  {classe.focus(); return false}
                else if (validate_classe(classe,"Inserisci correttamente la tua classe.\n Ad esempio: 3C")==false) 
			{classe.focus(); return false;}
                else if (validate_required(email,"Inserire l'email!")==false)  {email.focus(); return false}
		else if (validate_email(email,"Non è un indirizzo email valido!")==false) {email.focus(); return false;}
		else if (validate_required(materia,"Selezionare la materia richiesta!")==false)  {materia.focus(); return false;}
		//else if (document.getElementById('dettagli').value.length<5) {
		//	var pippo='abc dfg';
		//testo.value.length<16) {
			//alert(document.getElementById('dettagli').value);
			// alert("Inserire gli argomenti richiesti in modo dettagliato!");
			//return false;
		//}
		else if (validate_token.value.length != 4) {alert("La stringa inserita non è corretta!"); validate_token.focus(); return false}
	}
}

function validate_textarea(stringa)
{
	alert('test');
   if (stringa.length < 20) alert("Inserire gli argomenti richiesti in modo dettagliato!");
} 

