var ptable = [
	[1,"Hydrogen","H",1,1,"Nonmetal",false,false],
	[2,"Helium","He",1,18,"Noble gas",false,false],
	[3,"Lithium","Li",2,1,"Alkali metal",false,false],
	[4,"Beryllium","Be",2,2,"Alkaline earth metal",false,false],
	[5,"Boron","B",2,13,"Metalloid",false,false],
	[6,"Carbon","C",2,14,"Nonmetal",false,false],
	[7,"Nitrogen","N",2,15,"Nonmetal",false,false],
	[8,"Oxygen","O",2,16,"Nonmetal",false,false],
	[9,"Fluorine","F",2,17,"Halogen",false,false],
	[10,"Neon","Ne",2,18,"Noble gas",false,false],
	[11,"Sodium","Na",3,1,"Alkali metal",false,false],
	[12,"Magnesium","Mg",3,2,"Alkaline earth metal",false,false],
	[13,"Aluminium","Al",3,13,"Poor metal",false,false],
	[14,"Silicon","Si",3,14,"Metalloid",false,false],
	[15,"Phosphorus","P",3,15,"Nonmetal",false,false],
	[16,"Sulfur","S",3,16,"Nonmetal",false,false],
	[17,"Chlorine","Cl",3,17,"Halogen",false,false],
	[18,"Argon","Ar",3,18,"Noble gas",false,false],
	[19,"Potassium","K",4,1,"Alkali metal",false,false],
	[20,"Calcium","Ca",4,2,"Alkaline earth metal",false,false],
	[21,"Scandium","Sc",4,3,"Transition metal",false,false],
	[22,"Titanium","Ti",4,4,"Transition metal",false,false],
	[23,"Vanadium","V",4,5,"Transition metal",false,false],
	[24,"Chromium","Cr",4,6,"Transition metal",false,false],
	[25,"Manganese","Mn",4,7,"Transition metal",false,false],
	[26,"Iron","Fe",4,8,"Transition metal",false,false],
	[27,"Cobalt","Co",4,9,"Transition metal",false,false],
	[28,"Nickel","Ni",4,10,"Transition metal",false,false],
	[29,"Copper","Cu",4,11,"Transition metal",false,false],
	[30,"Zinc","Zn",4,12,"Transition metal",false,false],
	[31,"Gallium","Ga",4,13,"Poor metal",false,false],
	[32,"Germanium","Ge",4,14,"Metalloid",false,false],
	[33,"Arsenic","As",4,15,"Metalloid",false,false],
	[34,"Selenium","Se",4,16,"Nonmetal",false,false],
	[35,"Bromine","Br",4,17,"Halogen",false,false],
	[36,"Krypton","Kr",4,18,"Noble gas",false,false],
	[37,"Rubidium","Rb",5,1,"Alkali metal",false,false],
	[38,"Strontium","Sr",5,2,"Alkaline earth metal",false,false],
	[39,"Yttrium","Y",5,3,"Transition metal",false,false],
	[40,"Zirconium","Zr",5,4,"Transition metal",false,false],
	[41,"Niobium","Nb",5,5,"Transition metal",false,false],
	[42,"Molybdenum","Mo",5,6,"Transition metal",false,false],
	[43,"Technetium","Tc",5,7,"Transition metal",false,false],
	[44,"Ruthenium","Ru",5,8,"Transition metal",false,false],
	[45,"Rhodium","Rh",5,9,"Transition metal",false,false],
	[46,"Palladium","Pd",5,10,"Transition metal",false,false],
	[47,"Silver","Ag",5,11,"Transition metal",false,false],
	[48,"Cadmium","Cd",5,12,"Transition metal",false,false],
	[49,"Indium","In",5,13,"Poor metal",false,false],
	[50,"Tin","Sn",5,14,"Poor metal",false,false],
	[51,"Antimony","Sb",5,15,"Metalloid",false,false],
	[52,"Tellurium","Te",5,16,"Metalloid",false,false],
	[53,"Iodine","I",5,17,"Halogen",false,false],
	[54,"Xenon","Xe",5,18,"Noble gas",false,false],
	[55,"Caesium","Cs",6,1,"Alkali metal",false,false],
	[56,"Barium","Ba",6,2,"Alkaline earth metal",false,false],
	[57,"Lanthanum","La",6,0,"Lanthanide",false,false],
	[58,"Cerium","Ce",6,0,"Lanthanide",false,false],
	[59,"Praseodymium","Pr",6,0,"Lanthanide",false,false],
	[60,"Neodymium","Nd",6,0,"Lanthanide",false,false],
	[61,"Promethium","Pm",6,0,"Lanthanide",false,false],
	[62,"Samarium","Sm",6,0,"Lanthanide",false,false],
	[63,"Europium","Eu",6,0,"Lanthanide",false,false],
	[64,"Gadolinium","Gd",6,0,"Lanthanide",false,false],
	[65,"Terbium","Tb",6,0,"Lanthanide",false,false],
	[66,"Dysprosium","Dy",6,0,"Lanthanide",false,false],
	[67,"Holmium","Ho",6,0,"Lanthanide",false,false],
	[68,"Erbium","Er",6,0,"Lanthanide",false,false],
	[69,"Thulium","Tm",6,0,"Lanthanide",false,false],
	[70,"Ytterbium","Yb",6,0,"Lanthanide",false,false],
	[71,"Lutetium","Lu",6,3,"Lanthanide",false,false],
	[72,"Hafnium","Hf",6,4,"Transition metal",false,false],
	[73,"Tantalum","Ta",6,5,"Transition metal",false,false],
	[74,"Tungsten","W",6,6,"Transition metal",false,false],
	[75,"Rhenium","Re",6,7,"Transition metal",false,false],
	[76,"Osmium","Os",6,8,"Transition metal",false,false],
	[77,"Iridium","Ir",6,9,"Transition metal",false,false],
	[78,"Platinum","Pt",6,10,"Transition metal",false,false],
	[79,"Gold","Au",6,11,"Transition metal",false,false],
	[80,"Mercury","Hg",6,12,"Transition metal",false,false],
	[81,"Thallium","Tl",6,13,"Poor metal",false,false],
	[82,"Lead","Pb",6,14,"Poor metal",false,false],
	[83,"Bismuth","Bi",6,15,"Poor metal",false,false],
	[84,"Polonium","Po",6,16,"Metalloid",false,false],
	[85,"Astatine","At",6,17,"Halogen",false,false],
	[86,"Radon","Rn",6,18,"Noble gas",false,false],
	[87,"Francium","Fr",7,1,"Alkali metal",false,false],
	[88,"Radium","Ra",7,2,"Alkaline earth metal",false,false],
	[89,"Actinium","Ac",7,0,"Actinide",false,false],
	[90,"Thorium","Th",7,0,"Actinide",false,false],
	[91,"Protactinium","Pa",7,0,"Actinide",false,false],
	[92,"Uranium","U",7,0,"Actinide",false,false],
	[93,"Neptunium","Np",7,0,"Actinide",false,false],
	[94,"Plutonium","Pu",7,0,"Actinide",false,false],
	[95,"Americium","Am",7,0,"Actinide",false,false],
	[96,"Curium","Cm",7,0,"Actinide",false,false],
	[97,"Berkelium","Bk",7,0,"Actinide",false,false],
	[98,"Californium","Cf",7,0,"Actinide",false,false],
	[99,"Einsteinium","Es",7,0,"Actinide",false,false],
	[100,"Fermium","Fm",7,0,"Actinide",false,false],
	[101,"Mendelevium","Md",7,0,"Actinide",false,false],
	[102,"Nobelium","No",7,0,"Actinide",false,false],
	[103,"Lawrencium","Lr",7,3,"Actinide",false,false],
	[104,"Rutherfordium","Rf",7,4,"Transition metal",false,false],
	[105,"Dubnium","Db",7,5,"Transition metal",false,false],
	[106,"Seaborgium","Sg",7,6,"Transition metal",false,false],
	[107,"Bohrium","Bh",7,7,"Transition metal",false,false],
	[108,"Hassium","Hs",7,8,"Transition metal",false,false],
	[109,"Meitnerium","Mt",7,9,"Transition metal",false,false],
	[110,"Darmstadtium","Ds",7,10,"Transition metal",false,false],
	[111,"Roentgenium","Rg",7,11,"Transition metal",false,false],
	[112,"Ununbium","Uub",7,12,"Transition metal",false,false],
	[113,"Ununtrium","Uut",7,13,"Poor metal",false,false],
	[114,"Ununquadium","Uuq",7,14,"Poor metal",false,false],
	[115,"Ununpentium","Uup",7,15,"Poor metal",false,false],
	[116,"Ununhexium","Uuh",7,16,"Poor metal",false,false],
	[117,"Ununseptium","Uus",7,17,"Halogen",false,false],
	[118,"Ununoctium","Uuo",7,18,"Noble gas",false,false]
	]
	
var ptable_games = [
		[],
		[	"What's that symbol?",
			"We'll show you an element's full name and its location on the periodic table - you'll need to type in the correct symbol for the element (eg. 'Hydrogen' has the symbol 'H'). You can make as many guesses as you like for each element with no penalty. If you really can't get one, just click the <i>Don't Know</i> button to skip on to the next one. You'll have just 10 minutes to score as many as you can!",
			"Submit",
			"Don't know"
		],
		[	"How many can you name?",
			"You'll have just 10 minutes to type in as many elements' full names as you can - we'll fill in all the symbols on the table before you start, which ought to be a little help",
			"Submit",
			"Give up"
		],
		[	"What's that element?",
			"We'll show you an element's location on the periodic table and fill in its symbol - you'll need to type in the correct name of the element. You can make as many guesses as you like for each element with no penalty. If you really can't get one, just click the <i>Don't Know</i> button to skip on to the next one. You'll have just 10 minutes to score as many as you can!",
			"Submit",
			"Don't know"
		],
		[	"How many can you name?",
			"You'll have just 10 minutes to type in as many elements' full names as you can - we'll fill in the symbols on the table as you enter valid element names but you won't get any other help",
			"Submit",
			"Give up"
		],
		[	"What's that element?",
			"We'll show you just an element's location on the periodic table - you'll need to type in the correct name of the element. You can make as many guesses as you like for each element with no penalty. If you really can't get one, just click the <i>Don't Know</i> button to skip on to the next one. You'll have just 10 minutes to score as many as you can!",
			"Submit",
			"Don't know"
		]
	]
	
var ptable_game = 0;
var ptable_gamealarm = 0;
var ptable_gamescore = 0;
var ptable_gameanswer = "";
var ptable_gametarget = 0;
var ptable_endfeedback = 0;
	
function ptable_Ready() {
	setInterval("ptable_Core()",25);
	
	ptable_FlushGuess();
	ptable_FlushScore();
}
function ptable_BlankTable() {
	var i = -1;
	while (++i < ptable.length) {
		document.getElementById("ptable_c"+(i+1)).innerHTML = "&nbsp;";
	}
}
function ptable_FillSymbols() {
	var i = -1;
	while (++i < ptable.length) {
		document.getElementById("ptable_c"+(i+1)).innerHTML = ptable[i][2];
	}
}
function ptable_DescribeGame() {
	document.getElementById("ptable_interface_help").style.display = "block";
	document.getElementById("ptable_interface_game").style.display = "none";
	document.getElementById("ptable_interface_over").style.display = "none";

	var g = ptable_games[ptable_game];
	
	document.getElementById("ptable_gamename").innerHTML = g[0];
	document.getElementById("ptable_gamedesc").innerHTML = g[1];
	ptable_SetButtons( g[2], g[3] );
}
function ptable_StartCountdown(n) {
	document.getElementById("ptable_status1name").innerHTML = "Time Left:";
	document.getElementById("ptable_status1value").innerHTML = ""+n+":00";
	
	ptable_gamealarm = new Date().getTime() + (60000 * n);
}
function ptable_FlushScore() {
	var i = -1;
	while (++i < ptable.length) {
		ptable[i][6] = false;
	}
	
	document.getElementById("ptable_status2name").innerHTML = "Your Score:";
	document.getElementById("ptable_status2value").innerHTML = "0";
	
	ptable_gamescore = 0;
}
function ptable_FlushGuess() {
	document.getElementById("ptable_guess").value = "";
	document.getElementById("ptable_guess").focus();
}
function ptable_Highlight(z) {
	var e = document.getElementById("ptable_c"+(z+1));
	setClassAspect(e,"hi");
}
function ptable_Lowlight(z) {
	var e = document.getElementById("ptable_c"+(z+1));
	clearClassAspect(e,"hi");
}
function ptable_LowlightAll() {
	var i = -1;
	while (++i < ptable.length) {
		ptable_Lowlight(i);
	}
}
function ptable_Got(z) {
	ptable[z][7]=true;
}
function ptable_Ungot(z) {
	ptable[z][7]=false;
}
function ptable_UngotAll() {
	var i = -1;
	while (++i < ptable.length) {
		ptable_Ungot(i);
	}
}
function ptable_Done(z) {
	var e = document.getElementById("ptable_c"+(z+1));
	ptable[z][6]=true;
	setClassAspect(e,"done");
}
function ptable_Undone(z) {
	var e = document.getElementById("ptable_c"+(z+1));
	ptable[z][6]=false;
	clearClassAspect(e,"done");
}
function ptable_UndoneAll() {
	var i = -1;
	while (++i < ptable.length) {
		ptable_Undone(i);
	}
}
function ptable_Score(n) {
	ptable_gamescore += n;
	document.getElementById("ptable_status2value").innerHTML = "<b>"+ptable_gamescore+"</b>";
}
function ptable_Feedback(b,f,s) {
	ptable_endfeedback = new Date().getTime()+2000;
	var e = document.getElementById("ptable_feedback");
	e.style.backgroundColor = b;
	e.style.color			= f;
	e.innerHTML				= s;
}
function ptable_ShowSymbol(z) {
	document.getElementById("ptable_c"+(z+1)).innerHTML = ptable[z][2];
}
function ptable_IsValidName(n) {
	var i = -1;
	while (++i < ptable.length) {
		if (compare(ptable[i][1],n)) return i;
	}
	return -1;
}
function ptable_SetButtons(a,b) {
	if (a===null) {
		document.getElementById("ptable_button1").style.visibility = "hidden";
	} else {
		document.getElementById("ptable_button1").style.visibility = "visible";
		document.getElementById("ptable_button1").value = a;
	}
	if (b===null) {
		document.getElementById("ptable_button2").style.visibility = "hidden";
	} else {
		document.getElementById("ptable_button2").style.visibility = "visible";
		document.getElementById("ptable_button2").value = b;
	}
}
function ptable_YouMissed() {
	var i = -1;
	var r = "";
	while (++i < ptable.length) {
		if (ptable[i][7]==false) {
			r += "#"+(i+1)+". "+ptable[i][1]+" ("+ptable[i][2]+")<br>";
		}
	}
	return r;
}
function ptable_PickFree() {
	var c = 0;
	var i = -1;
	while (++i < ptable.length) if(ptable[i][6]==false) c+=1;
	if (c==0) return -1;

	do {	
		c = Math.floor( Math.random()*ptable.length );
	} while (ptable[c][6]==true);
	
	return c;
}

/*
** Game Start / Stop
*/
function ptable_game_Start() {
	document.getElementById("ptable_interface_help").style.display = "none";
	document.getElementById("ptable_interface_game").style.display = "block";
	document.getElementById("ptable_interface_over").style.display = "none";
	
	if (ptable_game==1) {
		ptable_game1_Start();
	} else if (ptable_game==2) {
		ptable_game2_Start();
	} else if (ptable_game==3) {
		ptable_game3_Start();
	} else if (ptable_game==4) {
		ptable_game4_Start();
	} else if (ptable_game==5) {
		ptable_game5_Start();
	} 
}
function ptable_game_Over() {
	document.getElementById("ptable_interface_help").style.display = "none";
	document.getElementById("ptable_interface_game").style.display = "none";
	document.getElementById("ptable_interface_over").style.display = "block";
	
	if (ptable_game==1) {
		ptable_game1_Over();
	} else if (ptable_game==2) {
		ptable_game2_Over();
	} else if (ptable_game==3) {
		ptable_game3_Over();
	} else if (ptable_game==4) {
		ptable_game4_Over();
	} else if (ptable_game==5) {
		ptable_game5_Over();
	} 
}

/*
** Game #1
*/
function ptable_game1() {
	ptable_game = 1;
	ptable_DescribeGame();
	ptable_BlankTable();
	ptable_UndoneAll();
	ptable_UngotAll();
	ptable_LowlightAll();
}
function ptable_game1_Start() {
	document.getElementById("ptable_interface_game").style.display = "block";
	ptable_FlushScore();
	ptable_FlushGuess();
	ptable_StartCountdown(10);
	ptable_Turn();
}
function ptable_game1_Turn() {
	var z = ptable_PickFree();
	if (z<0) {
		ptable_game_Over();
		return;
	} else {
		ptable[z][6] = true;
		ptable_Highlight(z);
		ptable_gameanswer = ptable[z][2];
		ptable_gametarget = z;
		document.getElementById("ptable_status3name").innerHTML = "Enter the <b>Symbol</b> for";
		document.getElementById("ptable_status3value").innerHTML = ptable[z][1];
	}
}
function ptable_game1_Over() {
	var e = document.getElementById("ptable_interface_over");
	e.innerHTML = "<h3>Game Over</h3><p>You scored <b>"+ptable_gamescore+"</b> out of a possible <b>"+ptable.length+"</b>.</p><p>You missed:<br>"+ptable_YouMissed()+"</p>";
}
/*
** Game #2
*/
function ptable_game2() {
	ptable_game = 2;
	ptable_DescribeGame();
	ptable_BlankTable();
	ptable_FillSymbols();
	ptable_UndoneAll();
	ptable_UngotAll();
	ptable_LowlightAll();
}
function ptable_game2_Start() {
	document.getElementById("ptable_interface_game").style.display = "block";
	ptable_FlushScore();
	ptable_FlushGuess();
	ptable_StartCountdown(10);
}
function ptable_game2_Over() {
	var e = document.getElementById("ptable_interface_over");
	e.innerHTML = "<h3>Game Over</h3><p>You scored <b>"+ptable_gamescore+"</b> out of a possible <b>"+ptable.length+"</b>.</p><p>You missed:<br>"+ptable_YouMissed()+"</p>";
}
/*
** Game #3
*/
function ptable_game3() {
	ptable_game = 3;
	ptable_DescribeGame();
	ptable_BlankTable();
	ptable_UndoneAll();
	ptable_UngotAll();
	ptable_LowlightAll();
}
function ptable_game3_Start() {
	document.getElementById("ptable_interface_game").style.display = "block";
	ptable_FlushScore();
	ptable_FlushGuess();
	ptable_StartCountdown(10);
	ptable_Turn();
}
function ptable_game3_Turn() {
	var z = ptable_PickFree();
	if (z<0) {
		ptable_game_Over();
		return;
	} else {
		ptable[z][6] = true;
		ptable_Highlight(z);
		ptable_ShowSymbol(z);
		ptable_gameanswer = ptable[z][1];
		ptable_gametarget = z;
		document.getElementById("ptable_status3name").innerHTML = "Enter the <b>Name</b> for";
		document.getElementById("ptable_status3value").innerHTML = ptable[z][2];
	}
}
function ptable_game3_Over() {
	var e = document.getElementById("ptable_interface_over");
	e.innerHTML = "<h3>Game Over</h3><p>You scored <b>"+ptable_gamescore+"</b> out of a possible <b>"+ptable.length+"</b>.</p><p>You missed:<br>"+ptable_YouMissed()+"</p>";
}
/*
** Game #4
*/
function ptable_game4() {
	ptable_game = 4;
	ptable_DescribeGame();
	ptable_BlankTable();
	ptable_UndoneAll();
	ptable_UngotAll();
	ptable_LowlightAll();
}
function ptable_game4_Start() {
	document.getElementById("ptable_interface_game").style.display = "block";
	ptable_FlushScore();
	ptable_FlushGuess();
	ptable_StartCountdown(10);
}
function ptable_game4_Over() {
	var e = document.getElementById("ptable_interface_over");
	e.innerHTML = "<h3>Game Over</h3><p>You scored <b>"+ptable_gamescore+"</b> out of a possible <b>"+ptable.length+"</b>.</p><p>You missed:<br>"+ptable_YouMissed()+"</p>";
}
/*
** Game #5
*/
function ptable_game5() {
	ptable_game = 5;
	ptable_DescribeGame();
	ptable_BlankTable();
	ptable_UndoneAll();
	ptable_UngotAll();
	ptable_LowlightAll();
}
function ptable_game5_Start() {
	document.getElementById("ptable_interface_game").style.display = "block";
	ptable_FlushScore();
	ptable_FlushGuess();
	ptable_StartCountdown(10);
	ptable_Turn();
}
function ptable_game5_Turn() {
	var z = ptable_PickFree();
	if (z<0) {
		ptable_game_Over();
		return;
	} else {
		ptable[z][6] = true;
		ptable_Highlight(z);
		ptable_gameanswer = ptable[z][1];
		ptable_gametarget = z;
		document.getElementById("ptable_status3name").innerHTML = "Enter the <b>Name</b> for";
		document.getElementById("ptable_status3value").innerHTML = "Element #"+ptable[z][0];
	}
}
function ptable_game5_Over() {
	var e = document.getElementById("ptable_interface_over");
	e.innerHTML = "<h3>Game Over</h3><p>You scored <b>"+ptable_gamescore+"</b> out of a possible <b>"+ptable.length+"</b>.</p><p>You missed:<br>"+ptable_YouMissed()+"</p>";
}

/*
** All-Games - Common
*/
function ptable_Core() {
	var now = new Date().getTime();
	
	if (ptable_gamealarm!=0) {
		var t = ptable_gamealarm-now;
		if (t>0) {
			t = Math.floor( t / 1000);
			var m = Math.floor( t / 60 );
			var s = t-(60*m);
			document.getElementById("ptable_status1value").innerHTML = ""+m+":"+pad(s,2);
		} else {
			ptable_Timeout();
		}
	}
	
	if ((ptable_endfeedback>0) && (now>ptable_endfeedback)) {
		var e = document.getElementById("ptable_feedback");
		e.style.backgroundColor 	= "white";
		e.style.color			 	= "black";
		e.innerHTML					= "&nbsp;";
	}
}
function ptable_Turn() {
	if (ptable_game==1) {
		ptable_game1_Turn();
	} else if (ptable_game==2) {
		//nop
	} else if (ptable_game==3) {
		ptable_game3_Turn();
	} else if (ptable_game==4) {
		//nop
	} else if (ptable_game==5) {
		ptable_game5_Turn();
	}
}
function ptable_Submit() {
	if (ptable_game==1) {
		var g = document.getElementById("ptable_guess").value;
		if (compare(g,ptable_gameanswer)) {
			ptable_Lowlight(ptable_gametarget);
			ptable_Done(ptable_gametarget);
			ptable_Got(ptable_gametarget);
			ptable_ShowSymbol(ptable_gametarget);
			ptable_Score(1);
			ptable_FlushGuess();
			ptable_Feedback("darkgreen","white","CORRECT!");
			ptable_Turn();
		} else {
			ptable_FlushGuess();
			ptable_Feedback("red","white","incorrect");
		}
	} else if (ptable_game==2) {
		var g = strtolower(trim(document.getElementById("ptable_guess").value));
		var v = ptable_IsValidName(g)
		if (v>=0) {
			if (ptable[v][6]==true) {
				ptable_FlushGuess();
				ptable_Feedback("darkgray","white","already got that one");
			} else {
				ptable_LowlightAll();
				ptable_Done(v);
				ptable_Got(v);
				ptable_Score(1);
				ptable_Feedback("darkgreen","white","CORRECT!");
				ptable_FlushGuess();
			}
		} else {
			ptable_Feedback("red","white","try again");
			ptable_FlushGuess();
		}
	} else if (ptable_game==3) {
		var g = document.getElementById("ptable_guess").value;
		if (compare(g,ptable_gameanswer)) {
			ptable_Lowlight(ptable_gametarget);
			ptable_Done(ptable_gametarget);
			ptable_Got(ptable_gametarget);
			ptable_ShowSymbol(ptable_gametarget);
			ptable_Score(1);
			ptable_FlushGuess();
			ptable_Feedback("darkgreen","white","CORRECT!");
			ptable_Turn();
		} else {
			ptable_FlushGuess();
			ptable_Feedback("red","white","incorrect");
		}
	} else if (ptable_game==4) {
		var g = strtolower(trim(document.getElementById("ptable_guess").value));
		var v = ptable_IsValidName(g)
		if (v>=0) {
			if (ptable[v][6]==true) {
				ptable_FlushGuess();
				ptable_Feedback("darkgray","white","already got that one");
			} else {
				ptable_LowlightAll();
				ptable_Done(v);
				ptable_Got(v);
				ptable_ShowSymbol(v);
				ptable_Score(1);
				ptable_Feedback("darkgreen","white","CORRECT!");
				ptable_FlushGuess();
			}
		} else {
			ptable_Feedback("red","white","try again");
			ptable_FlushGuess();
		}
	} else if (ptable_game==5) {
		var g = document.getElementById("ptable_guess").value;
		if (compare(g,ptable_gameanswer)) {
			ptable_Lowlight(ptable_gametarget);
			ptable_Done(ptable_gametarget);
			ptable_Got(ptable_gametarget);
			ptable_ShowSymbol(ptable_gametarget);
			ptable_Score(1);
			ptable_FlushGuess();
			ptable_Feedback("darkgreen","white","CORRECT!");
			ptable_Turn();
		} else {
			ptable_FlushGuess();
			ptable_Feedback("red","white","incorrect");
		}
	}
}
function ptable_NoAnswer() {
	if (ptable_game==1) {
		ptable_Feedback("lightblue","black","The answer was <tt>'"+ptable[ptable_gametarget][2]+"'</tt>");
		ptable_Lowlight(ptable_gametarget);
		ptable_ShowSymbol(ptable_gametarget);
	} else if (ptable_game==2) {
		ptable_gamealarm = new Date().getTime();
	} else if (ptable_game==3) {
		ptable_Feedback("lightblue","black","The answer was <tt>'"+ptable[ptable_gametarget][1]+"'</tt>");
		ptable_Lowlight(ptable_gametarget);
		ptable_ShowSymbol(ptable_gametarget);
	} else if (ptable_game==4) {
		ptable_gamealarm = new Date().getTime();
	} else if (ptable_game==5) {
		ptable_Feedback("lightblue","black","The answer was <tt>'"+ptable[ptable_gametarget][1]+"' ('"+ptable[ptable_gametarget][2]+"')</tt>");
		ptable_Lowlight(ptable_gametarget);
		ptable_ShowSymbol(ptable_gametarget);
	}
	ptable_FlushGuess();
	ptable_Turn();
}
function ptable_Timeout() {
	ptable_gamealarm = 0;
	ptable_Feedback("black","red","TIME'S UP!");
	ptable_SetButtons(null,null);
	ptable_game_Over();
}


/*
** Utils
*/
function compare(a,b) {
	a = trim(a.toLowerCase());
	b = trim(b.toLowerCase());
	if (a==b) {
		return true;
	} else {
		return false;
	}
}
function pad(v,l) {
	v = ""+v;
	while (v.length < l) v="0"+v;
	return v;
}
function endsWith(str,sub) {
   return ( ( str.substring( str.length ) - sub.length ) == sub );
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function strtolower(n) {
	return (""+n).toLowerCase();
}
function toggleClassAspect(e,n) {
	if (typeof(e)!="undefined") {
		if ((e.className) && (e.className!="")) {
			if (e.className==n) {
				e.className = "";
			} else if (e.className.indexOf(n)>0) {
				e.className = e.className.substring(0,e.className.indexOf(n)-1);
			} else {
				e.className = e.className + " " + n;
			}
		} else {
			e.className = n;
		}
	}
}
function setClassAspect(e,n) {
	if (typeof(e)!="undefined") {
		if (e.className=="") {
			e.className = n;
		} else if (e.className.indexOf(n) > -1) {
			e.className = e.className + " " + n;
		}
	}
}
function clearClassAspect(e,n) {
	if (typeof(e)!="undefined") {
		if ((e.className) && (e.className!="")) {
			if (e.className==n) {
				e.className = "";
			} else if (e.className.indexOf(n)>0) {
				e.className = e.className.substring(0,e.className.indexOf(n)-1);
			}
		}
	}
}
