﻿/*
see http://www.456bereastreet.com/archive/200709/how_to_create_an_unobtrusive_print_this_page_link_with_javascript/
*/
var addPrintLink = {
	init:function() {
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		if (!document.getElementById('print-link')) {return;} // Check that the target element actually exists
		if (!window.print) {return;} // Check that the browser supports window.print
		var oTarget = document.getElementById('print-link');
		oTarget.style.display = 'block'; // display the print links
		// for each link within the target, we need to add the onclick event
		var oChildren = oTarget.childNodes; // links are Elements (nodeType=1)
		for(var i=0;i<oChildren.length; i++)
		{
			var oChild = oChildren.item(i);
			var nodename = oChild.nodeName.toLowerCase();
			if (nodename == 'a') // it's a link
			{
				oChild.onclick = function() { window.print(); return false;}
			}
		}
	},
/*
addEvent function included here for portability. Replace with your own addEvent function if you use one.
*/
/* 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]);
		}
	}
};
addPrintLink.addEvent(window, 'load', function(){addPrintLink.init();});
