
/*
var tricosAjaxLoadScripts = ['/scripts/scriptaculous/src/builder.js', '/scripts/scriptaculous/src/effects.js', "/scripts/prototype-window/javascripts/window.js"];
*/


	
function tricosAjaxParseResult(obj)
{
	response=obj.responseXML.getElementsByTagName('response');
	status=response[0].getElementsByTagName('status')[0].childNodes[0].nodeValue;
	message=response[0].getElementsByTagName('message')[0].childNodes[0].nodeValue;
	data=response[0].getElementsByTagName('data')[0].childNodes[0].nodeValue;
	var ar = [status, message, data];
	return ar;
}


function tricosAjaxHandleResult(obj, callFunction)
{
	if(Dialog != null) {
		Dialog.closeInfo();
	}
	
	res=tricosAjaxParseResult(obj);
	status=res[0];
	message=res[1];
	data=res[2];
	
	if(status == '0') {
		if(Dialog != null) {
			Dialog.alert(tricosAjaxErrorMessage+message, {windowParameters: {width:tricosAjaxErrorDialogWidth, height:tricosAjaxErrorDialogHeight}, okLabel: "Ok", ok:function(win) { Dialog.closeInfo(); var rs=[false, obj, status, message, data]; }});
		}
	} else {
		var rs=[true, obj, status, message, data];
	}
	
	eval(callFunction+'(rs)');
}

function tricosAjaxShowWait(message)
{
	Dialog.info(message, {windowParameters: {width:250, height:100}, showProgress: true});
}

var myGlobalHandlers;


function tricosAjaxRegisterGlobalHandler(message)
{
	myGlobalHandlers = {
		onCreate: function(){
			//Element.show(divID);
			Dialog.info(message, {windowParameters: {width:250, height:100}, showProgress: true});
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				//Element.hide(divID);
				if(Dialog != null) {
					Dialog.closeInfo();
				}
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);
}

/*
function tricosAjaxInit()
{
	tricosAjaxLoadScripts.each(function(script) {
		document.write('<script type="text/javascript" src="'+script+'"></script>');
	});
}


Event.observe(window, 'load', tricosAjaxInit);
*/