
//create an array of sounds and hints
var sounds=new Array();
var soundHints=new Array();

sounds[0]="z,s,soft c";
soundHints[0]="z for zero";
sounds[1]="t,th,d";
soundHints[1]="t has one downstroke";
sounds[2]="n";
soundHints[2]="n has two down strokes";
sounds[3]="m";
soundHints[3]="m has three down strokes";
sounds[4]="r";
soundHints[4]="last sound in four";
sounds[5]="l";
soundHints[5]="Roman Numeral for 50 is L";
sounds[6]="j,sh,ch,soft g";
soundHints[6]="reversed j looks like a 6";
sounds[7]="k,q,hard c,hard g";
soundHints[7]="k is made of two 7's";
sounds[8]="f,v";
soundHints[8]="script f resembles an 8";
sounds[9]="p,b";
soundHints[9]="reversed p is a 9";					

//create arrays of words and hints
var words=new Array();
var hints=new Array();
words[0]="Ice";
hints[0]="keeps things cold";
words[1]="Tea";
hints[1]="Hot Drink";
words[2]="Honey";
hints[2]="Sweet Syrup";
words[3]="Ammo";
hints[3]="Used in weapons";
words[4]="Arrow";
hints[4]="Robin Hood Had Lots";
words[5]="Owl";
hints[5]="Noctural Bird of prey";
words[6]="Shoe";
hints[6]="Protects your foot";
words[7]="Key";
hints[7]="Opens a lock";
words[8]="Wave";
hints[8]="sea has lots of them";
words[9]="Bee";
hints[9]="Insect that polinates flowers";
words[10]="Dice";
hints[10]="Six sided cube";
words[11]="Tattoo";
hints[11]="Permanent design etched into skin";
words[12]="Tin";
hints[12]="Stores food";
words[13]="Dam";
hints[13]="Contained body of water";
words[14]="Door";
hints[14]="Secures the entrance to a room";
words[15]="Doll";
hints[15]="Little girls play with them";
words[16]="Dish";
hints[16]="We eat our food from this";
words[17]="Dog";
hints[17]="A domesticated 4 legged pet ";
words[18]="TV";
hints[18]="Electronic device which shows moving pictures and sound";
words[19]="Tap";
hints[19]="We get water on demand from this";
words[20]="Nose";
hints[20]="We can smell with this";
words[21]="Nut";
hints[21]="Tasty seed of a plant";
words[22]="Nanny";
hints[22]="Person who looks after children";
words[23]="Gnome";
hints[23]="A mythical creature living in your garden";
words[24]="Nero";
hints[24]="Was a cruel Roman emperor";
words[25]="Nail";
hints[25]="Small pointed metal item to fix things to walls";
words[26]="Hinge";
hints[26]="Allows something to open or close";
words[27]="Neck";
hints[27]="Keeps your head straight";
words[28]="Knife";
hints[28]="sharp metal object used to cut things";
words[29]="Nappy";
hints[29]="Babies need to wear these ";
words[30]="Maze";
hints[30]="You can get lost in this";
words[31]="Mat";
hints[31]="You can wipe your feet on this";
words[32]="Man";
hints[32]="Male person";
words[33]="Mom";
hints[33]="Person who brought us into this world";
words[34]="Hammer";
hints[34]="Tool used to hit something";
words[35]="Mail";
hints[35]="Letters from the postoffice";
words[36]="Match";
hints[36]="Can create fire";
words[37]="Mic";
hints[37]="Helps amplify your voice";
words[38]="Movie";
hints[38]="Moving pictures with sound";
words[39]="Map";
hints[39]="When you are lost ...";
words[40]="Rice";
hints[40]="staple Chinese diet";
words[41]="Rat";
hints[41]="Unhealthy rodent ";
words[42]="Rain";
hints[42]="Noah knew all about this";
words[43]="Room";
hints[43]="A house has many of these";
words[44]="Warrior";
hints[44]="Ancent brave soldier";
words[45]="Rail";
hints[45]="Trains travel on this";
words[46]="Rash";
hints[46]="Allergies often cause this";
words[47]="Rake";
hints[47]="Garden tool ";
words[48]="Roof";
hints[48]="Protects a building from the weather";
words[49]="Rope";
hints[49]="Flexible material used to secure things";
words[50]="Lice";
hints[50]="Some kids have this in their hair";
words[51]="Light";
hints[51]="The sun generates this";
words[52]="Lion";
hints[52]="Brave carnivore";
words[53]="Lamb";
hints[53]="Meek, woolly and tasty";
words[54]="Lorry";
hints[54]="Vehicle to carry goods";
words[55]="Lilly";
hints[55]="White flower";
words[56]="Leech";
hints[56]="Blood sucking creature";
words[57]="Lock";
hints[57]="Protects doors from unlawful entry";
words[58]="Leaf";
hints[58]="Found on trees";
words[59]="Lip";
hints[59]="Attached to a mouth";
words[60]="Cheese";
hints[60]="Mice love this";
words[61]="Jet";
hints[61]="Fast mode of transport";
words[62]="Chain";
hints[62]="Normally attached to a lock";
words[63]="Gym";
hints[63]="We lose something here";
words[64]="Chair";
hints[64]="Sit here";
words[65]="Jail";
hints[65]="Bad people go here";
words[66]="Judge";
hints[66]="Uses a gavel";
words[67]="Jack";
hints[67]="Used to lift up a car";
words[68]="Chef";
hints[68]="Prepares yummy food";
words[69]="Jeep";
hints[69]="Offroad vehicle";
words[70]="Case";
hints[70]="Carries things";
words[71]="Kite";
hints[71]="Kids fly this";
words[72]="Gun";
hints[72]="Weapon with a trigger";
words[73]="Comb";
hints[73]="Hair needs this every day";
words[74]="Car";
hints[74]="Common mode of transport";
words[75]="Clay";
hints[75]="Makes pottery";
words[76]="Cage";
hints[76]="zoos need these";
words[77]="Cake";
hints[77]="Birthday candles go here";
words[78]="Coffee";
hints[78]="Aeromatic drink made from the coco plant";
words[79]="Cup";
hints[79]="Container for drinks";
words[80]="Face";
hints[80]="Everyone has a unique one except identical twins";
words[81]="Foot";
hints[81]="Used for walking";
words[82]="Fan";
hints[82]="Keeps you cool";
words[83]="Foam";
hints[83]="White bubbles";
words[84]="Fire";
hints[84]="Hot form of energy";
words[85]="Fly";
hints[85]="Irritating insect";
words[86]="Fish";
hints[86]="Edible Water animal";
words[87]="Fog";
hints[87]="Prevents drivers from seeing clearly";
words[88]="Fifi";
hints[88]="Rich persons dog";
words[89]="VIP";
hints[89]="A celebrity";
words[90]="Bus";
hints[90]="Mass road transport";
words[91]="Bat";
hints[91]="Normally used with a ball";
words[92]="Pan";
hints[92]="Container for frying food";
words[93]="Bomb";
hints[93]="Terrorists use this";
words[94]="Bear";
hints[94]="Yogi is a famous one";
words[95]="Ball";
hints[95]="Round object normally hit with a bat";
words[96]="Badge";
hints[96]="Metal object that can be pinned to your shirt";
words[97]="Bike";
hints[97]="Two wheeled object";
words[98]="Beehive";
hints[98]="You'll find lots of honey here";
words[99]="Baby";
hints[99]="We were all once one";

//initialize wordlist quiz variables
var number=null;
var questionsAsked=0;
var questionsCorrect=0;
var questionsIncorrect=0;
var percentage=0;

//initialize alphabet quiz variables
var mnumber=null;
var msound=null;
var mquestionsAsked=0;
var mquestionsCorrect=0;
var mquestionsIncorrect=0;
var mpercentage=0;

function init()
{
	resetScore();
	resetmScore();
}

//reset the for score for the worlist quiz
function resetScore()
{
	questionsAsked=0;
	questionsCorrect=0;
	questionsIncorrect=0;
	percentage=0;
	document.getElementById("hints").innerHTML="";
	document.getElementById("questionsAsked").innerHTML=questionsAsked;
	document.getElementById("questionsCorrect").innerHTML=questionsCorrect;
	document.getElementById("percentage").innerHTML=percentage + "%";
	document.getElementById("questionsIncorrect").innerHTML=questionsIncorrect;
	document.getElementById("incorrectNumbers").innerHTML="";
	document.getElementById("numbersTested").innerHTML="";
	getNumber();
}

//reset the for score for the alphabet quiz
function resetmScore()
{
	mquestionsAsked=0;
	mquestionsCorrect=0;
	mquestionsIncorrect=0;
	mpercentage=0;
	document.getElementById("mquestionsAsked").innerHTML=mquestionsAsked;
	document.getElementById("mquestionsCorrect").innerHTML=mquestionsCorrect;
	document.getElementById("mpercentage").innerHTML=mpercentage + "%";
	document.getElementById("mquestionsIncorrect").innerHTML=mquestionsIncorrect;
	getmSound();
}

//calculate percentage correct for both quizes
function calcPercentage(qc,qa)
{
	var p=qc/qa*100;
	p=Math.round(p*100)/100;
	return p;
}

//get a hint for the word list quiz
function getHint()
{
	document.getElementById("hint").innerHTML=hints[number];
	document.getElementById("hints").innerHTML+=number+" ";
}

//lookup the word if they give up for the wordlist quiz
function getWord()
{
	document.wordform.word.style.background="navy";
	document.wordform.word.style.color="white";
	document.wordform.word.value=words[number];
	if (questionsCorrect+questionsIncorrect < questionsAsked)
	{
		questionsIncorrect++;
		document.getElementById("questionsIncorrect").innerHTML=questionsIncorrect;
	}
}

//lookup the number if they give up for the alphabet quiz
function getmNumber()
{
	document.alphabetform.mnumber.style.background="navy";
	document.alphabetform.mnumber.style.color="white";
	document.alphabetform.mnumber.value=mnumber;
	if (mquestionsCorrect+mquestionsIncorrect < mquestionsAsked)
	{
		mquestionsIncorrect++;
		document.getElementById("mquestionsIncorrect").innerHTML=mquestionsIncorrect;
	}	
}

//get a sound hint for the wordlist quiz
function getSoundHint()
{
	var sound="";
	var numstring=number.toString();
	for (var x=0;x<numstring.length;x++)
	{
		var num=numstring.charAt(x);
		sound+=sounds[num];
		if (numstring.length-1 > x)
			sound+=" ....... ";
	}
	document.getElementById("sound").innerHTML=sound;
}

//get a new random number for the wordlist quiz
function getNumber()
{
	document.getElementById("hint").innerHTML="";
	document.getElementById("sound").innerHTML="";
	document.wordform.word.value="";
	document.wordform.word.style.background="white";
	document.wordform.word.style.color="black";
	//get a random number between 0 and 99
	number=Math.ceil(Math.random()*99);
	document.getElementById("number").innerHTML=number;
	questionsAsked++;
	document.getElementById("questionsAsked").innerHTML=questionsAsked;
}

//get a new number and then sound for the alphabet quiz
function getmSound()
{
	document.alphabetform.mnumber.value="";
	document.alphabetform.mnumber.style.background="white";
	document.alphabetform.mnumber.style.color="black";
	//get a random number from 0-9
	mnumber=Math.ceil(Math.random()*9);
	//get the possible sounds for this number
	var possibleSounds=sounds[mnumber].split(",");
	//get a random number between 0 and the number of possible sounds for this number
	var rnum=Math.ceil(Math.random()*possibleSounds.length-1);
	msound=possibleSounds[rnum];
	document.getElementById("msound").innerHTML=msound;
	mquestionsAsked++;
	document.getElementById("mquestionsAsked").innerHTML=mquestionsAsked;
}

//check that the word entered is correct for the wordlist quiz
function checkWord()
{
	//only evaluate their answer if this is the first time they are submitting
	if (questionsCorrect+questionsIncorrect < questionsAsked)
	{
		document.wordform.word.style.color="white";
		//if correct
		if (document.wordform.word.value.toLowerCase()==words[number].toLowerCase())
		{
			document.getElementById("numbersTested").innerHTML+=number + " ";
			questionsCorrect++;
			percentage=calcPercentage(questionsCorrect,questionsAsked);
			document.getElementById("percentage").innerHTML=percentage + "%";
			document.getElementById("questionsCorrect").innerHTML=questionsCorrect;	
			document.wordform.word.style.background="green";
		}
		//if incorrect
		else
		{
			document.getElementById("numbersTested").innerHTML+=number + " ";
			questionsIncorrect++;
			document.getElementById("incorrectNumbers").innerHTML+=number + " ";
			percentage=calcPercentage(questionsCorrect,questionsAsked);
			document.getElementById("percentage").innerHTML=percentage + "%";
			document.wordform.word.style.background="red";
			document.getElementById("questionsIncorrect").innerHTML=questionsIncorrect;
		}
	}
}

//check that the number entered is correct for the alphabet quiz
function checkmNumber()
{
	//only evaluate their answer if this is the first time they are submitting
	if (mquestionsCorrect+mquestionsIncorrect < mquestionsAsked)
	{
		document.alphabetform.mnumber.style.color="white";
		//if correct
		if (document.alphabetform.mnumber.value==mnumber)
		{
			mquestionsCorrect++;
			mpercentage=calcPercentage(mquestionsCorrect,mquestionsAsked);
			document.getElementById("mpercentage").innerHTML=mpercentage + "%";
			document.getElementById("mquestionsCorrect").innerHTML=mquestionsCorrect;	
			document.alphabetform.mnumber.style.background="green";
		}
		//if incorrect
		else
		{
			mquestionsIncorrect++;
			mpercentage=calcPercentage(mquestionsCorrect,mquestionsAsked);
			document.getElementById("mpercentage").innerHTML=mpercentage + "%";
			document.alphabetform.mnumber.style.background="red";
			document.getElementById("mquestionsIncorrect").innerHTML=mquestionsIncorrect;
		}
	}
}

function toggle(lyr)
{
	var pic=lyr+"pic";
	var l=document.getElementById(lyr);
	var img=document.getElementById(pic);
	if (l.style.display=="none")
	{
		img.src="up.gif";
		l.style.display="block";
		var hash=lyr+"title";
		location.hash=hash;
	}
	else
	{
		l.style.display="none";
		img.src="down.gif";
	}
}

function go(lyr,lyr2)
{
	var hash=lyr+"title";
	var pic=lyr+"pic";
	var l=document.getElementById(lyr);
	var img=document.getElementById(pic);
	l.style.display="block";
	img.src="up.gif";
	if (lyr2!=null)
		document.getElementById(lyr2).style.display="block";
	location.hash=hash;
}

function check(f)
{
	var error="";
	if (f.name.value=="")
		error+="Please enter your name!\r\n";
	if (f.email.value.indexOf("@")==-1 || f.email.value.indexOf(".")==-1)
		error+="Please enter a valid email address!\r\n";
	if (f.comments.value=="")
		error+="Please enter your comments!\r\n";
	if (f.code.value.length!=6)
		error+="Please enter a valid security code!";
	if (error)
	{
		alert(error);
		return false;
	}
}