function formValidator()
{
	// set up array to hold error messages
	this.errorList = new Array;
	// set up object methods
	this.isEmpty = isEmpty; 
	this.isNumber = isNumber; 
	this.isAlphabetic = isAlphabetic; 
	this.isAlphaNumeric = isAlphaNumeric; 
	this.isWithinRange = isWithinRange; 
	this.isEmailAddress = isEmailAddress; 
	this.isHarvardEmailAddress = isHarvardEmailAddress; 
	this.isChecked = isChecked; 
	this.raiseError = raiseError; 
	this.numErrors = numErrors; 
	this.displayErrors = displayErrors; 
}

function isEmpty(val)
{
	if (val.match(/^s+$/) || val == ""){
		return true;
	}
	else {
		return false;
	} 
}

function isNumber(val)
{
	if (isNaN(val)){
		return false;
	}
	else {
		return true;
	} 
}

function isAlphabetic(val)
{
	if (val.match(/^[a-zA-Z]+$/)) {
		return true;
	}
	else {
		return false;
	} 
}

function isAlphaNumeric(val)
{
	if (val.match(/^[a-zA-Z0-9]+$/)) {
		return true;
	}
	else {
		return false;
	} 
}

function isWithinRange(val, min, max)
{
	if (val >= min && val <= max) {
		return true;
	}
	else {
		return false;
	} 
}

function isEmailAddress(val) {
	if (val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/)) {
	    return true;
	}
    else {
        return false;
    }
        
}

function isHarvardEmailAddress(val)
{
	//   ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$
	if ( val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@(post.harvard.edu)$/) ||  
		 val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@(harvard.edu)$/) ||  
		 val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(.hbs.edu)$/) || 
		 val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@(hbs.edu)$/) 
	   ) {
			return true;
	}
	else {
		return false;
	} 
}

function isChecked(obj)
{
	if (obj.checked) {
		return true;
	}
	else {
		return false;
	} 
}

function displayErrors()
{			
	document.getElementById('error').innerHTML = "";
	for (x=0; x<this.errorList.length; x++) {
		if(x==0) {
			document.getElementById('error').innerHTML += "<font color='red'>The following problems must be fixed:</font>";
			er = "The following problems must be fixed:\n";
		}
		document.getElementById('error').innerHTML += "<br/>"+this.errorList[x];
		er += "\n" + this.errorList[x];
		if(x == this.errorList.length-1) {
			//document.getElementById('error').innerHTML += "</font>"
			alert(er);
		}
	}
}

function raiseError(msg)
{
	this.errorList[this.errorList.length] = msg;
}

function numErrors()
{
	return this.errorList.length;
}
