function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

ViewAlert = function(tovar_id) {  
    $('div#body_div').show().css({ 
        'width': getClientWidth() + 'px',   
        'height': getClientHeight() + 'px',  
        'opacity': 0
    }).animate({
        opacity: 0.8
    }, 1000, '', function(){
                
        $("#body_div").unbind().bind("click", function(e) { 
            $('#body_div').hide(); 
            $('#container').hide();
            $("#body_div").unbind();    
        });
        
        $(document).keydown(function(e) {               
            if (e.keyCode == 27) {  
                $('#body_div').hide(); 
                $('#container').hide();  
                $(document).unbind("keydown");
            } 
            
            if (e.keyCode == 13) {
                CloseAlert(); 
                return false; 
            } 
        });  
                
        $('#container').show().html('<img src="/images/flower.gif" style="margin-top:155px;">'); 
        
        $.post('/ajax/shopping_cart.php', {
            'action':'add_basket',             
            'tovar_id':tovar_id
        },
        function(data){
            
            jsonResponse = eval('(' + data + ')');   
                     
             _text = '<div style="width:100%; height:155px; background:url(/images/sale.jpg) no-repeat center; "></div>'; 
             _text += '<div style="width:495px; height:120px; _height:130px; background:url(/images/big_cart.gif) no-repeat right center; border-top:1px solid #CCCCCC; border-bottom:1px solid #CCCCCC; margin-left:5px; padding:10px 0;">';
             _text += '<div style="font-size:14px; color:#2D8154; text-align:center;"><b>Товар успешно добавлен в корзину</b></div>'; 
             _text += '<div style="margin:20px 0px; padding:0 0 0 40px;">';
             _text += '<div id="container1" class="left">1</div>';
             _text += '<div id="container2" class="left">2</div>';               
             _text += '</div>';  
             _text += '</div>';
             _text += '<div style="margin:15px 0 0 0; height:30px;">';  
             _text += '<div style="float:left; width:145px; padding-left:25px;"><a href="/'+jsonResponse['cart_url']+'"><img src="/images/btn_cart.gif" alt="Оформить&nbsp;заказ"></a></div>';
             _text += '<div style="float:left; width:160px; padding-left:130px;"><img src="/images/btn_close.gif" alt="Продолжить&nbsp;покупки" onclick="CloseAlert(); return false;" style="cursor:pointer;"></div>';
             _text += '</div>';
             
            $('#container').html(_text);  
            
            if(jsonResponse['cart_sum_all']) { 
                _cart_sum_all = jsonResponse['cart_sum_all'];
                _cart_etems_all = jsonResponse['cart_etems_all'];  
                                
                $('#cart_sum_all').html( _cart_sum_all + ' руб.'); 
                $('#cart_etems_all').html(_cart_etems_all); 
                
                $('#container1').html('Товаров в корзине: <b>' + _cart_etems_all + '</b>'); 
                $('#container2').html('Сумма заказа: <b>' + _cart_sum_all + 'руб.</b>'); 
            }  
            
        });        
    }); 
    
    
}   

CloseAlert = function() {  
    $('#body_div').hide(); 
    $('#container').hide(); 
}


DelCartTovar = function(id) {
    $('#cart_quantity_input_'+id).val(0);
    $('tr#cart_quantity_'+id).fadeOut("slow", function(){
        $('tr#cart_quantity_'+id).remove();
         $("table.cart").zebra(
        {
          bgEven: "#E8E7E7",
          bgOdd: "#FFF",
          fontEven: "#3B3B3B",
          fontOdd: "#3B3B3B",
          bgHover: "#F3C5DC",
          fontHover: "#3B3B3B"
        });  
        
        $.post('/ajax/shopping_cart.php', {
            'action':'del_tovar',             
            'tovar_id':id
        },
        function(data){  
            jsonResponse = eval('(' + data + ')'); 
                       
            _cart_sum_all = jsonResponse['cart_sum_all'];
            _cart_etems_all = jsonResponse['cart_etems_all']; 
            
            if(_cart_etems_all == 0 ) {
                document.location.href='/'+jsonResponse['cart_url'];  
                return false; 
            } 
                            
            $('#cart_sum_all').html(_cart_sum_all + ' руб.'); 
            $('#cart_etems_all').html('(' + _cart_etems_all + ')'); 
            $('#basket_cart_sum_all').html(_cart_sum_all);
        });
        
    }); 
    //$('tr#cart_quantity_'+id).remove();
   
}
