
function getXMLHTTPRequest()
{
var req=false;
try
	{
	req= new XMLHttpRequest();
	}
	catch(err1)
	{
	try
		{
		req=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(err2)
		{
		try
			{
			req= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(err3)
			{
			req=false;
			}
		}
	}
	return req;	
}

myRequest = getXMLHTTPRequest();

function responseAjax()
{
if(myRequest.readyState == 4)
	{
	if(myRequest.status == 200)
		{
			document.getElementById("ramka_plywajaca").innerHTML=myRequest.responseText;
		}
	}
	else
	{
		document.getElementById("ramka_plywajaca").innerHTML='<img src="img/wait.gif" height="60">';
	
	}
}

function callAjax(podstrona,param1,param2)
{
	var url="php/lib/ajaxreturn.lib.php?podstrona="+podstrona+"&param1="+param1+"&param2="+param2+"&rand=";
	var myRandom= new Date().getTime();
	myRequest.open("GET",url+myRandom,true);
	myRequest.onreadystatechange=responseAjax;
	myRequest.send(null);
}

function callAjaxReturn(podstrona,param1,param2)
{
	var url="php/lib/ajaxreturn.lib.php?podstrona="+podstrona+"&param1="+param1+"&param2="+param2+"&rand=";
	var myRandom= new Date().getTime();
	myRequest.open("GET",url+myRandom,true);
	myRequest.onreadystatechange=
				
				function()
				{
					if(myRequest.readyState == 4)
					{
					if(myRequest.status == 200)
						{
							
							document.getElementById(param2+'_id').value=myRequest.responseText;
							//responseAjax;
						}
					}	
				}
	myRequest.send(null);
}

function callAjaxReturnPopup(podstrona,param1,param2)
{
	var url="../../php/lib/ajaxreturn.lib.php?podstrona="+podstrona+"&param1="+param1+"&param2="+param2+"&rand=";
	var myRandom= new Date().getTime();
	zwrocone=null;
	myRequest.open("GET",url+myRandom,true);
	myRequest.onreadystatechange=
				function()
				{	
					if(myRequest.readyState == 4)
					{
					if(myRequest.status == 200 || myRequest.status == 304)
						{ 
							zwrocone=myRequest.responseText;
							window.opener.document.getElementById(param2+'_id').value=zwrocone;	
							//window.opener.document.getElementById(param2+'_id').value=zwrocone;
							//window.opener.document.getElementById('test').value='poszlo'+zwrocone;
							//alert(zwrocone);
							
						}
					}
					
					//alert(zwrocone);
				}
				
		myRequest.send(null);
		
}

function callAjaxSprKota(nazwa,id)
{

	var url="php/lib/ajaxreturn.lib.php?podstrona=sprawdzNazweKota&param1="+nazwa+"&param2=&rand=";
	var myRandom= new Date().getTime();
	var sprawdz;
	myRequest.open("GET",url+myRandom,true);
	myRequest.onreadystatechange=
				
				function()
				{
					if(myRequest.readyState == 4)
					{
					var sprawdz;
					if(myRequest.status == 200)
						{
							sprawdz=myRequest.responseText;
							if(sprawdz!='0')
							{
								alert(sprawdz);
								return 1;
							}
						}
					//wyswietl(sprawdz,id);
					}	
				}
	myRequest.send(null);
}

function callAjaxSprKotaPopup(nazwa,id,ob1)
{
	var url="ajaxreturn.lib.php?podstrona=sprawdzNazweKotaPopup&param1="+nazwa+"&param2=&rand=";
	var myRandom= new Date().getTime();
	var sprawdz;
	wyslane=0;
	myRequest.open("GET",url+myRandom,true);
	myRequest.onreadystatechange=
				
				function(ob)
				{
					if(myRequest.readyState == 4)
					{
					var sprawdz;
					if(myRequest.status == 200)
						{
							sprawdz=myRequest.responseText;
							if(sprawdz!='0')
							{
								alert(sprawdz);
								ob1.value='';
							}
						}
					//wyswietl(sprawdz,id);
					}	
				}
	myRequest.send(null);
}

function callAjaxKolory()
{
	for (i=0;i<2;i++)
	{
		var url="php/lib/ajaxreturn.lib.php?podstrona=printColors&kolory="+i+"&rand=";
		var myRandom= new Date().getTime();
		myRequest.open("GET",url+myRandom,false);
		myRequest.onreadystatechange=	
					function()
					{
						if(myRequest.readyState == 4)
						{
							if(myRequest.status == 200)
								{
									kolory_kotow[i]=myRequest.responseText;
								}
						}
					}
		myRequest.send(null);
		
	}
}

function callAjaxUpdateFoto(foto)
{	
	document.getElementById("foto_big").innerHTML='<img src="img/wait.gif" height="60">';
	var url="php/lib/ajaxreturn.lib.php?podstrona=updateFoto&foto="+foto+"&rand=";
	var myRandom= new Date().getTime();
	myRequest.open("GET",url+myRandom,true);
	myRequest.onreadystatechange=	
				function()
				{
					if(myRequest.readyState == 4)
					{
						if(myRequest.status == 200)
						{
							document.getElementById("foto_big").innerHTML=myRequest.responseText;
						}
						else
						{
							document.getElementById("foto_big").innerHTML='<img src="img/wait.gif" height="60">';	
						}
					}
					else
					{
						document.getElementById("foto_big").innerHTML='<img src="img/wait.gif" height="60">';
						
					}
				}
	myRequest.send(null);
}
