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) {
	$.get('/httpr/AddBasket.php',{itemid:id},function() {
		$(self).css('background-image','url(/img/inbasquet.gif)');
		$(self).click = null;
	});
}
function setPrice(minp,maxp) {
	$.get('/httpr/SetPrice.php',{from:minp, to:maxp}, 
	function() {
					window.location.replace('/');
	 		 });
}
function setKind(id) {
	$.get('/httpr/ByKind.php',{kind:id}, 
				function() {
					window.location.replace('/');
				});
}
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 {
							$('#pageText').html(text);
						}
					}
				});
}
function startSearch() {
	alert("Поиск: "+$('#searchStr').val());
}