/* (c) 2007 Division by Zero Pty Ltd */

function getXmlHttpRequest() {

    var xmlHttpRequest;
    
    if (window.XMLHttpRequest) {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
    
    return xmlHttpRequest;
}


function updateCaptchaInfo() {
    
    var the_object;
    var http_request = getXmlHttpRequest();

    // prefixing a '?' forces browsers to get fresh content and not cache
    // the result from this http request
    http_request.open("GET", "/captcha/json/?", true);

    http_request.onreadystatechange = function () {
        if (http_request.readyState == 4) {

            if (http_request.status == 200) {
                the_object = eval("(" + http_request.responseText + ")");

                var id = the_object.id;

                // set the id and image src
                document.getElementById('captcha_id').value = id;
                document.getElementById('captcha_image').src = 
		    "/captcha/i/?id="+id;
            }
            else {
                alert("There was a problem with the URL.");
            }
            http_request = null;
        }
    };

    http_request.send(null);

    return false;
}
