/* 
 * Copyright(c) Binario Information Technologies SRL. All Rights Reserved.
 * This software is the proprietary information of BinarioIT SRL.
 */

var base_url = "/cart/";

function addToCart(lineNumber) {
    var productId = $("#productId_" + lineNumber).val();
    var quantity = $("#quantity_" + lineNumber).val();

    $.post(base_url + "CartAJAX.php", {action: "add", productId: productId, quantity: quantity}, function (responseHtml) {
        $("#cart_result").html(responseHtml);
        loadCartPreview();
    }); 
}

function loadCartPreview() {
    $.get(base_url + "CartAJAX.php?action=preview", function (responseHtml) {
        $("#cart_content").html(responseHtml);
    });
}

function clearCart() {
    $.post(base_url + "CartAJAX.php", {action: "clear"}, function (responseHtml) {
        $("#cart_result").html(responseHtml);
        loadCartPreview();
    });
}

function modifyCart(lineNumber) {
    var productId = $("#productId_" + lineNumber).val();
    var quantity = $("#quantity_" + lineNumber).val();

    $.post(base_url + "CartAJAX.php", {action: "modify", productId: productId, quantity: quantity}, function (responseHtml) {
        location.reload();
    });
}

function removeFromCart(lineNumber) {
    var productId = $("#productId_" + lineNumber).val();

    $.post(base_url + "CartAJAX.php", {action: "modify", productId: productId}, function (responseHtml) {
        location.reload();
    });
}
