function send_order(form) {
	var v = $("input[name='basket_person_count']").val();
	if(!v || isNaN(v)) {
		alert("Укажите количество персон");
		return false;	
	}
	return true;
}

var curChangedId = -1;
var curChangeTimeout;
var curChangeValue;
var curChangeOriginalValue;

function bskChCount(domInput, id, original) {
	if(id == curChangedId) {
		clearTimeout(curChangeTimeout);
	} else {
		curChangedId = id;
	}
	curChangeOriginalValue = original;
	curChangeValue = domInput.value;
	curChangeTimeout = setTimeout(bskChange, 1000);
}

function bskChange() {
	if(curChangeOriginalValue!=curChangeValue && 
		(curChangedId=='time' || !isNaN(curChangeValue))) {
		
		$.post("/ajax/basket/add",{
			basket_action: 'count',
			item_index: curChangedId,
			item_value: curChangeValue
		}, onLoadBasket);
	}
}

function bskRemove(removeId) {
	$.post("/ajax/basket/add",{
		basket_action: 'remove',
		item_index: removeId	
	}, onLoadBasket);
	return false;
}

function onLoadBasket(res) {
	$("#basket_cont").html(res);
	initFlyBasked();
}

//полёты во сне и наяву
var domFly;
var flyTop = 0;

function initFlyBasked() {
	domFly = document.getElementById('basket_fly');
	if(domFly) {
		domFly.className = '';
		
		var o = domFly;
		flyTop = domFly.offsetTop;
		while(o = o.offsetParent) {
			flyTop += o.offsetTop;
		}
		if($.browser.msie && $.browser.version.match(/^\d+/)[0] < 8) {
			flyTop -= 309;
		}			
		onScrollWindow();
	}
}

function onScrollWindow() {
	if(!domFly)
		return;
	var scrollTop = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	if(flyTop - scrollTop > 15) {
		if(domFly.className == 'basket-fly') {
			domFly.className = '';
			//domFly.style.width = '';
		}
	} else {
		if(domFly.className != 'basket-fly') {
			domFly.className = 'basket-fly';	
			domFly.style.width = domFly.parentNode.offsetWidth + 'px';
		}			
	}
}	

$().ready(function(){
	var defaultValue = "Как можно скорее";
	
	$("input[name='basket_time']")
	.keyup(function(){
		document.cookie = "bsk_time="+encodeURIComponent(this.value)+"; path=/";
	})
	.change(function(){
		document.cookie = "bsk_time="+encodeURIComponent(this.value)+"; path=/";
	})
	.focus(function(){
		if(this.value == defaultValue)
			this.value = '';
	})
	.blur(function(){
		if(this.value.length == 0)
			this.value = defaultValue;
	});
	
	$("input[name='basket_person_count']")
	.keyup(function(){
		document.cookie = "bsk_person="+encodeURIComponent(this.value)+"; path=/";
	})
	.change(function(){
		document.cookie = "bsk_person="+encodeURIComponent(this.value)+"; path=/";
	})
	
	$("select[name='basket_day']").change(function(){
		document.cookie = "bsk_day="+this.options[this.selectedIndex].value+"; path=/";
	});
	
	onscroll = onScrollWindow;
	setTimeout(initFlyBasked, 1000);
});
function send_order(form) {
	var v = $("input[name='basket_person_count']").val();
	if(!v || isNaN(v)) {
		alert("Укажите количество персон");
		return false;	
	}
	return true;
}

var curChangedId = -1;
var curChangeTimeout;
var curChangeValue;
var curChangeOriginalValue;

function bskChCount(domInput, id, original) {
	if(id == curChangedId) {
		clearTimeout(curChangeTimeout);
	} else {
		curChangedId = id;
	}
	curChangeOriginalValue = original;
	curChangeValue = domInput.value;
	curChangeTimeout = setTimeout(bskChange, 1000);
}

function bskChange() {
	if(curChangeOriginalValue!=curChangeValue && 
		(curChangedId=='time' || !isNaN(curChangeValue))) {
		
		$.post("/ajax/basket/add",{
			basket_action: 'count',
			item_index: curChangedId,
			item_value: curChangeValue
		}, onLoadBasket);
	}
}

function bskRemove(removeId) {
	$.post("/ajax/basket/add",{
		basket_action: 'remove',
		item_index: removeId	
	}, onLoadBasket);
	return false;
}

function onLoadBasket(res) {
	$("#basket_cont").html(res);
	initFlyBasked();
}

//полёты во сне и наяву
var domFly;
var flyTop = 0;

function initFlyBasked() {
	domFly = document.getElementById('basket_fly');
	if(domFly) {
		domFly.className = '';
		
		var o = domFly;
		flyTop = domFly.offsetTop;
		while(o = o.offsetParent) {
			flyTop += o.offsetTop;
		}
		if($.browser.msie && $.browser.version.match(/^\d+/)[0] < 8) {
			flyTop -= 309;
		}			
		onScrollWindow();
	}
}

function onScrollWindow() {
	if(!domFly)
		return;
	var scrollTop = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	if(flyTop - scrollTop > 15) {
		if(domFly.className == 'basket-fly') {
			domFly.className = '';
			//domFly.style.width = '';
		}
	} else {
		if(domFly.className != 'basket-fly') {
			domFly.className = 'basket-fly';	
			domFly.style.width = domFly.parentNode.offsetWidth + 'px';
		}			
	}
}	

$().ready(function(){
	var defaultValue = "Как можно скорее";
	
	$("input[name='basket_time']")
	.keyup(function(){
		document.cookie = "bsk_time="+encodeURIComponent(this.value)+"; path=/";
	})
	.change(function(){
		document.cookie = "bsk_time="+encodeURIComponent(this.value)+"; path=/";
	})
	.focus(function(){
		if(this.value == defaultValue)
			this.value = '';
	})
	.blur(function(){
		if(this.value.length == 0)
			this.value = defaultValue;
	});
	
	$("input[name='basket_person_count']")
	.keyup(function(){
		document.cookie = "bsk_person="+encodeURIComponent(this.value)+"; path=/";
	})
	.change(function(){
		document.cookie = "bsk_person="+encodeURIComponent(this.value)+"; path=/";
	})
	
	$("select[name='basket_day']").change(function(){
		document.cookie = "bsk_day="+this.options[this.selectedIndex].value+"; path=/";
	});
	
	onscroll = onScrollWindow;
	setTimeout(initFlyBasked, 1000);
});
