// $URL: svn+ssh://svn.mems-exchange.org/repos/trunk/DurusWorks/qp/demo/proto/static/proto.js $
// $Id: proto.js 32736 2010-09-10 15:28:45Z dbinger $
// Javascript to demonstrate XMLHTTPRequest callback operation.

function request (url, callback) {
    // Get an XMLHTTPRequest object and send a GET for the URL.
    // When the complete response has returned, call the callback
    // function with the XMLHTTPRequest object as the argument.
    var req = null;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (exc) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (exc) {
                req = new ActiveXObject("Msxml2.XMLHTTP.4.0");
            }
        }
    }
    req.onreadystatechange = function (e) { 
        if (req.readyState == 4) callback(req); 
    }
    req.open("GET", url, true);
    req.send("");
}

function retrieve (url, id) {
    // Retrieve the url and use the results to replace the content
    // of the document element with the given id.
    request(url, 
        function (req) {
            if (req.status == 200) {
                document.getElementById(id).innerHTML = req.responseText;
            } else {
                document.getElementById(id).innerHTML = req.statusText;
            }
        }
        );
}
