/**
 * Wrapper pro jquery.ajax* funkce prizpusobeny Xendu
 */

function AjaxClient_call ( model, method, args, callback) {
	if(args != null) {
		args = args.toLocaleString();
	}
	if(this.debug) {
		alert(args);
	}
	data = {model:model,method:method,args:args};
	
	$.get(this._targetUrl, data, callback, "json");
}

function AjaxClient_OwnCall( args, callback) {
	$.getJSON(this._targetUrl, args, callback);
}


var defaultOptions = {
	type:'json', //Typ odpovedi
	debug:0
}



function AjaxClient( options) 
{
	if(options == null) {
		options = defaultOptions;
	}
	//response type
	if(options.type != null) {
		this._type = options.type;
	}
	else {
		this._type = defaultOptions.type;
	}
	//AJAX Server url
	if(options.targetUrl != null) {
		this._targetUrl = options.targetUrl;
		this.call = AjaxClient_OwnCall;
	}
	else {
		this._targetUrl = defaultOptions.targetUrl;
		this.call = AjaxClient_call;
	}
	//enable debug mode
	if(options.debug) {
		this.debug = true;
	}
	else {
		this.debug = false;
	}
	
	//Ajax indicator
	$(function() {
		
		Loader.init();
	    $(document).ajaxSend(function() {
	       Loader.show();
	    });
	    $(document).ajaxStop(function() {
	       	Loader.hide();
	    });
});
	
	
}


