var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
	var xmlHttp;
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp = false;
		}
	}
	else
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch(e)
		{
			xmlHttp = false;
		}
	}
	
	if(!xmlHttp)
		alert("Blad podczas tworzenia obiektu XMLHttpRequest.");
	else
		return xmlHttp;
}

function validate(type)
{
	if(xmlHttp.readyState == 4 || xmlHttp.readyState ==0)
	{
		ajax_response_ready = 0;
		
		document.getElementById("shopList").innerHTML = "<img src=\"img/ajax-loader.gif\">";
		
		login = encodeURIComponent(document.getElementById("wojewodztwo").value);
		xmlHttp.open("GET","galleries.php?wojewodztwo=" + login + "&type=" + type, true);
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
}

function handleServerResponse()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			//xmlResponse = xmlHttp.responseXML;
			//xmlDocumentElement = xmlResponse.documentElement;
			//helloMessage = xmlDocumentElement.firstChild.data;
			
			var tableContent = xmlHttp.responseText;
			
			//document.getElementById("divMessage").innerHTML = "<table>" + tableContent + "</table>";
			//document.getElementById("shopListTitle").innerHTML = "<b>Województwo</b>";
			
			var parameters = tableContent.split(';');
			var prefix_lenght = parameters[0].length;
			
			prefix_lenght++;
			
			tableContent = tableContent.substring(prefix_lenght);
			
			document.getElementById("shopList").innerHTML = tableContent;
		
			licznik = parameters[0];
			
			$$.Slideshow.Counter = 1;
			
			$$.Slideshow.FirstRun = 1;
			
			
			
			
			if(click) 
			{
				click = false;
				$$.Slideshow.Interrupted = false;
				//$$.Slideshow.Counter = 1;
				//$$.Slideshow.Transition();
			}
			
			ajax_response_ready = 1;
			/*else
			{
				
			}*/
			
			
			
			//alert(licznik);
			
			/*if(licznik != 1)
			{
				$$.Slideshow.Ready(licznik);
			}
			else
			{
				show_one_photo();
			}*/
		}
		else
		{
			alert("Wystapil blad podczas uzyskiwania dostepu do serwera:" + xmlHttp.statusText);
		}
	}
}


