
/*
JSTarget function by Roger Johansson, www.456bereastreet.com
*/
var JSTarget = {
	init: function(att,val,warning) {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
			var oWarning;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];
				if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
					oWarning = document.createElement("em");
					oWarning.appendChild(document.createTextNode(strWarning));
					oLink.appendChild(oWarning);
					oLink.onclick = JSTarget.openWin;
				}
			}
			oWarning = null;
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	/*
	addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	*/
	addEvent: function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
//JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external","");});


/* text size tool */

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(function() {
	// activate style switcher
	var cookie = readCookie("style");
	if (document.getElementsByTagName) {
		var title = cookie ? cookie : getPreferredStyleSheet();
		setActiveStyleSheet(title);
		fontSizer(0);
	}
});

// style switcher
function setActiveStyleSheet(title) {
	if (document.getElementsByTagName) {
		var i, a, main;
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel") &&
			a.getAttribute("rel").indexOf("style") != -1 &&
			a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
		createCookie("style", title, 365);
	} else {
		notSupported();
	}
}
function getActiveStyleSheet() {
	var i, a;
	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel") &&
		a.getAttribute("rel").indexOf("style") != -1 &&
		a.getAttribute("title") &&
		!a.disabled
		) return a.getAttribute("title");
	}
	return null;
}
function getPreferredStyleSheet() {
	var i, a;
	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel") &&
		a.getAttribute("rel").indexOf("style") != -1 &&
		a.getAttribute("rel").indexOf("alt") == -1 &&
		a.getAttribute("title")
		) return a.getAttribute("title");
	}
	return null;
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function fontSizer(adj) {
	if (document.getElementById) {
		iInit = readCookie('fontSize');
		if (adj != 'reset') {
			if (isNaN(iInit) || iInit == null) {
				i = 0 + adj;
			} else {
				i = parseInt(iInit) + adj;
			}
			if (i > 16) {
				i = 5;
				alert("The text size cannot be increased any further.");
			}
			if (i < -5) {
				i = -5;
				alert("The text size cannot be decreased any further.");
			}
		} else {
			i = 0;
		}
		b = document.getElementById('container');
		b.style.fontSize =  100 + (i * 10) + '%';
		b.style.lineHeight = 160 + (i * 5) + '%'; 
		c = createCookie('fontSize',i,365);
		return b;
	} else {
		notSupported();
	}
}
