var tooltips = new Array();

/**
 * performs Ajax request
 * 
 * @param url - target url of action
 * @param data - data to send
 * @param callback - callback function
 * @param busy_button - id of busy button if used
 * @return
 */
function Core_Ajax(url, data, callback, busy_button) {
	var kw = {
			url: "<?php echo PUBLIC_ROOT ?>"+url,
		    handleAs: "json",
		    content : data,
		    load: function(response){
	        		if(tooltips.length != 0) {
	            		for (var i in tooltips) {
	                		tooltips[i].destroy();
	            		}
	        		}
	        		if (response.errors != "") {           		
	            		for (var i in response.errors) {
	            			tooltips.push(new dijit.Tooltip({
	            	            connectId: [response.errors[i].elementID],
	            	            label: response.errors[i].message
	            	        }));
	            	        dijit.byId(response.errors[i].elementID).focus();
	            	        break;
	            		}
	        		}
	        		else {
	            		callback(response.data);
	        		}
	        		if (busy_button != null)
	        			dijit.byId(busy_button).cancel();
		    },
		    error: function (response) {
			        console.debug("AJAX ERROR: "+response);
		    } 
		};
	dojo.xhrPost(kw);
}
