var i, elements = $('[class="notempty"]');

function checkNotEmpty() {
	is_all_values = true;
	elements.each(function(){
		if ($(this).val() == '' || $(this).val() == 0 || $(this).val() == 'выберите' || $(this).val() == 'select') {
			$(this).css('border-color', '#cc0000');
			is_all_values = false;
		} else {
			$(this).css('border-color', '#fff');
		}
	})

	if ($('#transfer').val() == 'yes' && $('#details').val() == '') {
	    $('#details').css('border-color', '#cc0000');
	    is_all_values = false;
	} else {
	    $('#details').css('border-color', '');
	}
	
	if (is_all_values) {
	    $('#rederror').css('color', '');
	} else {
		$('#rederror').css('color', '#cc0000');
 	}
	
	return is_all_values;
}

$('input[name=send]').click(function(event){
	event.preventDefault();

	if (checkNotEmpty()) {
		jQuery.post( '/sendbooking.php', $("#mailform").serialize(), function(data){
			if (data == '1') {
				$('.mailform').css('display', 'none');
				$('.water').css('height', '800px');
				$('#form_ok').css('display', 'block');
			} else {
				$('#form_ok').css('display', 'none');
				$('.mailform').css('display', 'block');

	            checkNotEmpty();
			}
		});
	}
})

$(function(){
	$("#date_in").datepicker($.datepicker.regional[lang]);
	$("#date_out").datepicker($.datepicker.regional[lang]);

	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

});

function check_visitors() {
    adults   = parseInt($('#adults').val());
	children = parseInt($('#children').val().substr(0, 1));
	count	 = parseInt($('#count').val());

	if ( ( $('#type').val().indexOf('Standart') >= 0 && (adults + children) > 2 * count ) ||
	     ( $('#type').val().indexOf('Superior') >= 0 && (adults + children) > 4 * count) ) {
	    $('#room_error').css('color', 'red');
	} else {
	    $('#room_error').css('color', '#fff');
	}
}

$('#type, #adults, #children, #count').change(function(event){
	event.preventDefault();

    check_visitors();
})

$(document).ready(function () {
	check_visitors();
})