﻿function AddToCart(url, productId) {
    jQuery(document).ready(function ($) {
        if (this.timer) clearTimeout(this.timer);
        this.timer = setTimeout(function () {
            $.ajax({
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                url: '/Default.aspx/AddToCart',
                data: "{\"productID\": \"" + productId + "\" }",
                success: function (data) {
                    alert('Sản phẩm của bạn đã được đưa vào giỏ hàng');
                    UpdateMiniCart();
                    //document.location.href = url;
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    //alert(xhr.status);
                    //alert(thrownError);
                }
            });
        }, 1000);
    });
}

function UpdateMiniCart() {
    jQuery(document).ready(function ($) {
        //alert($('#mini-cart strong').html());
        var item = $('#mini-cart strong');
        var count = parseInt(item.html()) + 1;
        item.html(count);
    });
}

