var x;
var y;
var j=0;
var move;
var t=60;
var body = new Array();
var animal =  new Array();
var food = new Array();
var cl = new Array();
	 		 	  	  			 			 		     	    		  	   		   	 		   			   		  	      	    		  
var txt = new Array("albatross", "anorak", "fingernail",  "pasta", "chest", "shorts", "kipper", "jacket", "chin", "hat", "soup", "jersey", "lungs", "icecream", "rodent", "sternum", "doe", "stomach", "bison", "stockings", "cheek", "trousers", "sandwich", "beef", "mutton", "lemur", "knee", "suit", "koala", "nose", "blouse", "emu", "throat", "vole", "broth", "warthog", "wrist", "fox", "porcupine", "pants", "cornea", "hotdog", "spine", "jackal", "hamburger", "tights", "chips", "sweets", "peanuts", "sweater", "knuckle", "leggings", "tendon", "waistcoat", "chocolate", "thigh", "salad", "goat", "scalp", "camel", "jumper", "bread", "bagel", "raincoat", "skin", "socks", "yak", "thumb", "shirt", "hedgehog", "pullover", "curry", "seagull", "pizza", "popcorn", "snail", "vest", "lolly", "ankle", "mongoose", "scarf", "bowel", "skirt", "nightingale", "sausage", "osprey", "abdomen", "mince", "elbow", "zebra", "cap", "cuticle", "coat", "skull", "ibis", "veil", "veal", "cat", "sardines", "turtle");

var cell = new Array("s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", "s32", "s33", "s34", "s35", "s36", "s37", "s38", "s39", "s40", "s41", "s42", "s43", "s44", "s45", "s46", "s47", "s48", "s49", "s50", "s51", "s52", "s53", "s54", "s55", "s56", "s57", "s58", "s59", "s60", "s61", "s62", "s63", "s64", "s65", "s66", "s67", "s68", "s69", "s70", "s71", "s72", "s73", "s74", "s75", "s76", "s77", "s78", "s79", "s80", "s81", "s82", "s83", "s84", "s85", "s86", "s87", "s88", "s89", "s90", "s91", "s92", "s93", "s94", "s95", "s96", "s97", "s98", "s99", "s100");

var elem = new Array(body, animal, food, cl);


var exper = new Array();
var xmlHttp;
var grampart;

function createXMLHttpRequest() {                       
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {                   
        xmlHttp = new XMLHttpRequest();
    }
}
		
function startRequest()
{
 createXMLHttpRequest();           
    xmlHttp.onreadystatechange = handleStateChange; 
    xmlHttp.open("GET", "xml/wordcategory.xml", true);  
    xmlHttp.send(null); 
}

function handleStateChange() {
    if(xmlHttp.readyState == 4) {                  
        if(xmlHttp.status == 200) {               
       		  parseResults();     
			
        }
    }
}

function parseResults()
{
var contents = null;
var bdy="";
var fd="";
var cloths="";
var anim="";
var results = xmlHttp.responseXML;
var cont = results.getElementsByTagName("word");
for(var i=0; i<cont.length; i++)
{
contents = cont[i];
bdy = contents.getElementsByTagName("body")[0].firstChild.nodeValue;
body.push(bdy);
fd = contents.getElementsByTagName("food")[0].firstChild.nodeValue;
food.push(fd);
cloths = contents.getElementsByTagName("clothes")[0].firstChild.nodeValue;
cl.push(cloths);
anim = contents.getElementsByTagName("animals")[0].firstChild.nodeValue;
animal.push(anim);
}
}
function chooseWrd(){

x = Math.floor(100*Math.random());
for(i=0; i< (100-x); i++){
document.getElementById(cell[i]).innerHTML = txt[x+i];
}
for(i=0; i<x; i++){
document.getElementById(cell[(100-x)+i]).innerHTML = txt[i];
}
}
function chooseCat(num){
document.getElementById("score").innerHTML = j;
y = num;
document.getElementById("table1").style.display = "none";
document.getElementById("table2").style.display = "";
if(y ==0) document.getElementById("categ").innerHTML = "BODY";
if(y ==1) document.getElementById("categ").innerHTML = "ANIMAL";
if(y ==2) document.getElementById("categ").innerHTML = "FOOD";
if(y ==3) document.getElementById("categ").innerHTML = "CLOTHES";
startClock();
}
function checkWord(data){
document.getElementById(data).style.color="red";
var n1 =0;
var n2=0;
for(i=0; i<25; i++){
if(document.getElementById(data).innerHTML == elem[y][i]) n1++;
}
for(i=0; i<exper.length; i++){
if(data == exper[i]) n2++;
}
if(n1>0 && n2==0){
exper.push(data);
j = j+1;
} else
{
 j=j-1;
 document.getElementById(data).style.color="black";
 }
document.getElementById("score").innerHTML = j;
}

function startClock(){
move = window.setInterval("countdown()", 1000);
}
function countdown(){
t = t-1;
if(t==0){
window.clearInterval(move);
document.getElementById("but").style.display = "";
 for(i=0; i< 100; i++){
document.getElementById(cell[i]).innerHTML = "";
document.getElementById(cell[i]).style.color = "blue";
  }}
document.getElementById("clock").innerHTML = t;
}
function restart(){

exper.splice(0, exper.length);

document.getElementById("table1").style.display = "";
document.getElementById("table2").style.display = "none";
document.getElementById("but").style.display = "none";
j = 0;
t = 60;
}