

function AjaxRequest() {
	 
	  if (window.XMLHttpRequest) {
	    try {
	      this.request = new XMLHttpRequest();
	    } catch(e) {
	      this.request = null;
	    }
	  // Now try the ActiveX (IE) version
	  } else if (window.ActiveXObject) {
	    try {
	      this.request = new ActiveXObject("Msxml2.XMLHTTP");
	    // Try the older ActiveX object for older versions of IE
	    } catch(e) {
	      try {
	        this.request = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch(e) {
	        this.request = null;
	      }
	    }
	  }

	  // If the request creation failed, notify the user
	  if (this.request == null)
	    alert("Ajax error creating the request.\n" + "Details: " + e);
	}


//Przesłamy żądanie na serwer używając technolgoii Ajax
AjaxRequest.prototype.send = function(type, url, handler, postDataType, postData) {
  if (this.request != null) {
    // Usuwamy wcześniejsze żądanie
    this.request.abort();

    // Dodajemy pomocniczy parametr by zapobiec pobraniu odpowiedzi 
    // z pamięci podręcznej przeglądarki
    url += "?dummy=" + new Date().getTime();

    try {
      this.request.onreadystatechange = handler;
      this.request.open(type, url, true); // zawsze asynchroniczne (true)
      if (type.toLowerCase() == "get") {
        // Generujemy żądanie GET: brak danych 
        this.request.send(null);
      } else {
        // Generujemy żadanie POST: ostatni argument to dane
        this.request.setRequestHeader("Content-Type", postDataType);
        this.request.send(postData);
      }
    } catch(e) {
      alert("Błąd komunikacji z serwerem.\n" + "Informacje szczegółowe: " + e);
    }
  }
}

AjaxRequest.prototype.getReadyState = function() {
  return this.request.readyState;
}

AjaxRequest.prototype.getStatus = function() {
  return this.request.status;
}

AjaxRequest.prototype.getResponseText = function() {
  return this.request.responseText;
}

AjaxRequest.prototype.getResponseXML = function() {
  return this.request.responseXML;
}