//	JavaScript function to insert a "close this window" and "print page" links
//  into a new paragraph element, just before the first occurrence of an <h1>
//  tag, in the <div> of class "content"
function insertLinks() {
	// First test if the browser supports the DOM
	if (!document.getElementsByTagName) return true;
	if (!document.createElement || !document.createTextNode) return true;
	// Now confirm that there is at least one "h1" tag on the page
	var h1tags = document.getElementsByTagName("h1");
	if (h1tags.length > 0) {
		// At least one "h1" tag, select the first
		var firsttag = h1tags[0];
		// Now fetch the "div" element "content"
		var divs = document.getElementsByTagName("div");
		for (var i = 0; i < divs.length; i++) {
			// "className" for IE, "class" for FF
			if ((divs[i].getAttribute("className") == "content") || (divs[i].getAttribute("class") == "content")) {
				var content = divs[i];
			}
		}
		// Create a new paragraph element
		var para = document.createElement("p");
		// Create a hyperlink ("a" element)
		var link1 = document.createElement("a");
		link1.setAttribute("href","#");
		link1.setAttribute("title","Print Document");
		// Now create the link text to display
		var link1text = document.createTextNode("Print this Document");
		// Append the text to the link
		link1.appendChild(link1text);
		// Now append the link to the new paragraph
		para.appendChild(link1);
		// And now create another hyperlink as above
		var link2 = document.createElement("a");
		link2.setAttribute("href","#");
		link2.setAttribute("title","Close Window");
		// Now create the link text to display
		var link2text = document.createTextNode("Close this Window");
		// Append the text to the link
		link2.appendChild(link2text);
		para.appendChild(link2);
		// Now insert some spacing into the paragraph
		var spacer = document.createTextNode("  |  ");
		para.insertBefore(spacer, link2);
		// Now insert the paragraph into the <div> element "content"
		// immediately in front of the first <h1> tag
		content.insertBefore(para, firsttag);
		// Finally, set up the actions to take on clicking the links
		link1.onclick = function() {
			window.print();
		}
		link2.onclick = function() {
			//window.open('','_parent',''); // problems with Firefox
			window.close();
		}
	} else {
		return true;
	}
}
window.onload = function() {
	insertLinks();
}