// JavaScript Document
function loading(e, optionVal, optionDesc) {
		$(e).attr("disabled", true); 
		var selectedOption = '0';
		var newOptions = {
			optionVal : optionDesc
		};  
		var select = $(e);
		var options = select.attr('options');
		$('option', select).remove();
		$.each(newOptions, function(val, text) {
		options[options.length] = new Option(text, val);
		});  
		select.val(selectedOption); 
}	
$(document).ready(function(){
	
	// If the Country Selector is changed...
	$('#searchCo').live("change", function(event) {
		$('#find').attr("disabled", true); 
		// Resorts, set to loading while data retrieved
		loading('#searchRe', '0', 'Loading resorts...');
		// Accommodation Type, set to loading while data retrieved
		loading('#searchAt', '0', 'Loading types...');
		// Star Rating, set to loading while data retrieved
		loading('#searchSt', '0', 'Loading stars...');
		// Sleeps, set to loading while data retrieved
		loading('#searchSl', '0', 'Loading sleeps...');
		//Now extract data from the databases
		//For the disabled selectors
		$('#searchResorts').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchRe', {co : $('#searchCo').val()});
		$('#searchRe').removeAttr("disabled"); 
		$('#searchAccommodationTypes').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchAt', {co : $('#searchCo').val(), re : $('#searchRe').val()});
		$('#searchAt').removeAttr("disabled"); 
		$('#searchStarRating').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchSt', {co : $('#searchCo').val(), re : $('#searchRe').val(), at : $('#searchAt').val()});
		$('#searchSt').removeAttr("disabled"); 
		$('#searchSleeps').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchSl', {co : $('#searchCo').val(), re : $('#searchRe').val(), at : $('#searchAt').val(), st : $('#searchSt').val()});
		$('#searchSl').removeAttr("disabled"); 
		$('#find').removeAttr("disabled"); 
	});

	// If the Resort Selector is changed...
	$('#searchRe').live("change", function(event) {
		$('#find').attr("disabled", true); 
		// Accommodation Type, set to loading while data retrieved
		loading('#searchAt', '0', 'Loading types...');
		// Star Rating, set to loading while data retrieved
		loading('#searchSt', '0', 'Loading stars...');
		// Sleeps, set to loading while data retrieved
		loading('#searchSl', '0', 'Loading sleeps...');
		//Now extract data from the database
		//For the disabled selectors
		$('#searchAccommodationTypes').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchAt', {co : $('#searchCo').val(), re : $('#searchRe').val()});
		$('#searchAt').removeAttr("disabled"); 
		$('#searchStarRating').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchSt', {co : $('#searchCo').val(), re : $('#searchRe').val(), at : $('#searchAt').val()});
		$('#searchSt').removeAttr("disabled"); 
		$('#searchSleeps').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchSl', {co : $('#searchCo').val(), re : $('#searchRe').val(), at : $('#searchAt').val(), st : $('#searchSt').val()});
		$('#searchSl').removeAttr("disabled"); 
		$('#find').removeAttr("disabled"); 
	});

	// If the Accommodation Type Selector is changed...
	$('#searchAt').live("change", function(event) {
		$('#find').attr("disabled", true); 
		// Star Rating, set to loading while data retrieved
		loading('#searchSt', '0', 'Loading stars...');
		// Sleeps, set to loading while data retrieved
		loading('#searchSl', '0', 'Loading sleeps...');
		//Now extract data from the database
		//For the disabled selectors
		$('#searchStarRating').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchSt', {co : $('#searchCo').val(), re : $('#searchRe').val(), at : $('#searchAt').val()});
		$('#searchSt').removeAttr("disabled"); 
		$('#searchSleeps').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchSl', {co : $('#searchCo').val(), re : $('#searchRe').val(), at : $('#searchAt').val(), st : $('#searchSt').val()});
		$('#searchSl').removeAttr("disabled"); 
		$('#find').removeAttr("disabled"); 
	});
	// If the Star Ratings Selector is changed...
	$('#searchSt').live("change", function(event) {
		$('#find').attr("disabled", true); 
		// Sleeps, set to loading while data retrieved
		loading('#searchSl', '0', 'Loading sleeps...');
		//Now extract data from the database
		//For the disabled selectors
		$('#searchSleeps').load('http://www.mountainbeds.com/apollo/ajax/searchpanel.php #searchSl', {co : $('#searchCo').val(), re : $('#searchRe').val(), at : $('#searchAt').val(), st : $('#searchSt').val()});
		$('#searchSl').removeAttr("disabled"); 
		$('#find').removeAttr("disabled"); 
	});
});
