/**
 * @author groening
 */

$(window).keydown(function(event){
	//alert('test');
  switch (event.keyCode) {
    default:
		//alert(event.keyCode);
  }
});

$(document).ready(function(){
	//updateSelectboxes();
	jQuery('#travel_destination').change(function(){
		updateSelectboxes();
	});
	
	$('form').submit(function(){
		if ($('#travel_date_from').val() != 'von' &&
		$('#travel_date_to').val() == 'bis') {
			$('#error').append('<p>Bitte wählen Sie ein Rückreisedatum aus!</p>');
			return false;
		}
		return true;
	});
});

function updateSelectboxes(){

	$('#error').empty();
	
	// fetch current values
	var travel_destination = $('#travel_destination').val();
	
	if (travel_destination == '') {
		$('#travel_dest_region').empty();
		$('#travel_dest_region').append('<option value="">Bitte erst Land auswählen</option>');
	}
	else {
		var data = 'travel_destination=' + travel_destination;
		$.getJSON('scripts/wol/ht_update_searchparams.php', data, handleUpdateData)
	}
}

function handleUpdateData(data, status){
	//alert(data.travel_destinations);
	
	// Travel destinations
	$('#travel_dest_region').empty();
	$('#travel_dest_region').append(data.travel_dest_regions);
	
}

function lockSearchPage()
{
	$.blockUI({ message: '<div id="check-avail-please-wait-loader" class="loader"><h2 class="clean">Bitte warten</h2><p><strong>Ihre Suche wird ausgeführt.</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' } });
}
