function addBasket(id)
{
        ajax(
                {
                        url:'/!ajax/ajax.basket.php',
                        type:'post'
                },
                function (msg)
                {
                        basketUpdate('.basket',1);
                },
                {
                        id:id,
                        act:'add'
                }
        );
}

function deleteBasket(id,th)
{
        ajax(
                {
                        url:'/!ajax/ajax.basket.php',
                        type:'post'
                },
                function (msg)
                {
                        if (msg == 'empty')
                                window.location.reload();
                        
                        basketUpdate('.basket');
                        $(th).parent().parent().remove();
                        updateFullPrice();
                },
                {
                        id:id,
                        act:'delete'
                }
        );
}

function basketUpdate(sel,message)
{
        ajax(
                {
                        url:'/!ajax/ajax.basket.php',
                        type:'post'
                },
                function (msg)
                {
                        $(sel).html(msg);
                        if (message == 1)
                        {
                                $('div.megaAlert').find('h2').html('Товар добавлен в корзину!');
                                $('div.megaAlert').find('div').html(msg.split('<br />').join('')+'<br /><a href="javascript:void();" onclick="$(this).parent().parent().toggle()">Продолжить покупку</a>\
                                &nbsp;&nbsp;&nbsp;\
                                <a href="/catalogue/cart/">Оформить заказ</a>');
                                $('div.megaAlert').css('display','block');
                        }
                },
                {
                        act:'update'
                }
        )
}

$(document).ready(function(){
        basketUpdate('.basket');
        $('div.megaAlert').css({
                'left': parseInt(($(window).width()-$('div.megaAlert').outerWidth())/2)+'px',                
                'top': parseInt(($(window).height()-$('div.megaAlert').outerHeight())/2)+'px'
        }).css('display','none');
});

