var ajaxRetriever=Class.create();
ajaxRetriever.prototype={
	//container: new Array(),
	destination: null,
	method: 'post',
	initialize:function(url, method){
		this.url=url;
		this.method=method;
		var options = Object.extend({
			br: false,
			append: false,
			onLoading: function(){},
			onFailure: this._ajaxRetrieverError.bind(this),
 			onCompleted: function(){},
 			onAjaxResponse: null
		}, arguments[2] || {});
		this.options  = options;
	},
	exe: function(params,append){
		//this.container.push(this.destination);
		this.options.append=append;
		var ajax=new Ajax.Request(
			this.url,
			{
				evalScripts:true,
				destination: this.destination,
				asynchronous: true,
				method: this.method,
				parameters: params,
				onLoading: this.options.onLoading.bind(this),
				onFailure: this.options.onFailure.bind(this),
				onComplete: (function (e){
					this.ajaxOnComplete(e, ajax.options.destination);
					ajax=null;
				}).bind(this)
			}
		);
	},
	ajaxOnComplete: function(e, destination){
		//destination=this.container.shift();
		this._ajaxRetrieverSuccess(e.responseText,destination,this.options.append,this.options.br, e);
	},
	_ajaxRetrieverSuccess:function(responseText,destination,append,br, e){
		if ((destination==null)||(destination=="")) {
			//return responseText;
		} else {
			switch($(destination).tagName.toLowerCase()){
				case 'input':
					if(append) $(destination).value+=responseText + (br?'<br />':'');
					else $(destination).value=responseText;
					break;
				default:
					if(append) $(destination).innerHTML+=responseText + (br?'<br />':'');
					else $(destination).innerHTML=responseText;
					break;
			}
		}
		if(this.options.onAjaxResponse) this.options.onAjaxResponse(responseText);
		if(this.options.onCompleted) this.options.onCompleted(e);
	},
	_ajaxRetrieverError:function(e){
		alert('error');
		return 'error';
	}
}
