function getAjaxObject()
{
	try{
		return new XMLHttpRequest();
	}
	catch(e)
	{
		var ajaxVersion = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
		for(var ind in ajaxVersion)
		{
			try{
				return new ActiveXObject(ajaxVersion[ind]);
			}
			catch(e){}
		}
	}
	return false;
}

function pass(req, callback)
{
	eval(callback+'(req.readyState, req.status, req.responseText, req.responseXML);');	
}
	
function ajax(url,getQuery,postQuery,callback,reqtype)
{
	var req = getAjaxObject();
	req.onreadystatechange = function(){pass(req, callback);}
	if(reqtype=='post')
	{
		req.open("POST", url+'?'+getQuery, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(postQuery);
	}
	else
	{
		myRand=parseInt(Math.random()*99999999);
		req.open("GET",url+'?'+getQuery+'&rand='+myRand,true);
		req.send(null);
	}
}

wartosc = null;
function getSuggestions()
{
		ajax('dane.php','','co='+wartosc,'pokaz','post');
}

function pokaz(state, status, text, xml)
{
	if(state == 4 && status == 200)
	{
		txt = '';
		var obj = eval('('+text+')');
		for(i in obj.tablica)
		{
			txt += '<a href="'+obj.linki[i]+'">'+obj.tablica[i]+'</a>';
		}
		document.getElementById('json').innerHTML = txt;
	}
}

function zmiana()
{
	if(document.getElementById('co').value != wartosc)
	{
		wartosc = document.getElementById('co').value;
		getSuggestions();
	}
}

function init() { 
if(getAjaxObject()) { setInterval('zmiana();', 100);}}
