/*
AJAX class
----------

Licence: GNU/GPL
Author : Fogler Tibor   foglert@robitbt.hu

function Tajax() {
   this.asyncron = false;
   this.setPost = function(varname,value);
   this.send = function(url,responseFv,extrapar);
}
igényelt responseFv
    function valami(HTTPrequest,extrapar) {
   	...
        HTTPrequest.responseXML,
        HTTPrequest.responseText használható
    };

 Tajax.req.responseXML,
 Tajax.req.responseText is használható

 Foglalt globális változó nevek: waitId, waitStr, ajaxError
 opcionális html tag: <input id="ajaxWait" style="...." value="" />

syncron üzemmod tesztelve: Opera 9.52, Firefox 3.05,  IE 7.06,

*/

// global
waitId = 'ajaxWait';  // egy input tag 'id' -je
waitstr = 'AJAX adatátvitel, türelmet kérek...';
ajaxError = 'Az AJAX (HTTPREQUEST) hivást nem támogatja böngésző!';

function Tajax() {
   // public
   this.asyncron = false;
   // private
   this.setPost = function(Name,Value) {
     var s = '';
     this.postNames.push(Name);
     s = String(Value).replace(/\+/gi,'__plus__');;
     s = s.replace(/&/gi,'__amp__');
     this.postValues.push(encodeURI(s));
   }
   this.send = function(url,responseFv,extraPar) {
      var i = 0;
      var s = '';
      var w = null;
      this.userResponseFv = responseFv;
      this.extraPar = extraPar;
      this.req = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
        this.req = new XMLHttpRequest();
        if (this.req.overrideMimeType) {
          this.req.overrideMimeType('text/xml');
        }
      } else if (window.ActiveXObject) { // IE
        try {
          this.req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            this.req = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {
            this.req = false;
          }
        }
      }
      if (this.req) {
        s = '';
        for (i=0; i<this.postNames.length; i++) {
          if (s != '') s = s + '&';
          s = s + this.postNames[i]+'='+this.postValues[i];
        }
        w = document.getElementById(waitId);
        if ((w != undefined) && (w != null))
          w.value = waitstr;
        if (this.asyncron)
           this.req.onreadystatechange = this.responseFv;
        else
           this.req.onreadystatechange = this.emptyFv;
        this.req.open('POST', url, this.asyncron);
        this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        this.req.setRequestHeader('Content-length', s.length);
        this.req.send(s);
        if (!this.asyncron)
           this.responseFv0();
        this.postNames = new Array();
        this.postValues = new Array();
      } else {
        alert(ajaxError);
      }
   }
   // private
   this.postNames = new Array();
   this.postValues = new Array();
   this.extraPar = '';
   this.req = false;
   this.userResposeFv = '';
   this.emptyFv = function() {
   }
   this.responseFv0 = function() {
           this.userResponseFv(this.req, this.extraPar);
           w = document.getElementById(waitId);
           if ((w != undefined) && (w != null))
                w.value = '';
   }
   this.responseFv = function() {
        if (this.req.readyState == 4)
           this.responseFv0();
   }
}

