// JavaScript Document
function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
};

// -----------------------------------------
//                  validateEmail
// Validates for correctness of email address
// -----------------------------------------
function validateEmail(field)   // true if required
{

  var tfld = trim(field.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
  if (!email.test(tfld)) 
  {
    return false;
  }
  
  return true;
}

// -----------------------------------------
//                  validateForm
// Validates all fields in the form
// -----------------------------------------
function validateForm()
{

	var frm = document.frmContact
	
	//Validate name field
	if(trim(frm.name.value)=='')
	{
		alert('Please provide your name.');
		frm.name.focus();
		return false;
	}
	
		//Validate email exists.
	if(trim(frm.email.value)=='')
	{
		alert('Please provide your email address.');
		frm.email.focus();
		return false;
	}
	
	//Validate email is valid.
	if(!validateEmail(frm.email))
	{
		alert('The email address provided is not valid.');
		frm.email.focus();
		return false;
	}
	
	
	return true;
}