﻿function RefreshBasket() {
    var rnd = Math.random();

    if (window.location.href.indexOf ("/basket.aspx") < 0)
        $.getJSON(BasketServicePageURL + "?a=get&rnd=" + rnd + "&callback=?", {}, onGetBasketSuccess);
}

function onGetBasketSuccess(obj) {
    $("#BasketStateSpan").empty();
    $("#BasketStateSpan").append("товаров <b>" + obj.Count + "</b> на сумму <b>" + obj.Sum + "</b> р.");

    try
    {
        if (window.opener)
            window.opener.onGetBasketSuccess(obj);
    }
    catch (e)
    {
    }
}

function AddToBasket(DataID, Count, IsPM) {
    var rnd = Math.random();

    $.getJSON(BasketServicePageURL + "?a=add&dataid=" + DataID + "&ispm=" + IsPM + "&count=" + Count + "&siteid=" + SiteID + "&rnd=" + rnd + "&callback=?", {}, onGetBasketSuccess);
}

function AddToBasketWithSite(DataID, SiteID1, Count, IsPM) {
    var rnd = Math.random();

    $.getJSON(BasketServicePageURL + "?a=add&dataid=" + DataID + "&ispm=" + IsPM + "&count=" + Count + "&siteid=" + SiteID1 + "&rnd=" + rnd + "&callback=?", {}, onGetBasketSuccess);
}

function onAddToBasketSuccess(obj) {
    onGetBasketSuccess(obj);
    window.opener.onGetBasketSuccess(obj);
}


function AddToBasketFromPopup(DataID, Count, IsPM) {
    var rnd = Math.random();

    $.getJSON(BasketServicePageURL + "?a=add&dataid=" + DataID + "&ispm=0&count=" + Count + "&siteid=" + SiteID + "&rnd=" + rnd + "&callback=?", {}, onGetBasketSuccess);
}

function ClearBasket() {
    var rnd = Math.random();

    $.getJSON(BasketServicePageURL + "?a=clear&rnd=" + rnd + "&callback=?", {}, onGetBasketSuccess);
}

function ApplyBasket(bstr) {
    var rnd = Math.random();

    $.getJSON(BasketServicePageURL + "?a=applybasket&bstr=" + escape (bstr) + "&rnd=" + rnd + "&callback=?", {}, onGetBasketSuccess);
}