//Declare global variables
  var c=0;
  var guess=0;
  var answer=clues[20];
  var mainframe=parent.frames[0];
  var clueframe=parent.frames[1];
  var solved=false;
  var previousclues=new Array();
  var cluehistory=new Array();

//Write clue(s)
function writeClue(){
  if (solved==true) {alert("Why are you still trying? You\'ve already solved this one!"); return false}
  else if (c>=20) {alert('There are no more clues left. You still have '+(3-guess)+' of your guesses left.'); return false}
  else if (guess>=3) {alert('You have used all your guesses. Refresh/Reload the page to try again'); return false}
  else {

  for (i=0; i<=c; ++i) {
  cluelist='<html><body bgcolor=\"ffffcc\"><font face=\"arial\" size=-1><b>Clue number '+(i+1)+':</b></font><font face=\"comic sans ms" size=-1><br>'+clues[i]+'<p>'+previousclues+'</font></body></html>';}
  parent.clueframe.location.replace("javascript:parent.mainframe.cluelist");
  parent.clueframe.document.close();
  if (clues[c].indexOf('picture clue')!=-1) {
	parent.pictureframe.document.write('<body bgcolor=\"ffffcc"><img style="position: absolute\; top: 10\; left: 10\;" src="'+pictureclue1+'">');
	if (clues[c].indexOf('second picture clue')!=-1){
	parent.pictureframe.document.write('<img style="position: absolute\; top: 10\; left: 200\;" src="'+pictureclue2+'"></body>');}
    parent.pictureframe.document.close();
    }
  cluehistory=clues[i-1]+'<br>'+cluehistory;
  previousclues='<font face="arial"><b>Previous Clues:</b></font><br><font face="comic sans ms" size="-1">'+cluehistory;
  ++c;
  }
}

//Check answer
function checkAnswer() {
  if (document.forms[0].country.selectedIndex==0) {alert("To guess an answer, click on a country from the list and then click on the \"Answer\" button."); return false}
  else if (guess>=3) {alert("You have used all of your guesses. Reload/Refresh the page to try again."); document.forms[0].country.value="Pick"; return false}
  else if (solved==true) {alert("Why are you still trying? You\'ve already solved this one!"); return false}
  else {
    ++guess;
    if (document.forms[0].country.options[document.forms[0].country.selectedIndex].value==answer) {
       solved=true;
       parent.progressframe.location.replace("../all/correctend.html");
	  endquiz='<HTML><BODY BGCOLOR=\"#ffffcc\"><FONT FACE=\"comic sans ms\" size=-1>'
	       +'To be listed in The Internet Geographer\'s \'Hall of Fame\' for correctly identifying the answer, enter your details and click on the button.'
	       +'<FORM NAME="EnterHall" METHOD="POST" ACTION="http://www.internetgeographer.com/tig/famehall/add.asp">'
	       +'<CENTER>Name:<INPUT TYPE="TEXT" SIZE=20 NAME="Name" maxlength="25"><br>Age:<INPUT TYPE="TEXT" SIZE=5 NAME="Age" maxlength="2"><br><FONT SIZE="-2">optional</FONT><INPUT TYPE="HIDDEN" NAME="Quiz" VALUE="20 Questions"><INPUT TYPE="HIDDEN" NAME="QuestionSet" VALUE="'+qnset+'">'
	       +'<P><INPUT TYPE="button" VALUE="Enter the \'Hall of Fame\'" onClick="parent.mainframe.checkName(EnterHall.Name.value);">'
	       +'</FORM></BODY></HTML>';
	parent.clueframe.location.replace("javascript:parent.mainframe.endquiz");
	}
    else if (guess==3) {endguess='<html><body bgcolor=\"ffffcc\"><font face=\"comic sans ms\" size=-1>Bad luck. That was your final guess.<br><b>'+document.forms[0].country.options[document.forms[0].country.selectedIndex].value
				+'</b> is not the correct answer.<p>Reload/Refresh the page to have another try.</font></body></html>';
		      parent.progressframe.location.replace("javascript:parent.mainframe.endguess");
    }
    else {badluck='<html><body bgcolor=\"#ffffcc\"><font face=\"comic sans ms\" size=-1>Bad luck. <b>'+document.forms[0].country.options[document.forms[0].country.selectedIndex].value
		 +'</b> is not the correct answer.<p>You have used '+guess+' of your guesses.<br>You have '+(3-guess)+' left.</font></body></html>';
	parent.progressframe.location.replace("javascript:parent.mainframe.badluck");
    }
    document.forms[0].country.options.selectedIndex=0;
  }
}

//Check name is entered for Fame Hall submission
function checkName(Entrant) {
	if (Entrant=="") {alert("If you wish to be entered in the Hall of Fame, please enter your name."); return false}
	else if (navigator.cookieEnabled==false) {alert("Please enable the use of cookies in your browser."); return false}
	else {parent.clueframe.document.forms.EnterHall.submit()}
}

//Reveal unused clues
function revealAll() {
  allclues=new Array();
  for (j=0; j<clues.length-1; ++j) {allclues=allclues+clues[j]+'<br>'}
  parent.clueframe.location.replace("javascript:\'<html><body bgcolor=\"ffffcc\"><font face=\"comic sans ms\" size=-1>'+parent.mainframe.endquiz+'<br>The complete 20 clues are listed below:<p align=left>'+parent.mainframe.allclues+'</font></body></html>\'");
  parent.pictureframe.document.write('<html><body bgcolor=\"ffffcc\"><img style="position: absolute\; top: 10\; left: 10\;" src="'+path+pictureclue1+'">'
	+ '<img style="position: absolute\; top: 10\; left: 200\;" src="'+path+pictureclue2+'">');
  parent.pictureframe.document.close();
}

//Ensure blank frames loaded even after refresh/reload
function loadStartframes() {
  parent.pictureframe.location.replace('../all/blank.html');
  parent.progressframe.location.replace('../all/prgstart.html');
}

