
function setActiveStyleSheet(title) {
	var i, a, main;

	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("title")) {
			a.disabled = true;
			if (a.getAttribute("title") == title)
				a.disabled = false;
		}
	}
}

 
function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
				&& a.getAttribute("rel").indexOf("alt") == -1
				&& a.getAttribute("title")) 
				return a.getAttribute("title");
	}
	return null;
}


function getActiveStyleSheet(title) {
	var i, a;

	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel").indexOf("style") != -1
				&& a.getAttribute("title") && !a.disabled) {
			return a.getAttribute("title");
			}
	}
	return null;
}

<!-- Thanks to Peter-Paul Koch for the cookie js -->
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 expires = "";

  	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


window.onload = function(e) {
	var cookie = readCookie("freyja.style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}


window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("freyja.style", title, 365);
}

<!-- A better way to generate this based on alternates later -->
function writeStyleSelectionLine(name)
{
	document.write("<a href=\"#\" onclick=\"setActiveStyleSheet('" + name + "'); return false;\">" + name + "</a>");
}

function writeLanguage(url)
{
	//<a href="index-jp.html" accesskey="j" title="View this page in Japanese">
	//		<li class="navcell2">日本語</li>
	//	</a>
}


function writeCSSValidator(linkname)
{
	document.write("<a href=\"http://validator.w3.org/check?uri=referer\">" + linkname + "</a>");
}


function writeStyleSelectionCSS()
{
	var i, a, main;

	// Style sheet selection
	document.write("<ul>");

	for (i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if (a.getAttribute("rel").indexOf("style") != -1 &&
			a.getAttribute("title"))
		{
			document.write("<li>");
       		writeStyleSelectionLine(a.getAttribute("title"))
			document.write("</li>");
		}
	}

	//document.write("</ul>");


	// Language selection
	//document.write("<ul>");

	for (i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if (a.getAttribute("rel").indexOf("lang") != -1)
		{
			title = a.getAttribute("title");
			url = a.getAttribute("href");

			document.write("<li>");
       		document.write("<a href=\"" + url + "\">" + title + "</a>");
			document.write("</li>");
		}
	}

	document.write("</ul>");
}


function writeW3CValidator()
{
	// w3c validator 
	writeCSSValidator("<img src=\"images/valid-xhtml10.png\" border=0>");
}


function Viewer(url, title, w, h)
{
	windowRef = window.open(url, title, 
							'toolbar=0,location=0,directories=0,status=true,' +
							'menubar=0,scrollbars=1,resizable=1,' +
							'width=' + w + ',height=' + h);
	doc= windowRef.document;
	doc.write("<html><head><title>"+title+"</title></head><body><img src=\"" + url + "\"><br><center><a href=\"#\" onclick=\"window.close()\">close</a></center></b></body></html>");
}


