﻿function BuyBoard(boardId, anchor){
    var boardIdIndex = basketList.indexOf(boardId);
    if(boardIdIndex == -1)
        basketList.push(boardId);
    else
        basketList.splice(boardIdIndex, 1);
    $("BasketCount").innerHTML = basketList.length;
    return Basket.BuyBoard(boardId, OnBasketComplete, OnServiceError, anchor);
}
function ClearBasket() {
    Basket.ClearBoard(OnBasketComplete, OnServiceError);
}
function OnBasketComplete(result, anchor, methodName) {
    switch(methodName){
        case 'BuyBoard':
            anchor.className = result ? 'buy' : 'buy2';
            anchor.setAttribute("alt", result ? "убрать из корзины" : "добавить в корзину");
            anchor.setAttribute("title", result ? "убрать из корзины" : "добавить в корзину");
            $('notepad').style.display = basketList.length > 0 ? 'block' : 'none';
            SetBasketPosition();
            break;
        case 'ClearBoard':
            $("BasketCount").innerHTML = '0';
            $('notepad').style.display = 'none';
            $$('#BoardListContainer a.buy').each(function(img) { img.className = 'buy2'; });
            basketList.each(function(boardId) { try{$('tit_' + boardId).className = 'tit';} catch(e) {} });
            basketList = [];
            break;
    }
}
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj) {
        var len = this.length;
        for (var i = 0; i < len; i++) {
            if (this[i] === obj) {
                return i;
            }
        }
        return -1;
    };
}