
function setActiveStyleSheet(title) {

	var i, a, main;

	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) {
				a.disabled = false;
			}
		}
	}
}

function selectStyle (vSelection) {

	makeCookie("layout", vSelection, 90, '/');
	setActiveStyleSheet(vSelection)
}

function onLoadStyle() {

	if (document.cookie.indexOf('layout=')!=-1) {
		css = readCookie('layout');

		setActiveStyleSheet(css)
	}
}

function readCookie(Name) {
  var cookies = document.cookie;
  if (cookies.indexOf(Name + '=') == -1) return null;
  var start = cookies.indexOf(Name + '=') + (Name.length + 1);
  var finish = cookies.substring(start,cookies.length);
  finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');
  return unescape(cookies.substring(start,finish));
}

function makeCookie(Name,Value,Expiry,Path,Domain,Secure){
  if (Expiry != null) {
    var datenow = new Date();
    datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
    Expiry = datenow.toGMTString();
  }

  Expiry = (Expiry != null) ? '; expires='+Expiry : '';
  Path = (Path != null)?'; path='+Path:'';
  Domain = (Domain != null) ? '; domain='+Domain : '';
  Secure = (Secure != null) ? '; secure' : '';

  document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;
}
