Ext.namespace("Garmin");

var ERROR_MESSAGE_CLASS = "errorMessage";
var WARN_MESSAGE_CLASS = "warnMessage";
var INFO_MESSAGE_CLASS = "infoMessage";
var MESSAGES_DIV = "messages";

/**
 * The Messages class is used to display messages in the standard location
 * and style as all other messages in the system.  Always go through this 
 * class to display messages from javascript.  This should be included by 
 * default on all pages.
 *
 * Author: Michael Bina
 */
Garmin.Messages = function() {
	
	return {
		init : function(){
		},
		
		clearMessages: function() {
			$(MESSAGES_DIV).innerHTML = '';
		},
		
		// NOTE: this does not know about JSF messages, only javascript
		isEmptyMessages: function() {
			return $(MESSAGES_DIV).innerHTML == '';
		},
		
		showErrorMessage: function(message) {
			this.showMessage(message, ERROR_MESSAGE_CLASS);
		},

		showInfoMessage: function(message) {
			this.showMessage(message, INFO_MESSAGE_CLASS);
		},

		showWarnMessage: function(message) {
			this.showMessage(message, WARN_MESSAGE_CLASS);
		},

		showMessage: function(message, clazz) {
			var errorMessage = document.createElement('li');
			errorMessage.innerHTML = message;
			errorMessage.className = clazz;
			$(MESSAGES_DIV).appendChild(errorMessage);
		}
	};  
}();
