////////////////////////////////////////////////////////////////////////////////////////
// Tworzenie Obiektow zadania
// Funkcje odbierajace odpowiedz z serwera
// Funkcje czyszczace zawartosc divow
///////////////////////////////////////////////////////////////////////////////////////

// holds an instance of XMLHttpRequest

// creates an XMLHttpRequest instance



// JavaScript Document
// <![CDATA[
	var obiekt1 = createXmlHttpRequestObject();	//obiekt zadania ktory zwraca odpowiedz do diva main
	var obiekt2 = createXmlHttpRequestObject();	//obiekt zadania ktory zwraca odpowiedz do diva main2
	var obiekt3 = createXmlHttpRequestObject(); //obiekt zadania ktory zwraca odpowiedz do diva main3
	var obiekt4 = createXmlHttpRequestObject(); //obiekt zadania ktory zwraca odpowiedz do diva main4
	var obiekt5 = createXmlHttpRequestObject(); //obiekt zadania ktory zwraca odpowiedz do diva main5
	var obiekt6 = createXmlHttpRequestObject(); //obiekt zadania ktory zwraca odpowiedz do diva mainErrors

function handleRequestStateChange()
	{	

	if (obiekt1.readyState == 4)
	{
		// continue only if HTTP status is "OK"
		if (obiekt1.status == 200)
		{
			try
			{
				response=obiekt1.responseText;
				myDiv = document.getElementById("bottom_find");
				//Effect.Appear('main', { duration: 0.9 });
	 			
				myDiv.innerHTML=response;
				//Effect.Opacity('main', { from: 0.0, to: 1.7, duration: 0.5 });
		
	
			}
			catch(e)
			{
				// display error message
				alert("Error reading the response: " + e.toString());
				}
			}else
				{
					// display status message
					alert("There was a problem retrieving the data:\n" +obiekt1.statusText);
				}
			}	
}

function handleRequestStateChange2()
{	
var loadingDiv;
	if (obiekt2.readyState == (1 || 0 ) )
	{
		loadingDiv = document.getElementById("loading");
		loadingDiv.innerHTML="";
	}

	if (obiekt2.readyState == (1 || 0 ) )
	{
		loadingDiv = document.getElementById("loading");
		loadingDiv.innerHTML="<img src=\"../images/ajax-loader.gif\" >";
		//loadingDiv.innerHTML="loading...";
	}

	if (obiekt2.readyState == 4)
	{
		loadingDiv = document.getElementById("loading");
		loadingDiv.innerHTML="";
		// continue only if HTTP status is "OK"
		if (obiekt2.status == 200)
		{
			try
			{
				response=obiekt2.responseText;
				myDiv = document.getElementById("main2");
				myDiv.innerHTML=response;
				
				//Effect.Appear('main2', { duration: 0.9 });
				//Effect.Opacity('text', { from: 1.0, to: 0.7, duration: 0.5 });
		
	
			}
			catch(e)
			{
				// display error message
				alert("Error reading the response: " + e.toString());
				}
			}else
				{
					// display status message
					alert("There was a problem retrieving the data:\n" +obiekt2.statusText);
				}
			}
}

function handleRequestStateChange3()
{	

	if (obiekt3.readyState == 4)
	{
		// continue only if HTTP status is "OK"
		if (obiekt3.status == 200)
		{
			try
			{
				response=obiekt3.responseText;
				myDiv = document.getElementById("main3");
				//Effect.Appear('main3', { duration: 0.2 });
				myDiv.innerHTML=response;
			
				//Effect.Opacity('text', { from: 1.0, to: 0.7, duration: 0.5 });
		
	
			}
			catch(e)
			{
				// display error message
				alert("Error reading the response: " + e.toString());
				}
			}else
				{
					// display status message
					alert("There was a problem retrieving the data:\n" +obiekt3.statusText);
				}
			}
}

function handleRequestStateChange4()
{	

	if (obiekt4.readyState == 4)
	{
		// continue only if HTTP status is "OK"
		if (obiekt4.status == 200)
		{
			try
			{
				response=obiekt4.responseText;
				myDiv = document.getElementById("main4");
				myDiv.innerHTML=response;
				//Effect.Appear('main4', { duration: 0.7 });
				
				//Effect.Opacity('text', { from: 1.0, to: 0.7, duration: 0.5 });
		
	
			}
			catch(e)
			{
				// display error message
				alert("Error reading the response: " + e.toString());
				}
			}else
				{
					// display status message
					alert("There was a problem retrieving the data:\n" +obiekt4.statusText);
				}
			}
}

function handleRequestStateChange5()
{	
	if (obiekt5.readyState == 4)
	{
		// continue only if HTTP status is "OK"
		if (obiekt5.status == 200)
		{
			try
			{
					response=obiekt5.responseText;
				myDiv = document.getElementById("main5");
				myDiv.innerHTML=response;	
				
				
				
				//myDiv.innerHTML=response;
				//Effect.Appear('main5', { duration: 0.7 });
				
				//Effect.Opacity('text', { from: 1.0, to: 0.7, duration: 0.5 });
		
	
			}
			catch(e)
			{
				// display error message
				alert("Error reading the response: " + e.toString());
				}
			}else
				{
					// display status message
					alert("There was a problem retrieving the data:\n" +obiekt5.statusText);
				}
			}
}

function handleRequestStateChange6()
{	
	if (obiekt6.readyState == 4)
	{
		// continue only if HTTP status is "OK"
		if (obiekt6.status == 200)
		{
			try
			{
					response=obiekt6.responseText;
				myDiv = document.getElementById("mainErrors");
				myDiv.innerHTML=response;	
				
				
				
				//myDiv.innerHTML=response;
				//Effect.Appear('main5', { duration: 0.7 });
				
				//Effect.Opacity('text', { from: 1.0, to: 0.7, duration: 0.5 });
		
	
			}
			catch(e)
			{
				// display error message
				alert("Error reading the response: " + e.toString());
				}
			}else
				{
					// display status message
					alert("There was a problem retrieving the data:\n" +obiekt6.statusText);
				}
			}
}


////czysci tekst we wszystkich divach z wyjatkiem podanego jako parametr////
	function clearAllText(zostaw)
	{
		var divy=new Array("main","main2","main3","main4","main5","mainErrors");
		var iloscDivow=divy.length;
		var el2;

		for (var i=0;i<iloscDivow; i++)
		{
			el2=document.getElementById(divy[i]);
			if (el2.id!==zostaw)
			{
				el2.innerHTML="";
			}
		}
	}
	
	function clearAll2()
	{
		var divy=new Array("main","main2","main3","main4","main5","mainErrors");
		var iloscDivow=divy.length;
		var el2;

		for (var i=0;i<iloscDivow; i++)
		{
			el2=document.getElementById(divy[i]);
			el2.innerHTML="";
		}
	}



function clearText(el)
{
	el2=document.getElementById(el);
	el2.innerHTML="";
}


function czysc_wybor(el){
    var div = document.getElementById(el);
    div.innerHTML = '';
}

var pow_min;
var pow_max;
var pietro;

function wybrano_min()
{
	pow_min=document.formaSzukania.min_pow.value;
	var url="Ajax/operacjeSzukania.php?co=wybrano_min_pow&min="+pow_min;
	sendRequest(obiekt2,url,handleRequestStateChange2);	
}

function wybrano_max_pow()
{
	pow_max=document.formaMax.max_pow.value;
	var url="Ajax/operacjeSzukania.php?co=wybrano_max_pow&min="+pow_min+"&max="+pow_max;
	sendRequest(obiekt3,url,handleRequestStateChange3);	
}

function wybrano_pietro()
{
	pietro=document.formPietra.pietro.value;
}

function szukajMieszkania()
{
	var url="Ajax/operacjeSzukania.php?co=szukajMieszkan&min="+pow_min+"&max="+pow_max+"&pietro="+pietro;
	sendRequest(obiekt4,url,handleRequestStateChange4);
}



// ]]>
