﻿function validate (myForm) {
   if (isEmpty (myForm.messageType)) {
      alert ('Please select the type of message you want to send');
      return false;
   }

  var missedField = ""; // This is the variable that will receive all the missed fields

// Check if any of the required field are empty
   if ((isEmpty (myForm.firstName))    ||
       (isEmpty (myForm.lastName))     ||
       (isEmpty (myForm.emailAddress)) ||
       (isEmpty (myForm.subject))      ||
       (isEmpty (myForm.message)))
	   {

       if (isEmpty (myForm.firstName))
   			{
			          missedField = missedField + "- your first name, \n";
			}
	   if (isEmpty (myForm.lastName))
			{
					  missedField = missedField + "- your last name, \n";
			}
        if (isEmpty (myForm.emailAddress))
	    	{
			         missedField = missedField + "- your e-mail address, \n";
			}
        if (isEmpty (myForm.subject))
	    	{
			         missedField = missedField + "- the subject, \n";
			}
        if (isEmpty (myForm.message))
	    	{
			         missedField = missedField + "- your message, \n";
			}

          missedField = missedField
		  alert("Please fill in: \n" + missedField + "\n Thank you.");
	     return false;

	   }

   else if (( ! isValidName  (myForm.firstName)) ||
            ( ! isValidName  (myForm.lastName)))   {
      alert ('One or more invalid characters were entered in one of the fields');
      return false;
   }
   else if ( ! isValidEmail (myForm.emailAddress)) {
      alert ('Please enter a valid e-mail address');
      return false;
	  
   }

	   formProtect();     // Call the function for the submit of the form. 

   return true;
   
}

/*



function validateForm()
{
    valid = true;

    if ( document.getElementById('verify').value != "orange" )
    {
        alert ( "You must answer the 'orange' question to submit this form." );
		document.getElementById('verify').value = "";
		document.getElementById('verify').focus();
		valid = false;
    }

    return valid;
}


*/