$(document).ready(function(){
    $("a[@action='remove_from_cart']").click(function() {
        id = $(this).attr("id");

        $("#result").html("<h3>Result:</h3>");
        $.get(
        "remote_call.php",
        {
            action: 'remove_item_from_cart',
            id: id
        },
        onRemoveItemSuccess);

        setTimeout("location.href = 'cart.html';",3000);
        return false;
    });

    function onRemoveItemSuccess(data) {
        $("#result").append("Product has been removed from your cart.<br/>");
        $("#tr_"+data).remove();
    }

    $("a[@action='update_cart']").click(function() {
        $("input[@name='qty_edit']").each(function(){
            id = $(this).attr("cart_id");
            qty = $(this).val();

            $.get(
            "remote_call.php",
            {
                action: 'update_cart',
                id: id,
                qty: qty
            },
            onUpdateItemSuccess);
        });
        setTimeout("location.href = 'cart.html';",3000);
        return false;
    });
    function onUpdateItemSuccess(data) {
        $("#result").append(data+"<br/>");
    }
});
