var polaczenie;
var url='/page/urbibot/index2.php';
function polacz()
{
    try
    {
        polaczenie = new XMLHttpRequest();
    }
    catch(e)
    {
       var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                    "MSXML2.XMLHTTP.5.0",
                    "MSXML2.XMLHTTP.4.0",
                    "MSXML2.XMLHTTP.3.0",
                    "MSXML2.XMLHTTP",
                    "Microsoft.XMLHTTP");
	
        for (var i=0; i<XmlHttpVersions.length; i++)
        {
            try
            {
                polaczenie = new ActiveXObject(XmlHttpVersions[i]);
            }
            catch (e) {}
        }
	

    }
    if (!polaczenie)
        alert("Błąd tworzenia obiektu!");
    else
        return polaczenie;    

}
function dajElement(id)
{
	var Netscape4=(document.layers)?true:false;
	var Netscape6=(navigator.vendor == ('Netscape6') || navigator.product == ('Gecko'));
	var iExplorer=false;
	var Opera=false;
	if (document.all)
	{
		if (navigator.userAgent.search('Opera')>=0)
		{ iExplorer=false; Opera=true;}
		 else 
		{iExplorer=true; Opera=false;}
	}
	if(iExplorer||Opera)
	{
	   return document.all[id];
	}
	if(Netscape4)
      {
	   return document.layers[id];
      }
	if(Netscape6)
	{
	  return document.getElementById(id);
	}
}
function wyslij(url,param)
{
    dajElement("odpowiedz").innerHTML='My¶lę, proszę czekać....';
    dajElement("wiadomosc").disabled=true;
    polaczenie.open("POST",url, true);
	polaczenie.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    polaczenie.onreadystatechange = przechwyc;
    polaczenie.setRequestHeader("Cache-Control","no-cache");
    polaczenie.send(param);
   
}
      
function przechwyc()
{
    if(polaczenie.readyState == 4)
    {
        if(polaczenie.status == 200)
        {
            tekst = polaczenie.responseText;
    	    pos=tekst.indexOf("\n",0);
	    zdjecie=tekst.slice(0,pos);
	    odp=tekst.slice(pos,tekst.length);
	   
	    dajElement("zdjecieBW").src = '/page/urbibot/'+zdjecie.slice(1,zdjecie.length);
            dajElement("odpowiedz").innerHTML = odp;
            dajElement("wiadomosc").disabled=false;
            dajElement("wiadomosc").focus();
        }
        else
            alert('Bł±d ajax');
    }
}
function klawisz(e) { 

  if (e) kodKlawisza = e.which
  else if (event) kodKlawisza=event.keyCode
  else {return false}; 
  if(kodKlawisza==13)
  {
	text=dajElement("wiadomosc").value;
	if(text.length>0)
	{
		dajElement("wiadomosc").value='';
		wyslij(url,'wiadomosc='+text);
	}
  }
}
function init()
{
	polacz();
	document.onkeypress=klawisz;
	if (navigator.appName == 'Netscape') {
   		 window.captureEvents(Event.KEYPRESS);
   	         window.onKeyPress = klawisz;
        }
}
init();
