function gdAjax()
{
	this.msg_divs = 0; // aktualna ilosc divow z wiadomosciami o aktualnie wykonywanych akcjac
	this.msg_q = []; // kolejka wiadomosci na temat aktualnie wykonywanych akcji..
	this.q = [];//queue
	this.aq;//active queue
	//this.callback_values_array = [];
	this.processing = false;
}

gdAjax.prototype.areq=function(method,url,params,id,finish_function)
{
	if(!this.http || this.processing==false) // tworzymy nowy obiekt gdy go nie ma lub gdy ostatni zakonczyl dzialalnosc..
	{
		try{this.http=new XMLHttpRequest();}catch (e){try{this.http=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){this.http=new ActiveXObject("Microsoft.XMLHTTP");}}
	}
	if(this.http==null) {alert ("Your browser does not support AJAX!");return;}
	this.q.push([method,url,params,id,finish_function]);
	if(this.processing === false)
	{
		this.processing = true;
		this.default_ajax_response_function();
	}
}

gdAjax.prototype.default_ajax_response_function=function()
{
	var handle=this;
	if(handle.http.readyState==0) // The request is not initialized
	{
		handle.aq = handle.q.shift();
		handle.http.open(handle.aq[0],handle.aq[1],true);
		handle.http.onreadystatechange=function(){handle.default_ajax_response_function()};
		if(handle.aq[0]=='POST')
			handle.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		handle.http.send(handle.aq[2]);
	}
	else if(handle.http.readyState==4) // The request is complete
	{
		if(handle.aq[3]!='')
		{
			// jesli ID jest poprzedzone znakiem '-' to oznacza, iz chcemy "schowac" ow element:
			if(handle.aq[3].substr(0,1) == '-')
			{
				document.getElementById(handle.aq[3].substr(1)).style.display = "none";
			}
			// jesli ID jest poprzedzone znakiem '=' to oznacza, iz chcemy "pokazac" ow element:
			else if(handle.aq[3].substr(0,1) == '=')
			{
				return_val = handle.http.responseText;
				// gdy zwrocono pusta wartosc lub "-1" (wartosc oznaczajaca jakis blad) to nie 'pokazujemy' elementu...:
				if(return_val!='')
				{
					document.getElementById(handle.aq[3].substr(1)).style.display = "";
					document.getElementById(handle.aq[3].substr(1)).innerHTML=return_val;
				}
				handle.return_val = return_val;
			}
			else
			{
				return_val = handle.http.responseText;
				
				// znak plus oznacza, iz nic nie robimy...:
				if(handle.aq[3].substr(0,1) == '+')
				{
					handle.return_val = return_val;
				}
				else
				{					
					document.getElementById(handle.aq[3]).innerHTML=return_val;
					handle.return_val = return_val;
				}
			}
		}
		else
		{
			return_val = handle.http.responseText;
			handle.return_val = return_val;
		}

		if(handle.aq[4])
		{
			//alert(aq[8]);
			handle.finish_function=handle.aq[4];
			handle.finish_function(handle.aq[3]);
		}
		
		if(handle.q.length > 0)
		{
			handle.aq = handle.q.shift();
			//aq[2].id = aq[3];//??
			handle.http.open(handle.aq[0],handle.aq[1],true);
			//handle.default_ajax_response_function.h=handle;
			handle.http.onreadystatechange=function(){handle.default_ajax_response_function();};
			if(handle.aq[0]=='POST')
				handle.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			handle.http.send(handle.aq[2])
		}
		if(handle.q.length == 0)
		{
			handle.processing = false;
		}
	}
}

gd_ajax=new gdAjax();