﻿
function LoadRendering(rendering, placeholder) {
    var id = $("#scID").attr("content");

    $.ajax({
        type: "POST",
        url: "/layouts/ecommerce/Ajax.aspx/LoadRendering",
        data: "{rendering:'" + rendering + "', id : '" + id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            // Replace the div's content with the page method's return.
            placeholder.html(msg.d);
        }
    });
}

function LoadSublayout(sublayout, placeholder, callback) {
    var id = $("#scID").attr("content");

    $.ajax({
        type: "POST",
        url: "/layouts/ecommerce/Ajax.aspx/LoadSublayout",
        data: "{sublayout:'" + sublayout + "', id : '" + id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: (callback) ? callback : function(msg) {
            placeholder.html(msg.d);
        }
    });
}

function SetCurrentTab(tab) {
    $.ajax({
        type: "POST",
        url: "/layouts/ecommerce/Ajax.aspx/SetCurrentTab",
        data: "{tab:'" + tab + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    });
}


function AddReview(title, text, rate) {
    var id = $("#scID").attr("content");
    $.ajax({
        type: "POST",
        url: "/layouts/ecommerce/Ajax.aspx/AddReview",
        data: "{title:'" + title + "', text :'" + text + "', rate:'" + rate + "', id : '" + id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    });
}

var addToShoppingCartIsProcessing = false;
function AddToShoppingCart(productId, quantity, uom) {
    if (!addToShoppingCartIsProcessing) {
        addToShoppingCartIsProcessing = true;
        setTimeout(function() {
            addToShoppingCartIsProcessing = false;
        }, 500);


        $.ajax({
            type: "POST",
            url: "/layouts/ecommerce/Ajax.aspx/AddToShoppingCart",
            data: "{productId:'" + productId + "', quantity:'" + quantity + "', uom :'" + uom + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                // Replace the div's content with the page method's return.
                LoadSublayout("/Expert/Sublayouts/ExpBasketTop", null, function(msg) {
                    $("#EXP-toppanel").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
                    $("#EXP-toppanel").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);
                });
                location.replace('/functions/xsales.aspx?ec_trk=Go+to+Shopping+Cart');
            }
        });
    }

}
function UpdateCart() {
    LoadSublayout("/Expert/Sublayouts/ExpBasketTop", null, function(msg) {
        $("#EXP-toppanel").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
        $("#EXP-toppanel").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);
    });

}






function DeleteFromShoppingCart(productId, uom) {
    $.ajax({
        type: "POST",
        url: "/layouts/ecommerce/Ajax.aspx/DeleteFromShoppingCart",
        data: "{productId:'" + productId + "', uom :'" + uom + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            // Replace the div's content with the page method's return.
        LoadSublayout("/Expert/Sublayouts/ExpBasketTop", null, function(msg) {
            $("#EXP-toppanel").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
            $("#EXP-toppanel").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);
            });
        }
    });
}

function UpdateShoppingCart(productId, quantity, uom) {
    $.ajax({
        type: "POST",
        url: "/layouts/ecommerce/Ajax.aspx/UpdateShoppingCart",
        data: "{productId:'" + productId + "' quantity:'" + quantity + "', uom :'" + uom + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    });
}

function UpdateTopBasket() {
    LoadSublayout("/Expert/Sublayouts/ExpBasketTop", null, function(msg) {
        $("#EXP-toppanel").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
        
    });
}
function UpdateMyStore() {
    UpdateBottomStore();
    UpdateTopStore();
}
function UpdateTopStore() {
    LoadSublayout("/Expert/Sublayouts/ExpTopStoreItem", null, function(msg) {
    $("#EXP-TopStoreContainer").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
    $("#EXP-TopStoreContainer").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);
    });
} function UpdateBottomStore() {
LoadSublayout("/Expert/Sublayouts/BottomStoreInfo", null, function(msg) {
    $("#EXP-BottomShop").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
    $("#EXP-BottomShop").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);
    });
}