function clearOptions(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}


function addToOptionsList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function populateDepartments(categoryList, departmentOptionsId, langId, localizedSelect, jsonClient) {
	
    
	var departmentsList = document.getElementById(departmentOptionsId);
	var lang = document.getElementById(langId).value;
	var categoryId = categoryList[categoryList.selectedIndex].value;
	var selectString = document.getElementById(localizedSelect).value;
	
	if (categoryId) {
		// Clear out the list of teams
		clearOptions(departmentsList);
		var departmentIds = jsonClient.NewsEventsJSONClient.getDepartmentsIds(categoryId);
		addToOptionsList(departmentsList, "WONoSelectionString", selectString);
		for (i=0;i < departmentIds.length;i++) {
			addToOptionsList(departmentsList, departmentIds[i], jsonClient.NewsEventsJSONClient.getDepartmentName(departmentIds[i], lang));
		}
		departmentsList.selectedIndex = 0;
		departmentsList.options[0].text = selectString;
		departmentsList.options[0].selected = true;
	}
}

jQuery(document).ready(function(){
   jQuery("#eventListFilterBtn").click(function(){
      jQuery("#eventFilterBox").slideToggle("slow", function() {
         if (jQuery(this).css('display') != 'none') { jQuery("#eventListFilterBtn").addClass('up') } else {jQuery("#eventListFilterBtn").removeClass('up')}
      });
   });
});
