
jQuery(function($) {

add_to_basket = function(tid,counter)
{
  counter=parseInt(counter);
  tid=parseInt(tid);
  if(isNaN(counter))
  {
    alert('Введите числовое значение количества товара');
    return false;
  }
  else if (counter <= 0)
  {
   counter = 1;
  }
  
  var i = Math.round(10000*Math.random());

  $.ajax({
   url: "_ajax_addtobasket.php?a="+i,
   type: "POST",
   data: ({id: tid, count: counter,mode:'add'}),
   dataType: 'script',
   success: function(msg){
      //alert(msg);
    }

   });
  
  return false;
}


$('.btnputin').each(function(){

 $(this).ajaxStart(function(){
   $(this).attr('disabled', 'true');

   if ($(this).hasClass( 'btn_ajax_loading' )) $(this).css('background', 'img/ajax-loader.gif');

 }).ajaxStop(function(){
   $(this).attr('disabled', '')
   
   if ($(this).hasClass( 'btn_ajax_loading' ))
   {
    $(this)
    .css('background', 'img/btn-incart.gif')
    .removeClass( 'btn_ajax_loading' );
   }
   
 }).ajaxError(function(){
  return true;
 });

 this.href = 'javascript:void(false);';

 $(this).click(function(){
  var id = $(this).attr('tovid');
  var count = $('#ivals'+id).val();

	 		var tovar = $(this).closest('.tovar');
	 		var tsrc = $('.gritimg', tovar).attr('src').split('&w',1) + '&w=73&h=73';
			$.gritter.add({
				title: 'Товар добавлен в корзину',
				text: '<b>' + $('.gritname', tovar).text() + '</b><br />' + $('.gritanons', tovar).text(),
				image: tsrc,
				sticky: false, 
				time: '2000'
			});	


  $(this).addClass('btn_ajax_loading');
  add_to_basket(id, count);
  return false;
 })
})

 //if (cookies_enabled==false) $('#msg').html('<h2>Внимание!</h2><p><b>Чтобы сделать заказ на данном сайте - необходимо включить "Cookies" в Вашем браузере. Спасибо.</b></p>');
})

