/*
 * Quark AJAX - Quark PHP Framework
 * version 1.0
 * Copyright 2011, Sahib Alejandro Jaramillo Leo.
 * http://quarkphp.com/
 * Licensed under the GNU General Public License (http://www.gnu.org/licenses/gpl.html).
 */
jQuery.quarkAjax = function(url, UsrConf){
	
	var Conf = {
		url: url + '&ajax=1', type: 'post', dataType: 'json',
		success: function(Response, st_text, Xhr){
			if( Response.error == false ) success(Response.data, Xhr);
			else error(Response.error);
		},
		error: function( Xhr, st_text, error){
			var msg = "Quark AJAX Request error:\nStatus text: " + st_text + "\nThrown error: " + error;
			if( window.console ) console.error( msg );
			else alert(msg);
		}
	};
	
	var success, error;
	success = error = function(){};
	
	// Bindear success y error callbacks
	if( typeof UsrConf.success == 'function' )
		success = UsrConf.success;
	if( typeof UsrConf.error == 'function' )
		error = UsrConf.error;
	
	// Evitar que entren en el siguiente jQuery.extend
	delete UsrConf.success;
	delete UsrConf.error;
	
	jQuery.extend(Conf, UsrConf);
	jQuery.ajax(Conf);
};

