function trim(astr) {
	while(astr.charAt(astr.length-1)==' ') astr=astr.slice(0, astr.length-1);
	while(astr.charAt(0)==' ') astr=astr.slice(1);
	return astr;
}
function inBasquet(id, self) { // Old Function
	$.get('/httpr/AddBasket.php',{itemid:id},function() {
		$(self).css('background-image','url(/img/inbasquet.gif)');
		$(self).click = null;
	});
}
function addInBasquet(id) { // New Function
	if(firstStart == true) {
		alert("ВНИМАНИЕ! ДОСТАВКА ЦВЕТОВ ОСУЩЕСТВЛЯЕТСЯ ТОЛЬКО ПО МОСКВЕ И МОСКОВСКОЙ ОБЛАСТИ!");
	}
	kolvo = $('#kolvo'+id).val();
	variant = $('#variant'+id).val();
	//alert(kolvo+'==='+variant);
	$.get('/httpr/AddBasket.php',{kolvo:kolvo,variant:variant,itemid:id},function() {
																		$('#basketbtn'+id).removeClass('order');
																		$('#basketbtn'+id).addClass('inbasket');
																		$('#basketbtn'+id).html('');
																	});
}
function setPrice(minp,maxp) {
	$.get('/httpr/SetPrice.php',{from:minp, to:maxp}, 
	function() {
					window.location.replace(window.location.href);
	 		 });
}
function setKind(id) {
	$.get('/httpr/ByKind.php',{kind:id}, 
				function() {
					window.location.replace(window.location.href);
				});
}
function selectByFlower(id) {
	$.get('/httpr/ByFlower.php',{flower:id}, 
				function() {
					window.location.replace('/');
				});
}
function selectByEvent(id) {
	$.get('/httpr/ByEvent.php',{eventid:id}, 
				function() {
					window.location.replace('/');
				});
}
function deleteItem(index) {
	if(confirm('Удалить товар из корзины заказа?')) {
		$.post('/httpr/RecalcBasket.php',{delid:index}, 
				function(text) {
					$('#pageText').html(text);
				});
	}
}
function recalcBasket() {
		var str = $("#BasketItems").serialize();
		$.post('httpr/RecalcBasket.php', str, 
				function(text) {
					$('#pageText').html(text);
				});	
}

function showOrder() {
		var str = $("#BasketItems").serialize();
		$.post('httpr/RecalcBasket.php', str, 
				function(text) {
					location.replace('/order.html');
				});	
}

function sendOrder() {
		var form = document.forms['orderForm'];
		if(trim(form.s_name.value)=='') {
			alert('Введите свои фамилию, имя и отчество!');
			return;
		}
		if(trim(form.s_tel.value)=='') {
			alert('Укажите телефон!');
			return;
		}
		if(trim(form.s_date.value)=='') {
			alert('Необходимо указать дату доставки!');
			return;
		}
		if(trim(form.s_addr.value)=='') {
			alert('Необходимо указать адрес доставки!');
			return;
		}
		var str = $("#orderForm").serialize();
		$.post('httpr/SendOrder.php', str, 
				function(text) {
					if(text=='capture'){
						alert('Вы не верно ввели контрольное число! Попробуйте ещё раз!');
					} else {
						if(text=='empty'){
							alert('Корзина пуста! Заявка не отправлена!');
						} else {
							if(text=='raiffaizen') { // SEE IT 
								window.location.replace('http://www.rozbl.ru/httpr/RaiffaizenForm.php');
							} else 
							if(text=='robokassa') { // SEE IT
								window.location.replace('http://www.rozbl.ru/httpr/Robokassa.php');
							} else {
								$('#pageText').html(text);
							}
						}
					}
				});
}
function startSearch() {
	alert("Поиск: "+$('#searchStr').val());
}
function showImg(midimg,bigimg) {
	$('#aflow').attr('href',bigimg);
	$('#iflow').attr('src',midimg);
}
