function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Set Body text size
function setSize(iSize) {
	if (!document.getElementsByTagName) return false;
		var bodyTag = document.getElementsByTagName("body");

	for (var i=0; i < bodyTag.length; i++) {
		if (!bodyTag[i].style.fontSize) {
			if (!readCookie("resize")) {
				bodyTag[i].style.fontSize = "62.5%";
			}
			else {
				bodyTag[i].style.fontSize = ((parseFloat(readCookie("resize"))) + "%");
			}
		}
		else {
			if (!readCookie("resize")) {
				bodyTag[i].style.fontSize = "62.5%";
			}
			else {
				var newSize = parseFloat(iSize) + parseFloat(readCookie("resize"));
				if ((newSize <= 72.5) && (newSize >= 52.5))
					bodyTag[i].style.fontSize = newSize + "%";
			}
		}
		cookieValue = bodyTag[i].style.fontSize;
		writeCookie("resize", cookieValue, 10000);
	}
}

// Attaches the onclick event to the correct ids to allow resizing
function resizeT(iID, iDir) {
	if (!document.getElementById) return false;
		var incLink = document.getElementById(iID);

	if (iDir == "decrease") {
		incLink.onclick = function() {
			setSize("-5%");
			return false;
		}
	}

	if (iDir == "increase") {
		incLink.onclick = function() {
			setSize("5%");
			return false;
		}
	}
}

// add increase / decrease font event handlers
addLoadEvent( function(){ resizeT("fntIncrease", "increase") } );
addLoadEvent( function(){ resizeT("fntDecrease", "decrease") } );

// set base font size
addLoadEvent( function(){ setSize("62.5%") } );



// Writes cookie
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours) {
	var expire = "";
	if(hours != null) {
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}

// Read Cookie
// alert( readCookie("myCookie") );
function readCookie(name){
	var cookieValue = "";
	var search = name + "=";

	if(document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);

	if (offset != -1) {
		offset += search.length;

	end = document.cookie.indexOf(";", offset);

	if (end == -1) end = document.cookie.length;
		cookieValue = unescape(document.cookie.substring(offset, end)) }
	}

	return cookieValue;
}




/* Start external links handler */
function externalLinks() {
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i];
      if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
         anchor.target = "_blank";
   }
}

addLoadEvent(externalLinks);
/* End external links handler */
