
var xmlHttp;

function GetXmlHttpObject()
{
    var xmlHttp = null;

    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    if (!xmlHttp)
    {
        alert ("Your browser does not support AJAX!");
    }

    return xmlHttp;
}

function AJAXConnect (callback)
{
    if ((xmlHttp = GetXmlHttpObject()) == null)
    {
        return false;
    }

    xmlHttp.onreadystatechange = function()
    {
        if (xmlHttp.readyState == 4)
        {
            callback (xmlHttp.responseText);
        }
    }
}

function AJAXGet (url, parameters, callback)
{
    AJAXConnect (callback);

    xmlHttp.open ('GET', url + '?' + parameters, true);
    xmlHttp.send (null);
}

function AJAXPost (url, parameters, callback)
{
    AJAXConnect (callback);

    xmlHttp.open ('POST', url, true);

    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.send (parameters);
}

