<html>
<head>
<title>Word Categories Game - RJM Programming - May, 2014</title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>

var clone=null;
var totalclone=null;
var five=5;

// Thanks to Five-Minute Activities bt Penny Ur and Andrew Wright pp. 6-7
var elementary = ["food-drink","animals-objects","big-small","round-square","land-sea-air"];
var elementary_food_drink = ["-tea","apple","bread","-coffee","cake","-water","egg","meat","-beer","-milk","chocolate","potato","rice","pasta","-orange juice"];
var elementary_animals_objects = ["dog","-pencil","-chair","elephant","-door","man","lion","-book","-table","cat","horse","donkey","-television"];
var elementary_big_small = ["elephant","-mouse","-matchbox","house","-flower","mountain","-pencil","-cigarette","-egg","sea"];
var elementary_round_square = ["sun","-book","-blackboard","ball","-window","-door","moon","-television","flower","-house","ring","wheel","-desk"];
var elementary_land_sea_air = ["--cloud","earth","rain","-fish","tree","-wave","fog","--sky","field","-ship","road","mountain","--wind","-swimmer"];

var advanced = ["sad-happy","loud-soft","good-bad","superior-inferior","sick-healthy"];
var advanced_sad_happy = ["-smile","tears","-laugh","miserable","tragedy","-cheerful","-pleasure","depressing","-fortunate","-celebration","weep","-amusing","mourn","-joke","-delight"];
var advanced_loud_soft = ["shout","scream","-whisper","crash","-murmur","-rustle","roar","-hum","bang","-sigh","-squeak","cheer","thunder","-tick"];
var advanced_good_bad = ["ethical","-evil","-wicked","virtuous","-immoral","-naughty","-villainous","-faulty","saintly","perfect","excellent","-deplorable"];
var advanced_superior_inferior = ["-servant","queen","master","chief","-subordinate","commander","-assistant","-slave","captain","prince","-follower","head"];
var advanced_sick_healthy = ["-well","fever","-fit","-energetic","disease","pain","-flourishing","sickness","invalid","-blooming","collapse","coma","-fine"];
var nelementary = elementary.length;
var nadvanced = advanced.length;
var numdivs = 0;
var divstrs = [];
var divptrs = [];
var divnums = [];
var divstrnames = [];
var easnames = [];
var score = 0;
var goes = 0;

function check(bis) {
var plusbit = 0, jj, oois;
goes = goes + 1;
var sisvalue = document.getElementById(bis.id.replace("i_", "s_")).value;
var asis = sisvalue.split("_");
var proposedurl = "http://www.thefreedictionary.com/" + asis[1].replace("-1", "").replace("-2", "").replace(" ", "+").replace(" ", "+");
var radis = document.getElementsByName(bis.id.replace("i_", "r_"));
var radvalue = '';
for (var i = 0, length = radis.length; i < length; i++) {
if (radis[i].checked) {
radvalue = radis[i].value;
if (sisvalue.indexOf(radvalue) == 0) {
if (sisvalue.indexOf("-2") != -1) {
plusbit = 2;
} else {
plusbit = 1;
}
}
break;
}
}

score = eval(score + plusbit);
document.getElementById('score').innerHTML = "Score: " + score + " from " + goes + " goes";

if (plusbit == 0) {
var maybe = prompt("If you want to see a dictionary lookup press OK button.", asis[1].replace("-1", "").replace("-2", ""));
if (maybe != null) {
if (maybe.replace(" ", "+").replace(" ", "+") == asis[1].replace("-1", "").replace("-2", "").replace(" ", "+").replace(" ", "+")) {
window.open(proposedurl, asis[1].replace("-1", "").replace("-2", "").replace(" ", "+").replace(" ", "+"), "top=20,left=20,width=800,height=600");
}
}
}

for (jj=0; jj<numdivs; jj++) {
if (bis.id.replace("i_", "") == divstrnames[jj]) {
oois = document.getElementById("s_" + divstrnames[jj]);
oois.value = easnames[Math.floor(Math.random() * (divptrs[jj + 1] - divptrs[jj])) + divptrs[jj]];
}
}
}


function writeItOut() {
var i = 0, j = 0, k = 0, ois, selbit = '', myarr = [], mycat = [], answercat = [], thisrb = "", elementarycell = "<td>", advancedcell = "<td>";
var esnames = new Array(nelementary);
var asnames = new Array(nadvanced);
var tstr = "<table style='background-color: yellow;' border=5 cellpadding=5 cellspacing=5><tbody id='wctbody'><tr style='background-color: pink;'><th>Elementary (1 point per correct answer)</th><th>Advanced (2 points per correct answer)</th></tr><tr>";
for (i=0; i<nelementary; i++) {
divptrs[numdivs] = k;
mycat = elementary[i].split("-");
esnames[i] = "elementary_" + elementary[i].replace("-", "_").replace("-", "_");
divstrnames[numdivs] = esnames[i];
thisrb = "<form action='' id='f_" + divstrnames[numdivs] + "' name='f_" + divstrnames[numdivs] + "'>";
for (j=0; j<mycat.length; j++) {
thisrb = thisrb + "<input type='radio' name='r_" + divstrnames[numdivs] + "' value='" + mycat[j] + "'>" + mycat[j] + "<br>";
}
thisrb = thisrb + "</form>";
divnums[numdivs] = 0;
divstrs[numdivs] = "<div id='" + divstrnames[numdivs] + "' style='border: 2px solid green;'></div>";
divstrs[numdivs] = divstrs[numdivs].replace("</div>", "<table><tbody><tr><td><br> Please choose </td><td>" + thisrb + "</td><td><input id='i_" + divstrnames[numdivs] + "' type='button' onclick='check(this);' value='Check category choice to left with word below'></input></td></td></tr></tbody></table>  <select id='s_" + divstrnames[numdivs] + "'></select><br></div>");
for (j=0; j<eval(esnames[i] + ".length"); j++) {
myarr[j] = eval(esnames[i] + "[" + j + "]");
answercat = myarr[j].split("-");
divstrs[numdivs] = divstrs[numdivs].replace("</select>", "<option value='" + mycat[answercat.length - 1] + "_" + answercat[answercat.length - 1] + "-1" + "'>" + answercat[answercat.length - 1] + "</option></select>");
easnames[k] = mycat[answercat.length - 1] + "_" + answercat[answercat.length - 1] + "-1";
k = eval(k + 1);
divnums[numdivs] = eval(1 + divnums[numdivs]);
}
elementarycell = elementarycell + divstrs[numdivs];
numdivs++;
}
elementarycell = elementarycell + "</td>";
tstr = tstr + elementarycell;

for (i=0; i<nadvanced; i++) {
divptrs[numdivs] = k;
mycat = advanced[i].split("-");
asnames[i] = "advanced_" + advanced[i].replace("-", "_").replace("-", "_");
divstrnames[numdivs] = asnames[i];
thisrb = "<form action='' id='f_" + divstrnames[numdivs] + "' name='f_" + divstrnames[numdivs] + "'>";
for (j=0; j<mycat.length; j++) {
thisrb = thisrb + "<input type='radio' name='r_" + divstrnames[numdivs] + "' value='" + mycat[j] + "'>" + mycat[j] + "<br>";
}
thisrb = thisrb + "</form>";
divnums[numdivs] = 0;
divstrs[numdivs] = "<div id='" + divstrnames[numdivs] + "' style='border: 2px solid red;'></div>";
divstrs[numdivs] = divstrs[numdivs].replace("</div>", "<table><tbody><tr><td><br> Please choose </td><td>" + thisrb + "</td><td><input id='i_" + divstrnames[numdivs] + "' type='button' onclick='check(this);' value='Check category choice to left with word below'></input></td></td></tr></tbody></table>  <select id='s_" + divstrnames[numdivs] + "'></select><br></div>");
for (j=0; j<eval(asnames[i] + ".length"); j++) {
myarr[j] = eval(asnames[i] + "[" + j + "]");
answercat = myarr[j].split("-");
divstrs[numdivs] = divstrs[numdivs].replace("</select>", "<option value='" + mycat[answercat.length - 1] + "_" + answercat[answercat.length - 1] + "-2" + "'>" + answercat[answercat.length - 1] + "</option></select>");
easnames[k] = mycat[answercat.length - 1] + "_" + answercat[answercat.length - 1] + "-2";
k = eval(k + 1);
divnums[numdivs] = eval(1 + divnums[numdivs]);
}
advancedcell = advancedcell + divstrs[numdivs];
numdivs++;
}
advancedcell = advancedcell + "</td>";
tstr = tstr + advancedcell;
divptrs[numdivs] = eval(k + 1);


tstr = tstr + "</tr></tbody></table>";
document.write(tstr);

for (j=0; j<numdivs; j++) {
ois = document.getElementById("s_" + divstrnames[j]);
ois.value = easnames[Math.floor(Math.random() * (divptrs[j + 1] - divptrs[j])) + divptrs[j]];
}
}

function goagain() {
if (clone != null) {
clone.close();
clone=null;
}
if (totalclone != null) {
totalclone.close();
totalclone=null;
}
if (clone == null && totalclone == null) {
var h1s=document.getElementsByTagName('h1');
var h3s=document.getElementsByTagName('h3');
var divs=document.getElementsByTagName('div');
clone=window.open('','_blank','top=60,left=60,width=1090,height=660');
clone.document.write("<html>" + document.head.outerHTML.replace('function goaga' + 'in() {', 'function goaga' + 'in() { return; ') + "<body>" + h1s[0].outerHTML.replace('Categories Game', 'Categories ' + five + ' Second Game') + h3s[0].outerHTML + divs[0].outerHTML + "</body>" + "</html>");
totalclone=window.open('','_blank','top=60,left=160,width=1090,height=660');
totalclone.document.write("<html>" + document.head.outerHTML.replace('function goaga' + 'in() {', 'function goaga' + 'in() { return; ') + document.body.outerHTML.replace('Categories Game', 'Categories ' + five + ' Second Game') + "</html>");
}
setTimeout(goagain, eval(five * 1000));
five++;
}


function begin() {
writeItOut();
//goagain();
}


</script>
</head>
<body style="background-color: yellow;">

<h1 align='center'>Word Categories Game</h1>
<h3 align='center' id='score'>Score: 0 from 0 goes</h3>
<div align='center'>
<script> begin(); </script>
</div>
</body>
</html>