function FormValidator()
{
	this.is_valid = true;
	this.errors = Array();

	this.alpha_regex =  /^[a-zA-Z]+$/;
	this.alpha_numeric_regex = /^[a-zA-Z0-9]+$/;
	this.email_regex = /(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)/i;
}

FormValidator.prototype.raiseError = function(msg)
{
	this.is_valid = false;
	this.errors[this.errors.length] = msg;
}

FormValidator.prototype.isValid = function()
{
	return this.is_valid;
}

FormValidator.prototype.countErrors = function()
{
	return this.errors.length;
}

FormValidator.prototype.getErrors = function()
{
	return this.errors;
}

FormValidator.prototype.alertErrors = function()
{
	var msg = 'Please correct the following errors:\n';
	for(var i=0;i<this.errors.length;i++) {
		msg += this.errors[i] + '\n';	
	}
	alert(msg);
}

FormValidator.prototype.notEmpty = function(value, msg)
{
	if(value.length == 0) {
		this.is_valid = false;
		this.errors[this.errors.length] = msg;
		return false;
	}

	return true;
}

FormValidator.prototype.notEquals = function(value, not_value, msg)
{
	if(value == not_value) {
		this.is_valid = false;
		this.errors[this.errors.length] = msg;
		return false;
	}
	return true;
}

FormValidator.prototype.isNumeric = function(value, msg)
{
	if(isNaN(val)) {
		this.is_valid = false;
		this.errors[this.errors.length] = msg;
		return false;
	}
	return true;
}

FormValidator.prototype.isWithinNumericRange = function(value, min, max, msg)
{
	if(val < min || val > max) {
		this.is_valid = false;
		this.errors[this.errors.length] = msg;
		return false;
	}
	return true;
}

FormValidator.prototype.isAlpha = function(value, msg)
{
	return this.matchRegex(value, this.alpha_regex, msg);
}

FormValidator.prototype.isAlphaNumeric = function(value, msg)
{
	return this.matchRegex(value, this.alpha_numeric_regex, msg);
}

FormValidator.prototype.isEmail = function(value, msg)
{
	return this.matchRegex(value, this.email_regex, msg);
}

FormValidator.prototype.matchRegex = function(value, regex, msg)
{
	if(typeof regex != 'Object') {
		regex = new RegExp(regex);
	}
	
	if(value.search(regex) == -1) {
		this.is_valid = false;
		this.errors[this.errors.length] = msg;
		return false;
	}
	return true;
}

FormValidator.prototype.isChecked = function(field, msg)
{
	for(var i=field.length-1;i>-1;i--) {
		if(field[i].checked) {
			return true;
		}
	}

	this.is_valid = false;
	this.errors[this.errors.length] = msg;
	return false;
}
