var xmlHttp=makeObject();


function makeObject() 
{
  
  var xmlHttp;
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
          
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
 
  if (!xmlHttp)
    alert("Aplikacja AJAX nie mogła być zainicjowana.");
  else 
  
    return xmlHttp;
}

//  pozostale 

function letter(fun,identy)
{
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    adres = escape(document.getElementById("adres1").value);
        
        
        odata=new Date();
        date=odata.getTime();
        
    xmlHttp.open("GET", "ajax/letter.php?adres="+adres+"&name="+name+"&data="+date+"&fun="+fun+"&identy="+identy, true);
    xmlHttp.onreadystatechange = handleServerResponsel;
 
    xmlHttp.send(null);
  }
  else
    setTimeout('letter()', 1000);
}


function handleServerResponsel()
{


 if (xmlHttp.readyState == 1) 
  {
  cel=document.getElementById("help1");
  cel.innerHTML='<br/><b>Przetwarzanie danych...</b><br><br>';
  }else{
  cel=document.getElementById("help1");
  cel.innerHTML='&nbsp;';

  
  }
  // kontynuuje jedynie jesli transakcja zostala zakonczona
  if (xmlHttp.readyState == 4) 
  {
    // status 200 oznacza pomyslne ukonczenie transakcji
    if (xmlHttp.status == 200) 
    {
      
     // xmlResponse = xmlHttp.responseXML;
      //xmlDocumentElement = xmlResponse.documentElement;
     // helloMessage = xmlDocumentElement.firstChild.data;
         
         //xmlHttp.setRequestHeader("Cache-Control","no-cache");
         helloMessage=xmlHttp.responseText;
         
         
      
      document.getElementById("help1").innerHTML = helloMessage;
      
    } 
    
    else 
    {
      alert("Wystapil blad podczas uzyskiwania dostepu do serwera: " + xmlHttp.statusText);
    }
  }
}
