/* =========================================================================

JavaScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1

NAME: 

AUTHOR: Anthony Pollock , County of Henrico Public Library
DATE  : 2/17/2009

COMMENT: 

============================================================================ */

function validateForm(){
	var objForm = document.forms[0];
	var strError = "";
	
	if ( objForm.Question.value.length == 0 ) {
		strError += "- No question was entered\r\n";
		objForm.Question.focus();
	}
	
	if ( objForm.Email.value.length == 0 ) {
		strError += "- Email Field Required\r\n";
		objForm.Email.focus();
	}
	
	if ( !isValidEmail( objForm.Email.value ) ) {
		strError += "- Not a valid email address\r\n";
		objForm.Email.select();
		objForm.Email.focus();
	}
	
	if ( strError.length > 0 ) {
		alert( "Please correct the following errors:\r\n\r\n" + strError );
		return false;
	} else {
 		objForm.submit();
	}
}

//function to check valid email address
function isValidEmail( strEmail ){
	var isValid = true;
	var validRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
	// search email text for regular exp matches
   	if (strEmail.search(validRegExp) == -1){
     	isValid = false;
   	} 
   	return isValid; 
}

function resetForm() {
	var objForm = document.forms[0];
	
	objForm.reset();
	objForm.Email.focus();
} 