// JavaScript Document

document.form1.onsubmit = function validate_me () {

return FormValidator(document.form1); 
}


 function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf('@');
  if (index > 0)
  {
    var pindex = theStr.indexOf('.',index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function FormValidator(theForm)
{

  /* if (theForm.entrycode.value != 'MPA')
  {
    alert('Sorry, that was an incorrect Competition Entry Code.');
    theForm.entrycode.focus();
    return (false);
  } */
  if (theForm.firstname.value == '')
  {
    alert('Please enter something for \'Your First Name\' field.');
    theForm.firstname.focus();
    return (false);
  }
  if (theForm.lastname.value == '')
  {
    alert('Please enter something for \'Your Last Name\' field.');
    theForm.lastname.focus();
    return (false);
  }
  if (theForm.street.value == '')
  {
    alert('Please enter something for \'Address\' field.');
    theForm.street.focus();
    return (false);
  }
  if (theForm.suburb.value == '')
  {
    alert('Please enter something for \'Suburb\' field.');
    theForm.suburb.focus();
    return (false);
  }
  if (theForm.pcode.value == '')
  {
    alert('Please enter something for \'Postal Code\' field.');
    theForm.pcode.focus();
    return (false);
  }
  if (theForm.email.value == '')
  {
    alert('Please enter something for the \'Your Email Address\' field.');
    theForm.email.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.email.value))
  {
    alert('Please enter a complete email address in the form:\n yourname@yourdomain.com');
    theForm.email.focus();
    return (false);
  }
   
  if (theForm.email.value.length < 3)
  {
    alert('Please enter at least 3 characters in the \'Your Email Address\' field.');
    theForm.email.focus();
    return (false);
  }
  return (true);
}

