function showCondition() {
$("#condition").dialog({
    bgiframe: true,
    autoOpen: false,
    height: 510,
    width: 700,
    modal: true,
    resizable: false,
	buttons: { 'Закрыть': function() { $("#condition").dialog('close'); } }
	});
$("#condition").show();
$("#condition").dialog('open');
}
$(function() {
	var theDate = new Date();
	var curYear = (theDate.getYear() < 2000) ? theDate.getYear()+1900 : theDate.getYear();
	$.datepicker.setDefaults( {dateFormat: 'dd.mm.yy', changeMonth: true, changeYear: true, duration: 'fast', yearRange: curYear+':'+(curYear*1+10),
		monthNamesShort: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
		dayNamesMin: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'] }, $.datepicker.regional['ru'] );
	$("#tourDate").datepicker({	showOn: 'both', buttonImage: '/images/a_calendar.gif', buttonImageOnly: true,
		onSelect: function(dateText, inst) {
			var selDate = dateText.split('.');
			$.post('/ajax/reloadtoursprice.php', {hotelId:gup('item'), level:gup('order'), currDate:selDate[2]+'-'+selDate[1]+'-'+selDate[0]},
			function(result){ $('#priceTblBody').html(result); });
		}
	 });
});

function calculatePrice() {
	$('#allPrice').html('');
	$('.roomNum').each(function(){
		var room = $(this).attr('rel');
		var val = $(this).val();
		if(val != '') $('#price'+room).html( '<span class="summ">'+$('#'+room).text()*val+'</span>$' );
		else $('#price'+room).html('');
	});
	var summ = 0;
	$('.summ').each(function(){
		summ += $(this).text()*1;
	});
	if( $('#addBoardSelect').val() == 'yes' && summ != '' ) {
		summ += $('#addBoard').text()*1;
		$('#addBoardSumm').html($('#addBoard').text()+'$');
	} else {
		$('#addBoardSumm').html('');
	}
	if (summ != 0) $('#allPrice').html(summ+'$');
}

function doOrder() {
if ( $('#allPrice').text() != '' && $('#tourDate').val() != '' ) {
	$('#doOrderRooms').html('');

	$('#doOrderTourDate').text( $('#tourDate').val() );

	var doOrderPriceList = '<p>';

	$('.roomNum').each(function(){
		if( $(this).val() != '' ) {
			var roomId = $(this).attr('rel');
			doOrderPriceList += 'Номер: <strong>'+$('#roomName'+roomId).text()+'</strong>&nbsp;&nbsp;цена:&nbsp;<strong>'
							 +$('#'+roomId).text()+'$</strong>&nbsp;&nbsp;количество:&nbsp;<strong>'+$(this).val()
							 +'</strong>.&nbsp;&nbsp;&nbsp;Сумма:&nbsp;<strong class="blue">'+$('#price'+roomId).text()+'</strong><br />';
		}
	});
	if( $('#addBoardSelect').val() == 'yes' ) doOrderPriceList += 'Доплата за ужин: <strong class="blue">'+$('#addBoardSumm').html()+'</strong><br />';
	doOrderPriceList += '</p><p>Общая сумма заказа: <strong class="blue" style="font-size:11pt">'+$('#allPrice').text()+'</strong><p>';
	$('#doOrderRooms').append(doOrderPriceList);

	if( $.cookie('clientName') != '' && $.cookie('clientName') != null ) $('#clientName').val($.cookie('clientName'));
	if( $.cookie('clientCountry') != '' && $.cookie('clientCountry') != null ) $('#clientCountry').val($.cookie('clientCountry'));
	if( $.cookie('clientPhone') != '' && $.cookie('clientPhone') != null ) $('#clientPhone').val($.cookie('clientPhone'));
	if( $.cookie('clientEmail') != '' && $.cookie('clientEmail') != null ) $('#clientEmail').val($.cookie('clientEmail'));

	$("#order").dialog({
	    bgiframe: true,
	    autoOpen: false,
	    width:390,
	    modal: true,
	    resizable: false,
	    close: function() { $('#errorDivOrder').html('').hide(); },
		buttons: {
		'Отмена': function() {
				$('#errorDivOrder').html('').hide();
				$("#order").dialog('close');
			},
		'Заказать': function() {
				loader();
				$('#errorDivOrder').html('').hide();
				var orderBody = $('#orderBody').html();
				var clientName = $('#clientName').val();
				var clientCountry = $('#clientCountry').val();
				var clientPhone = $('#clientPhone').val();
				var clientEmail = $('#clientEmail').val();
				var clientNote = $('#clientNote').val();

				$.cookie('clientName', clientName, {expires: 90});
				$.cookie('clientCountry', clientCountry, {expires: 90});
				$.cookie('clientPhone', clientPhone, {expires: 90});
				$.cookie('clientEmail', clientEmail, {expires: 90});

				$.post('/ajax/hotelorder.php', {orderBody:orderBody, clientName:clientName, clientCountry:clientCountry, clientPhone:clientPhone, clientEmail:clientEmail, clientNote:clientNote},
				function(result){
					loader();
					if(result.substr(0,2) == 'ok') {
	        			var result = result.substr(2);
	        			$("#order").dialog('close');
	        			$("#orderOk").html(result);
	        			$("#orderOk").dialog({
						    bgiframe: true,
						    autoOpen: false,
						    modal: true,
						    resizable: false,
						    close: function(){ window.location.href = $('#backScript').val(); },
							buttons: { 'Закрыть': function() {
										$(this).dialog('close');
										window.location.href = $('#backScript').val();
									}
								}
							});
						$("#orderOk").show();
						$("#orderOk").dialog('open');
					} else {
						$('#errorDivOrder').html(result).show();
					}
				});
			}
		}
		});
	$("#order").show();
	$("#order").dialog('open');
} else {
	$("#orderError").dialog({
	    bgiframe: true,
	    autoOpen: false,
	    modal: true,
	    resizable: false,
		buttons: { 'Закрыть': function() { $("#orderError").dialog('close'); } }
		});
	$("#orderError").show();
	$("#orderError").dialog('open');
}
}
