/* motorolatest.js */
// setting up a group of variables outside of any fx to enable their use by any fx
var rTime=0;
var pTime=1;
var rtimer;
var pgtimer;
var f;

/* two dimensional array
each element is reference by two params
[x][y] where x is the outer array index and y is the inner array index
for example EBay1.htm reference [4][0]="<fully qualified url>"; reference [4][1]="20"
*/
var website = new Array();
website[0] = new Array("http://nextmillennium.projectxxi.com","45");
website[1] = new Array("http://bowling.projectxxi.com","35");
website[2] = new Array("http://zmakarate.com","45");
website[3] = new Array("http://www.giggleboxes.org","45");
website[4] = new Array("http://personal.projectxxi.com","45");
website[5] = new Array("http://personal.projectxxi.com/JKerstetter.html","35");
website[6] = new Array("http://personal.projectxxi.com/Warriors.html","35");
website[7] = new Array("http://www.summitacademies.com/index.php","35");
website[8] = new Array("http://www.akronschools.com/","40");
website[9]= new Array("TestFinished.htm","");

// timers
//calculate total test running time and display in Running Total text box on TestHome_alt.html

function runningTime(){
var runtimer = function () {
     rTime++;
     document.form2.clock.value=parseInt(rTime);
};
rtimer = setInterval(runtimer, 1000);
}	



//fx updating the Page Countdown text box on TestHome.html
function pgTime(){
if(location.search.substring(1)=="autostart"){
f=1;
}else{
f=0;
}
	var countDown = function () {
		     pTime--;
		     document.form2.pgclock.value=pTime;
		     if (pTime <= 0) {
		       f++;
		       
				if(website[f][0]!="TestFinished.htm"){
				window.ifrm.location.href=website[f][0];
				document.form2.testpg.value=website[f][0];
				pTime=website[f][1];
				}else{
				//alert("Test Completed");
				clearInterval(rtimer);
				clearInterval(pgtimer);

				window.ifrm.location.href="TestFinished.htm";
				document.form2.testpg.value="TestFinished.htm";
				document.form2.pgclock.value="";
				document.form2.forcepg.disabled=true;
				}
			}
	};
pgtimer = setInterval(countDown, 1000);
}


function forcePg(){
f++;
	//first conditional test if the referenced array element is NOT TestFinished.htm
	if(website[f][0]!="TestFinished.htm"){
	window.ifrm.location.href=website[f][0];
	pTime=website[f][1];
	document.form2.testpg.value=website[f][0];
	}else{
	//second conditional if referenced array element IS TestFinished.htm
	//alert is optional comment out if you wish
	window.ifrm.location.href="TestFinished.htm";
	//disable the Force Pg button as it is not longer relevant
	document.form2.forcepg.disabled=true;
	document.form2.testpg.value="TestFinished.html";
	clearInterval(rtimer);
	clearInterval(pgtimer);
	//clear Page Countdown text field, no longer relevant
	document.form2.pgclock.value="";

	}
}

//fx to start all over
function restartTest(){
location.href="TestHome.html";
}
var x;
//fx to gather and display information about the test resources
function inventory(){
var testpagecount = website.length-1;
var testcyclelength = 0;
var pagetime = 0;
	for(x=0;x<testpagecount;x++){
	pagetime = parseInt(website[x][1]);
	testcyclelength+=pagetime;
	}
	document.write("# of Pages to be visited: " + testpagecount + " &nbsp;&nbsp;||&nbsp;&nbsp; Approx Time (No Forced Pages): " + testcyclelength + " seconds / ~" + testcyclelength/60 + " minutes" );
}

/* a convenience fx, note we are calling mulitiple functions at window.onload, necessary when you need more than one at onload because if you call them independently and separately the second will override the first onload event
also sets up the page with desired initial values
there are alternative ways of doing this but this is the simplest to understand */


function startTest(){
f=0;
//start the fx runningTime at TestHome_alt.html
runningTime();
//start the fx pgTime at TestHome_alt.html
pgTime();
document.form2.testpg.value=website[0][0];
document.getElementById('controlpanel').style.display="none"
window.ifrm.location.href=website[0][0];
}

function pgInit(){
//get the time element for the first outer index value
pTime = website[0][1];
//make sure the Force Pg button is NOT disabled, a required starting condition
document.form2.forcepg.disabled=false;

}

/* auto-start fx */
function autoStart(){

	if(window.location.search.substring(1)!=""){
	qstring=window.location.search.substring(1);
		if(qstring=="autostart"){		
		startTest();

		}
	}
}


