//This function verifies the field data.
//Return true or false.
function verify(Form) {

	//VALIDATE field must be set to 'true'
	if (document.faster.VALIDATE.value == "True") {

		//Regular expressions.
		var BlankFormat = /^.+$/
		var DateFormat = /^\d{1,2}\D?(\d{1,2}\D?)?\d{2}(\d{2})?$/
		var PhoneFormat = /^\D?[2-9]\d{2}\D?\d{3}\D?\d{4}$/
		var EmailFormat = /^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]?))*@([0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*\.{1}[a-zA-Z]{2,4})+$/
		var ZipFormat = /^(\d{5}(-\d{4})?)$|^([a-zA-Z]\d[a-zA-Z]( )?\d[a-zA-Z]\d)$/
		var IntFormat = /^\d+$/
		var CardNumFormat = /^\d{4}\D?\d{4}\D?\d{4}\D?\d{4}$/

		var AlertMessage = "There are errors in these fields:\n\n";

		//This variable represents if the form is valid or not.
		var Verified = true;

		//This variable represents if the individual field passes validation.
		var Passed = false;

		var email;
		var confirmEmail;

		//Loops through each input in the form.
		for (var i = 0; i < Form.length; i++) {

			//Set the form element to a variable.
			var e = Form.elements[i];

			//If the field is not hidden, a submit button, or a reset button...
			if (e.type != "hidden" && e.type != "submit" && e.type != "reset") {

				if (e.name == "VEMAILEmail") email = e.value;
				if (e.name == "VEMAILConfirmEmail") confirmEmail = e.value;

				//This If..Else block checks each field's Name for certain key words.
				//If the Name contains a key word, it checks the fields value against
				//the appropriate regular expression, setting the Passed variable to 
				//either true or false.
				if (e.name.search("VLD") != -1) { Passed = BlankFormat.test(e.value); }                        			            //Blank field check
				else if (e.name.search("VINT") != -1) { Passed = IntFormat.test(e.value); } 		                                    //Integer-only check
				else if (e.name.search("VCHECKED") != -1) { e.name.replace("VCHECKED", ""); if (!e.checked) { Passed = false; } }             //Checkbox-is-checked chec
				else if (e.name.search("VDROPDOWN") != -1) { e.name.replace("VDROPDOWN", ""); if (e.selectedIndex == 0) { Passed = false; } } //Drop down first option not selected check
				else if (e.name.search("VZIP") != -1) { Passed = ZipFormat.test(e.value); } 		                                    //Zip code format check
				else if (e.name.search("VEMAIL") != -1) { Passed = EmailFormat.test(e.value); } 	                                    //Email format check
				else if (e.name.search("VPHONE") != -1) { Passed = PhoneFormat.test(e.value); } 	                                    //Phone number format check
				else if (e.name.search("VCC") != -1) { Passed = CardNumFormat.test(e.value); } 		                                //Credit card number format check
				else if (e.name.search("VDATE") != -1) { Passed = DateFormat.test(e.value); } 		                                //Date format check
				else { Passed = true; }

				//If the field does not pass validation, Verified is set to false,
				//and the border is set to red and adds the field's ID to the alert message.
				if (!Passed) {
					e.style.border = '3px solid red';
					AlertMessage += "* " + e.id + "\n";
					Verified = false;
				} else {
					e.style.border = '2px solid green';
				}
			}
		}

		//If the form is not Verified, a dialog box is displayed with the alert message.
		if (Verified == true) {
			if (email == confirmEmail)
				return true;
			else {
				alert("Email addresses must match");
				return false;
			}
		}
		else {
			alert(AlertMessage + '\n\nCorrect these problems to continue.');
			return false;
		}

	}

	return true;
};
