var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
	var xmlHttp;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for(var i=0;i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e)
			{
				
			}
		}
		
	}
	
	if(!xmlHttp)
	{
		displayError("Błąd podczas tworzenia obiektu XMLHttpRequest");
	}
	else
	{
		return xmlHttp;
	}
}

function displayError($message)
{
	alert("Wystąpił bład: \n"+$message);
}

function process(server)
{
	loaderOn();
	if(xmlHttp && (xmlHttp.readyState==4 || xmlHttp.readyState==0))
	{
		try
		{
			xmlHttp.open("GET",server,true);
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.send(null);
		}
		catch(e)
		{
			alert("Nie mogę nawiązać połączenia z serwerem: \n"+e.toString());
		}
	}
}

function handleRequestStateChange()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status==200)
		{
			try
			{
				handleServerResponse();
			}
			catch(e)
			{
				alert("Wystąpił błąd podczas odczytu odpowiedzi: "+e.toString());
			}
		}
		else
		{
			alert("Pojawił się problem podczas odbierania danych: \n" 
			+ xmlHttp.statusText);
		}
	}
	
}

function handleServerResponse()
{
	setTimeout('wait();',3000);
}
function wait()
{
	loaderOff();
	response = xmlHttp.responseText;
	document.getElementById('galeriaRightSide').innerHTML = response;
	
}


function loaderOn()
{
	document.getElementById("loader").style.display = "block";
}
function loaderOff()
{
	document.getElementById("loader").style.display = "none";
}
