/**
* a javascript class for form validation
* for now it's only validating required fields, you may add your own validation
* @author: markg
* @on: 5/25/2008
* @email: markglibres@yahoo.com
*/
function FormValidator()
{
	this.requireFields = null;
	this.requireFieldDescription = null;
	
};

FormValidator.prototype.getFields = function()
{
	if(!this.requiredFields)
	{
		this.requiredFields = new Array();
		this.requireFieldDescription = new Array();
	}
	
}

FormValidator.prototype.addField = function(fieldName, fieldDescription, validationType)
{
	this.getFields();
	/**sets default validation type**/
	if(validationType == null)
		validationType = 'required';
		
	if(validationType == 'required')
	{
		this.requiredFields[this.requiredFields.length] = fieldName;
		this.requireFieldDescription[this.requireFieldDescription.length] = fieldDescription;
	}


};

FormValidator.prototype.validate = function()
{
	var notValidated = new Array();
	for(i=0;i<this.requiredFields.length;i++)
	{
		obj = document.getElementById(this.requiredFields[i]).value;

		if(!obj.replace(/^\s+|\s+$/g, ''))
		{
			notValidated[notValidated.length]= this.requireFieldDescription[i];
			
		}
	}
	if(notValidated.length > 0)
	{
		msg = "The following fields are required:\n ";
		for(i=0;i<notValidated.length;i++)
			msg += "\n"+notValidated[i];
		alert(msg);
		return false;
	}
	return true;
};

