	function MatchGame() {

		this.questions = new Object();

		this.loaded = false;

		this.score = 0;
		this.total = null;

		this.addAnswer = function(strQuestion,strAnswer) {

			// New question
			if(!isArray(this.questions[strQuestion])) {
				this.questions[strQuestion] = new Array();
				this.total++;
			}

			var len = this.questions[strQuestion].length
			this.questions[strQuestion][len] = strAnswer

		}

		this.guess = function(strQuestion,strAnswer) {

			for(var i=0;i < this.questions[strQuestion].length;i++) {
				if(this.questions[strQuestion][i] == md5(strAnswer)) {
					this.score++;
					return true;
				}
			}
			return false;
		}

	}

	function checkAnswer(intQuestion) {

		if(!game.loaded) {
			return;
		}

    var answerObj = getGameElement("answer",intQuestion);
    var buttonObj = getGameElement("button",intQuestion);

		if(game.guess("answer"+intQuestion,answerObj.value.toLowerCase())) {

      var imageObj = new Image();
      imageObj.name = "image" + intQuestion;
      imageObj.src = "images/correct.gif"
      imageObj.title = "Correct!"
      imageObj.alt = "Correct!"

      //buttonObj.style.display = "none";
      //buttonObj.style.visibility = "hidden";
      //buttonObj.parentNode.appendChild(imageObj)
      //buttonObj.parentNode.replaceChild(imageObj,buttonObj.parentNode.firstChild)
      buttonObj.parentNode.innerHTML = "<img src=\"images/correct.gif\" title=\"Correct!\" alt=\"Correct!\">";

			document.getElementsByName("answer"+intQuestion)[0].value = answerObj.value;

      answerObj.readOnly = true

			if(game.score == game.total) {
			  displayWinner();
			} else {
				//selectNextQuestion(intQuestion)
				displayScore()
				setScoreLevelText();
			}

		} else {

		  buttonObj.src = "images/wrong.gif"
		  buttonObj.title = "Wrong!"
		  buttonObj.alt = "Wrong!"
		  answerObj.focus();
		  answerObj.select();
		}

	}

	function resetIncorrectAnswer(intQuestion) {

    var buttonObj = getGameElement("button",intQuestion);
    var answerObj = getGameElement("answer",intQuestion);

    if(answerObj.value == "") {
    	return
    }

    if(!answerObj.readOnly) {

      buttonObj.src = "images/submit.gif"
		  buttonObj.title = "Submit Answer!"
		  buttonObj.alt = "Submit Answer!"

    }

	}

	function displayScore() {
		document.getElementById("scoreText").innerHTML = game.score + " out of " + game.total
	}

	function setScoreLevelText() {

		var levelText = "";
		var colours;
		if(game.score == 5) {
			colours = new Array("#ff6600","#ff9900","#ffcc33","#FF0000");
			levelText = "You're warming up!"
		} else if(game.score == 10) {
			colours = new Array("#ff6600","#ff9900","#ffcc33","#FF0000");
			levelText = "Now you're cooking!"
		} else if(game.score == 15) {
			colours = new Array("#ff6600","#ff9900","#ffcc33","#FF0000");
			levelText = "Over the hill now!"
		} else if(game.score == 20) {
			colours = new Array("#ff6600","#ff9900","#ffcc33","#FF0000");
			levelText = "Hey you're a pro...only 5 to go!"
		}

		if(levelText != "") {
			document.getElementById("scoreLevelText").innerHTML = levelText
			var interval=0;
			var increment = 200;
			for(i=0;i< colours.length;i++){
				interval += increment;
				setTimeout("setScoreLevelColour('" + colours[i]+ "')",interval);
			}
		}


	}

	function setScoreLevelColour(theHex) {

		document.getElementById("scoreTable").style.background = theHex


	}


	function displayWinner() {

	  //if(game.score == game.total) {
  	  //document.getElementById("questionsSection").style.display = "none";
  	  //document.getElementById("winnerSection").style.display = "";
  	  document.forms[0].submit();
  	//}
	}

	function resetGame() {

    for (var i in game.questions) {

			var theObj = document.getElementsByName("quiz_" + i)[0]
			if(theObj) {
      	theObj.value = ""
      } else {

      }
    }
	  //document.getElementById("questionsSection").style.display = "";
	  //document.getElementById("winnerSection").style.display = "none";
	}

	function getGameElement(theType,intQuestion) {
	  return document.getElementsByName("quiz_" + theType + intQuestion)[0];
	}

	function selectNextQuestion(intCurrent) {

		var intNext = -1;
		var questionObj;
		while(intCurrent != intNext) {

			if(intNext == -1) {
				intNext = intCurrent;
			}

			if(intNext > game.total) {
				intNext = 1;
			}

			questionObj = document.getElementsByName("quiz_answer" + intNext)[0]
			if(!questionObj.readOnly) {

				questionObj.focus();
				break;
			}

			intNext++;

			if(intNext == intCurrent) {
				break;
			}

		}

	}

	function isArray(a) {
	    return isObject(a) && a.constructor == Array;
	}

	function isObject(a) {
	    return (a && typeof a == 'object') || isFunction(a);
	}

	function isFunction(a) {
	    return typeof a == 'function';
	}

  // creates array variable getVars
  // this contains all variables passed using the get method
  function parseGetString() {

    // Array of get pairs ie name=stuart
    var pairs = new Array();

    // Associative array of pairs ie getVars['name'] = "stuart"
    var getVars = new Array();

    // temp array used in the creation of getVars
    var temp = new Array();

    pairs =  window.location.search.substring(1, window.location.search.length).split("&");

    for(var i in pairs) {
      pairstr = pairs[i];
      temp = pairstr.split("=");
      getVars[temp[0]] = temp[1];

    }
    return getVars;
  }

  function openWindow(windowUrl,windowName,windowOptions) {

    window.open(windowUrl,windowName,windowOptions);

  }