var Comment = {
	errors : [],
	emailRegex : /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,

	submit : function(){
		if(this.validate()){
			return true;
		}	else {
			return false;
		}
	}

	validate : function(){
		this.hideErrors();
		var valid = false;
		return this.validateName() && this.validateEmail() && this.validateComment();
	},

	validateName : function(){
		var name = $.trim($('#comment-name').val());
		if(name == ''){
			this.displayError('name', 'cannot be blank');
			return false;
		}
	},

	validateEmail : function(){
		var email = $.trim($('#comment-email').val());
		if(email == ''){
			this.displayError('email', 'cannot be blank');
			return false;
		}
		if(!this.emailRegex.test(email)){
			this.displayError('email', 'does not appear to be valid');
		}
	},

	validateComment : function(){
		var comment = $.trim($('#comment-comment').val());
		if(comment == ''){
			this.displayError('comment', 'cannot be blank');
			return false;
		}
	},

	hideErrors : function(){
		var els = $('.comment-error');
		for(var i=0, l=els.length; i < l; ++i){
			els[i].hide();
		}
	},

	displayError : function(field, message){
		var el = $('#comment-' + field + 'error');
		el.innerHTML = message;
		el.show();
	}
};
