﻿/*------------------------------------------------------------------------------
                              .-= cwAjax Class =-. 
................................................................................
  Keszitette:
  Radics Peter
  2007.01.30. 16:08:43
  htp://www.cleanweb.hu
--------------------------------------------------------------------------------
*/
  function cwAjax()
  {   
    // CONSTRUCTOR ---------------------------------------------------------
        // Firefox
        if (window.XMLHttpRequest)
        {
          this.Ajax = new XMLHttpRequest();
          this.Ajax.overrideMimeType('text/html'); 
        }
        else
          if (window.ActiveXObject) // Explorer
          { 
             this.Ajax = new window.ActiveXObject("Microsoft.XMLHTTP"); 
          }
    //-----------------------------------------------------------------------
      
    // kuldes GET-tel
    this.sendGET = function(url,method_,ReadyFunction)
    {
       this.Ajax.onreadystatechange = ReadyFunction;
       this.Ajax.open(method_,url,true);
       this.Ajax.send(null);
    }
    
    // kuldes GET-tel
    this.sendPOST = function(url,parameters,ReadyFunction)
    {
      this.Ajax.onreadystatechange = ReadyFunction;
      this.Ajax.open('POST',url,true);
      this.Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      this.Ajax.setRequestHeader("Content-length", parameters.length);
      this.Ajax.setRequestHeader("Content-encoding","utf-8");
      this.Ajax.setRequestHeader("Connection", "close");
      this.Ajax.send(parameters);
      this.ShowProgress();
    }
    
              
    // a megjott adatot adja vissza
    this.Data = function()
    {
      return this.Ajax.responseText;
    }
       
    // ellenorzi, hogy megjott-e az adat
    this.Ready = function()
    {
      if (this.Ajax.readyState == 4 || this.Ajax.readyState == "complete") this.HideProgress();
      return this.Ajax.readyState == 4 || this.Ajax.readyState == "complete"; 
    }
    
    
    // statusz megjelenitese
    this.ShowProgress = function()
    {
	scroll(0,0);
        var NewDiv = document.createElement('div');
        NewDiv.id = 'ProgressBar';
        NewDiv.style.position = "absolute";
        NewDiv.style.top = "0px";
        NewDiv.style.left = "0px";
        NewDiv.style.backgroundColor = "#f00";
        NewDiv.style.color = "#fff";
        NewDiv.innerHTML = 'Feltöltés...';
        document.body.appendChild(NewDiv);
    }
      
    this.HideProgress = function()
    {
        document.body.removeChild(document.getElementById('ProgressBar'));
    }
  }



