var waiterComponentManager = null;
var Callback = new Class({
	myAjax: null,
	/**
	 * Object constructor
	 * @param String url
	 * @param Object data
	 * @param function onOk
	 * @param function onError
	 * @return Callback
	 */
	initialize: function(url,data, onOk, onError){
		waiterComponentManager = new waiterManager({component: $('c1')});
    	var method = 'GET';
    	if(data!=null){
    		method = 'POST';
    	}
    	var params = Object.toQueryString(data);
    	var callback = this;
    	this.onOkFnc = onOk;
    	this.onErrorFnc = onError;
		this.myAjax = new Ajax(
			url, {
				method: method, 
				data: params, 
				onComplete:	function(responseText){
					callback.onComplete(responseText);
				} 
			})
    },
    /**
     * function called on completed callback event
     * @param String responseText
     */
    onComplete: function(responseText){
    	var decoded = Json.evaluate(responseText);
		switch(decoded.status){
		case 1:
			this.onOkFnc(decoded);
			waiterComponentManager.stop();
		break;
		case 0:
			this.onErrorFnc(decoded);
			waiterComponentManager.stop();
		break;
		}
    },
    /**
     * Fires the callback event
     */
    request: function(){
		waiterComponentManager.start();
		this.myAjax.request();
    },
    /**
     * destroyes the callback
     */
    destroy: function(){
    	if(this.myAjax!=null)   	this.myAjax.cancel();
    	this.myAjax=null;
    	this.onComplete = function(responseText){};
    }
});