﻿
function LoadRendering(rendering, placeholder) {
    var id = $("#scID").attr("content");

    $.ajax({
        type: "POST",
        url: "/layouts/damask/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/damask/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/damask/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/damask/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/damask/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("Damask/UserControls/ShoppingCartSpot", null, function(msg) {
                    $("#small_ShoppingCart_container").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
                    $("#small_ShoppingCart_container").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);

                });
                LoadSublayout("Damask/UserControls/webshop/ShoppingCart/SmallCartInfo", null, function(msg) {
                $("#SmallCartInfo_container").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
                $("#SmallCartInfo_container").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);
                });

            }
        });
    }

}



function DeleteFromShoppingCart(productId, uom) {
    $.ajax({
        type: "POST",
        url: "/layouts/damask/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("Damask/UserControls/ShoppingCartSpot", null, function(msg) {
                $("#small_ShoppingCart_container").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
                $("#small_ShoppingCart_container").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);

            });
            LoadSublayout("Damask/UserControls/webshop/ShoppingCart/SmallCartInfo", null, function(msg) {
                $("#SmallCartInfo_container").animate({ opacity: 0.3 }, 200).replaceWith(msg.d);
                $("#SmallCartInfo_container").css({ opacity: 0.3 }).animate({ opacity: 1 }, 600);
            });
        }
    });
}

function UpdateShoppingCart(productId, quantity, uom) {
    $.ajax({
        type: "POST",
        url: "/layouts/damask/Ajax.aspx/UpdateShoppingCart",
        data: "{productId:'" + productId + "' quantity:'" + quantity + "', uom :'" + uom + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    });
}

function SwapImage(Elem_id, className) {

  
    var elem = document.getElementById(Elem_id);

    elem.setAttribute("class", className);



}
