function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}


// stretch div#body to fill the screen
// this is more reliable than using just a CSS method

addLoadEvent(function() {
	winH = windowHeight(); //This returns the screen heigth
	heightNeeded = document.getElementById('body').offsetHeight; 
	if (winH > heightNeeded) { // viewport is longer than content
		document.getElementById('body').style.height=winH+'px'; // stretch content to viewport height
	}
})

// ancillary stretch function
function windowHeight(){
	var alto= 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		alto= window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		alto= document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		alto= document.body.clientHeight;
	}
	return alto;
}


	// For the popup links on pages - only requires a class in the html
	
	addLoadEvent(function() {
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop 
	if (!document.getElementsByTagName) {
		return false; 
	} 
	// create an array of objects of each link in the document 
	var popuplinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
	for (var i=0; i < popuplinks.length; i++) {	
		// if the link has a class of "popuparchive"...	
		if (popuplinks[i].className == "popup900-600") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp(this.getAttribute("href"));	
			return false; 	
			} 	
		}
		else if (popuplinks[i].className == "popup800-500") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp2(this.getAttribute("href"));	
			return false; 	
			} 	
		}
		else if (popuplinks[i].className == "popup600-400") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp3(this.getAttribute("href"));	
			return false; 	
			} 	
		}
		else if (popuplinks[i].className == "popup500-400") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp4(this.getAttribute("href"));	
			return false; 	
			} 	
		}
		else if (popuplinks[i].className == "popup400-300") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp5(this.getAttribute("href"));	
			return false; 	
			} 	
		}
		else if (popuplinks[i].className == "popup650-500") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp6(this.getAttribute("href"));	
			return false; 	
			} 	
		}
		else if (popuplinks[i].className == "popup640-427") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp7(this.getAttribute("href"));	
			return false; 	
			} 	
		}		
	} 
})


// ancillary popup functions
function openPopUp(linkURL) {
	    remote = window.open(linkURL,'popup1','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,width=900,height=600');
		if (window.focus) {remote.focus()}
}

function openPopUp2(linkURL) {
	    remote = window.open(linkURL,'popup2','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=500');
		if (window.focus) {remote.focus()}
}

function openPopUp3(linkURL) {
	    remote = window.open(linkURL,'popup3','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400');
		if (window.focus) {remote.focus()}		
}

function openPopUp4(linkURL) {
	    remote = window.open(linkURL,'popup4','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,width=500,height=400');
		if (window.focus) {remote.focus()}
}

function openPopUp5(linkURL) {
	    remote = window.open(linkURL,'popup5','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,width=400,height=300');
		if (window.focus) {remote.focus()}
}
function openPopUp6(linkURL) {
	    remote = window.open(linkURL,'popup6','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,width=650,height=500');
		if (window.focus) {remote.focus()}
}
function openPopUp7(linkURL) {
	    remote = window.open(linkURL,'popup7','toolbar=no,location=no,menubar=no,scrollbars=no,resizable=yes,width=640,height=427');
		if (window.focus) {remote.focus()}
}
