﻿// JavaScript Document
// to CHECK form fields
// written by Norm Schurdell @ Why Not Design 2006 www.whynotdesign.com
// **** gdform.php CANNOT have form fields starting with NUMBERS validated with JavaScript!!! ***

function CheckFormData() {
	
	error = 'No'
	
	if (contactform.aFirstName.value <= 2) {
			alert("Did you forget to enter your First Name?");
			error = 'Yes';
			contactform.aFirstName.focus();
			contactform.aFirstName.select();
			return false;
		} 
	
	if (contactform.bLastName.value <= 2) {
			alert("Did you forget to enter your Last Name?");
			error = 'Yes';
			contactform.bLastName.focus();
			contactform.bLastName.select();
			return false;
		} 
		
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	
	if (re.test(contactform.cEmail.value)) {
			error = 'No';
			return true;
	} else {
			alert("Did you enter a valid Email Address?");
			error = 'Yes';
			contactform.cEmail.focus();
			contactform.cEmail.select();
			return false;
	}
	
	if (error == 'Yes') {
		return false;
	} else if (error == 'No') {
		return true;
	} else {
		alert("Something went wrong while processing the form. Please email support@whynotdesign.com!");
	}
}

function CheckFormDataEnews() {
	
	error = 'No'
	
	if ((enewsform.aFullName.value == 'Your Full Name') || (enewsform.aFullName.value.length <= 5)) {
			alert("Did you forget to enter your Full Name?");
			error = 'Yes';
			enewsform.aFullName.focus();
			enewsform.aFullName.select();
			return false;
		}
		
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	
	if (re.test(enewsform.bEmail.value)) {
			error = 'No';
			return true;
	} else {
			alert("Did you enter a valid Email Address?");
			error = 'Yes';
			enewsform.bEmail.focus();
			enewsform.bEmail.select();
			return false;
	}
	
	if (error == 'Yes') {
		return false;
	} else if (error == 'No') {
		return true;
	} else {
		alert("Something went wrong while processing the form. Please email support@whynotdesign.com!");
	}
}