
function formValidator() {
	
	var errors = new Array();
	this.checkText = checkText;
	this.checkSelect = checkSelect;
	this.checkNumeric = checkNumeric;
	this.validateEmailAddress = validateEmailAddress;
	this.numberOfErrors = numberOfErrors;
	this.displayErrors = displayErrors;
	this.getReturn = getReturn;
	this.addError = addError;
	
	function checkText( elID, errorMsg ) {
		if ( document.getElementById( elID ).value == '' ) {
			addError( errorMsg )
			return false;
		} else {
			return true;
		}
	}
	
	function checkSelect( elID, nothingValue, errorMsg ) {
		if ( document.getElementById( elID ).value == nothingValue ) {
			addError( errorMsg )
			return false;
		} else {
			return true;
		}
	}
	
	function checkNumeric( elID, errorMsg ) {
		if ( isNaN( document.getElementById( elID ).value ) ) {
			addError( errorMsg )
			return false;
		} else {
			return true;
		}
	}
	
	function validateEmailAddress( elID, errorMsg ){
		if ( this.checkText( elID, errorMsg ) ) {
			emailAddress = document.getElementById( elID ).value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if ( !filter.test( emailAddress )){
				errors.push( errorMsg );
			}
		}
	}
		
	function addError( str ) {
		errors.push( str );
	}
	
	function numberOfErrors() {
		return errors.length;
	}
	
	function displayErrors() {
		var str = 'Please enter the following details:' + "\n\n";
		for ( var i in errors ) {
			str = str + " - " + errors[i] + "\n";
		}
		alert( str );
	}
	
	function getReturn() {
		if ( this.numberOfErrors() > 0 ) {
			this.displayErrors();
			return false;
		} else {
			return true;
		}
	}
}