function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }  //eof anon
  }  //end of else
} //eof addLoadEvent


function getTextValue(el) {
  var k;
  var s;
  // Find and concatenate the values of all text nodes contained within the element.
  s = "";
  if(!el.childNodes) {return s;}
  for (k = 0; k <el.childNodes.length; k++) {
    if (el.childNodes[k].nodeType == document.TEXT_NODE) {
      s += el.childNodes[k].nodeValue;
    } else {  //else1
    if (el.childNodes[k].nodeType == document.ELEMENT_NODE &&
             el.childNodes[k].tagName == "BR") {
      s += " ";
   } else {  // else2
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[k]);
   }   //end of else2
  }    //end of else1
  return normaliseString(s);
  }   //end of for k
}     //eof getTextValue
  

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  } //endof else
} //eof addClassName


function normaliseString(s) {
// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");
  s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space - fails with I.E. 
  return s;
  } //eof normaliseString
  
  
function getElemsByClassName(strClass, strTag) {
var classElements = new Array;
if (strClass ==undefined) strClass =" ";
if ( strTag == null) strTag = '*';
var elems = document.getElementsByTagName( strTag); //node replaced by document
var elemsLen = elems.length;
var normalStrClass = normaliseString(strClass)
var j=0;
for (var i = 0; i< elemsLen; i++) {
if (normalStrClass == elems[i].className ) {
 classElements[j] = elems[i];
    j++; 
    } //end of if     
  } //end of for i  
  return classElements;
} //eof getElemsByClassName


/* the function putMessage below is now redundant but kept in case it is needed again
function putMessage(msage,ttle,divId){ 
//create button to go on bottom of Print Info message, so that clickking it removes message
var w =584; //width of message holder
//set up OK button
 var OKText="Click here to remove Printing Information";
var OKTxtNode = document.createTextNode(OKText);
var btnTag = document.createElement("button");
btnTag.style.fontSize ="12pt";// sets font size of bottom section of full message 
btnTag.style.width =w+"px";
btnTag.style.margin = "0px 0px";
btnTag.appendChild(OKTxtNode);

//
if(document.all){ //get onclick attribute - I.E. only
srceClickElemPara = document.getElementById("noPrntMsg");
srceClickElemIp = srceClickElemPara.getElementsByTagName("input");
srceClick = srceClickElemIp[0].getAttribute("onclick");
btnTag.setAttribute("onclick",srceClick);
}
else{
btnTag.setAttribute("onclick","removeMessage()");
}
 buttonDiv = document.createElement("div"); //global
 buttonDiv.className = "buttonClass noprint";
 buttonDiv.setAttribute("align","center");
 buttonDiv.style.margin ="0px";
 buttonDiv.style.width = w + "px";
 buttonDiv.appendChild(btnTag);
 
 //Set up title textNode
  var ttleTxtNode = document.createTextNode(ttle);
  
 ttleDiv = document.createElement("div"); //Create title of Print Info message
 ttleDiv.setAttribute("align","center");
 ttleDiv.style.width = w + "px";
 ttleDiv.className = "titleClass noprint";
 ttleDiv.appendChild(ttleTxtNode);
 
 //Set up message paragraph
 var msgeTxtNode = document.createTextNode(msage);
 var msgePre = document.createElement("pre");
 msgePre.style.fontSize="11pt";//Sets font size of central section of full message
 msgePre.style.fontFamily="Arial";
 msgePre.appendChild(msgeTxtNode);
 var msgePara = document.createElement("p");
 msgePara.appendChild(msgePre);
 
 //Set up  main content
 contentArea = document.createElement("div");  //global
 contentArea.style.width = w + "px";
contentArea.className = "contentClass noprint";
contentArea.appendChild(msgePara);
//contentArea.setAttribute("borderWidth","5px");
//contentArea.setAttribute("borderColor","#844");

//Set up Main Table
var mainTable = document.createElement("table");
mainTable.setAttribute("cellSpacing","0");
mainTable.setAttribute("cellPadding","0");
var tbodyMain = document.createElement("tbody");
var rowMain = document.createElement("tr");
cellMain = document.createElement("td"); //global
cellMain.style.borderRight ="5px solid #050";
cellMain.style.borderLeft ="5px solid #050";
cellMain.appendChild(contentArea);
rowMain.appendChild(cellMain);
tbodyMain.appendChild(rowMain);
mainTable.appendChild(tbodyMain);

//Set up title table
var ttleTable = document.createElement("table");
ttleTable.setAttribute("cellSpacing","0");
ttleTable.setAttribute("cellPadding","0");
ttleTable.setAttribute("border","0");
var tbodyTtle = document.createElement("tbody");
var rowTtle = document.createElement("tr");
cellTtle = document.createElement("td"); //global
cellTtle.style.border ="5px solid #050";
cellTtle.appendChild(ttleDiv);
rowTtle.appendChild(cellTtle);
tbodyTtle.appendChild(rowTtle);
ttleTable.appendChild(tbodyTtle);

//Set up button table
var btnTable = document.createElement("table");
btnTable.setAttribute("cellSpacing","0");
btnTable.setAttribute("cellPadding","0");
btnTable.setAttribute("border","0");
btnTable.setAttribute("valign","top");

var tbodyBtn = document.createElement("tbody");
var rowBtn = document.createElement("tr");
cellBtn = document.createElement("td"); // global
cellBtn.style.border ="5px solid #050";
cellBtn.appendChild(buttonDiv);
rowBtn.appendChild(cellBtn);
tbodyBtn.appendChild(rowBtn);
btnTable.appendChild(tbodyBtn);

// set up outer container
outerDiv = document.getElementById(divId);
outerDiv.appendChild(ttleTable);
outerDiv.appendChild(mainTable);
outerDiv.appendChild(btnTable);
} //eof putMessage


function removeMessage(){ //used in putMesage
outerDiv.style.display = "none";

divNote.style.visibility ="visible"; // bring back original note.
}
*/

function scrollPageToTxt(){
var pixelsFromTop =screen.height-80;
alert("pixelsFromTop = " + pixelsFromTop);
var pixelsFromLeft = 0;
window.scrollTo(pixelsFromLeft,pixelsFromTop);
}


function changeOpacityUsingId(id, startOpac, endOpac, millisecs,frameTime) { // startOpac and endOpac are percentages, 0 to 100 inclusive.
  // millisecs is the time to change from startOpac to endOpac in millisecs.
  //Because of probable rounding errors and inaccuracies in setTimeout method, this time will be approximate. 
  //frameTime is the time to display one frame in millisecs.(say 10 to 30 millisecs)
  // Beware: browesers tend to produce flickering with large images.
	var counter = 0;
	var noSteps= Math.round(millisecs/frameTime);
  var incOpac=Math.round((startOpac-endOpac)/noSteps); //incremental changes in opacity.
  var  magnitudeIncOpac=Math.abs(incOpac);
  var startPoint=Math.floor(startOpac/magnitudeIncOpac);
  var endPoint=Math.floor(endOpac/magnitudeIncOpac);

	//Determine the direction for the blending, If start and end are the same nothing happens
	if(startOpac > endOpac) {
		for(i = startPoint; i >= (endPoint-incOpac); i--) {// Subtract one increment (incOpac) to ensure endOpac is reached
		newOpac=i*incOpac;
		if(newOpac<endOpac){newOpac=endOpac;}
		//now repeatedly apply the changes in opacity, each change after a time interval equal to frameTime
			setTimeout("setOpacUsingId(" + newOpac + ",'" + id + "')",(counter * frameTime)); 
			counter++;
		}
	} else if(startOpac < endOpac) {
		for(i = startPoint; i <= (endPoint +incOpac); i++){ // Add one increment (incOpac) to ensure endOpac is reached
			newOpac=i*incOpac;
			if(newOpac>endOpac){newOpac=endOpac;}
			//now repeatedly apply the changes in opacity, each change after a time interval equal to frameTime
			setTimeout("setOpacUsingId(" + newOpac + ",'" + id + "')",(counter * frameTime)); 
			counter++;
		}
	}
} //eof changeOpacityUsingId


function setOpacUsingId(opacity,id) { //Note: rules that specify an element id overrule other rules if there is a conflict in style definitions
var objectElement= document.getElementById(id);
var objectCSS=objectElement.style;
if(document.all){ 
 objectCSS.filter="alpha(opacity=" + opacity +")"; // for IE browsers
 } else if(objectCSS.MozOpacity){ // for old Mozilla browsers
 objectCSS.MozOpacity=(opacity/100);
 }else{
 objectCSS.opacity=(opacity/100); // for latest browsers other than IE
 }
// objectCSS.KhtmlOpacity=(opacity/100); // this could be included for Konquerer browsers
} // eof setOpacUsingId


//Set global variables
longTbl = true;
count=0; 
prntInfoSet = false;
mapping= false;
//prntContent = document.createElement("div"); //this div is global and will sit inside prntDiv. It is used by printprog.js and toggleMap.js


//Set global object to pass state of map display from toggleMap.js to tooltips.js
function mapDisplay(state){
this.on=state;
}
mapDisplay.on=false;


