var FV = new Object();
Object.extend(FV, {
	
	theForm: '',
	theErrors: Array(),
	theValidity: false,
	theChecks: Array(),
	
	Install: function(aForm, aList)
	{
		this.theForm = aForm;
		this.theChecks = aList;		
	},
	
	Run: function()
	{
		this.Validate();
		
		if(!this.IsValid())
		{
			alert(this.ReportErrors());
			return false;
		}
		
		return true;
	},
	
	Validate: function()
	{
		this.theErrors = Array();
		
		for(var i=0; i<this.theChecks.length; i++)
		{
			if(!this.ValidationChooser(this.theChecks[i].type, this.theForm[this.theChecks[i].name].value))
			{
				this.AddError(this.theChecks[i].msg);
			}
		}
		
		this.theValidity = (this.theErrors.length > 0) ? false : true;
		return this.IsValid();
	},
	
	IsValid: function()
	{
		return this.theValidity;
	},
	
	ValidationChooser: function(aType, aValue)
	{
		switch(aType.toLowerCase())
		{
			case "empty":
				return this.ValidateEmpty(aValue);
				break;
			
			case "email":
				return this.ValidateEmail(aValue);
				break;
		}
	},
	
	ValidateEmpty: function(aValue)
	{
		return (aValue.length > 0 && aValue != "0") ? true : false;
	},
	
	ValidateEmail: function(anEmail)
	{
		return (anEmail.indexOf("@") != -1 && anEmail.length > 6) ? true: false;
	},
	
	AddError: function(anError)
	{
		this.theErrors.push(anError);
	},
	
	ReportErrors: function(aType)
	{
		var theMsg = "There were some errors with the form.\n\n";
		
		for(var i=0; i<this.theErrors.length; i++)
		{
			theMsg += this.theErrors[i] + "\n";
		}
		
		return theMsg;
	},
	
	ClearErrors: function()
	{
		this.theErrors = Array();
	}
	
});