/**
 * @author groening
 */

$(document).ready(function(){
	$('#travel_date_from').focus(function(){
		switchToRQButton('date');
	});
	$('#travel_date_to').focus(function(){
		switchToRQButton('date');
	});
	$('.category').change(function(){
		switchToRQButton('category');
	});
	$('form').submit(function(){
		return validateForm();
	});
});

function changeImage(focused_image){
	document.getElementById('main_image').src = focused_image.src;
}

function switchToRQButton(type) {
	$('#booking_link').empty();
	$('#booking_hint').hide();
	if (($('#check_booking_link_date').css('display') == 'none') && ($('#check_booking_link_category').css('display') == 'none')) {
		$('#check_booking_link_' + type).show();
	}
}

function validateForm(){
	$('#error').empty();
	$('#error').hide();
	if ($('#travel_date_from').val() == 'von') {
		$('#error').append('<p>Bitte wählen Sie ein Reisedatum aus!</p>');
		$('#error').show();
		return false;
	}
	
	if ($('#travel_date_from').val() != 'von' &&
	$('#travel_date_to').val() == 'bis') {
		$('#error').append('<p>Bitte wählen Sie ein Rückreisedatum aus!</p>');
		$('#error').show();
		return false;
	}
	
	$is_cat_selected = false;
	$('.category').each(function(){
		$is_cat_selected = $is_cat_selected || ($(this).val() != '0');
	});
	if (!$is_cat_selected) {
		$('#error').append('<p>Bitte wählen Sie mindestens eine Zimmerkatgorie aus!</p>');
		$('#error').show();
		return false;
	}
	if (($('#check_booking_link_date').css('display') != 'none') || ($('#check_booking_link_category').css('display') != 'none')) {
		//lockPage('check-avail-please-wait');
		//alert('lock');
		$.blockUI({ message: '<div id="check-avail-please-wait-loader" class="loader"><h2 class="clean">Bitte warten</h2><p><strong>Die Verfügbarkeit Ihres Hotels wird geprüft.</strong><br><br>Bitte haben Sie einen Augenblick Geduld.</p><img src="/webfiles/wol/img/layout/loader.gif" width="220" height="19" alt="Loader"></div>', overlayCSS: { backgroundColor: '#fff' }, css: { border: 'none' } });
		
	}
	return true;
}

function displayLegend(){
	$('#pic_legend').toggle();
	if ($('#pic_legend').css('display') == 'block') {
		$('#legend-link').css('backgroundImage', 'url(/webfiles/wol/img/layout/arrow-bottom.png)');
	}
	else {
		$('#legend-link').css('backgroundImage', 'url(/webfiles/wol/img/layout/arrow-right.png)');
	}
}

