<!--
/*
 AJAX GRUNDFUNKTIONEN
 *################################################################################*
*/
var xmlHttp = false;

// constants
var REQUEST_GET        = 0;
var REQEST_POST        = 2;
var REQUEST_HEAD       = 1;
var REQUEST_XML        = 3;

var automatic          = 1;
var isactivedata       = 0;

var php_file           = '';
var target_div         = '';
var last_received_data = '';



function getXMLRequester( )
{     
    try
    {
        // Internet Explorer
        if( window.ActiveXObject )
        {
            for( var i = 5; i; i-- )
            {
                try
                {
                    if( i == 2 )
                    {
                        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );    
                    }
                    else
                    {
                        
                        xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
                    }
                    break;
                }
                catch( excNotLoadable )
                {                        
                    xmlHttp = false;
                }
            }
        }
        else if( window.XMLHttpRequest )
        {
            xmlHttp = new XMLHttpRequest();
        }
    }
    catch( excNotLoadable )
    {
        xmlHttp = false;
    }
    return xmlHttp ;
}



function sendRequest( strSource, strData, intType, intID )
{
    if( !strData )
        strData = '';

    // standart type (0 = GET, 1 = xml, 2 = POST )
    if( isNaN( intType ) )
        intType = 0;
    if( xmlHttp && xmlHttp.readyState )
    {
        xmlHttp.abort( );
        xmlHttp = false;
    }       
    if( !xmlHttp )
    {
        xmlHttp = getXMLRequester( );
        if( !xmlHttp )
            return;
    }
    
    if( intType != 1 && ( strData && strData.substr( 0, 1 ) == '&' || strData.substr( 0, 1 ) == '?' ) )
        strData = strData.substring( 1, strData.length );
		
    var dataReturn = strData ? strData : strSource;
    
    switch( intType )
    {
        case 1:    // xml
            strData = "xml=" + strData;
        case 2: // POST
            xmlHttp.open( "POST", strSource, true );
            xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
            xmlHttp.setRequestHeader( 'Content-length', strData.length );
            break;
        case 3: // HEAD
            xmlHttp.open( "HEAD", strSource, true );
            strData = null;
            break;
		case 4: //Eine Datei
            xmlHttp.open( "POST", strSource, true );
            xmlHttp.setRequestHeader( 'Content-Type', 'multipart/form-data' );
            xmlHttp.setRequestHeader( 'Content-length', strData.length );		  
		    break;
        default: // GET
            var strDataFile = strSource + (strData ? '?' + strData : '' );
            xmlHttp.open( "GET", strDataFile, true );
            strData = null;
    }
    
    xmlHttp.onreadystatechange = new Function( "", "processResponse(" + intID + ")" ); ;
    xmlHttp.send( strData );    // param = POST data
    
    return dataReturn;
}
    
function processResponse( intID )
{
    switch( xmlHttp.readyState )
    {
        // uninitialized
        case 0:
        // loading
        case 1:
        // loaded
        case 2:
        // interactive
        case 3:
            break;
        // complete
        case 4:    
            // check http status
            if( xmlHttp.status == 200 )    // success
            {
                processData( xmlHttp, intID );
            }
            // fehlschlag.. z.B: Datei nicht vorhanden etc.
            else
            {
                if( window.handleAJAXError )
                    handleAJAXError( xmlHttp, intID );
                else
                    alert( "ERROR\n HTTP status = " + xmlHttp.status + "\n" + xmlHttp.statusText ) ;
            }
    }
}

 function processData( xmlHttp, intID )
 {
  // process text data
    last_received_data = xmlHttp.responseText;
	if (automatic == 1)
	{
     isactivedata = 0;     
	 document.getElementById(target_div).innerHTML = last_received_data;
	}
	else
	{
	 isactivedata = 1;	
	}
 }
/*
 *################################################################################*
 ENDE DER AJAX GRUNDFUNKTIONEN 
 #################################
 NUN DIE STANDART FUNKTIONSAUFRUFE
 *################################################################################*
*/


 //##Aufrufen um externe PHP Datei auszuführen
 function RequestInformation(targ_div, phpf, auto)
 {
  if (targ_div != '' && phpf != '' && (auto==1 || auto==0))
  {

   automatic = auto;   
   php_file = phpf;
   target_div = targ_div;
   sendRequest( php_file );
  }
 }

 //##Gibt die zuletzt erhaltenen Daten zurück
 function GetLastData()
 {
	return last_received_data;
 }
 
 //##Resetet die Aktiven Daten
 function ResetActiveData()
 {
   isactivedata = 0;
 }
 
 //##Setzt manuele Daten ins gesetzte Div ein
 function SetManuelDiv()
 {
   if (isactivedata == 1)
   {
	isactivedata = 0;     
	document.getElementById(target_div).innerHTML = last_received_data; 
   }
 }
 
 //##Gibt zurück, ob es neue MANUELE Daten gibt..
 function IsActiveData()
 {
	 return isactivedata;
 }
 -->

