// This js file contains the global functions that will be used throughout the courseware

//the popUpWindow function will create a new pop-up Window
function popUpWindow(url)
	{
		if(document.layers){
			//alert("You are working with NS");
			url = url + ".html";
			newWindow = top.window.open(url, "newWindow","toolbar=no, menubar=no, height=548px, width=794px,scrollbars=no, resizable=0");	
			newWindow.resizeTo(794,548);
			
		}else if(!document.all && document.getElementById){
			//alert("popUpWindow");
			url = url + ".html";
			newWindow = window.open(url, "newWindow","toolbar=no, menubar=no, height=548px, width=794px, scrollbars=no, resizable=0");	
			 
		//	self.close();
		}else{
		//	alert();
			url = url + ".html";
			newWindow = window.open(url, "newWindow","toolbar=no, menubar=no, height=548px, width=794px, scrollbars=no, resizable=0");	

		}
	}

//the href function will specify what the next or previous page is going to be
function previous(previousPg){
		//document.location = previousPg + ".html";
		history.back();
	}
	
function next(nextPg){
		document.location = nextPg + ".html";
	}
	
function mainMenu(mainMenuURL){
		document.location = mainMenuURL +".html";
	}

//this function is used for the status bar of each html page
//variable tPages is located on the individual html pages
function progressBar ()
	{
	if(document.layers){
		vHTML = " ";
		fUpdateLayer('pPer', vHTML)
		}
	if(!document.all && document.getElementById){
	//NS6.2
	var pBarW = 160;
	var pBarH = 10;
	var calc = (pBarW / tPages) * pgNum;
	var percent = Math.round((calc/pBarW)*100);
		Math.round(document.getElementById("pBar").style.width = calc);
		document.getElementById("pBar").style.backgroundColor = "red";
		vHTML = "<div align ='right'>" +percent+ " %</div>";//eval(calculation)
		fUpdateLayer('pPer', vHTML)		
	}
	if(document.all){	
		var pBarW = 160;
		var pBarH = 10;
		var calc = (pBarW / tPages) * pgNum;
		var percent = Math.round((calc/pBarW)*100);
		Math.round(document.all.pBar.style.width = calc);
		document.all.pBar.style.width = calc;
		document.all.pBar.style.backgroundColor = "red";
		//			***** END DO NOT TOUCH *****	
	vHTML = "<div align ='right'>" +percent+ " %</div>";//eval(calculation)
	fUpdateLayer('pPer', vHTML)
	}
}
	
function topWindow(){
	// commented out line below to prevent contact.html from appearing on Broken Links Report
	//popup = window.open("contact.html","","height=400,width=400,scrollbars=yes");
}

function noBack(){//disables keyboard when key is pressed J.F.
	return false;
	}
	
//this function updates the user interface throughout the courseware
function initUI() 
	{
	//document.onkeydown=noBack//call function to disable keyboard when key is pressed J.F.
	
	var vHTML = " ";
	checkNav();
	
	vHTML = "Page #" +pgNum;
	fUpdateLayer('pgNum',vHTML)
	
	vHTML = "<img src=media/" + pMeter + ".gif alt='Progress Meter' >"
	fUpdateLayer('pMeter',vHTML)
	
	vHTML = "<img src=media/" + pMeter + ".gif>"
	fUpdateLayer('pBg',vHTML)
	
	vHTML = "";//eval(calculation)
	fUpdateLayer('pBar', vHTML)
	
	if(!document.all && document.getElementById){
	vHTML = "<img src = 'media/pblank.gif'>";
	fUpdateLayer('pBar',vHTML);
	}
	
	vHTML = "<a href='http://www.epa.gov'>";
	vHTML += "<img src='media/tlogo.gif' border='0' target='_blank' alt='EPA logo - Click here to go to www.EPA.gov'></a>"//logo
	fUpdateLayer('logo',vHTML)

	vHTML = "<img src='../media/shim.gif' border='0' alt='U.S. Environmental Protection Agency' width='390' height='25'>"
	fUpdateLayer('overlay1',vHTML)
	
	vHTML = "<img src='../media/shim.gif' border='0' alt='Risk-Based Air Toxics' width='270' height='30'>"
	fUpdateLayer('overlay2',vHTML)
	
	vHTML = "<a href = 'javascript: previous(previousPg)' onMouseOver = 'imageOn(3)' onMouseOut = 'imageOff(3)'>";
	vHTML += "<img src ='media/help.gif' alt='Help' name ='btn3' height = '46' width ='71' border=0></a>";
	fUpdateLayer('help',vHTML)
	
	progressBar();
	}

//this array below will provide the image states for the lesson menu buttons.
	//creating the "on" array and populate with Image objects
	var onImgArray = new Array()
	onImgArray[0] = new Image(40,188)
	onImgArray[1] = new Image(48,30)
	onImgArray[2] = new Image(40,188)
	onImgArray[3] = new Image(71,46)
	
	onImgArray[0].src = "media/backr.gif";
	onImgArray[1].src = "media/menu.gif";
	onImgArray[2].src = "media/nextr.gif";
	onImgArray[3].src = "media/helpr.gif";
	
	//creating the "off" array and populate with Image objects
	var offImgArray = new Array()
	offImgArray[0] = new Image(40,188)
	offImgArray[1] = new Image(48,30)
	offImgArray[2] = new Image(40,188)
	offImgArray[3] = new Image(71,46)
	
	offImgArray[0].src = "media/backu.gif";
	offImgArray[1].src = "media/menu.gif";
	offImgArray[2].src = "media/nextu.gif";
	offImgArray[3].src = "media/help.gif";
	
	//creating the "down" array and populate with Image objects
	var downImgArray = new Array()
	downImgArray[0] = new Image(40,188)
	downImgArray[1] = new Image(40,30)
	downImgArray[2] = new Image(40,188)
	
	downImgArray[0].src = "media/backd.gif";
	downImgArray[1].src = "media/menu.gif";
	downImgArray[2].src = "media/nextd.gif";
	
	//}
	
function imageOn(i)
	{
		{
		document.images["btn"+i].src = onImgArray[i].src
		}
	}
	
function imageOff(i)
	{
		{
		document.images["btn" +i].src = offImgArray[i].src
		}
	}	
	
function imageDown(i)
	{
		{
		document.images["btn" +i].src = downImgArray[i].src
		}
	}

function checkNav(navState){
	var vHTML = "";
	//alert(top.navState);
	switch(top.navState){
		case '1'://all active
	vHTML = "<a href = 'javascript: previous(previousPg)' onMouseOver = 'imageOn(0); onMouseOut = 'imageOff(0)' onMouseDown = 'imageDown(0)'>";
	vHTML += "<img src ='media/backu.gif' alt='Back Button' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)

	vHTML = "<a href = 'javascript: doTrans()' onMouseOver = 'imageOn(1)' onMouseOut = 'imageOff(1)'>";
	vHTML += "<img src ='media/menu.gif' alt='Menu Button' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
		
	vHTML = "<a href = 'javascript: next(nextPg)' onMouseOver = 'imageOn(2)' onMouseOut = 'imageOff(2)' onMouseDown = 'imageDown(2)'>";//
	vHTML += "<img src ='media/nextu.gif' alt='Next Button' name ='btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
		break;
	
		case '2'://Back inactive
	vHTML += "<img src ='media/backi.gif' alt='Back Button Inactive' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)
	
	vHTML = "<a href = 'javascript: next(nextPg)' onMouseOver = 'imageOn(2)' onMouseOut = 'imageOff(2)'>";//
	vHTML += "<img src ='media/nextu.gif' alt='Next Button' name ='btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
	
	vHTML = "<a href = 'javascript: mainMenu(mainMenuPg)' onMouseOver = 'imageOn(1)' onMouseOut = 'imageOff(1)'>";
	vHTML += "<img src ='media/mainu.gif' alt='Menu Button' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
		break;
		
		case '3'://Next inactive
	vHTML += "<img src ='media/nexti.gif' alt='Next Button Inactive' name = 'btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
	
	vHTML = "<a href = 'javascript: previous(previousPg)' onMouseOver = 'imageOn(0); onMouseOut = 'imageOff(0)' onMouseDown = 'imageDown(0)'>";
	vHTML += "<img src ='media/backu.gif' alt='Back Button' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)
	
	vHTML = "<a href = 'javascript: mainMenu(mainMenuPg)' onMouseOver = 'imageOn(1)' onMouseOut = 'imageOff(1)'>";
	vHTML += "<img src ='media/mainu.gif' alt='Menu Button' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
		break;
		
		case '4'://Main inactive
	vHTML = "<img src ='media/maini.gif' alt='Menu Button Inactive' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
	
	vHTML = "<a href = 'javascript: next(nextPg)' onMouseOver = 'imageOn(2)' onMouseOut = 'imageOff(2)'>";//
	vHTML += "<img src ='media/nextu.gif' alt='Next Button' name = 'btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
	
	vHTML = "<a href = 'javascript: previous(previousPg)' onMouseOver = 'imageOn(0); onMouseOut = 'imageOff(0)' onMouseDown = 'imageDown(0)'>";
	vHTML += "<img src ='media/backu.gif' alt='Back Button' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)
		break;
		
	case '5'://Main & Back inactive
	//vHTML = "<a href = 'javascript: mainMenu(mainMenuPg)' onMouseOver = 'imageOn(1)' onMouseOut = 'imageOff(1)'>";
	vHTML = "<img src ='media/maini.gif' alt='Menu Button Inactive' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
	
	//vHTML = "<a href = 'javascript: previous(previousPg)' onMouseOver = 'imageOn(0); onMouseOut = 'imageOff(0)' onMouseDown = 'imageDown(0)'>";
	vHTML = "<img src ='media/backi.gif' alt='Back Button Inactive' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)
	
	vHTML = "<a href = 'javascript: next(nextPg)' onMouseOver = 'imageOn(2)' onMouseOut = 'imageOff(2)'>";//
	vHTML += "<img src ='media/nextu.gif' alt='Next Button' name = 'btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
		break;
	
	case '6':
	vHTML = "<img src ='media/maini.gif' alt='Menu Button Inactive' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
	
	vHTML = "<a href = 'javascript: previous(previousPg)' onMouseOver = 'imageOn(0); onMouseOut = 'imageOff(0)' onMouseDown = 'imageDown(0)'>";
	vHTML += "<img src ='media/backu.gif' alt='Back Button' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)
	
	vHTML = "<img src ='media/nexti.gif' alt='Next Button Inactive' name = 'btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
		break;
	
	case '7':
	vHTML = "<img src ='media/nexti.gif' alt='Next Button Inactive' name = 'btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
	
	vHTML = "<img src ='media/backi.gif' alt='Back Button Inactive' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)
	
	vHTML = "<a href = 'javascript: mainMenu(mainMenuPg)' onMouseOver = 'imageOn(1)' onMouseOut = 'imageOff(1)'>";
	vHTML += "<img src ='media/mainu.gif' alt='Menu Button' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
		break;
	
	case '8':
	
	vHTML = "<img src ='media/nexti.gif' alt='Next Button Inactive' name = 'btn2' height = '188' width ='40' border=0></a>";
	fUpdateLayer('nextPg',vHTML)
	
	vHTML = "<img src ='media/backi.gif' alt='Back Button Inactive' name ='btn0' height = '188' width ='40' border=0></a>";
	fUpdateLayer('previousPg',vHTML)
	
	vHTML = "<img src ='media/maini.gif' alt='Menu Button Inactive' name ='btn1' height = '33' width ='48' border=0></a>";
	fUpdateLayer('menu',vHTML)
		break;
	
	default:
		alert("default nav case");
		break;
		}
	}	

//this function disables right mouse click
var message="Right Button Functionality is not permitted throughout this courseware.";
function rightButtonDisable(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
	}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
		}
	}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=rightButtonDisable;