/* 
 Onload 
*/ 
window.onload = initCSS; 
// initCSS: If there's a "mystyle" cookie, set the active stylesheet when the page loads 
function initCSS() { 
 var style = readCookie("mystyle"); 
 if (style) { 
 activeCSS(style); 
 } 
} 
/* 
 Switcher functions 
*/ 
// activeCSS: Set the active stylesheet 
function activeCSS(title) { 
 var i, oneLink; 
 for (i = 0; (oneLink = document.getElementsByTagName("link")[i]); i++) { 
 if (oneLink.getAttribute("title") && findWord("stylesheet", oneLink.getAttribute("rel"))) { 
 oneLink.disabled = true; 
 if (oneLink.getAttribute("title") == title) { 
 oneLink.disabled = false; 
 } 
 } 
 } 
 setCookie("mystyle", title, 365); 
} 
// findWord: Used to find a full word (needle) in a string (haystack) 
function findWord(needle, haystack) { 
 var init = needle + "\\b"; 
 return haystack.match(needle + "\\b"); 
} 
/* 
 Cookie functions 
*/ 
// Set the cookie 
function setCookie(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+";"; 
} 
// Read the cookie 
function readCookie(name) { 
 var needle = name + "="; 
 var cookieArray = document.cookie.split(';'); 
 for(var i=0;i < cookieArray.length;i++) { 
 var pair = cookieArray[i]; 
 while (pair.charAt(0)==' ') { 
 pair = pair.substring(1, pair.length); 
 } 
 if (pair.indexOf(needle) == 0) { 
 return pair.substring(needle.length, pair.length); 
 } 
 } 
 return null; 
} 

// Last modified
function lastMod()
{
	var x = new Date (document.lastModified);
	Modif = new Date(x.toGMTString());
	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730)
	{
		daysago = Math.floor(daysago/365);
		unit = 'years';
	}
	else if (daysago > 60)
	{
		daysago = Math.floor(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14)
	{
		daysago = Math.floor(daysago/7);
		unit = 'weeks'
	}
	var towrite = 'Page revised: ';
	if (daysago == 0) towrite += 'Today';
	else if (daysago == 1) towrite += 'Yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite;
}


function takeYear(theDate)
{
	var x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

