// Make an AJAX object to load content

var HTTP = new Object;
/* From Javascript: The Definitive Guide, 5th Edition (O'Reilly) page 480 */
// return an appropriate XML Request object
HTTP._factories = [
    function() { return new XMLHttpRequest(); },             // most browsers
    // IE-specific
    function() { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); },
    function() { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); },
    function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
    function() { return new ActiveXObject("Microsoft.XMLHTTP"); } // older IE
];

// when we find a factory that works, store it here
HTTP._factory = null;

// create and return a new XMLHttpRequestObject
HTTP.newRequest = function() {
    if (HTTP._factory != null) return HTTP._factory();

    for (var i = 0; i < HTTP._factories.length; i++) {
        try {
            var factory = HTTP._factories[i];
            var request = factory();
            if (request != null) {
                HTTP._factory = factory;
                return request;
            }
        }
        catch (e) {
            continue;
        }
    }

    // uh oh, no XMLHttpRequest objects are available
    // don't throw an exception, though, this is merely a nice-to-have.
}

