function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function xmlIni()
{
	var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		  alert ("Twoja przegldarka nie obsuguje AJAXa!");
		  return;
	} 
	else return xmlHttp;
}

function AjaxPost()
{
	//adres,zmienne,id
	this.xml = new Array();
	this.wynik = new Array();
	for(i=0;i<arguments.length;i++)
	{
		this.xml[i] = xmlIni();
		this.xml[i].open("POST",arguments[i][0],false);
		this.xml[i].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; text/html; charset=utf-8');
		this.xml[i].send(arguments[i][1]);
		obj = $(arguments[i][2]);
		if(obj) obj.innerHTML = this.xml[i].responseText;
		this.wynik[i] = this.xml[i].responseText;
	}
}


function loading(l)
{
	var obj1=$('loading1');
	var obj2=$('loading2');
	var obj3=$('glowna');
	if(l==0)
	{
		if(obj1) obj1.style.display='';
		if(obj2) obj2.style.display='';
		if(obj3) obj3.className='glownaload';
	}
	else
	{
		if(obj1) obj1.style.display='none';
		if(obj2) obj2.style.display='none';
		if(obj3) obj3.className='glownaidle';
	}
}

function Ajax(url,pst,did,f)
{
	//loading(0);
	var xmlHttp=xmlIni();
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			obj = document.getElementById(did);
			if(obj) obj.innerHTML = xmlHttp.responseText;
			//loading(1);
			var wynik=xmlHttp.responseText;
			if(f!="") eval(f);
		}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; text/html; charset=utf-8');
	xmlHttp.send(pst);
}