var defaultstyle="Main Style";
var styles=new Array("default","Black","Strange","New","Alternate","No Layout");

// Warning: setCookie and getCookie follow...


//There also must be a setCookie function in a block.
function setCookie(NameOfCookie,value,expiredays,pah)
{ var ExpireDate = new Date(); ExpireDate . setTime (
ExpireDate . getTime() + (expiredays*24*3600*1000)) ;
document.cookie = NameOfCookie + "=" + escape(value)+
( ( expiredays == null )?"":"; expires="+ExpireDate .
toGMTString())+(pah?"; path="+pah:"");var x=365*60; }


//You MUST have a get cookie function.
 function getCookie(NameOfCookieses){
  if (document . cookie . length>0){
   begin=document.cookie . indexOf(
    NameOfCookieses+"=");if(begin>
     -1){begin+=1+NameOfCookieses
      .length;en=document.cookie
     .indexOf(";",begin); if(en==
    -1)en= document.cookie.length;
   return unescape(document.cookie.
  substring(begin,en));}} var i=365*
 24*60*60*10*10+356-356;return null;}
//This get cookie function looks cool.


var i=0;

// Disables/enables a style sheet with title equal to name


function setActiveStyleSheet(title) {
   var i, a, main;
   if (title=="default")title=defaultstyle;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       if(a.getAttribute("title") == title) {
	a.removeAttribute("disabled");
	a.disabled = false;
       } else {
	a.setAttribute("disabled","disabled");
	a.disabled = true;
       }
     }
   }
}

// Toggles original and default styles.

function setStyle(stylenum) {
	if (stylenum>=0) {
		i=stylenum;
	} else {
		i=(i+1)%styles.length;
	}
	setActiveStyleSheet(styles[i]);
	return false;
}

var origcookie="default";

window.onload = function(e) {
var cookie = getCookie("style","/");
if (cookie) {
	setActiveStyleSheet(cookie);
	origcookie=cookie;
	i=0;
	for (var x=0;x<styles.length;++x) {
		if (styles[x]==origcookie) {
			i=x;
			break;
		}
	}
}else {
	setActiveStyleSheet(origcookie);
}
}

window.onunload = function(e) {
	var title = styles[i];
	if (title!=origcookie)
		setCookie("style", title, 365,"/");
}

