// Copyright (c) 2009 Chuck Ehenulo. All rights reserved.

// display pop-up windows 
function MM_openBrWindow(theURL,winName,features){ //v2.0
	window.open(theURL,winName,features);
};

// Font sizing 
function bo() {
	//alert(document.cookie)
}

function start () {
	//alert(document.cookie.fontSize);
	if (getCookie("fontSize") == null) {
		var fontSize = "12";
		setCookie("fontSize",fontSize);
	}
		
	if ((getCookie("fontSize") != null) && (getCookie("fontSize") != '')) {
		fontSize = getCookie("fontSize");
	}
	
	if (fontSize != 12) {
		document.body.style.fontSize = percyfy(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 == '') {
		size = 12;
	}
	size++;
	if (size > 27) {size = 27} else {size = size+5}
	document.body.style.fontSize = percyfy(size)+'%';
	setCookie("fontSize",size);
}

function shrinkFont() {
	var size = getCookie("fontSize");
	if (size == null || size == '') {
		size = 12;
	}
	size--;
	if (size < 12) {size = 12} else {size = size-5}
	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/16)*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()+";path=/";
}

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));
};

// display pop-up windows 
function MM_openBrWindow(theURL,winName,features){ //v2.0
	window.open(theURL,winName,features);
};

// bookmark this page
function bookmark(title,url) { 
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) { 
		window.external.AddFavorite( url, title); 
	} else if( window.opera && window.print ) { 
	return true; 
	} 
} 