var xmlHttp = createXmlHttpRequestObject(); 

function createXmlHttpRequestObject() 
{
	var xmlHttp;
	// Internet Explorer
	if (window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) 
		{
			xmlHttp = false;
		}
	}
  	// Mozilla
	else
	{
		try 
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) 
		{
			xmlHttp = false;
		}
	}
	// error
	if (!xmlHttp)
		alert("Wysiąpił błąd podczas tworzenia obiektu XMLHttpRequest.");
	else 
		return xmlHttp;
}

function processHttpRequest(url, handleServerResponse, xml)
{
	if (xml)
	{
		if (xml.readyState == 4 || xml.readyState == 0)
		{
			xml.open("GET", url, true);  
			xml.onreadystatechange = handleServerResponse;
			xml.send(null);
		}
	}
	else
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
		{
			xmlHttp.open("GET", url, true);  
			xmlHttp.onreadystatechange = handleServerResponse;
			xmlHttp.send(null);
		}
		else
		{
			setTimeout('processHttpRequest(\''+url+'\','+handleServerResponse+')', 500);
		}
	}
}

function processHttpRequestPost(url, handleServerResponse, params, xml)
{
	if (xml)
	{
		if (xml.readyState == 4 || xml.readyState == 0)
		{
			xml.open("POST", url, true);  
			xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xml.setRequestHeader("Content-length", params.length);
			xml.setRequestHeader("Connection", "close");
			xml.onreadystatechange = handleServerResponse;
			xml.send(params);
		}
	}
	else
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
		{
			xmlHttp.open("POST", url, true);  
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = handleServerResponse;
			xmlHttp.send(params);
		}
		else
		{
			setTimeout('processHttpRequest(\''+url+'\','+handleServerResponse+')', 500);
		}
	}
}


