// function to validate the form
function validate_form(obj) 
{
  var strNeges;
  var blnValid = true;
      
  strNeges = "___________________________________________________________________________\n\n"
  strNeges += "There are problems with the form. Fill in all fields.\n"
  strNeges += "Please correct the following:\n"
  strNeges += "___________________________________________________________________________\n\n"
 
  if (obj.visitor_name.value=="")
  {
	  blnValid = false
	  strNeges += "- Enter your name\n\n"
  }
  
  if (obj.email_address.value=="")
  {
    blnValid = false
    strNeges += "- Enter your email address\n\n"
  }

  if(!gwiro_ebost(obj.email_address.value))
  {
    blnValid = false
    strNeges += "- The email address is not valid\n\n"
  }
  
  if (obj.comment.value=="")
  {
    blnValid = false
    strNeges += "- Enter a comment\n\n"
  }
 
 if (obj.comment.value.length < 5)
  {
    blnValid = false
    strNeges += "- Enter a longer comment\n\n"
  }
  
  // If there are problems, then show the error message
  if (blnValid==false)
  {
    alert(strNeges)
    return false
  }
}

//Check the email address
function gwiro_ebost(prmCyfeiriad_ebost)
{
  var strCyfeiriad;
  var regAnghywir;
  var regCywir;

  strCyfeiriad = prmCyfeiriad_ebost;

  regAnghywir = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; //correct e-mail pattern
  regCywir = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9\-]+)(\]?)$/; //incorrect e-mail pattern
  
  if ( !regAnghywir.test(strCyfeiriad) && regCywir.test(strCyfeiriad) )
  {
	return true;
  }
  else
  {
	return false;
  }
}