//var BASE_URL is defined in calling file
$(document).ready(function(){

	var frmSearch = $("form#frmSearch");
	var lstAdventureStyle = $("form#frmSearch select[name='Style']");
	var lstActivity = $("form#frmSearch select[name='Activity']");
	var lstCountry = $("form#frmSearch select[name='Country']");
	var lstLocation = $("form#frmSearch select[name='Location']");
	
	frmSearch.attr("action", BASE_URL + "search/"); //submit to same page
	
	//lstCountry.val("0");
	
	lstAdventureStyle.removeAttr('disabled');
	lstCountry.removeAttr('disabled');
	
	lstAdventureStyle.change(function(){
		lstActivity.attr("disabled", "disabled");
		lstActivity.empty();

		//load data and enable listbox in callback
		lstActivity.load(BASE_URL +  "request/activities/" + lstAdventureStyle.val() + '/',
						'',
						function(){ lstActivity.removeAttr("disabled") }); 
	})
	
	lstCountry.change(function(){
		lstLocation.attr("disabled", "disabled");
		lstLocation.empty();
		
		if (lstCountry.val() == '0') {
			lstLocation.append('<option value="0">(All Hubs)</option>');
			lstLocation.attr("disabled", "disabled");
		}
		else {
			lstLocation.load(BASE_URL + "request/locations/" + lstCountry.val() + "/", '', function(){
				lstLocation.removeAttr("disabled")
			}); //load data and enable listbox in callback
		}			
	})
	

});