//  ############  MATH FLASH CARDS - JAN 17, 2003
//  ############  CREATED BY PATRICK LEWIS
//  ############  WWW.PATRICKLEWIS.NET
//  ############  VERSION 1.9

function BadBrowser () {
alert("           * * * * * A T T E N T I O N * * * * * \n\nThis page will not work with your browser.  \n\nUse either Netscape 6x or Internet Explorer 5x or higher.    ");
}

//   ##############  SIMPLE  BROWSER SNIFFER
if (document.layers) {navigator.family = "nn4"; BadBrowser();}
if (window.navigator.userAgent.toLowerCase().indexOf('opera') != -1) {navigator.family = "opera"; BadBrowser();}
if (document.all) {navigator.family = "ie4"}
if (window.navigator.userAgent.toLowerCase().indexOf('gecko') != -1) {navigator.family = "gecko";
	document.Flash.diff[0].setting = "Easy";
	document.Flash.diff[1].setting = "Medium";
	document.Flash.diff[2].setting = "Hard";
	document.Flash.diff[3].setting = "Expert";
	}
if (window.navigator.platform.toLowerCase().indexOf('mac') != -1) {navigator.OS = "mac";}
//PMF: Values for the timers for the slide show

var TimerID =0;
var TimerID1 =0;
var CorrectAns=0;
farray = new Array("+","-","*","/","+ -","+ - * /");
farray1 = new Array(5,10);
farray2 = new Array(2,4);
farray3 = new Array(3,6);
farray4 = new Array(2,3,4,5,10);
farray5 = new Array(7,7);
farray6 = new Array(8,9);
var seconds=5; 
var gamestart=true;
WriteMessage("d2", 5); 

RunGame();
display();

function StartGame() {
if (gamestart) {return;}
else {	gamestart=true; RunGame(); }
}

function RunGame() {
clearTimeout(TimerID);
if (!gamestart) {return;}
else {
       seconds=5;
       showProblem();
       TimerID = setTimeout("RunGame()",10*1000);
     }
}

function StopGame(){
if (!gamestart) {return;}
else {	gamestart=false;}
}


function showProblem () {
if (document.Flash.func.selectedIndex < 3) {
	MathSign = farray[document.Flash.func.selectedIndex];
	}
else {	RSign = farray[document.Flash.func.selectedIndex].split(" ");
	MathSign = RSign[Math.floor(Math.random() * RSign.length)];
	}
num1 = Math.floor(Math.random() * document.Flash.diff[document.Flash.diff.selectedIndex].value);
num2 = Math.floor(Math.random() * document.Flash.diff[document.Flash.diff.selectedIndex].value);

series = document.Flash.diff[document.Flash.diff.selectedIndex].value ;

if (series >  100) {
     num1 = Math.floor(Math.random() * 12) + 1;
}

if (series == 101) {
	num2 = farray1[Math.floor(Math.random() * farray1.length)]; }
else if ( series == 102 ) {	
	num2 = farray2[Math.floor(Math.random() * farray2.length)]; }
else if ( series == 103 ) {	
	num2 = farray3[Math.floor(Math.random() * farray3.length)]; }
else if ( series == 104 ) {	
	num2 = farray4[Math.floor(Math.random() * farray4.length)]; }
else if ( series == 105 ) {	
	num2 = farray5[Math.floor(Math.random() * farray5.length)]; }
else if ( series == 106 ) {	
	num2 = farray6[Math.floor(Math.random() * farray6.length)]; }


if (MathSign == "-") {
	if (num1 < num2) {
		temp=num1;
		num1=num2;
		num2=temp;
		}
	}
if (MathSign == "/") {
	CorrectAns = num1 * num2;
	if (CorrectAns == 0 && num2 == 0) {
		//  ####  THIS WILL PUT THE NON-ZERO NUMBER SECOND
		temp=num1;
		num1=num2;
		num2=temp;
		}
	else {
		tempy = num1;
		num1 = CorrectAns;
		CorrectAns = tempy;
		}
	}
else {	CorrectAns = eval(num1 + MathSign + num2);
	}	

WriteMessage("Q1" , num1);
WriteMessage("Q2" , num2);

if (MathSign == "*") 		{WriteMessage("Sign", "x");}
else if (MathSign == "/") 	{WriteMessage("Sign", "<img src=div.jpg>");}
else				{WriteMessage("Sign", MathSign);}


WriteMessage("Ans1" , " ? ");

TimerID1 = setTimeout("WriteAnswer(CorrectAns)",5*1000);
}

function WriteAnswer (ans) {
WriteMessage("Ans1" , ans);
}

function WriteMessage(where,what,addto) {
if (window.navigator.userAgent.toLowerCase().indexOf('gecko') != -1) {navigator.family = "gecko";}
if (addto) {
	if (navigator.family == "ie4")		{document.all[where].innerHTML += what;}
	if (navigator.family == "gecko")	{document.getElementById(where).innerHTML += what;}
	}
else {
	if (navigator.family == "ie4")		{document.all[where].innerHTML = what;}
	if (navigator.family == "gecko")	{document.getElementById(where).innerHTML = what;}
	}
}


function display(){ 

 if (seconds<=0){ 
    WriteMessage("d2", seconds); 
 } 
 else 
    seconds-=1 
    WriteMessage("d2", seconds); 
    setTimeout("display()",1000) 
} 

