Ajax.currentRequests = {};
Ajax.Responders.register({
	onCreate: function(request) {
		if (request.options.onlyLatestOfClass && Ajax.currentRequests[request.options.onlyLatestOfClass]) {
			// if a request of this class is already in progress, attempt to abort it before launching this new request
			try { Ajax.currentRequests[request.options.onlyLatestOfClass].transport.abort(); } catch(e) {}
		}
		// keep note of this request object so we can cancel it if superceded
		Ajax.currentRequests[request.options.onlyLatestOfClass] = request;
	},
	onComplete: function(request) {
		if (request.options.onlyLatestOfClass) {
			// remove the request from our cache once completed so it can be garbage collected
			Ajax.currentRequests[request.options.onlyLatestOfClass] = null;
		}
	}
});

function ajaxRequestOnSuccessWrapper(orig, transport)
{	
	try {
		var json_response = transport.responseText.evalJSON();
		if (!json_response.Success) {
			if (json_response.ErrorCode == 99999)
				{
				new MessageBar(Language['9057'],{Type:'error'});
				}
			else if (json_response.ErrorCode == 99998)
				{
				window.location.href = "./login.php";
				}
			else if (json_response.ErrorCode == 99997)
				{
				new MessageBar(Language['9094'],{Type:'error'});
				}
		}
	} catch(e) {
	}
	orig(transport);
}

function makeRequest(url, options) {
	options.onSuccess = (options.onSuccess || Prototype.emptyFunction).wrap(ajaxRequestOnSuccessWrapper);
	return new Ajax.Request(url, options);
}

function ajaxUpdater(container, url, options) {
	options.onSuccess = (options.onSuccess || Prototype.emptyFunction).wrap(ajaxRequestOnSuccessWrapper);
	return new Ajax.Updater(container, url, options);
}