var generationDate = "(?)";
window.defaultStatus ="Math Review";
var pageType = "Intro"; // always initialize to "Intro"
var theDateText;
var currentStep = 0;
var theTimeout;
var reviewImagePath = "../../../../ptt/ReviewImages/";
var problemsDoneFlag = false;

// The API code is loaded in the header frame, which is a child of
// the main review frame.  Its sibling frame is the content frame.
// Within the content frame, there
// are body and footer frames.


var FOOTER;
var BODY;
var CONTENT;
var MAIN

function getFrames (){
 MAIN = window.parent;
 CONTENT = MAIN.content;
 FOOTER = CONTENT.footer;
 BODY = CONTENT.body;
}

var introImage = new Image();
introImage.src = reviewImagePath + "h_intro" + langSuf + ".gif";

var step1Image = new Image();
step1Image.src = reviewImagePath + "h_step1" + langSuf + ".gif";

var step2Image = new Image();
step2Image.src = reviewImagePath + "h_step2" + langSuf + ".gif";

var step3Image = new Image();
step3Image.src = reviewImagePath + "h_step3" + langSuf + ".gif";

var step4Image = new Image();
step4Image.src = reviewImagePath + "h_step4" + langSuf + ".gif";

var step5Image = new Image();
step5Image.src = reviewImagePath + "h_step5" + langSuf + ".gif";

var step6Image = new Image();
step6Image.src = reviewImagePath + "h_step6" + langSuf + ".gif";

var tiImage = new Image();
tiImage.src = reviewImagePath + "h_tryit" + langSuf + ".gif";

var bnImage = new Image();
bnImage.src = reviewImagePath + "h_bonus" + langSuf + ".gif";

var rpImage = new Image();
rpImage.src = reviewImagePath + "h_quiz" + langSuf + ".gif";

var exitImage = new Image();
exitImage.src = reviewImagePath + "exit" + langSuf + ".gif";


function addZeroToNum( theInt )
{
	var theString;
	if ( theInt < 10 )
	{
		theString = "0" + theInt;
	} else {
		theString = theInt;
	}
	return theString;
}

var gradeStr = addZeroToNum( grade );
var chapterStr = addZeroToNum( chapter );
var lessonStr = addZeroToNum( lesson );

if(lessonStr == "99"){ 
       lessonStr="ps"; 
}

var reviewName = "r" + gradeStr + "_" + chapterStr + "_" + lessonStr + "_0";
	
function goNext()
{
	if ( pageType == "INTRO" )
	{		
		//alert("Calling goStep(1)");
		goStep( 1 );
	} else if ( currentStep >= numSteps ) {		
		//alert("Calling goTI()");
		goTI();
	} else {		
		//alert("Calling goStep(" + (currentStep + 1) + ")");
		goStep( currentStep + 1 );
	}
}

function goBack()
{
	if ( currentStep == 1 ){		
		//alert("Calling goINTRO()");
		goINTRO();
	} else if ( pageType == "TI" ) {		
		//alert("Calling goStep(" + numSteps + ")");
		goStep( numSteps );
	} else {		
		//alert("Calling goStep(" + (currentStep - 1) + ")");
		goStep( currentStep - 1 );
	}	
}

function setBody(newURL){
	getFrames();
	BODY.location.href = newURL;
}

function goToPage( newPageType, stepNum )
{
	var delayInterval = 50;
	var stepStr = "";	
	var newURL;
	getFrames();

	//ensure that theTimeout is defined
	if (theTimeout != null)	
		clearTimeout( theTimeout );
			
	// Figure out what to stick into the path where the step number usually goes	
	if ( stepNum == 0 )
	{
		stepStr = "";
	} else {
		stepStr = stepNum;
	}
			
	newURL =  reviewName + pageType + stepStr + langSuf + ".htm";
	

	if (newPageType == "RP" || newPageType == "BN")
	{
		CONTENT.location.href = newURL;
	} else {
		//BODY.location.href = newURL;
		theTimeout = setTimeout("setBody('" + newURL + "');", delayInterval);
		//setBody(newURL);
	}
}

function writeFooter(frameNum){
	//alert(FOOTER.location);
	var newURL;
	getFrames();
	if (frameNum == "intro"){
		newURL = "../ptt/nextback.htm";
	} else if (frameNum == "tryit") {
		newURL = "../ptt/nextback_tryit.htm";
	} else {
		newURL = "../ptt/nextback_step.htm";
	}
	
	FOOTER.location.href = newURL;

}

function old_writeFooter(frameNum){

var flashString = ''
+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> '
+ '<html><head>'
+ ' <SCRIPT LANGUAGE="JavaScript">'
+ ' var ContentWindow = window.parent;'
+ ' var API = ContentWindow.parent.header;'
+ ' </SCRIPT></head><body bgcolor=FFFF00 topmargin=0> '
+ '<center> '
+ ' <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
+ ' WIDTH=300 HEIGHT=30'
+ ' CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
+ ' <PARAM NAME="MOVIE" VALUE="nextback.swf?frameNum=' + frameNum + '">'
+ ' <PARAM NAME="PLAY" VALUE="true">'
+ ' <PARAM NAME="LOOP" VALUE="false">'
+ ' <PARAM NAME=bgcolor VALUE=#FFFF00>'
+ ' <PARAM NAME="QUALITY" VALUE="high">'
+ ' <PARAM NAME="MENU" VALUE="false">'
+ ' <EMBED SRC="nextback.swf?frameNum=' + frameNum + '"'
+ ' WIDTH=300 HEIGHT=30'
+ ' PLAY="true"'
+ ' LOOP="false"'
+ ' QUALITY="high"'
+ ' BGCOLOR=#FFFF00'
+ ' MENU="false"'
+ ' TYPE="application/x-shockwave-flash"'
+ ' PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
+ ' </EMBED> '
+ ' </OBJECT>'
+ ' <center>'
+ ' </body</html>';

getFrames();
FOOTER.document.open();
FOOTER.document.write(flashString);
FOOTER.document.close();
void 0;
}

// Structure for "go" functions:
// - Set correct page type and step number (these are globals)
// - Make sure we're showing the correct GIF image
// - Show/hide appropriate buttons and graphics even if it's not necessary;
//   this costs very little and is a bit more robust
// - Change the content page
// - Display the page type


function goRP()
{
	pageType = "RP";
	currentStep = 0;
	goToPage( "RP", 0 );
	showStatus();
}

function goINTRO()
{		
	pageType = "INTRO";
	currentStep = 0;
	goToPage( "INTRO", 0 );
	showStatus();
	getFrames();
//	FOOTER.displayFrame("intro");
	writeFooter("intro");
}

function goStep( stepNum )
{
	pageType = "S";
	currentStep = stepNum;
	getFrames();
//	FOOTER.displayFrame("step");
	writeFooter("step");
	goToPage("S", stepNum);
	showStatus();
}

function goTI()
{
	pageType = "TI";
	currentStep = 0;
	getFrames();
	writeFooter("tryit");
//	FOOTER.displayFrame("tryit");
	goToPage("TI", 0);
	showStatus();
}

function closeReview()
{
	top.close();
}

function restart()
{		
	window.parent.location = window.parent.location;
}

function problemsDone (scoreString){
	problemsDoneFlag = true;
	writeObj("scoreArea", scoreString);
	writeObj("bonusButton", exitButtonString);
	//alert("scoreString = " + scoreString);
	showStatus();
}

var exitButtonString = "<table width=180><tr><td align=right><a href='javascript:window.top.close();'><img src='../../../../ptt/ReviewImages/exit.gif' border=0></a></td></tr></table>";
function showStatus ()
{
	showHeaderStatus(currentStep, pageType);
	if (pageType == "RP" && problemsDoneFlag == true) {
		show("bonusButton");
		show("scoreArea");
	} else {
		hide("bonusButton");
		hide("scoreArea");
	}
}

function isEven(n)
{
	var x;
	x = ((n / 2) - (Math.floor(n / 2)));
	if (x == 0)
	{
		return true;
	} else {
		return false;
	}
}

function showHeaderStatus(stepNum, pageType )
{
	var theIMG = document["statusIMG"];
	
	if (pageType == "INTRO")
	{
		theIMG.src = introImage.src;
	} else if (pageType == "S") {
		if (stepNum == 1){
			theIMG.src = step1Image.src;
		} else if (stepNum == 2){
			theIMG.src = step2Image.src;
		} else if (stepNum == 3){
			theIMG.src = step3Image.src;

		} else if (stepNum == 4){
			theIMG.src = step4Image.src;

		} else if (stepNum == 5){
			theIMG.src = step5Image.src;

		} else if (stepNum == 6){
			theIMG.src = step6Image.src;
		}

	} else if (pageType == "TI") {
		theIMG.src = tiImage.src;
	} else if (pageType == "BN") {
		theIMG.src = bnImage.src;
	} else if (pageType == "RP") {
		theIMG.src = rpImage.src;
	}
}

