var validate = function(){
    this.errors = [];
	this.formErrorClass;
	
	//check if a field is blank
	this.isBlank = function(field){
        var value = field.val()
		//console.log(value);
		var id = this.formatFieldName(field);
		//console.log("id: " + id);
		if(value == ""){
			this.errors.push(id + " cannot be blank");
			this.highLightErrors(field); 
			return false;
		} else {
			field.removeClass(this.formErrorClass);
			return true;
		}
	}

	//check to make sure a valid email address is provided
	this.isEmail = function(field){
		var filter = /^([\w-]+(?:\.[\w-]+)*)\@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$|(\[?(\d{1,3}\.){3}\d{1,3}\]?)$/i;
		var str = field.val();
		var id = this.formatFieldName(field);
		if(filter.test(str)){
			field.removeClass(this.formErrorClass);
			return true;
		} else {
			this.errors.push(id + " is not a valid email address");
			this.highLightErrors(field);
			return false;
		}
		
	}
	
	//check the minimum length of field
	this.isMinChars = function(field,len){
		var str = field.val();
		var id = this.formatFieldName(field);
		if(str.length < len){
			this.errors.push(id + " needs to be at least " + len + " characters");
			this.highLightErrors(field);
			return false;
		} else {
			field.removeClass(this.formErrorClass);
			return true;	
		}
	}
	
	//format the id of the field with inital caps
	this.formatFieldName = function(field){
		var initialCap = field.attr("title").substring(0,1).toUpperCase();
		var restName = field.attr("title").substring(1,field.attr("title").length);
		return id = initialCap + restName;
		
	}
	
	//check for errors
	this.isErrors = function(){
		if(this.errors.length > 0){
			return true;
		} else {
			return false;
		}
	}
	
	//add error css to the field with the error
	this.highLightErrors = function(field){
		field.addClass(this.formErrorClass);
	}
	
	//get the errors
	this.getErrors = function(ele){
		var msg = "<h2>Sorry, there are some errors. Please fix the following items:</h2>";
		msg += "<ul>";
		var error = this.errors;
		for(i=0; i < this.errors.length; i++){
			msg += "<li>" + error[i] + "</li>";
		}
		msg += "</ul>";
		//console.log(msg);
		ele.html(msg);
	}
}
