var ajaxObj = null;
var handler = null;
var updateInProgress = 0;
function getAjaxObject()
{
	try
	{
		ajaxObj = new XMLHttpRequest();
		ajaxObj1 = new XMLHttpRequest();
	}
	catch(error)
	{
		try
		{
			ajaxObj = new ActiveXObject('MSXML2.XMLHTTP');
			ajaxObj1 = new ActiveXObject('MSXML2.XMLHTTP');
		}
		catch(error)
		{
			try
			{
				ajaxObj = new ActiveXObject('Microsoft.XMLHTTP');
				ajaxObj1 = new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch(error)
			{
				alert('AJAX konnte nicht gestartet werden, wird aber f&uuml;r die Seite ben&ouml;tigt.');
			}
		}
	}
	
	return true;	
}

function sendReq(scriptPath, returnHandler)
{
  if(updateInProgress == 0){
    updateInProgress = 1;
  	
  	if(ajaxObj == null){
  		getAjaxObject();
  	}
  	handler = returnHandler;
  	ajaxObj.open('get', scriptPath, true);
  	
  	ajaxObj.onreadystatechange = ReadystateChanged;
  	ajaxObj.send(null);
  	return true;
	}
	else{
    setTimeout("sendReq('" + scriptPath + "', " + handler + ")", 20);
  }
}

function sendPostReq(scriptPath, returnHandler, arguments)
{
  if(updateInProgress == 0){
    updateInProgress = 1;
  	
  	if(ajaxObj == null){
  		getAjaxObject();
  	}
  	handler = returnHandler;
  	ajaxObj.open('post', scriptPath, true);
  	ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	ajaxObj.onreadystatechange = ReadystateChanged;
  	ajaxObj.send(arguments);
  	return true;
	}
	else{
    setTimeout("sendReq('" + scriptPath + "', " + handler + ")", 20);
  }
}

function ReadystateChanged()
{
	if(ajaxObj.readyState == 4)
	{
		if(ajaxObj.status == 200)
		{
		  handler();
		}
		else
		{
			alert('Fehler: ' + ajaxObj.statusText);
		}
	}
	return true;
}

