
function XMLRequester(callback, datatype)
{
    var xmlHttp = new getXMLRequester();
    if( !xmlHttp ) return;
    this.send = send;
    this.process = process;

    function send (method, query,data, sync)
    {
		sync = sync ? false : true;
		/* sync=>true asyncroner Request sync=>false sycroner Request */
		switch (method)
	    {
		    case 'POST':
				xmlHttp.open("POST", query, sync);
				xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
				xmlHttp.setRequestHeader( 'Content-length', data.length );
				break;
		    case 'HEAD':
				xmlHttp.open("HEAD", query, sync);
				data = null;
				break;
		    default: // GET
				xmlHttp.open("GET", query, sync);
	    }
		/* aber hier neu eingefügt für den syncronen aufruf KH 17.12.08 */
		if (sync) xmlHttp.onreadystatechange = this.process;
		xmlHttp.send(data);
		if (sync==false)
		{
			switch(xmlHttp.readyState)
		    {
				// uninitialized
			    case 0:
				// loading
			    case 1:
				// loaded
			    case 2:
				// interactive
			    case 3:
				break;
				// complete
			    case 4:
					if( xmlHttp.status == 200 )	// success
						callback(datatype == 'xml' ? xmlHttp.responseXML : xmlHttp.responseText);
					else // loading not successfull, e.g. page not available
						callback(xmlHttp.statusText, xmlHttp.status);
		    }
	    }
		/* ende */
    }

    function process ()
    {
	// status 0 UNINITIALIZED open() has not been called yet.
	// status 1 LOADING send() has not been called yet.
	// status 2 LOADED send() has been called, headers and status are available.
	// status 3 INTERACTIVE Downloading, responseText holds the partial data.
	// status 4 COMPLETED Finished with all operations.
	switch(xmlHttp.readyState)
	    {
		// uninitialized
	    case 0:
		// loading
	    case 1:
		// loaded
	    case 2:
		// interactive
	    case 3:
		break;
		// complete
	    case 4:
			if( xmlHttp.status == 200 )	// success
				callback(datatype == 'xml' ? xmlHttp.responseXML : xmlHttp.responseText);
			else // loading not successfull, e.g. page not available
				callback(xmlHttp.statusText, xmlHttp.status);
	    }
    }
}


function SendRequest (query, callback, method, data, datatype, sync)
{
    var req = new XMLRequester(callback, datatype);
    if( !req ) return;
    req.send(method, query, data, sync);
}

/**
 * instantiates a new xmlhttprequest object
 *
 * @return xmlhttprequest object or false
 */
function getXMLRequester( )
{
    var xmlHttp = false;
    // try to create a new instance of the xmlhttprequest object
    try	{
	// Mozilla, Opera und Safari
	if( window.XMLHttpRequest ) {
	    xmlHttp = new XMLHttpRequest();
	}
	// Internet Explorer
	else if( window.ActiveXObject ) {
	    for( var i = 5; i; i-- ) {
		try {
		    // loading of a newer version of msxml dll (msxml3 - msxml5) failed
		    // use fallback solution
		    // old style msxml version independent, deprecated
		    if( i == 2 ) {
			xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
		    }
		    // try to use the latest msxml dll
		    else {
			xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
		    }
		    break;
		}
		catch( excNotLoadable ) {
		    xmlHttp = false;
		}
	    }
	}
    }
    // loading of xmlhttp object failed
    catch( excNotLoadable ) {
	xmlHttp = false;
    } 
    return xmlHttp ;
}
