
////////////////////////////////////////////////////////////////

function CallSjax( url, query, id, onFeedback )
{
 var request = new SjaxRequest( url, query, id );
 if ( request != null )
 {
  request.onFeedback = onFeedback; 
  request.Perform();
 }
}

////////////////////////////////////////////////////////////////

function CreateRequestSjax()
{
 var httpRequest = null;

 if ( window.XMLHttpRequest )   // Mozilla, Safari, ...
 {
  httpRequest = new XMLHttpRequest();
 } 
 else if (window.ActiveXObject) // IE
 { 
  try 
  {
   httpRequest = new ActiveXObject("Msxml2.XMLHTTP.6.0");
  } 
  catch (e) 
  {
   try 
   {
    httpRequest = new ActiveXObject("MSXML2.XMLHTTP.3.0");
   } 
   catch ( e ) 
   {
    try 
    {
     httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch ( e ) 
    {
     try 
     {
      httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
     } 
     catch ( e ) 
     {
      httpRequest = null;
     }
    }
   }
  }
 }

 return httpRequest;
}

function onCompletedHelperSjax( self )
{
 if ( self.id != null )
 {
  if ( self.onCompleted != null )
  {
   self.onCompleted( self.id, self.request.responseText );
  }
 }
}

function onErrorHelperSjax( self )
{
 if ( self.id != null )
 {
  if ( self.onError != null )
  {
   self.onError( self.id, self.status, self.statusText );
  }
 }
}

//////////////////////////////////////////////

function onCompletedSjax( id, responseText )
{
 SetElementTextById( id, responseText );
}

function onErrorSjax( id, status, statusText )
{
 SetElementTextById( id, status + " " + statusText );
}

//////////////////////////////////////////////

function SetMethodSjax( method )
{
 this.method = method;
}

function PerformSjax()
{
 this.request = this.CreateRequest();
 if ( this.request != null )
 {
  setCursorHourglass();
  
  var url = this.url;
  if ( this.query != null )
  {
   url += "?" + this.query;
  }

  this.request.open( this.method, url, false ); 

  this.request.send( null ); 

  if ( this.request.status == 200 )
  {
   this.onCompletedHelper( this );
  }
  else
  {
   this.onErrorHelper( this );
  }

  this.request = null;

  setCursorDefault();
 }
}

////////////////////////////////////////////////////////////////

// CLASS SjaxRequest

function SjaxRequest( url, query, id )
{
 // member variables
 this.url     = url;
 this.query   = query;
 this.id      = id;
 this.request = null;
 this.method  = "GET";

 // member methods for handling request
 this.CreateRequest = CreateRequestSjax;
 this.Perform       = PerformSjax;
 this.SetMethod     = SetMethodSjax;

 // helper member methods for handling feedback
 this.onCompletedHelper   = onCompletedHelperSjax;
 this.onErrorHelper       = onErrorHelperSjax;

 this.onCompleted = onCompletedSjax;
 this.onError     = onErrorSjax;

 // member variable to class for handling feedback
 this.onFeedback    = null;
}

////////////////////////////////////////////////////////////////


