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;
}

function do_Set_CSS (CSSfile) { href = '/' + CSSfile + '.css'; document.getElementById ("CSSmain").href = href; return null; }

function do_Get_CSS() {
	href = document.getElementById ("CSSmain").href;
	x = href.lastIndexOf('/') + 1; y = href.lastIndexOf('.')
	CSSfile = href.substring(x, y);
	return CSSfile;
}

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 switchSize(fontSize) {
	switch (fontSize) {
		case 1: do_Set_CSS('mcp_sm'); break;
		case 2: do_Set_CSS('mcp_med'); break;
		case 3: do_Set_CSS('mcp_lg'); break;
	}
}

window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : do_Get_CSS ();
	if (cookie != null) { do_Set_CSS(title); } 
}

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