   treeOn = new Image();  treeOn.src = "/images/games/secretstamps/stampwhite.gif";
   rockOn = new Image();  rockOn.src = "/images/games/secretstamps/stampred.gif";
  waterOn = new Image(); waterOn.src = "/images/games/secretstamps/stampblack.gif";
   cartOn = new Image();  cartOn.src = "/images/games/secretstamps/stampblue.gif";
  emptyOn = new Image(); emptyOn.src = "/images/games/secretstamps/empty.gif";
      xOn = new Image();     xOn.src = "/images/games/secretstamps/x.gif";
     gOnl = new Image();    gOnl.src = "/images/games/secretstamps/firer.gif";
     gOnd = new Image();    gOnd.src = "/images/games/secretstamps/fireu.gif";
     gOnr = new Image();    gOnr.src = "/images/games/secretstamps/firel.gif";
     gOnu = new Image();    gOnu.src = "/images/games/secretstamps/fired.gif";
      rOn = new Image();     rOn.src = "/images/games/secretstamps/hit.gif";
  ArrowOnu = new Image(); ArrowOnu.src = "/images/games/secretstamps/arrowu.gif";
  ArrowOnd = new Image(); ArrowOnd.src = "/images/games/secretstamps/arrowd.gif";
  ArrowOnl = new Image(); ArrowOnl.src = "/images/games/secretstamps/arrowl.gif";
  ArrowOnr = new Image(); ArrowOnr.src = "/images/games/secretstamps/arrowr.gif";
        a = new Array("1","2","3","4","5","6","7","8");           // Left
        b = new Array("10","20","30","40","50","60","70","80");   // Bottom
        c = new Array("91","92","93","94","95","96","97","98");   // Right
        d = new Array("19","29","39","49","59","69","79","89");   // Top
        e = new Array("1","2","3","4","5","6","7","8","10","20","30","40","50","60","70","80","91","92","93","94","95","96","97","98","19","29","39","49","59","69","79","89");
  ValidPlay=true;
  function checkWork() {
    if (ValidPlay)
    {
      rtree = document.holes.tree.value;
      rrock = document.holes.rock.value;
      rwater = document.holes.water.value;
      rcart = document.holes.cart.value;
      ptree = document.coord.tree.value;
      prock = document.coord.rock.value;
      pwater = document.coord.water.value;
      pcart = document.coord.cart.value;
      shots = document.holes.shots.value;
      if ( ptree == 0) {msg = "You must mark the location of the Mirror Stamp";}
      if ( prock == 0) {msg = "You must mark the location of the Red Stamp";}
      if (pwater == 0) {msg = "You must mark the location of the Shadow Stamp";}
      if ( pcart == 0) {msg = "You must mark the location of the Blue Stamp";}
      if ( rtree == ptree && rrock == prock && rwater == pwater && rcart == pcart) 
      {
        ValidPlay=false;
        alert("You did it!  You found all the secret stamps in just " + document.holes.shots.value + " shots.  Great job, Detective.");
        var nPoints = Math.round(100 / document.holes.shots.value * 400 * 16);
        var strMsg = "Your score is " + nPoints + " points. \nPlease enter your name for the scoreboard:";
        var strPlayerName = "";
        strName = prompt(strMsg, strPlayerName);
        if(strName != null && strName != "")
        {
          strPlayerName = strName.substr(0, 20);
          strURL = "/html/games/games_addscore.php" + "?b=secretstamps&n=" + escape(strPlayerName) + "&p=" + nPoints;
          window.open(strURL, "Highscore", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=440,height=600");
        }
      }
      else 
      {
        msg = "I'm sorry, Detective.  You have not yet correctly identified the secret stamps.  Keep trying!";
        alert(msg);
      }
    }
    return false;
  }

  function checkRadio(baddy) {document.choices.hazard[baddy].checked = true;}
  function nothing() {}
  function hitBall(xy) {if (document.holes.state.value == 0) {hitBall2(xy)} else {nothing()}}
    
  function hitBall2(xy) {
    document.holes.state.value = 1
    shots = document.holes.shots.value
    i=0;
    for (i=0; i<8; i++) {if (a[i] == xy) {change = 1; shots++; side="l";}}; i=0;
    for (i=0; i<8; i++) {if (b[i] == xy) {change = 2; shots++; side="d";}}; i=0;
    for (i=0; i<8; i++) {if (c[i] == xy) {change = 3; shots++; side="r";}}; i=0;
    for (i=0; i<8; i++) {if (d[i] == xy) {change = 4; shots++; side="u";}};
    document["i" + xy].src = eval("gOn" + side + ".src");
    result = roll(xy,change);
    codeExit = result.split(",");
    code = codeExit[0];
    exit = codeExit[1];
    window.setTimeout("exitNow()", 300);
    moof = xy;
    window.setTimeout("goBack(moof,exit)", 1000);
  }

  function goBack(xy,exit) {
         if (side == "l") {side1 = "r";}
    else if (side == "r") {side1 = "l";}
    else if (side == "u") {side1 = "d";}
       else {side1 = "u";}
       
    document["i" + xy].src = eval("ArrowOn" + side1 + ".src");
    if (code == 2) 
    {
      found = 0;
      for (var x = 0; x <= 7; x++)
      {
            //alert("exit: " + exit + " a(" + a[x] + "): " + (exit == a[x]) + " b(" + b[x] + "): " + (exit == b[x]) + " c(" + c[x] + "): " + (exit == c[x]) + " d(" + d[x] + "): " + (exit == d[x]) + "...");
             if (exit == a[x]) {side2 = "r"; found = 1;}
        else if (exit == b[x]) {side2 = "u"; found = 1;}
        else if (exit == c[x]) {side2 = "l"; found = 1;}
        else if (exit == d[x]) {side2 = "d"; found = 1;}
             if (found == 1) {break;}
      }
      document["i" + exit].src = eval("ArrowOn" + side2 + ".src");
    }
    document.holes.shots.value = shots;
    document.holes.par.value = shots;
    document.holes.state.value = 0;
  }

  function exitNow() {
    if (code == 2) {document["i" + exit].src = eval("rOn.src");}
    if (code == 1) {}
  }

  function roll(xy,change) {
    result = 10;
    if (document.holes.tree.value == xy) {change = change+2;}
    if (document.holes.rock.value == xy) {change = change-1;}
    if (document.holes.water.value == xy) {change = 10;}
    if (document.holes.cart.value == xy) {change = change+1;}
    if (change == 5) {change = 1;}
    if (change == 0) {change = 4;}
    if (change == 6) {change = 2;}
    if (change == 1) {xy = xy+10;}
    if (change == 2) {xy = xy+1;}
    if (change == 3) {xy = xy-10;}
    if (change == 4) {xy = xy-1;}
    if (change == 10) {result = 1; out = "water"}; i=0;
    for (i=0; i<32; i++) {if (e[i] == xy) {out = xy; result = 2;}}
    if (result > 9) {roll(xy,change);}
    return result + "," + out;
  }

  function random() {
    randomNum = Math.floor((Math.random() * 8));
    randomNum++;
    return randomNum;
  }

  function makeHoles() {
    one = random();
    two = random();
    three = random();
    four = random();
    five = random();
    six = random();
    seven = random();
    eight = random();
    document.holes.tree.value = one + "" + two;
    document.holes.rock.value = three + "" + four;
    document.holes.water.value = five + "" + six;
    document.holes.cart.value = seven +  "" + eight;
    document.holes.par.value=0;
    document.holes.shots.value=0;
  }

  function placeHazard(xy) {
    for (i=0; i<document.choices.hazard.length; i++) {if (document.choices.hazard[i].checked) {type = i;}}
    if (type != 4) 
    {
      haz = document.choices.hazard[type].value; 
      prev = document.coord[haz].value; 
      if (prev != "0") {document["i" + prev].src = eval("emptyOn.src");
    }
      
    for (i=0; i<document.coord.length; i++) {if (document.coord[i].value == xy) {document.coord[i].value = "0"}}
    if (prev == xy) 
    {
      document["i" + xy].src = eval("emptyOn.src"); 
      document.coord[haz].value = "0";
    }
    else 		// was it the X?
    {
      document["i" + xy].src = eval(haz + "On.src"); 
      document.coord[haz].value = xy;}
    }
    if (type == 4) 
    {
      if (document["i" + xy].src == xOn.src) {document["i" + xy].src = eval("emptyOn.src");} 
      else 
      {
        for (i=0; i<document.coord.length; i++) {if (document.coord[i].value == xy) {document.coord[i].value = "0"}}
        document["i" + xy].src = eval("xOn.src");
      }
    }
  }