var ajaxOBJ;
var responseHandler;
var errors = 0;
var working = false;
var queue = true;
var theQueue = Array();

function loadXMLDoc(url, handler)
{	if (queue && working)
		addQueue(url, handler);
	else
	{	responseHandler = handler;
		working = true;
		ajaxOBJ = false;
		try
		{	ajaxOBJ = new XMLHttpRequest();
		}
		catch(e)
		{	try
			{	ajaxOBJ = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{ 	try
				{	ajaxOBJ = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e)
				{	try
					{	ajaxOBJ = window.createRequest();
					}
					catch(e)
					{ 	ajaxOBJ = false;
					}
				}
			}	
		}
	
		if(ajaxOBJ)
		{	ajaxOBJ.onreadystatechange = processReqChange;
			ajaxOBJ.open("GET", url, true);
			ajaxOBJ.setRequestHeader("Pragma", "no-cache");
			ajaxOBJ.setRequestHeader("Cache-Control", "must-revalidate");
			ajaxOBJ.setRequestHeader("If-Modified-Since", document.lastModified);
			ajaxOBJ.send("");
		}
    	else
		{	alert("AJAX could not initialize!\nPlease enable JavaScript or ActiveX(IE only)")
		}
  	}
}

function processReqChange()
{	if (ajaxOBJ.readyState == 4)
	{	if (ajaxOBJ.status == 200)
			eval(responseHandler +"(ajaxOBJ.responseText)");
		else
		{	errors++;
			if (errors >= 5)
			{	//alert("too much errors!\nreloading the page....");
				//window.location.reload();
			}
			else //alert("Error retriving data!\nErrormsg: "+ ajaxOBJ.statusText);
			{	//window.location.reload();
			}
		}
		working = false;
		nextInQueue();
	}
}
function addQueue(url, handler)
{	theQueue[theQueue.length] = "loadXMLDoc('"+ url +"', '"+ handler +"');";
}
function nextInQueue()
{	if (!working)
	{	theQueue.reverse();
		eval(theQueue[theQueue.length-1]);
		theQueue.splice(theQueue.length-1, 1);
		theQueue.reverse();
	}
}
function getCurrRelUrl() //url aufsplitten
{	var lastslash = window.location.href.lastIndexOf("/");
	if(lastslash) return window.location.href.substr(0, lastslash+1);
	else return false;
}
