/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function createRequestObject()
{
     var ro;
     ro = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();

     return ro;
}

var http = createRequestObject();

function sndReq(action,arg)
{
    $('#tienda-loading').show();
    if(action=="update")
    {
        arg = "updateData=";
        var $inputs = $('.tienda-input-cantidad');
        var values = {};
        $inputs.each(function() {
            values[this.name] = $(this).val();
            var qtyid = this.name + "," + $(this).val() + ";";
            arg += qtyid;
        });        
    }

    if(action=="delete")
    {
        arg = "id="+arg;
        var mensaje="\n\u00bfSeguro que desea quitar el libro de la cesta?";
        if(!confirm(mensaje))
        {
            $('#tienda-loading').hide();
            return;
        }
    }

    http.open('get', 'rpc.php?action='+action+'&'+arg);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse()
{
     if(http.readyState == 4)
     {         
          var response = http.responseText;
          document.getElementById("carrito").innerHTML = response;
     }
     $('#tienda-loading').hide();
}


