function createXMLHttpRequest( )
{
	var httpRequest;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                 }

    if (!httpRequest) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }else{
			return httpRequest;
	}
}

var req = createXMLHttpRequest( );

function sendRequest( page )
{
	req.open( 'get', page + '&rand=' + Math.random( ) );
	req.onreadystatechange = handleResponse;
	req.send( null );
}

function setSessionVariables( page )
{
	req.open( 'get', page + '&rand=' + Math.random( ) );
	req.send( null );
	return true;
}

function sendData( params )
{
	/* Store form data so we can pass it to the server. */
	req.open( 'post', window['phppage'] );
	req.onreadystatechange = handleResponse;

	/* Specify that the body of the request contains form data. You must
	** do this for the POST method. I think this has to come after the "open" call.
	*/
	req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );

	/* For a GET, the "send" arguments are null. For a POST, you’d add
	** a string containing the data you want to pass to the server, like below.
	** I note this here because I spent a good hour or so trying to
	** figure out why my script wasn’t working, only to realize I was trying
	** to pass these arguments in the "open" function…!
	** Note the use of the amphersand (&) between arguments.
	*/
	req.send( params );
}


function handleResponse( )
{
	if( req.readyState == 4 )
		RespondeOutput( req.responseText );
}
