var Ajax = null;
function getHTTPObject()
{
    if (window.ActiveXObject)
        return new ActiveXObject("Microsoft.XMLHTTP");
    else
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else //No soporta ajax
            return false;
}

/*
 * destino: Pagina php que procesa el texto.
 * tipo: "POST" o "GET".
 * params: array con nombre y valor de las variables. EJ: (params[0] = "hola = 75)
 * asyncronous: Modo de envio, Synchronous retorna el valor
 * exit: Funcion que procesa el retorno. null en caso de sync
 */
function sendAjaxRequest(destino, tipo, params, asyncronous, exit)
{
    Ajax = getHTTPObject();
    if (!Ajax)
        return false;

    // Unimos la cadena
    var sendInfo = "";
    if (params.length > 0)
        sendInfo = params.join("&");

    if (tipo == "POST")
    {
        Ajax.open("POST", destino, asyncronous);

        // Colocamos los headers
        Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        Ajax.setRequestHeader("Content-length", sendInfo.length);
        Ajax.setRequestHeader("Connection", "close");
        if (asyncronous)
            Ajax.onreadystatechange = exit;

        Ajax.send(sendInfo);
        if (!asyncronous)
            return Ajax.responseText;
        return true;
    } 
    else if (tipo == "GET")
    {
        Ajax.open("GET", destino + "?" + sendInfo, asyncronous)
        if (asyncronous)
            Ajax.onreadystatechange = exit;

        Ajax.send(null);
        if (!asyncronous)
            return Ajax.responseText;
        return true
    }
    return false;
}

function SendSyncAjaxRequest(destino, tipo, params)
{
    return sendAjaxRequest(destino, tipo, params, false, null);
}

function SendAsyncAjaxRequest(destino, tipo, params, exit)
{
    return sendAjaxRequest(destino, tipo, params, true, exit);
}

