/**
 * make Prototype compatible with mootools
 * 
 * @version $Id$
 * @author tvlgiao
 */

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};


if (typeof vfm != 'object') vfm = {};

/**
 * @package vfm.Element
 */
vfm.Element = {
	/**
	 * @static
	 */
	hide: function (obj) {
		$(obj).style.display = 'none';
	},
	
	/**
	 * @static
	 */
	show: function (obj) {
		$(obj).style.display = '';
	},
	
	/**
	 * @static
	 */
	remove: function (obj) {
		$(obj).remove();
	},
	
	/**
	 * @static
	 */
	addClassName: function (obj, className) {
		$(obj).addClass(className);
	},
	
	/**
	 * @static
	 */
	removeClassName: function (obj, className) {
		$(obj).removeClass(className);
	}
};

/**
 * @package vfm.Event
 */
vfm.Event = {
	/**
	 * @static
	 */
	observe: function (elm, event, callback, capture) {
		return $(elm).addEvent(event, callback, capture);
	}
};

/**
 * @package vfm.Ajax
 */
vfm.Request = {
	Json: new Class({
		initialize: function(){
			new Request({method: 'get', url: 'http://site.com/requestHandler.php'}).send('name=john&lastname=dorian');
		}
	})
};

vfm.Ajax = {
	/**
	 * @class
	 */
	Request: new Class({
		/**
		 * @constructor
		 */
		initialize: function(url, options) {
			if (typeof options == 'object' && options.parameters != 'undefined')
				options.data = options.parameters;
					
			new Ajax(url, options).request();
		}
	}),
	
	/**
	 * @class
	 */
	Updater: new Class({
		/**
		 * @constructor
		 */
		initialize: function(container, url, options) {
			if (typeof options != 'object') options = {};
			options.update = $(container);
			options.data = options.parameters;
			var text = url+"?"+options.parameters;

			new Ajax(text, options).request();
		}
	})
};

/**
 * @package
 */
vfm.Insertion = {};

/**
 * @package
 */
vfm.Form = {
	serialize: function(obj){
		var test = $(obj).toQueryString();
		return test;
	}
};

/**
 * @class
 */
vfm.Insertion.After = new Class({
	initialize: function (elm, content) {
		var div = new Element('div');
		div.setHTML(content).injectBefore($(elm));
		div.getChildren().each(function (child) {
			child.injectBefore(elm);
		});
		div.remove();
	}
});


if (typeof $F == 'undefined') 
	$F = function (elm) {
		return $(elm).getValue();
	}