// JavaScript Validation

// Email Validation
function validEmail(email){
	invalidChars = "/:,;"
	
	if (email == ""){		// cannot be empty
		return false
	}
	for (i=0; i<invalidChars.length; i++){		// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1){
			return false
		}
	}
	atPos = email.indexOf("@",1)		// there must be one "@" symbol
	if (atPos == -1){
		return false
	}
	if (email.indexOf("@",atPos+1) != -1){		//and only one "@" symbol
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1){						//and at least one "." after the "@"
		return false
	}
	if (periodPos+3 > email.length) {			// must be at least 2 characters after the "."
		return false
	}
	return true
}

function submitIt(theForm){

	var errMessage = "";
	
	//First Name Validation
	if(theForm.txtFirstName.value == "") {
		errMessage += "- First Name \n";
	}
	
	//Last Name Validation
	if(theForm.txtLastName.value == "") {
		errMessage += "- Last Name \n";
	}
	
	//Email Validation
	if (!validEmail(theForm.txtEmail.value)) {
		errMessage += "- Email Address \n";
		theForm.txtEmail.focus()
		theForm.txtEmail.select()
	}
	
	//Question Comment Validation
	if(theForm.txtaComments.value == "") {
		errMessage += "- Comments \n";
	}
	if (!(errMessage == ""))
	{ 
	alert("The following fields are required: \n" + errMessage);
	return false
	}
	else 
	{
	
	document.forms.theForm.submit();
	
	}
	window.location="handle_form.php";
}
