//function for the selection of a period via radio buttons for timetables
//note: this function requires ShowHideSelectedItem.js to be included as well
function periodSelectionChanged(tagName, group, period, selectID){
	var selectElem = document.getElementById(selectID);  
	//retain selection of dropdownlist
	var selectedTextBefore;
	if (selectElem.selectedIndex>-1) selectedTextBefore = selectElem.options[selectElem.selectedIndex].text; 
	//retain first option
	var firstOption = selectElem.options[0];
	selectElem.options.length=0;
	selectElem.options[0]=firstOption; 
	//start index for the rest of the options
	optionIndex=1; 
	//set the chosen period as 'period' attribute on the dropdownlist
	selectElem.setAttribute("period",period); 
	//walk through all elements on the page that apply 
	var items= document.getElementsByTagName(tagName);
	for (var index=0; index<items.length; index++){
		//make sure we only change elements that belong to the given group
		if (items[index].getAttribute("title")==group){
			items[index].style.display="none";
			//make sure we only change elements that belong to the given period
			if (items[index].getAttribute("period")==period){
				var optionText= items[index].getAttribute("continent");
				selectElem.options[optionIndex] = new Option(optionText,"continent_div_"+optionText+"_"+period);
				//reset selection of dropdownlist
				if (optionText==selectedTextBefore) selectElem.options[optionIndex].selected="selected";
				optionIndex++;
				items[index].style.display="block";
			}
		}
	} 
	//apply selected value of dropdownlist
	showSelectedItemWithExtraAttribute(selectID, tagName, group, "period");
}

//this function sets attributes (period and continent) on the timetable elements for filtering
// it gets its information from dissecting the id: "continent_div_" + continent + "_"+ period
function addPeriodAndContinentAttributes(tagName, group){
	var items= document.getElementsByTagName(tagName);
	for (var index=0; index<items.length; index++){
		if (items[index].getAttribute("title")==group){
			var continentAndPeriod = items[index].id.substring(14).split("_");
			var continent = continentAndPeriod[0];
			var period = continentAndPeriod[1];
			
			items[index].setAttribute("continent", continent);
			items[index].setAttribute("period", period);
		}
	}

}