/* These validation functions are based on sample code from
   http://javascript.internet.com/forms/mailing-list.html and
   http://www.w3schools.com/js/js_form_validation.asp. However,
   the code has been improved for better programming style
   and use of functions.
*/

function validateForm(doc)
{
   var valid = true;
   if (!doc.firstName.value)
   {
      document.getElementById('fNameLbl').style.color = "#ff0000";
      valid = false;
   }
   else	// Fields are 'blackened', in case they had been 'reddened' during a previous parsing pass.
      document.getElementById('fNameLbl').style.color = "#000000";
   
   if (!doc.lastName.value)
   {
      document.getElementById('lNameLbl').style.color = "#ff0000";
      valid = false;
   }
   else
      document.getElementById('lNameLbl').style.color = "#000000";
   
   if (!doc.custEmail.value)
   {
      document.getElementById('emailLbl').style.color = "#ff0000";
      valid = false;
   }
   else
      if (!validateEmail(doc.custEmail.value))
      {
         document.getElementById('emailLbl').style.color = "#ff0000";
         valid = false;
      }
      else
         document.getElementById('emailLbl').style.color = "#000000";
 
   if (!valid)
   {
      alert("Please check the fields marked in red.\n" +
            "They are either not filled out, \nor have" +
            " an incorrect value.");
      return false;
   }
   else
      return true;
}

function validateEmail(address)
{
   emailRegExp = /\S+@\S+\.\S{1,4}/;
   if (emailRegExp.exec(address))
      return true;
   else
      return false;
}
