function AggiungiCarrello(codice,idgamma, quantita) {
    //$.blockUI();
    $.ajax({
        type: "POST",
        url: "ajax/add_carrello.asp",
        cache: false,
        data: "codice=" + codice + "&idgamma=" + idgamma+ "&quantita=" + quantita,
        error: function() {
            //$.unblockUI();
            alert("Errore durante l'operazione. Riprovare più tardi");
        },
        success: function(msg) {
            //$.unblockUI();
            if (msg == '0')
                alert("Impossibile aggiungere il prodotto. Contattare il webmaster");
            else if (msg > 0) {
                /*alert("Prodotto aggiunto al carrello");*/
				if(isNaN(quantita))quantita = 1;
				$.modaldialog.success('Quantità prodotti inserita: <b>'+quantita+'</b>',  {title:'Prodotto aggiunto al carrello',timeout: 2,width: 250,height: 50 });
                $("#numprodotti").text(msg);
            }
            else if (msg == '-1')
                alert("Sessione di lavoro scaduta. Rieffettuare il login");
        }
    });

}


function AddQuantitaCarrello(codice, idordineprodotto) {
    //$.blockUI();
    //leggo quantità carrello inserita
    var quantita = $('#quantita_' + idordineprodotto).val();
    var quantita_reg_exp = /^([0-9])+$/;
    if (quantita_reg_exp.test(quantita)) {
        $.ajax({
            type: "POST",
            url: "ajax/add_quantita_carrello.asp",
            cache: false,
            dataType: "xml",
            data: "codice=" + codice + "&idordineprodotto=" + idordineprodotto + "&quantita=" + quantita,
            error: function() {
                //$.unblockUI();
                alert("Errore durante l'operazione. Riprovare più tardi");
            },
            success: function(xml) {
                //$.unblockUI();
                $("articolo", xml).each(function() {
                    var _status = $("status", this).text();

                    if (_status > 0) {
                        var _status = $("status", this).text();
                        var _quantita = $("quantita", this).text();
                        var _prezzoprodotto = $("prezzoprodotto", this).text();
                        var _prezzoq = $("prezzoq", this).text();
                        var _iva = $("iva", this).text();
                        var _prezzoT = $("prezzoT", this).text();
                        var _prezzoTnoIva = $("prezzoTnoIva", this).text();

                        $("#quantita_" + idordineprodotto).val(_quantita);
                        $("#prezzo_quantita_" + idordineprodotto).text(_prezzoq);
                        $("#prezzototale").text(_prezzoTnoIva);
                        $("#prezzoiva").text(_iva);
                        $("#prezzototaleiva").text(_prezzoT);
                    }
                    else if (_status <= 0)
                        alert("Impossibile modificare la quantità")
                });

            }


        });
    }
    else
        alert("Attenzione! Il valore della quantità non è valido");    

}


function DelQuantitaCarrello(codice, idordineprodotto) {
    //$.blockUI();
    $.ajax({
        type: "POST",
        url: "ajax/del_quantita_carrello.asp",
        cache: false,
        dataType: "xml",
        data: "codice=" + codice + "&idordineprodotto=" + idordineprodotto,
        error: function() {
            //$.unblockUI();
            alert("Errore durante l'operazione. Riprovare più tardi");
        },
        success: function(xml) {
            //$.unblockUI();
            $("articolo", xml).each(function() {
                var _status = $("status", this).text();

                if (_status > 0 && _status < 2) {
                    var _status = $("status", this).text();
                    var _quantita = $("quantita", this).text();
                    var _prezzoprodotto = $("prezzoprodotto", this).text();
                    var _prezzoq = $("prezzoq", this).text();
                    var _iva = $("iva", this).text();
                    var _prezzoT = $("prezzoT", this).text();
                    var _prezzoTnoIva = $("prezzoTnoIva", this).text();

                    $("#quantita_" + idordineprodotto).text(_quantita);
                    $("#prezzo_quantita_" + idordineprodotto).text(_prezzoq);
                    $("#prezzototale").text(_prezzoTnoIva);
                    $("#prezzoiva").text(_iva);
                    $("#prezzototaleiva").text(_prezzoT);
                }
                else if (_status <= 0)
                    alert("Impossibile rimuovere la quantità del prodotto")
                else if (_status = 2)
                    document.location.href='carrello.asp';
            });

        }


    });

}



function EliminaProdottoCarrello(codice, idordineprodotto) {
    //$.blockUI();
    if (confirm("Eliminare il prodotto dal carrello?")) {
        $.ajax({
            type: "POST",
            url: "ajax/del_prodotto_carrello.asp",
            data: "codice=" + codice + "&idordineprodotto=" + idordineprodotto,
            cache: false,
            error: function() {
                //$.unblockUI();
                alert("Errore durante l'operazione. Riprovare più tardi");
            },
            success: function(msg) {
                //$.unblockUI();
                if (msg == '-1')
                    alert("Sessione di lavoro scaduta. Rieffettuare il login");
                else if (msg == '0')
                    alert("Impossibile eliminare il prodotto. Contattare il webmaster");
                else if (msg == '1')
                    document.location.href = 'carrello.asp';

            }
        });
    }

}


function VerificaCarrello() {
        $.ajax({
            type: "GET",
            url: "ajax/verifica_carrello.asp",
            cache: false,
            error: function() {
                //$.unblockUI();
                alert("Errore durante l'operazione. Riprovare più tardi");
            },
            success: function(msg) {
                //$.unblockUI();
                if (msg == '-1')
                    alert("Sessione di lavoro scaduta. Rieffettuare il login");
                else if (msg == '0')
                    document.location.href = 'carrello_verifica.asp';
                else if (msg == '1')
                    document.location.href = 'riepilogo.asp';

            }
        });
    
}

