window.onload = function() { stmp(); }
window.onresize = function() { stmp(); }
function stmp() {
	var o = document.getElementById("stamp");
	if (document.body.clientWidth < 1100) {
		o.style.backgroundImage = "url(img/stamp.jpg)";
		o.href = "javascript:void(0)";
		o.style.cursor = "default";
	} else {
		o.style.backgroundImage = "none";
		o.href = "index.php";
		o.style.cursor = "pointer";
	}
}

function show_cost(cost) {
	var res_cost = "";
    cost = Math.round(cost);
	for (var i = cost.toString().length - 3; i > 0; i -= 3)
		res_cost = cost.toString().substr(i, 3) + " " + res_cost;

	i += 3;
	res_cost = cost.toString().substr(0, i) + " " + res_cost;

	return "<b>"+res_cost + "</b>руб.";
}

function refreshPrice()
{	if ($("input[name='zaezd']:checked").val()<6 && $("input[name='zaezd']:checked").val()>0){cost = 19800;}
	else if ($("input[name='zaezd']:checked").val()>5){cost = 27800;}
	else{cost = 0;}

    vol = 1;

    $('#peoplecount option:selected').each(function ()
		{
			vol = $(this).val();
		});
	per = 0;
	if (vol>2) per = 0.15;
	if (vol>3) per = 0.20;
	if (vol>4) per = 0.25;
	if (vol>5) per = 0.30;
	if (vol>6) per = 0.35;
	if (vol>7) per = 0.50;
	if (vol>8) per = 0.70;
	if (vol>9) per = 0.80;
	if (vol>10) per = 1;
	//alert(vol+' - '+cost);

	if (cost > 0) {
		//$('#lowpricelabel').style.display='none';
		$('#lowprice').show();
		$('#lowpricelabel').show();
		$('#lowprice').show();
		$('#or').show();
		$('#costonman').show();
		$('#costongroup').show();
		$('#lowprice2').show();
	}

	$('#lowprice').html('цена на всю группу: '+show_cost(cost * vol - cost * per));
	$('#costonman').html('цена на 1 человека в группе: '+show_cost(cost));
	$('#costongroup').html('цена на руководителя группы: '+show_cost(cost - cost * per)+' <br />(в т.ч. скидка руководителю - '+show_cost(cost * per)+' руб.)');
	//alert((cost * vol - cost * per)/vol);
	$('#lowprice2').html('цена на каждого со скидкой: '+show_cost((cost * vol - cost * per)/vol)+' <br />(в т.ч. скидка каждому - '+show_cost((cost * per)/vol)+' руб.)');
}

$(document).ready(function() {
	$("input[name='zaezd']").click(function(){
		refreshPrice();
	});
	$('#peoplecount').change(function()
	{
		refreshPrice();
	});
		$('#lowprice').hide();
		$('#lowpricelabel').hide();
		$('#lowprice').hide();
		$('#or').hide();
		$('#costonman').hide();
		$('#costongroup').hide();
		$('#lowprice2').hide();
})

function setMountDiv(mountDivId) {
	if ($('#divmamay') && $('#divdavan')) {
		$('#divmamay').hide();
		$('#divdavan').hide();

		if (mountDivId==0) {
			$('#divmamay').show();
			$('#divdavan').hide();
			//$('#wheretosky').selectedIndex = 1;
			//var cit = $('#city1');
    		//$('#city1 option:selected').each(function ()
			//{
			//	vol = $(this).val();
			//	if ($(this).text() == 'Иркутск') $(this).attr('selected', 'selected');
			//});
			//for(var i = 0; i < cit.length; i++)
			//	if (cit.options[i].text == 'Иркутск') cit.eq(i).attr('selected', 'selected');
			$('#divanothercity').hide();
			$('#mamaiothercity').hide();
		}
		if (mountDivId==1) {
			$('#divmamay').hide();
			$('#divdavan').show();
			//$('#wheretosky2').selectedIndex = 0;
    		//$('#city0 option:selected').each(function ()
			//{
			//	vol = $(this).val();
			//	if ($(this).text() == 'Москва') $(this).attr('selected', 'selected');
			//});
			//var cit = $('#city0');
			//for(var i = 0; i < cit.length; i++)
			//	if (cit.eq(i).text() == 'Москва') cit.eq(i).attr('selected', 'selected');
			$('#mamaiothercity').hide();
			$('#divanothercity').hide();
		}
	}
}

function changeCity(cityvalue) {
	if ($('#divanothercity')) {
		if (cityvalue!='') {
			$('#divanothercity').hide();
		} else {
			$('#divanothercity').show();
		}
	}
	if ($('#mamaiothercity')) {
		if (cityvalue!='') {
			$('#mamaiothercity').hide();
		} else {
			$('#mamaiothercity').show();
		}
	}
}


function Order(form) {
	var errors = '';
	if (form == 'makeorder1') {
		if (document.makeorder1.fio.value == '') errors += 'Укажите свои Ф.И.О.' + String.fromCharCode(13);
		if (document.makeorder1.phone.value == '') errors += 'Укажите свой телефон' + String.fromCharCode(13);
		if (document.makeorder1.mail.value == '') errors += 'Укажите свой e-mail' + String.fromCharCode(13);
		//if (document.makeorder1.city.value == '' && document.makeorder1.anothercity.value == '') errors += 'Укажите свой город' + String.fromCharCode(13);
		if (document.makeorder1.city.value == '') errors += 'Укажите свой город' + String.fromCharCode(13);
		if (document.makeorder1.peoplecount.value == '') errors += 'Укажите кол-во человек в группе' + String.fromCharCode(13);
		var zaezd = 0;
		if (!$("input[name='zaezd']:checked").val()) errors += 'Укажите дату катания' + String.fromCharCode(13);
	} else {
		if (document.makeorder2.fio.value == '') errors += 'Укажите свои Ф.И.О.' + String.fromCharCode(13);
		if (document.makeorder2.phone.value == '') errors += 'Укажите свой телефон' + String.fromCharCode(13);
		if (document.makeorder2.mail.value == '') errors += 'Укажите свой e-mail' + String.fromCharCode(13);
		//if (document.makeorder2.city.value == '' && document.makeorder2.anothercity.value == '') errors += 'Укажите свой город' + String.fromCharCode(13);
		if (document.makeorder2.city.value == '') errors += 'Укажите свой город' + String.fromCharCode(13);

		if (!document.makeorder2.dayscount[0].checked && !document.makeorder2.dayscount[1].checked) errors += 'Укажите дату катания' + String.fromCharCode(13);
	}

	if (errors == '') document.getElementById(form).submit();
	else alert(errors);
}

