/*  © Copyright 2001 - 2006 Excira Technologies, Inc. All Rights Reserved.
 * -----------------------------------------------------------------------
 *
 */

var Momento = function() {
	
	return {
	
		/**
		 *
		 */
		generateGetURL : function(module) {

			if ( module == "" )
				return "/";
				
			return "/get" + module.substr(0, 1).toUpperCase() + module.substr(1) + ".ajax";
		},
		
		/**
		 *
		 */
		generatePostURL : function(module) {

			if ( module == "" )
				return "/";
				
			return "/post" + module.substr(0, 1).toUpperCase() + module.substr(1) + ".ajax";
		},
	
		/**
		 *
		 */
		get : function(getSpec) {
		
			// Setup the store
			var store = new Ext.data.JsonStore({
				url:Momento.generateGetURL(getSpec.module),
				root:getSpec.root,
				fields:getSpec.fields
			});
			
			// Get the records and execute callback
			store.load({
				callback:getSpec.callback
			});
		},
		
		/**
		 *
		 */
		removeChildren : function(tagName, parentId) {

			var parentEl = Ext.get(parentId);
			if ( !parentEl )
				return;

			var toRemove = Ext.query(tagName, parentId);
			for ( var i = 0 ; i < toRemove.length ; i++ ) {
				var elToRemove = Ext.get(toRemove[i]);
				if ( elToRemove )
					elToRemove.remove();
			}
		}
	}; 
}();