<!--// Hide from inept browsers
// var pattern = new RegExp('[^@,\s]*%?[^@,\s]+@\w+[\.\w+]+$');
// var pattern = new RegExp('^.+@.+\..{2,3}$');
// var pattern = new RegExp('^\w+@\w+(\.\w+)+$'); // Charity Kahn's "sane" email RegExp
// var pattern = new RegExp('^\w+\.*\w*@\w+(\.\w+)*\.\w{2,3}$'); // My new RegExp (11/2/99)
var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,6}$/;
// var pattern = new RegExp("^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z][a-zA-Z][a-zA-Z]?$");

function isEmail(s) {
   if(s != "") {
		if(!pattern.test(s)) {
			alert("\""+s+"\""+" non è un indirizzo di posta elettronica valido.");
			return false;
		}
   }
   else {
      alert("You appear to have left the email address field blank. What's up with that?");
      return false;
   }
return true;   
}

function empty(s) {
  // An empty string is defined as a string that is null
  // or a string that is empty (contains no characters)
  // once all whitespace has been removed from the
  // beginning and end. If your definition is different
  // you would define a different function.
  return (s == null || (new String(s)).Trim() == "");
}
// Trim prototypes from the FAQ
// <url: http://jibbering.com/faq/#FAQ4_16 />
String.prototype.LTrim=new Function("return this.replace(/^\\s+/,'')");
String.prototype.RTrim=new Function("return this.replace(/\\s+$/,'')");
String.prototype.Trim= new Function("return this.replace(/^\\s+|\\s+$/g,'')");

function validate(){ 

	if (empty(document.LibroOspitiForm.nome.value)) {
    	alert("Inserire il nome");
    	document.LibroOspitiForm.nome.focus();
    	return false;
	}
	if (empty(document.LibroOspitiForm.soggetto.value)) {
    	alert("Inserire il soggetto");
    	document.LibroOspitiForm.soggetto.focus();
    	return false;    	
	}
	if (empty(document.LibroOspitiForm.commento.value)) {
    	alert("Inserire il commento");
    	document.LibroOspitiForm.commento.focus();
    	return false;    	
	}
	if (!empty(document.LibroOspitiForm.email.value)) {
    	 //check for valid date structures
         validdate1 = isEmail(document.LibroOspitiForm.email.value);
         
          if (!validdate1) {
            document.LibroOspitiForm.email.focus();
            return false;
          }
	}
return true;		
} 