function bo() {
	alert(document.cookie)
}

function start () {
	var fontSize = "16";
	if ((getCookie("fontSize") != null) &&  (getCookie("fontSize") != '')) {
		fontSize = getCookie("fontSize");
		setCookie("fontSize",'');
	}
	if (fontSize != 12) {
		document.body.style.fontSize = percyfy(fontSize) + "%";
	}
	setCookie("fontSize",fontSize);

	var cookie = getCookie("screen");
	var title = (cookie) ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
			
}

function toggleScreen() {
	if (getCookie("screen") == 'inverse') {
		setActiveStyleSheet(null);
	} else {
		setActiveStyleSheet('inverse');
	}
		
}

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.getAttribute("media").indexOf("screen") != -1 ) {
      a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
  }
  setCookie("screen",title);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
    		&& a.getAttribute("title")
    		&& !a.disabled
    		&& a.getAttribute("media").indexOf("screen") != -1 )
    	return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
			 && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       && a.getAttribute("media").indexOf("screen") != -1
       ) return a.getAttribute("title");
  }
  return null;
}

function enlargeFont() {
	var size = getCookie("fontSize");
	if (size == null) {
		size = 12;
	}
	size++;
	if (size > 25) {size = 25}
	document.body.style.fontSize = percyfy(size)+'%';
	setCookie("fontSize",size);
}

function shrinkFont() {
	var size = getCookie("fontSize");
	if (size == null) {
		size = 12;
	}
	size--;
	if (size < 12) {size = 12}
	document.body.style.fontSize = percyfy(size)+'%';
	setCookie("fontSize",size);
}

function setSize(size) {
	if (size < 12) {size = 12}
	document.body.style.fontSize = percyfy(size)+'%';
	setCookie("fontSize",size);
}

function restoreSize() {
	size = "12";
	document.body.style.fontSize = percyfy(size)+'%';
	setCookie("fontSize",'');
}


function percyfy(size) {
	return (size/12)*100;
}

function setCookie(cookieName,cookieValue) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*1000);
	document.cookie = cookieName + "="+escape(cookieValue)+";expires="+expire.toGMTString();
}

function getCookie(cookieName) {
	var cookie = document.cookie;
	var index = cookie.indexOf(cookieName + "=");
	if (index == -1) return null;
	index = cookie.indexOf("=", index) + 1;
	var endstr = cookie.indexOf(";", index);
	if (endstr == -1) endstr = cookie.length;
	return unescape(cookie.substring(index, endstr));
}

