<!---- // No script guards
//------------------------------------------------------
// CookieTheme.js
//	Author: Josh Dovishaw
//	Date: 11-08-09
//	Purpose: Support for themes saved in cookies.
//------------------------------------------------------

//------------------------------------------------------
// Properties
//------------------------------------------------------
var expDays = 30;										// lifespan in days
var bannerDirectory = "banners/";								// directory of theme objects
var defaultTheme = "blue";									// default theme

//------------------------------------------------------
// Theme Functions
//------------------------------------------------------
function UpdateTheme(tColor)
{
	if(tColor == "" || tColor == null)
		tColor = defaultTheme;
	
	document.getElementById("Banner").src = bannerDirectory + tColor + "/" +		// set banner directory
		Math.floor(Math.random()*2+1) + ".png";						// choose random banner image

	var links = document.getElementsByTagName("link");
	
	for(var i = 0; i < links.length; i++)
	{
		if(links[i].rel.indexOf("stylesheet") != -1 && links[i].title)			// only want stylesheets with titles
		{
			if(links[i].title == tColor)						// enable the correct one
				links[i].disabled = false;
			else									// disable the rest
				links[i].disabled = true;
		}
	}

	SetCookie("ThemeColor", tColor, expDays);						// update cookie with theme color
}

function UpdateThemeFromCookie()
{
	UpdateTheme(GetCookie("ThemeColor"));							// update theme from cookie
}

//------------------------------------------------------
// Cookie Functions					
//------------------------------------------------------

function SetCookie(cName, cValue, cLife, cDomain)
{
	document.cookie =									// set the cookie
		cName + "=" + encodeURIComponent(cValue) +					// set the cookie's value, encoded
		"; max-age=" + (86400 * cLife) +						// set the cookie's age in seconds
		"; path=/;" + 									// default path
		(cDomain ? (" domain=" + cDomain) : '');					// set the cookie's valid domain
}

function GetCookie(cName)
{
	if(document.cookie.length > 0)								// check if cookie is valid
	{
		var cStart = document.cookie.indexOf(cName + "=");				// get string index of value
		if(cStart != -1)
		{
			cStart = cStart + cName.length + 1;					// move past the '='
			var cEnd = document.cookie.indexOf(";", cStart);			// set the end at the delimiter
			if(cEnd == -1) cEnd = document.cookie.length;				// or the end of the file
			return decodeURIComponent(document.cookie.substring(cStart, cEnd));	// return the resulting theme string
		}
	}
	return "";										// invalid cookie theme
}

// End no script guards ---->
