function ajaxHTTPObject() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                return false;
            }
        }
    }
    return xmlHttp;
}


/* 
    In order to use ajaxLoader, you need to do 2 things:
    
    1. Define a state change handler that accepts an XMLHttpRequest object as
    its first parameter -- this is the callback in which you actually get to do
    stuff with the server response, e.g.:

        function handleStateChange(req) {
          if (req.readyState == 4 && req.status == 200) {
            el = document.getElementById("output");
            el.innerHTML = req.responseText;
          }
        }

    2. Call ajaxLoader as the onload handler of your document's body tag,
    passing in handleStateChange as the second param, e.g.: 

    <html>
        <head>
            <title="Simple Ajax Example"/>
            <!-- ... define/load ajaxLoader and handleStateChange ... -->
        </head>
        <body onload="ajaxLoader('something.epl', handleStateChange)">
            Text retrieved from server will go here:
            <div id="output"></div>
        </body>
    </html>
*/


var xhr;
var xhrTimeout;

function ajaxLoader(url, stateChangeHandler, arg1, arg2, arg3, arg4, arg5) {
    if (document.getElementById) {
        xhr = ajaxHTTPObject();
    }
    if (xhr) {
        xhr.onreadystatechange = function() {
            stateChangeHandler(xhr, arg1, arg2, arg3, arg4, arg5);
        };
        xhr.open("GET", url, true);
        xhr.send(null);
    }
}


