/*
	Nur ein Ajax-Prozess zur selben zeit...
	Rückgabevariablen als Get-String
*/

var AjaxActionVars = {
	'loading' : false,
	
	freeAjaxAction: function() {
		AjaxActionVars.loading = false;
	}
}

var AjaxAction = Class.create();
AjaxAction.prototype = {
	initialize: function(url, callback, parameter) {
		this.url = url;
		if (callback && typeof(callback) == 'function') this.callback = callback;
		
		if (typeof(parameter) == "undefined") var parameter = {};
		this.parameter = parameter;
		
		this.object = new Object();
		
	
	},
	
	sendRequest: function() {
		if (!AjaxActionVars.loading) {	
			AjaxActionVars.loading = true;
			new Ajax.Request(this.url,
			{
				method:'post',
				parameters: this.parameter,
				onSuccess: function(transport) {
				  var response = transport.responseText || "no response text";
				  if (this.callback && typeof(this.callback) == 'function') {
					  AjaxActionVars.freeAjaxAction();
					  this.callback(response, this.object);
					  this.initVars();
				  } else {
				  	AjaxActionVars.freeAjaxAction();
					this.initVars();
				  }
				 				  
				}.bind(this),
				onFailure: function(){ 
					alert('Something went wrong...');
					AjaxActionVars.freeAjaxAction();
					this.initVars();
				}
			 });
		} else {
			alert ('Please wait - still loading ');
		}
	},
	
	
	saveObject: function(obj) {
		this.object = obj;
	},
	
	initVars: function (){
		this.lasturl = this.url;
		this.url = "";
		this.callback = "";
		this.parameter = {};
		this.object = new Object();
	}


}; // end class




