// =================================================================

// FUNCTION NAME: valForm

//       PURPOSE: Validates the form passed in from contact.php

//        AUTHOR: Robert W. Makynen, MCSD

//          DATE: March 27, 2007

//      MODIFIED: March 31, 2007

//         NOTES: Additional field checks can be added to the

//                valForm function if validation of other data

//                is desired.

// =================================================================

function valForm(sForm) {

	

	// Check for a valid first name...

	if (sForm.txtFirstName.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please tell us your first name");

			sForm.txtFirstName.focus();

			return false;

	}

	

	// Check for a valid last name...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (sForm.txtLastName.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please tell us your last name");

			sForm.txtLastName.focus();

			return false;

	}*/

	

	// Check for a valid address...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (sForm.txtAddress.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please provide your address");

			sForm.txtAddress.focus();

			return false;

	}*/

	

	// Check for a valid city...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (sForm.txtCity.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter your city");

			sForm.txtCity.focus();

			return false;

	}*/

	

	// Check for a valid state...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (sForm.txtState.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter your state");

			sForm.txtState.focus();

			return false;

	}*/

	

	// Check for a valid zip code...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (!IsNumeric(sForm.txtZip.value) || sForm.txtZip.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter a valid zip code");

			sForm.txtZip.focus();

			return false;

	}*/

	

	// Check for a valid phone area code...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (!IsNumeric(sForm.txtArea.value) || sForm.txtArea.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter a valid telephone area code");

			sForm.txtArea.focus();

			return false;

	}*/

	

	// Check for a valid phone exchange...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (!IsNumeric(sForm.txtExchange.value) || sForm.txtExchange.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter a valid telephone exchange");

			sForm.txtExchange.focus();

			return false;

	}*/

	

	// Check for a valid phone number...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (!IsNumeric(sForm.txtNumber.value) || sForm.txtNumber.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter a valid telephone number");

			sForm.txtNumber.focus();

			return false;

	}*/

	

	// Check for a valid cell area code...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (!IsNumeric(sForm.txtCellArea.value) || sForm.txtCellArea.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter a valid fax area code");

			sForm.txtCellArea.focus();

			return false;

	}*/

	

	// Check for a valid fax exchange...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (!IsNumeric(sForm.txtCellExchange.value) || sForm.txtCellExchange.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter a valid fax exchange");

			sForm.txtCellExchange.focus();

			return false;

	}*/

	

	// Check for a valid fax number...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (!IsNumeric(sForm.txtCellNumber.value) || sForm.txtCellNumber.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please enter a valid fax number");

			sForm.txtCellNumber.focus();

			return false;

	}*/

	

	// Check for a valid email address...

	if (!valEmail(sForm.txtEmail.value)){

			// If we get here, no data was entered into the email

			// field, or a valid email address wasn't entered...

			alert("Please provide us with a valid email address.");

			sForm.txtEmail.focus();

			return false;

	}

	

	// Check for a valid confirmation email address...

	if (!valEmail(sForm.txtEmailConfirm.value)){

			// If we get here, no data was entered into the email

			// field, or a valid email address wasn't entered...

			alert("Please provide us with a valid confirmation email address.");

			sForm.txtEmailConfirm.focus();

			return false;

	}

	

	// Now we need to make sure that the two email address fields match...

	if (sForm.txtEmail.value !== sForm.txtEmailConfirm.value){

			// If we get here the email values don't match...

			alert("Your email confirmation does not match the email value you entered.");

			sForm.txtEmailConfirm.focus();

			return false;

	}

	

	// Check to make sure the user provided a comment or question...

	/* Procedure removed at the request of Shelley Ladin on 3/30/2007

	if (sForm.txtComment.value == ''){

			// If we get here, no data was entered into the field...

			alert("Please share your comment or question");

			sForm.txtComment.focus();

			return false;

	}*/

}





// =================================================================

// FUNCTION NAME: IsNumeric

//       PURPOSE: Checks for valid numeric strings

//        AUTHOR: Robert W. Makynen, MCSD

//          DATE: February 28, 2007

//      MODIFIED: March 01, 2007

//         NOTES: (None)

// =================================================================

function IsNumeric(strString) {

   //  Check for valid numeric strings...

   var strValidChars = "0123456789";

   var strChar;

   var blnResult = true;



   if (strString.length == 0) return false;



   //  Test that strString consists of valid characters listed above...

   for (i = 0; i < strString.length && blnResult == true; i++)

      {

      strChar = strString.charAt(i);

      if (strValidChars.indexOf(strChar) == -1)

         {

         blnResult = false;

         }

      }

   return blnResult;

}





// =================================================================

// FUNCTION NAME: valEmail

//       PURPOSE: Validates the email address passed in

//                to see if it is valid

//        AUTHOR: Robert W. Makynen, MCSD

//          DATE: February 28, 2007

//      MODIFIED: March 01, 2007

//         NOTES: (None)

// =================================================================

// =================================================================

function valEmail(email) {



	AtPos = email.indexOf('@') // Position of the '@' symbol

	StopPos = email.lastIndexOf('.') // Position of the '.'

	

	if (email == "") {

		// Email field was blank...

		return false;

	}

	

	if (AtPos == -1 || StopPos == -1) {

		// Text does not contain '@' or '.'

		return false;

	}

	

	if (StopPos < AtPos) {

		// The last occurrence of '.' appeared before '@'

		return false;

	}

	

	if (StopPos - AtPos == 1) {

		// The '.' appears directly after '@'

		return false;

	} 

	

	// If we get this far then we're in the clear and

	// we have a valid email address, so we'll return

	// 'true' to the caller...

	return true;

}

