/**
 * @author Paweł Skrzypiec
 * @desc Ajax rsponse
 * @version 1.0
 * @example
 * $("element").ajaxresponse({
 *
 * 		update: 'update'
 *
 * });
 * @obs With no arguments, the default is update
 * @license free
 * @param string update container
 * @contribution Paweł Skrzypiec
 *
 */
(function($){  
 $.fn.ajaxresponse = function(options) {
	 
	 _update = getObject(options.update);
	 
	options = $.extend({
		params: options.params || {},
		dialog: options.dialog || false,
		mode: options.mode || 'json'
		
	}, options || {});
	 
	activateProgress($(this)); 
	
	if (options.mode == 'json')
		getJSON(options.url, _update, options);
	else
		getPost(options.url, _update, options);
	
	return false;
	

 };
 
 
 function getPost(url, update, options){
	 
		$.post(url, options.params, 
		
			function(data, textStatus) { 
				
					if (update)
						update.show().html(data);
					
					if( options.callback )
						options.callback.apply();					
					
					deactivateProgress(); 
					
		}, 'html');
		
		return false;
 }
 
 function getJSON(url, update, options){
	 
		$.post(url, options.params, 
		
			function(data) { 
				
					if (update)
						update.show().html(data.content);
					
					if (data.success){
					
						if( options.callback )
							options.callback.apply();
						
						if (options.dialog)
							jQuery.showDialogSuccess(data.content);
						
					}
					
					if (data.error){
						jQuery.showDialogError(data.content);
					}
					
					deactivateProgress(); 
					
		}, 'json');
		
		return false;
 } 
 
})(jQuery);

