function contact_verify ()
{
  var elements = new Array("name", "email", "message");

  for (var a = 0; a < elements.length; a++)
  {
    var element = document.getElementById("contact_" + elements[a]);

    if (element.value === null || element.value === "")
    {
      alert("Please complete your " + elements[a] + " before sending your message. Thank you!");
      element.focus;
      return false;
    }
  }

  return true;
}


var game_colours = new Array("blue", "red", "green", "yellow", "orange", "purple", "pink", "turquoise");
var game_counter = null;
var game_difficulty = null;
var game_remaining = null;
var game_reset = null;
var game_selected = null;
var game_socks = new Array();
var game_time = null;
var game_total = null;


function game_actuate (difficulty)
{
  if (document.getElementsByTagName && document.createElement)
  {
    if (game_difficulty === null)
    {
      game_difficulty = difficulty;
      game_generate();
      game_timer("start");
    }
    else
    {
      if (game_remaining === 1)
      {
        var confirmation = true;
      }
      else
      {
        var confirmation = confirm("Are you sure you want to stop this game?");
      }

      if (confirmation === true)
      {
        window.clearTimeout(game_counter);

        if (game_reset !== null)
        {
          window.clearTimeout(game_reset);
          game_reset = null;
        }

        document.getElementById("game_time").value = 0;
        document.getElementById("game_message").value = "To start the game please select your skill level";

        game_colours = new Array("blue", "red", "green", "yellow", "orange", "purple", "pink", "turquoise");
        game_counter = null;
        game_difficulty = null;
        game_remaining = null;
        game_selected = null;
        game_socks = new Array();
        game_time = null;
        game_total = null;

        var playground = document.getElementById("game_playground");
        var content = document.getElementById("content");
        content.removeChild(playground);

        var playground = document.createElement("div");
        playground.setAttribute("id","game_playground");
        content.appendChild(playground);
      }
    }
  }
  else
  {
    alert("Sorry! Your web browser does not support this game. Please upgrade to the latest version if you wish to play.");
  }
}


function game_generate ()
{
  switch (game_difficulty)
  {
    case "easy":
      game_total = 4;
      break;
    case "medium":
      game_total = 8;
      break;
    case "hard":
      game_total = 16;
      break;
  }

  game_remaining = game_total / 2;

  for (var a = 0; a < game_remaining; a++)
  {
    game_socks[a] = game_colours[a] + 0;
    game_socks[a + game_remaining] = game_colours[a] + 1;
  }

  game_socks.sort(game_random);

  var playground = document.createElement("div");
  playground.setAttribute("id","game_playground");
  document.getElementById("content").appendChild(playground);
  document.getElementById("game_playground").style.width = (Math.round(Math.sqrt(game_total)) * 112) + "px";

  for (var b = 0; b < game_total; b++)
  {
    sock = document.createElement("p");
    sock.setAttribute("id", game_socks[b]);
    document.getElementById("game_playground").appendChild(sock);
    abc = document.getElementById(game_socks[b]);
    abc.onclick = game_click;
  }
}


function game_click (e)
{
  var e = window.event;
  var id = this.id;
  var current = id.substring(0, (id.length-1));
  var message = document.getElementById("game_message");

  document.getElementById(id).setAttribute("class",current);
  document.getElementById(id).setAttribute("className",current);

  if (game_selected === null)
  {
    game_selected = id;
  }
  else
  {
    var selected = id.substring(0, (game_selected.length-1));

    if (current === selected && game_remaining === 1)
    {
      message.value = "Congratulations you've finished!";
      window.setTimeout("document.getElementById('"+id+"').removeAttribute('onclick')", 500);
      window.setTimeout("document.getElementById('"+game_selected+"').removeAttribute('onclick')", 500);
      window.setTimeout("document.getElementById('"+id+"').setAttribute('class','yoink')", 1000);
      window.setTimeout("document.getElementById('"+id+"').setAttribute('className','yoink')", 1000);
      game_timer("stop");
      game_reset = window.setTimeout("game_actuate()", 10000);
    }
    else if (current === selected && game_remaining > 1)
    {
      message.value = "Keep going!";
      window.setTimeout("document.getElementById('"+id+"').removeAttribute('onclick')", 500);
      window.setTimeout("document.getElementById('"+game_selected+"').removeAttribute('onclick')", 500);
      window.setTimeout("document.getElementById('"+id+"').setAttribute('class','yoink')", 1000);
      window.setTimeout("document.getElementById('"+id+"').setAttribute('className','yoink')", 1000);
      game_selected = null;
      game_remaining = parseFloat(game_remaining) - 1;
    }
    else
    {
      message.value = "Keep Trying!";
      window.setTimeout("document.getElementById('"+id+"').removeAttribute('class')", 500);
      window.setTimeout("document.getElementById('"+id+"').removeAttribute('className')", 500);
      window.setTimeout("document.getElementById('"+game_selected+"').removeAttribute('class')", 500);
      window.setTimeout("document.getElementById('"+game_selected+"').removeAttribute('className')", 500);
      game_selected = null;
    }
  }
}


function game_random (a, b)
{
  return Math.round(Math.random() - Math.random());
}


function game_timer (command)
{
  var time = document.getElementById("game_time");

  switch (command)
  {
    case "start":
      time.value = 0;
      game_timer('up');
      break;
    case "up":
      time.value = game_time++;
      game_counter = window.setTimeout("game_timer('up')", 1000);
      break;
    case "stop":
      window.clearTimeout(game_counter);
      break;
  }
}


function joke ()
{
  var library = new Array
  (
    "Q: What do ghosts wear in the sun?\nA: Sunscream!",
    "Q: What do you call a ghost in the jungle?\nA: Ramboo!",
    "Q: Why do ghosts not like water?\nA: It dampens their spirits!",
    "Q: Why are ghosts no good at telling lies?\nA: Because you can see right through them!",
    "Q: Why are ghosts at their loudest in the summer?\nA: Because they are on their howlidays!"
  );

  alert(library[Math.round(Math.random()) * (library.length - 1)]);
}