var PopupBlocker = "undefined";
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
window.onload = function(){ 
	prepareExternalLinks(); 
	footnoteLinks('content','content');
	document.execCommand("BackgroundImageCache", false, true);
} 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function prepareExternalLinks() { 
	if (!document.getElementsByTagName) return false; 
	var hrefs = document.getElementsByTagName("a"); 
	var linkrel; 
	for (var i=0; i < hrefs.length; i++) { 
		linkrel= hrefs[i].getAttribute("rel"); 
		if (linkrel != null){ 
			if (linkrel == "External Link"||linkrel == "external") {
				hrefs[i].target = "_blank"
/*				hrefs[i].onclick = function() {
						var oWin = window.open(this.href);
						if (oWin==null || typeof(oWin)=="undefined") {
							PopupBlocker = true;
							return true;
						}
						else {
							return false;
						}
				} 
*/				hrefs[i].onkeypress = hrefs[i].onclick; 
			}
		} 
	} 
} 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function IsPopupBlocker() {
	if (PopupBlocker!="undefined") {
		return PopupBlocker;
	}
	else {
		var oWin = window.open("","testpopupblocker","width=10,height=10,top=0,left=0");
		if (oWin==null || typeof(oWin)=="undefined") {
			return true;
			PopupBlocker = true;
		}
		else {
			oWin.close();
			return false;
		}
	}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function footnoteLinks(containerID,targetID) {
	if (!document.getElementById || 
		!document.getElementsByTagName ||
		!document.createElement) return false;
	if (!document.getElementById(containerID) ||
		!document.getElementById(targetID)) return false;
	var container = document.getElementById(containerID);
	var target    = document.getElementById(targetID);
	var h2        = document.createElement('h2');
	addClass.apply(h2,['printOnly']);
	var div       = document.createElement('div');
	addClass.apply(div,['printOnly']);
	div.id = 'Links';
	var h2_txt    = document.createTextNode('Links');
	h2.appendChild(h2_txt);
	var coll = container.getElementsByTagName('a'); // change to '*' for graphics.
	var ol   = document.createElement('ol');
	addClass.apply(ol,['printOnly']);
	var myArr = [];
	var thisLink;
	var num = 1;
	for (var i=0; i<coll.length; i++) {
		if ( coll[i].getAttribute('href') ||
			coll[i].getAttribute('cite') ) { 
			thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
			var note = document.createElement('sup');
			addClass.apply(note,['printOnly']);
			var note_txt;
			var j = inArray.apply(myArr,[thisLink]);
			if ( j || j===0 ) { // if a duplicate
				// get the corresponding number from 
				// the array of used links
				note_txt = document.createTextNode(j+1);
			} else { // if not a duplicate
				var li     = document.createElement('li');
				var li_txt = document.createTextNode(thisLink);
				li.appendChild(li_txt);
				ol.appendChild(li);
				myArr.push(thisLink);
				note_txt = document.createTextNode(num);
				num++;
			}
			note.appendChild(note_txt);
			if (coll[i].tagName.toLowerCase() == 'blockquote') {
				var lastChild = lastChildContainingText.apply(coll[i]);
				lastChild.appendChild(note);
			} else {
				coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
			}
		}
	}
	if (thisLink) {
		target.appendChild(div);
		div.appendChild(h2);
		div.appendChild(ol);
	}
	return true;
}
if(Array.prototype.push == null) {
	Array.prototype.push = function(item) {
		this[this.length] = item;
		return this.length;
	};
};
if (!Function.prototype.apply) {
	Function.prototype.apply = function(oScope, args) {
		var sarg = [];
		var rtrn, call;
		if (!oScope) oScope = window;
		if (!args) args = [];
		for (var i = 0; i < args.length; i++) {
			sarg[i] = "args["+i+"]";
		};
		call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
		oScope.__applyTemp__ = this;
		rtrn = eval(call);
		oScope.__applyTemp__ = null;
		return rtrn;
	};
};
function inArray(needle) {
	for (var i=0; i < this.length; i++) {
		if (this[i] === needle) {
			return i;
		}
	}
	return false;
}
function addClass(theClass) {
	if (this.className != '') {
		this.className += ' ' + theClass;
	} else {
		this.className = theClass;
	}
}
function lastChildContainingText() {
	var testChild = this.lastChild;
	var contentCntnr = ['p','li','dd'];
	while (testChild.nodeType != 1) {
		testChild = testChild.previousSibling;
	} 
	var tag = testChild.tagName.toLowerCase();
	var tagInArr = inArray.apply(contentCntnr, [tag]);
	if (!tagInArr && tagInArr!==0) {
		testChild = lastChildContainingText.apply(testChild);
	}
	return testChild;
}
