function StackSimply()
{
   this.init = function()
   {
      this.stacks[ '@ok' ] = new Array();
   }

   this.add = function( threat, list )
   {
      this.stacks[ threat ].push( list );
   }

   this.execute = function( threat )
   {
      for( i in this.stacks[ threat ] )
      {
         switch( typeof this.stacks[ threat ][ i ] )
         {
            case 'function': this.stacks[ threat ][ i ](); break;
            default: eval( this.stacks[ threat ][ i ] );
         }
      }
   }
}

RequestSimply.prototype = new StackSimply();

function RequestSimply( url, parm )
{
   var myThis  = this;

   this.stacks = new Array();
   this.init();

   this.url = url;
   this.parm = parm;

   this.MSXML = new Array(
   	   'Msxml2.XMLHTTP.7.0',
       'Msxml2.XMLHTTP.6.0',
       'MSXML2.XMLHTTP.5.0',
       'MSXML2.XMLHTTP.4.0',
       'MSXML2.XMLHTTP.3.0',
       'MSXML2.XMLHTTP',
       'Microsoft.XMLHTTP' );

   this.initXMLHttp = function()
   {
      try
      {
         this.XMLHttp = new XMLHttpRequest();
      }
      catch( e )
      {
         var success = false;
         for ( var i = 0; i < this.MSXML.length && !success; i++ )
         {
            try
            {
               this.XMLHttp = new ActiveXObject( this.MSXML[i] );
               success = true;
            }
            catch (e){}
         }
         if( !success )
         {
            alert( 'Nie można utworzyć obiektu odpowiadającego za transmisję danych. Proszę zainstalować nowszą wersję przeglądarki.' );
         }
      }
   }

   this.onreadystatechange = function()
   {
      try { readyState = this.XMLHttp.readyState; }
      catch(e) { readyState = 0; }

      if( this.XMLHttp.readyState != 4 ) return false;

      try { Status = this.XMLHttp.status; }
      catch(e) { Status = 'None.' }

      if( Status == 12030 ) return alert( 'Komunikacja z serwerem została przerwana. Najczęstszą przyczyną wystąpienia błędu jest obciążone łącze lub serwer. Ponów żądanie klawiszem F5.\nKod błędu: 12030' );
      if( Status == 12152 ) return alert( 'Komunikacja z serwerem została przerwana. Najczęstszą przyczyną wystąpienia błędu jest obciążone łącze lub serwer. Ponów żądanie klawiszem F5.\nKod błędu: 12152' );
      if( Status != 200 ) return false;

      this.execute( '@ok' );

      return true;
   }

   this.StripEmpty = function( ArrayIN )
   {
      ArrayTMP = new Array();
      for( i in ArrayIN )
         if( ArrayIN[ i ] ) ArrayTMP = ArrayTMP.concat( ArrayIN[ i ] );
      return ArrayTMP;
   }

   this.get = function( data )
   {
      query = this.StripEmpty( new Array( this.parm, data, 'cache=' + Math.random()*100000000000000000 ) ).join( '&' );
      query = this.StripEmpty( new Array( this.url, query ) ).join( '?' );
      this.XMLHttp.open( "GET", encodeURI( query ), true );

      this.XMLHttp.onreadystatechange = function() { myThis.onreadystatechange(); }

      this.XMLHttp.send( null );
   }

   this.post = function( data )
   {
      this.execute( '@start' );

      this.XMLHttp.open( "POST", this.url + '?cache=' + Math.random()*100000000000000000, true );

      this.XMLHttp.onreadystatechange = function() { myThis.onreadystatechange(); }

      queryString = this.StripEmpty( new Array( this.parm, data ) ).join( '&' );

      this.XMLHttp.send( queryString );
   }

   this.abort = function()
   {
      try
      {
         status = this.XMLHttp.status;
         if( status != 0 || status != 4 ) this.XMLHttp.abort();

         return true;
      }
      catch(e)
      {
         this.initXMLHttp();

         return false;
      }
   }

   this.initXMLHttp();
}
