function checkMailForm() {
	var formobj = document.mailform;
	if(!formobj.mailsubject.value){
		alert("Inserire l'oggetto del messaggio che ci vuoi inviare...");
		formobj.mailsubject.focus();
		return false;
	}
	if(!controllaEmail(formobj.mailsender.value)){
		formobj.mailsender.focus();
		return false;
	}   
	if(formobj.mailbody.value.length<20){
		alert("Il messaggio deve contenere almeno 20 caratteri.");
		formobj.mailbody.focus();
		return false;
	}
	if(formobj.mailbody.value.length>500){
		alert("Il messaggio deve contenere un massimo di 500 caratteri.");
		formobj.mailbody.focus();
		return false;
	}
	bloccaPulsanti(formobj);
	return true;
}

// ==================================================================================================
function bloccaPulsanti(formobj){
// ==================================================================================================
   for(x=0;x<formobj.length;x++) {
     if(formobj.elements[x].type=="button" || formobj.elements[x].type=="submit" || formobj.elements[x].type=="images"){ 
	    formobj.elements[x].disabled = true;
	 }
   }
}
// ==================================================================================================
function controllaEmail(StrMail) {
// ==================================================================================================
	msg = "L'indirizzo email inserito non sembra essere valido, controlla i dati e riprova";
	if (StrMail.length>6) {
		var pos;
		var dotpos;
		pos = StrMail.indexOf("@");
		if ( (pos >= (StrMail.length-3) ) || (pos < 2) ) {
			alert(msg);
			return (false);
        }
      	pos=pos+1;
      	dotpos = StrMail.indexOf(".", pos);
      	if (dotpos > (StrMail.length-3) ) {
			alert(msg);
        	return (false);
        }
      	Strmail=StrMail.substr(pos);
		if ( (StrMail.length < 5) || (dotpos <= 0) ){
			alert(msg);
        	return (false);
        }
	} else {
		alert(msg);
		return false;
	}
    return true;
}

