/**
 * @author groening
 */

$(document).ready(function(){
	updateSelectboxes();
	jQuery('select').change(function(){
		// Call some function to handle Ajax request
		updateSelectboxes();
	});
});

function updateSelectboxes(){

	// fetch current values
	var travel_destination = $('#travel_destination').val();
	var travel_type = $('#travel_type').val() == undefined ? '' : $('#travel_type').val();
	var travel_topic = $('#travel_topic').val() == undefined ? '' : $('#travel_topic').val() ;
	var travel_duration = $('#travel_duration').val() == undefined ? '' : $('#travel_duration').val();
	var travel_price = $('#travel_price').val() == undefined ? '' : $('#travel_price').val();
	
	var utf8 = $('#utf8').val();
	if ($.browser.msie) {
		utf8 = 0;
	}
	
	
	var data = 'travel_destination=' + travel_destination + '&travel_type=' + travel_type + '&travel_topic=' 
				+ travel_topic + '&travel_duration=' + travel_duration + '&travel_price=' + travel_price + '&utf8=' + utf8;
	$.getJSON('scripts/wol/er_update_searchparams.php', data, handleData) 
}

function handleData(data, status){
	//alert(data.travel_destinations);
	
	// Travel destinations
	$('#travel_destination').empty();
	$('#travel_destination').append(data.travel_destinations);
	
	// Travel types
	$('#travel_type').empty();
	$('#travel_type').append(data.travel_types);
	
	// Travel topics
	$('#travel_topic').empty();
	$('#travel_topic').append(data.travel_topics);
	
	//Travel durations
	$('#travel_duration').empty();
	$('#travel_duration').append(data.travel_durations);
	
	/*
	// Travel topics
	var travel_topic = $('#travel_topic').val();
	$('travel_topics', xml).each(function(){
		$('#travel_topic').empty();
		$('travel_topic', xml).each(function(){
			if (travel_topic == this.textContent) {
				$('#travel_topic').append('<option selected="selected">' + this.textContent + '</option>');
			}
			else {
				$('#travel_topic').append('<option>' + this.textContent + '</option>');
			}
		});
	});
	
	var travel_duration = $('#travel_duration').val()
	$('travel_durations', xml).each(function(){
		$('#travel_duration').empty();
		$('travel_duration', xml).each(function(){
			if (travel_duration == this.textContent) {
				$('#travel_duration').append('<option selected="selected">' + this.textContent + '</option>');
			}
			else {
				$('#travel_duration').append('<option>' + this.textContent + '</option>');
			}
		});
	});*/
}

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&uuml;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' } });
}

