 var submiting = false;  
 var whitespace = " \t\n\r";
 var defaultEmptyOK = false

function isEmpty(s)
 {
  return ((s == null) || (s.length == 0));
 }

function isWhitespace(s)
 {
  var i;
  if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++)
   {   
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) return false;
   }
  return true;
 }

function isEmail (s)
 {
  if (isEmpty(s))
   if (isEmail.arguments.length == 1) 
    return defaultEmptyOK;
   else 
    return (isEmail.arguments[1] == true);
  if (isWhitespace(s)) return false;
  var i = 1;
  var sLength = s.length;
  while ((i < sLength) && (s.charAt(i) != "@"))
   {
    i++
   }

  if ((i >= sLength) || (s.charAt(i) != "@"))
   return false;
  else 
   i += 2;
  while ((i < sLength) && (s.charAt(i) != "."))
   {
    i++
   }
  if ((i >= sLength - 1) || (s.charAt(i) != "."))
   return false;
  else
   return true;
 }
 
function isNumber(s)
 {
  var i;
  if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++)
   {   
   	var c = s.substring(i,i+1);
    if (c < "0" || "9" > c) return false; break;
   }
  return true;
 }
 
function warnEmpty (theField, s)
 {
  theField.focus()
  alert("Il campo " + s + " è obbligatorio.")
  return false
 }
 
function warnNumber (theField, s)
 {
  theField.focus()
  alert("Il valore " + s + " deve essere un numero.")
  return false
 }
 
function warnInvalid (theField, s)
 {
  theField.focus()
  theField.select()
  alert(s)
  return false
 }
              
function checkString (theField, s, emptyOK)
 {   
  if (theField == null) return true;
  if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  if (isWhitespace(theField.value))
   return warnEmpty (theField, s);
  else 
   return true;
 }

function checkNumber(theField, s, emptyOK)
 {   
  if (theField == null) return true;
  if (checkNumber.arguments.length == 2) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  if (isNumber(theField.value))
   return warnNumber (theField, s);
  else 
   return true;
  }
 
 function checkEmail (theField, emptyOK)
 {
  if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value)))
   return true;
  else 
   if (!isEmail(theField.value, false))
    return warnInvalid (theField, "L'indirizzo Email deve essere valido!");
   else
    return true;
 }

function validateFormInfo(form)
 {
  if ( submiting )
   {
	return false;
   }

   if (checkString(form.elements["from"],"Indirizzo Email")&&checkEmail(form.elements["from"]))
   {
    submiting = true;
    return true;
   }
  else
   return false;
 }