
function selectNavigationTab(tabid) {
	// Unhighlight all navigation tabs
	document.getElementById("topics_tab").style.background = "none";
	document.getElementById("months_tab").style.background = "none";

	// Hide all navigation tab contents
	document.getElementById("topics").style.display = "none";
	document.getElementById("months").style.display = "none";
	
	// Highlight and show appropriate elements
	document.getElementById(tabid + "_tab").style.background = "#dddddd";
	document.getElementById(tabid).style.display = "block";

	// Save highlighted tab in cookie
	createCookie("tab",tabid,"365");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(valName) {
	var value = valName + "=";
	var cookieArray = document.cookie.split(';');
	for (var i=0; i < cookieArray.length; i++) {
		var cookie = cookieArray[i];
		while (cookie.charAt(0)==' ') {
			cookie = cookie.substring(1,cookie.length);
			if (cookie.indexOf(value) == 0) {
				return cookie.substring(value.length,cookie.length);
			}
		}
	}
	return null;
}

function showCookiedTab() {
	var tabValue = readCookie("tab");

	if (tabValue == null) {
		// Create default cookie
		createCookie("tab","topics","365");
		tabValue = "topics";
	}

	selectNavigationTab(tabValue);
}
