function addTovar(tid,count){ 
	showInfo('Корзина','Добавляем товар в корзину...');
	var get_srt = 'add_tovar_id='+tid+'&add_tovar_count='+count;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/cart.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
				showInfo('Корзина','Получаем информацию о корзине...');
		    	getCartCount();
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function updateTovarCount(tid,count){
//	alert(Number(count));
	if(Number(count) < 1 || Number(count) == NaN) return false;
	
	showInfo('Корзина','Изменяем количество товара...');
	var get_srt = 'upd_tovar_id='+tid+'&upd_tovar_count='+count;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/cart.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
				showInfo('Корзина','Получаем информацию о корзине...');
		    	RefreshCartView();
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
			}
		  }
	  );
}

function getCartCount(){
	var get_srt = 'get_count=1';
	new Ajax.Request('http://'+document.location.host+'/public/ajax/cart.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	$('cart_count').innerHTML = originalRequest.responseText;
		    	showInfo('Корзина','Товаров в корзине: '+ originalRequest.responseText);
		    	hideInfo();
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );	
}

function RefreshCartView(){
	showInfo('Корзина','Обновляем...');
	var get_srt = 'update_view=1';
	new Ajax.Request('http://'+document.location.host+'/public/ajax/cart.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	$('ajax_body').innerHTML = originalRequest.responseText;
		    	getCartCount();
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function GetReportXLS(){
	showInfo('Корзина','Подготовка файла...');
	$('d_excel_text').innerHTML = 'Подготовка файла. Ожидайте...';
	$('exc_img').src = '/public/img/ajax-load.gif';
	var get_srt = 'get_report=EXCEL';
	new Ajax.Request('http://'+document.location.host+'/public/ajax/cart.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	if(originalRequest.responseText == '-'){
		    		$('d_excel').innerHTML = 'Вам отказано в генерации файла, это может произойти из-за того, что в корзине нету товаров, или количесво товаров в корзине превышает установленный лимит для выполнения данной операции...';
		    		showInfo('Корзина','Отказано...');
		    		hideInfo();
		    		return false;
		    	}
		    	showInfo('Корзина','Файл сгенерирован...');
		    	$('d_excel').innerHTML = originalRequest.responseText;
		    	hideInfo();
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function DeleteCartItem(tid){
	showInfo('Корзина','Подтверждеие удаления...');
//	var pname = 'row_'+tid;
//	alert(pname);
//	new Effect.Puff($(pname));
	
	var cnf = confirm('Удаляем данный товар из корзины?');
	if(!cnf){
		showInfo('Корзина','Удаление отменено...');
		hideInfo();
		return false;
	}
	showInfo('Корзина','Удаляем товар из корзины...');
	var get_srt = 'del_tovar_id='+tid;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/cart.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
				showInfo('Корзина','Получаем информацию о корзине...');
		    	RefreshCartView();
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function createEditor(container, tid, cnt){
	var html = '<input id="cnt_val_'+tid+'" style="width:30px;text-align:right;" type="text" value="'+cnt+'" /><input type="button" value="Ok" onclick="updateTovarCount('+tid+', $(\'cnt_val_'+tid+'\').value);"/>';
	$(container).innerHTML = html;
}