var arrHTTPServicesSendStack = new Array();
var bolHTTPServicesCurrentlySending = false;

function HTTPServicesOnAddToSendStack(in_objService)
{
	arrHTTPServicesSendStack.push(in_objService);
	HTTPServicesTryToSendNext();
}

function HTTPServicesTryToSendNext()
{
	if (!bolHTTPServicesCurrentlySending && arrHTTPServicesSendStack.length > 0)
	{
		arrHTTPServicesSendStack[0].send();
		bolHTTPServicesCurrentlySending = true;
	}
}

function HTTPServicesHandleResponseServiceState()
{
	if (arrHTTPServicesSendStack[0].objRequest.readyState == 4)
	{
		var objHTTPServiceCurrentService = arrHTTPServicesSendStack.shift();
		bolHTTPServicesCurrentlySending = false;
		HTTPServicesTryToSendNext();
		objHTTPServiceCurrentService.handleResponse();
	}
}


function httpServiceObject(in_strUrl, in_strResponseFunctionOk)
{
	this.strUrl = in_strUrl;
	this.strResponseFunctionOk = in_strResponseFunctionOk;
	this.objRequest = null;
	this.strMethod = 'POST';
	this.strContentType = 'application/x-www-form-urlencoded';
	this.strData = '';
	this.objLastResult = null;
	this.bolIsInit = false

	this.init = function()
	{
		this.objRequest = this.createXMLHttpRequest();
	}

	this.createXMLHttpRequest = function()
	{
		var objRequest = null;
		try
		{
			objRequest = new ActiveXObject("MSXML2.XMLHTTP");
		}
		catch (exc)
		{
			try
			{
				objRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (exc)
			{
				try
				{
					objRequest = new XMLHttpRequest();
				}
				catch (exc)
				{
					//alert('Ihr Browser unterstützt kein Ajax.');
				}
			}
		}
		return objRequest;
	}

	this.addToSendStack = function(in_strData)
	{
		if (in_strData)
		{
			this.strData = in_strData;
		}
		HTTPServicesOnAddToSendStack(this);
	}

	this.send = function()
	{
		this.objRequest.open(this.strMethod, this.strUrl + '?dau=' + Math.random(), true);
		if (this.strData)
		{
			this.objRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			this.objRequest.setRequestHeader('Content-length', this.strData.length);
		}
		this.objRequest.onreadystatechange = HTTPServicesHandleResponseServiceState;
		this.objRequest.send(this.strData);
		this.bolIsInit = false
	}

	this.handleResponse = function()
	{
		if(this.objRequest.status == 200)
		{
			this.lastResult = this.objRequest.responseXML;
			this.bolIsInit = true;
			eval(this.strResponseFunctionOk + '()');
		}
		else
		{
			alert("Error loading data.\nStatus: " + this.objRequest.status);
		}
	}
}