// Some adjustments to jquery by Yereth Jansen; www.yereth.nl, www.wharf.nl
(function($){
	$.trim = function(t){
		return typeof t != 'string' ? t : (t||"").replace(/^\s+|\s+$/g, "");
	};
	
	// Serialize an array of form elements or a set of
	// key/values into a query string
	// We add the clean arg, so we can remove values which are not set
	$.param = function( a, clean ) {
		var s = [ ];

		function add( key, value, array ){
			if (!clean || $.trim(value)) s[ s.length ] = encodeURIComponent(key) + (array ? '[]=' : '=') + encodeURIComponent(value);
		};

		// If an array was passed in, assume that it is an array
		// of form elements
		if ( jQuery.isArray(a) || a.jquery )
			// Serialize the form elements
			jQuery.each( a, function(){
				add( this.name, this.value );
			});

		// Otherwise, assume that it's an object of key/value pairs
		else
			// Serialize the key/values
			for ( var j in a )
				// If the value is an array then the key names need to be repeated
				if ( jQuery.isArray(a[j]) )
					jQuery.each( a[j], function(){
						add( j, this, true );
					});
				else
					add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] );

		// Return the resulting serialization
		return s.join("&").replace(/%20/g, "+");
	};
})(jQuery);