var emptyString = /^\s*$/ ;

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}
// --------------------------------------------
//            validar cadena
// Validate if something has been entered
// Returns true if so 
// --------------------------------------------

function validatePresent(valfield)   // element to be validated
 
{
 return !(emptyString.test(trim(valfield.value)))
}


// --------------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// --------------------------------------------

function validateEmail  (valfield) // element to be validated
                        
{
 

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;

  return (email.test(tfld));
}


  function validateOnSubmit() {

    var errs=0;
   
    if (!validateEmail  (document.forms.formulario.email))        errs += 1; 
    if (!validatePresent(document.forms.formulario.fname))        errs += 1;
	if (!validatePresent(document.forms.formulario.lname))        errs += 1; 
	
    if (errs>0)  alert('There are '+errs+' field(s) which need correction before sending.');
      
    return (errs==0);
  }
  
	
  };
  //festivaprods 2006
