﻿function $(id)
{
	return document.getElementById(id);
};

function getCookie(sName) {
	var aCookie = document.cookie.split("; ");
	for (var j=0; j < aCookie.length; j++)
	{
		var aCrumb = aCookie[j].split("=");
		if(escape(sName) == aCrumb[0] && aCrumb[1]!="''")return aCrumb[1];
	};
	return null;
};

function setCookie(sName,sValue,expireHours)
{
	var cookieString = sName + "=" + escape(sValue);
	var date = new Date();
	if(expireHours > 0)
	{
		date.setTime(date.getTime() + expireHours * 3600 * 1000);
		cookieString = cookieString + "; expires=" + date.toGMTString();
	};
	document.cookie = cookieString;
};

function clearCookie(sName)
{
	themeCss = null;
	var date=new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = sName + "=; expires=" + date.toGMTString();
};

function changeTheme(o)
{
	var a = o.id.split("-");
	var theme = a[1];
	$("linkThem").href = "theme/"+ theme + ".css";
	setCookie("theme",theme);
};

function getCss()
{
	var themeCookieName=getCookie("theme");
	if(themeCookieName != "not" && themeCookieName != "illusion" && themeCookieName != "sky" && themeCookieName != "cartoon" && themeCookieName != "naive")
	{
		themeCookieName=null
	};
	themeCss = themeCookieName || "not";
	$("linkThem").href = "theme/" + themeCss + ".css";
};

getCss();