﻿function UpdateShopCartInfoBox() {

    $.ajax({

        url: "/Shop/MiniCart",
        global: false,
        cache: false,
        type: "GET",
        dataType: "html",
        success: function(msg) {
            $('#minicart').html(msg);
        }
    });

}


function InsertIntoShopCartFromOverview(button, multiVariant) 
{
    var t = $(button).parents('form').serializeArray();    

    InsertIntoShopCart(t[2]["value"], t[1]["value"], t[0]["value"]);
}

function InsertIntoShopCart(articleId, articleVariantId, amount) {

    $.ajax({
        url: "/Shopcart/InsertIntoShopCart",
        global: false,
        cache: false,
        type: "POST",
        dataType: "html",
        data: {
            articleId: articleId,
            articleVariantId: articleVariantId,
            amount: amount
        },
        success: function (msg) {
            UpdateShopCartInfoBox();

            $('.infomessage').fadeToggle();
            window.setTimeout(function () { $('.infomessage').fadeToggle(); }, 4000);
        }
    });

}

function CheckVoucherCode() {

    if ($('#Voucher_Code').val() != "") {

        $.ajax({
            url: "/Shopcart/CheckVoucherCode",
            global: false,
            cache: false,
            type: "POST",
            dataType: "json",
            data: {
                voucherCode: $('#Voucher_Code').val()
            },
            success: function (msg) {

                if (msg.result) {
                    $('#voucherform').submit();
                } else {
                    $('#voucherError').html(msg.message);
                }
            }
        });

    }
}

