// Cookies.js
var style = "";
function setCSS() {
	var prefStyle=GetJBCookie('jayis');
	if(!prefStyle || (prefStyle && (prefStyle != "styles-siteh1.css" && prefStyle != "styles-siteh2.css" && prefStyle != "styles-siteh3.css" && prefStyle != "styles-siteh4.css" && prefStyle != "styles-siteh5.css" && prefStyle != "styles-siteh6.css" && prefStyle != "styles-siteh7.css" && prefStyle != "styles-siteh8.css"))) {
		prefStyle = "styles-siteh8.css";
		style = "h8";
	} else style = prefStyle.substr(11,2);
	var theHtml = '<link rel="stylesheet" title="Default style" href="/'+prefStyle+'" type="text/css" id="cssHolder" />';
	document.write(theHtml);
}
var style = "";
function chCSS() {
	var prefStyle=GetJBCookie('jayis');
	if(!prefStyle || (prefStyle && (prefStyle != "styles-siteh1.css" && prefStyle != "styles-siteh2.css" && prefStyle != "styles-siteh3.css" && prefStyle != "styles-siteh4.css" && prefStyle != "styles-siteh5.css" && prefStyle != "styles-siteh6.css" && prefStyle != "styles-siteh7.css" && prefStyle != "styles-siteh8.css"))) {
		prefStyle = "styles-siteh8.css";
		style = "h8";
	} else style = prefStyle.substr(11,2);
	document.getElementById('cssHolder').setAttribute('href','/'+prefStyle);
	//alert(document.getElementById('cssHolder').getAttribute('href'));
}

function switchCSS(num,url) {
	if(num != "h1" && num != "h2" && num != "h3" && num != "h4" && num != "h5" && num != "h6" && num != "h7" && num != "h8") num = "h8";
	var today = new Date();
	// expires in 30 days....
	var expiry = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
	SetJBCookie('jayis','styles-site'+num+'.css',expiry,'/','','');
	if(url == "/index.php") url="http://jayisgames.com/";
	window.location = url;
}

function switchCSSprefs(num,theform) {
	if(num != "h1" && num != "h2" && num != "h3" && num != "h4" && num != "h5" && num != "h6" && num != "h7" && num != "h8") num = "h8";
	var today = new Date();
	// expires in 30 days....
	var expiry = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
	SetJBCookie('jayis','styles-site'+num+'.css',expiry,'/','','');
	document.forms[theform].prefstyle.value = num;
	document.forms[theform].submit();
}

function saveFavoritesCookie(num,theCookieStr) {
	var theCookie;
	if(num > 0) theCookie = 'fav'+num;
	else theCookie = 'fav';
	var today = new Date();
	// expires in 30 days....
	var expiry = new Date(today.getTime() + 270 * 24 * 60 * 60 * 1000);
	SetJBCookie(theCookie,theCookieStr,expiry,'/','','');
}

function GetJBCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function GetJBCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return GetJBCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
}

function DeleteJBCookie(name,path,domain) {
	if (GetJBCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function SetJBCookie(name,value,expires,path,domain,secure) {
	var curCookie = name + "=";
	curCookie = curCookie + escape(value);
	curCookie = curCookie + ((expires) ? ";expires=" + expires.toGMTString() : "");
	curCookie = curCookie + ((path) ? ";path=" + escape(path) : "");
	curCookie = curCookie + ((domain) ? ";domain=" + escape(domain) : "");
	curCookie = curCookie + ((secure) ? ";secure" : "");
	document.cookie = '' + curCookie;
}