function concurrentDocumentLoaderText() {
    var urls = [ "http://www.google.com", "http://www.yahoo.com", "http://www.amazon.com" ];
    try {
        ConcurrentDocumentLoader.loadAll( urls, function( reqArray ) {
             if ( reqArray.length != 3 ) {
                 alert( "Error: expected 3 docs, got: " + reqArray.length );
             } else {
                 alert( "Sucess!");
             }
        } );
    } catch ( e ) {
        alert( "loadAll error: " + e );
    }
}

var ConcurrentDocumentLoader = new function() {
    // public
    this.loadAll = function( urls, callback ) {
        var outstanding = urls.length;
        var results = [];
        for ( var i = 0; i < urls.length; i++ ) {
             asyncLoadDocument( urls[i], function( req ) {
                outstanding--;
                results.push( req );
                if ( outstanding == 0 ) {
                    callback.call( null, results );
                }
            } );
        }
    }
    // private
    function asyncLoadDocument( url, callback ) {
        var xmlhttp = getXmlHttpRequest();
        // This is needed for testing locally in Mozilla
        if ( window.netscape && netscape.security.PrivilegeManager.enablePrivilege) {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
        }

        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState == 4 ) {
                callback.call( xmlhttp );
            }
        };
        xmlhttp.send(null);
    }

    function getXmlHttpRequest() {
        try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
        try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
        if ( typeof XMLHttpRequest!='undefined') {
            try { return new XMLHttpRequest(); } catch (e) {}
        }
        if ( window.createRequest) { return window.createRequest(); }
        throw "Can't create XMLHttpRequest!";
    }
}