
function GetHTTPProxy() 
{
    var proxy;
    if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
        proxy = new XMLHttpRequest();

    else // code for IE6, IE5
        proxy = new ActiveXObject("Microsoft.XMLHTTP");

    return proxy;

}


function SendQuery(proxy, strUrl, respFunc) 
{
    if (proxy) 
    {
        proxy.open("GET", strUrl, true);
        proxy.onreadystatechange = respFunc;

        proxy.send(null);

    }

}

//	update format: id|innerHTML
function HandleSimpleUpdate(proxy) 
{
    if (proxy.readyState == 4) 
    {
        var strResp = proxy.responseText;

        if (strResp.indexOf('invalid') == -1) 
        {
            var astrSplit = strResp.split("|", 2);
            var strTarget = astrSplit[0];
            var strUpdate = astrSplit[1];

            document.getElementById(strTarget).innerHTML = strUpdate;                    

        }

    }

}

//	update format: id|data[|id|data...]
//	where id is either an element id and the data is the element's new innerHTML
// 	or the id is "script" and the data is a js function to be inserted in the page
function HandleComplexUpdate(proxy) 
{
    if (proxy.readyState == 4) 
    {
        var strResp = proxy.responseText;

        if (strResp.indexOf('invalid') == -1) 
        {
            var astrSplit = strResp.split("|");

            for (var i = 0; i < astrSplit.length; i += 2) 
            {
                var strTarget = astrSplit[i];
                var strUpdate = astrSplit[i + 1];

                if (strTarget == "script") 
                {
                    var head = document.getElementsByTagName('head')[0];
                    var script = document.createElement('script');
                    script.type = 'text/javascript';
                    script.innerHTML = strUpdate;
                    head.appendChild(script);

                }

                else
                    document.getElementById(strTarget).innerHTML = strUpdate;

            }
            
        }

    }

}

