////////////////////////////////////////////////////////////////////////////////
//
// Klasse:
//  cAjaxObj
////  
// @Copyright:
//  TIXEL|media GmbH
//  www.tixelmedia.de
// @Autor:
//  Dennis Schmitt (schmitt@tixelemdia.de)
// @Protocol:
//  09.01.2007 - Dennis Schmitt | Klasse erstellt
//  
////
// Beschreibung:
//  
//
function cAjaxObj()
{
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.setLoadingDiv  = function( LoadingString, IndicatorImage )
  {
    // loading string definieren
    LoadingString = ( LoadingString == undefined ) ? 'loading':LoadingString;
    LoadingDivHTML = LoadingDivHTML.replace( /\{LOADING_TEXT\}/, LoadingString );
    
    // indicatorimage setzen
    // IndicatorImage = IMAGE;WIDTH;HEIGHT
    IndicatorImage = ( IndicatorImage == undefined ) ? 'indicator.gif;16;16':IndicatorImage;
    IndicatorImage = IndicatorImage.split(';');
    
    LoadingDivHTML = LoadingDivHTML.replace( /\{INDICATOR_IMAGE\}/, IndicatorImage[0] );
    LoadingDivHTML = LoadingDivHTML.replace( /\{INDICATOR_WIDTH\}/, IndicatorImage[1] );
    LoadingDivHTML = LoadingDivHTML.replace( /\{INDICATOR_HEIGHT\}/, IndicatorImage[2] );
    
    
    this.fillContainer( LoadingDivHTML );
  }
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.add2Container  = function( sValue )
  {
    ContainerObj.innerHTML = ContainerObj.innerHTML + sValue;
  }
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.setStyles2Container = function( aObj, aValue )
  {
    for( i in aObj )
    {
      ContainerObj.style[aObj[i]] = aValue;
    }
  }
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.clearContainer = function()
  {
    ContainerObj.innerHTML = '';
  }
  
  this.getContainerContent = function()
  {
    alert( ContainerObj.innerHTML );
  }

  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.initContainer  = function( ContainerId )
  {
    ContainerObj = document.getElementById( ContainerId );
  }
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.checkHttpRequest = function()
  {
    return ( xmlHttpRequest ) ? true:xmlHttpRequest=this.getXMLHttpRequest();
  }
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.getXMLHttpRequest = function()
  {
    axObjs = new Array( 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0',
                        'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 
                        'Microsoft.XMLHTTP' );
                        
    for( var i=0; i<axObjs.length; i++ )
      try
      {
        return new ActiveXObject( axObjs[i] );
      }
      catch( eXeption ){}

  	return new XMLHttpRequest();
  }
  
  
  this.waitQueryGoDown = function()
  {
    if( isLoading == false && WaitQuery.length > 0 )
    {
      Entry = WaitQuery[0];
      
      mContainer = Entry[3];
      mCallback  = Entry[2];
      mASync     = Entry[1];
      mUrl       = Entry[0];

      this.initContainer( mContainer );
      this.getUrl( mUrl, mASync, mCallback );
    }
  }
  
  this.waitQueryPop = function()
  {
    WaitQuery.shift();
  }
    
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.fillContainer  = function( sValue )
  {
    ContainerObj.innerHTML = sValue;
    
    try
    {
      if( WaitQuery.length > 0 && typeof(oAjax) != 'undefined' )
        oAjax.waitQueryGoDown();
        
      if( WaitQuery.length > 0 && typeof(bAjax) != 'undefined' )
        bAjax.waitQueryGoDown();
    }
    catch( eXeption ){}
  }
  
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.CallBackHandler = function()
  {	
    if( xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200 )
    {     
      Respon = xmlHttpRequest.getResponseHeader('Content-type');
      
      if( Respon.indexOf('xml') > -1 )
        Result = xmlHttpRequest.responseXML;
      else
        Result = xmlHttpRequest.responseText;

      CallBackFunc( Result );
      
      isLoading = false;
      
      try
      {
        if( typeof(oAjax) != 'undefined' )
        {
          oAjax.waitQueryPop();
          oAjax.waitQueryGoDown();
        }
        if( typeof(bAjax) != 'undefined' )
        {
          bAjax.waitQueryPop();
          bAjax.waitQueryGoDown();
        }
      }
      catch( eXeption ){}
    }
  }
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.getUrl = function( sUrl, bASync, fCallBack )
  {
    if( !this.checkHttpRequest() ) return null;
    
    CallBackFunc = fCallBack;
    
    xmlHttpRequest.onreadystatechange = this.CallBackHandler;
    
    isLoading = true;
    
    
    xmlHttpRequest.open( "GET", sUrl, bASync );
    xmlHttpRequest.setRequestHeader('Content-Type','text/html;charset=utf-8');
    xmlHttpRequest.send( null );
  }

  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.getUrlASync = function( sUrl, fCallBack )
  {
    this.getUrl( sUrl, true, fCallBack );
  }
  
  //////////////////////////////////////////////////////////////////////////////
  // Beschreibung:
  //  Legt den Container fest in dem die Inhalte kommen
  this.getUrlSync = function( sUrl, fCallBack )
  {
    this.getUrl( sUrl, false, fCallBack );
  }
  
  
  this.addToQuery = function( sUrl, bSync, fCallBack, ContainerId )
  {
    Dummy = new Array();
    
    Dummy.push(sUrl);
    Dummy.push(bSync);
    Dummy.push(fCallBack);
    Dummy.push(ContainerId);
    
    WaitQuery.push(Dummy);
    this.waitQueryGoDown();
  }

  //////////////////////////////////////////////////////////////////////////////
  // attributs
  var xmlHttpRequest   = this.getXMLHttpRequest();
  var xmlHttpCache     = false;
  
  var LoadingDiv       = true;
  var LoadingDivHTML   = '<div style="text-align:center;height:100%;Font-Family: Verdana, Arial, sans-serif; Font-size: 11px; Color: #666666;"><div style="height:40%;"></div><img src="images/{INDICATOR_IMAGE}" style="Width: {INDICATOR_WIDTH}px; Height: {INDICATOR_HEIGHT}px;"><br>{LOADING_TEXT}</div>';
  var WaitQuery        = new Array();
  var isLoading 	   = false;
  
  var CallBackFunc     = null;
  var ContainerObj     = null;
}
