// This file is now defunct, so to save time going through
// and looking for all pages that have popup.js on it and
// replacing them with npower.js, this will now automatically
// load npower.js if it's not already loaded.
// going forward, popup.j2 should be replaced by npower.js
// wherever possible.

var attempts = 0;
var timer;

window.onload = function(){
	//look for the npowerJSLoad function. If it's not there then
	//we need to load npower.js
	if(typeof npowerJSLoad == "undefined"){
		loadExternalFile("/idc/WCMSFragments/javascript/npower.js", "js");
		tryNpowerLoad();
	}
}

function tryNpowerLoad(){
	if (typeof npowerJSLoad == "undefined" && attempts < 20){
		timer = setTimeout("tryNpowerLoad()",500);
		attempts++;
	}else{
		clearTimeout(timer);
		npowerJSLoad();	
	}
}

function loadExternalFile(filename, filetype){
	var fileref;
	if (filetype=="js"){ //if filename is a external JavaScript file
		fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", filename)
	}
	else if (filetype=="css"){ //if filename is an external CSS file
		fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", filename)
	}
	
	if (typeof fileref!="undefined") {
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}


