
function FormField(name, description, type, additional_params){
	
	this.name = name;
	this.description = description;
	this.type = type;	
	this.additional_params = additional_params; // multi-use
	this.isValid = function(f){
			
				switch(this.type){
					case "text" :
					return (f.elements[this.name].value != "");
					break;
					
					case "number" :
					var number_regex = /^[0-9]+$/;
					return ( number_regex.test(f.elements[this.name].value));
					break;
					
					case "email" :
					var email_regex = /^([a-z0-9_-]+\.)*[a-z0-9_-]+@([a-z0-9_-]+\.)+[a-z]{2,3}$/i;
					return (email_regex.test(f.elements[this.name].value));
					break;
					
					default : return false;
				};
		};
	
}

function validateForm(f){
	
		var fields_with_errors = new Array();
		for (var i in required_fields){
				if(!required_fields[i].isValid(f)){
					
					fields_with_errors[fields_with_errors.length] = required_fields[i].description;
				}
		}
		
		if(fields_with_errors.length > 0){
			alert("Make sure following fields are complete and correct:\n\n-" + fields_with_errors.join("\n -"));
			return false;
		}else{
		return true;
		}
		return false;
}




