    //JavaScript Dreidel Game created by Tracey R Rich
    //Copyright Tracey R Rich 2000
    //All Rights Reserved

    //set up initial variables
    Pic = new Array(4);
    Outcome = new Array(5);
    Score = new Array(2);
    BtnLabel = new Array(3);
    Pot = 0;
    Move = "Ante";
    Player = 1;

    Score[1] = 10;
    Score[2] = 10;

    BtnLabel[0] = "                    ";
    BtnLabel[1] = "Spin Dreidel!";
    BtnLabel[2] = "     Stop!     ";
    BtnLabel[3] = "Ante Up!";

    Pic[0] = "nunstop.gif";
    Pic[1] = "gimmelstop.gif";
    Pic[2] = "hehstop.gif";
    Pic[3] = "shinstop.gif";

    Outcome[0] = "Letter: Nun\nMeans: Nichts (Nothing)\nYou do not get any coins, but you do not lose any coins.";
    Outcome[1] = "Letter: Gimmel\nMeans: Ganz (All)\nYou get all of the coins in the pot.\nAll players must put a coin in the pot (ante up) to rebuild it.";
    Outcome[2] = "Letter: Hei\nMeans: Halb (Half)\nYou get half of the coins in the pot.\nIf this leaves the pot empty, all players must put in a coin (ante up) to rebuild it.";
    Outcome[3] = "Letter: Shin\nMeans: Shtell (Put)\nYou must put a coin into the pot.";
    Outcome[4] = "Click the NEW GAME button below to play again.";
    Outcome[5] = "Designed for two players, but you can play both.\nThe buttons will tell you what to do.\nResults will be explained here.";

    function ante() {
	Score[1] = Score[1] - 1;
	Score[2] = Score[2] - 1;
	Pot = Pot + 2;
      document.myForm.Score1.value = Score[1];
      document.myForm.Score2.value = Score[2];
      document.myForm.Pot.value = Pot;
      Move="Spin";
	document.myForm.Ante.disabled = "TRUE";
      document.myForm.Ante.value = BtnLabel[0];
	if (Score[1] < 0) {
	  endgame(2);
	} else if (Score[2] < 0) {
	  endgame(1);
	} else {
	  eval("document.myForm.Player" + Player + ".disabled = 0;");
	  eval("document.myForm.Player" + Player + ".value=BtnLabel[1];");
	}
    }

    function spin() {
	if (Move == "Spin") {
        document.images["dreidel"].src="spinning.gif";
	  Move ="Stop";
	  eval("document.myForm.Player" + Player + ".value=BtnLabel[2];");
	} else if (Move == "Stop") {
	  randgen = new Date();
	  randgen = randgen.getSeconds()
	  randgen = randgen % 4;
        document.images["dreidel"].src=Pic[randgen];
	  document.myForm.Rules.value=Outcome[randgen];
        processResults(randgen);
	  eval("document.myForm.Player" + Player + ".disabled = 1;");
	  eval("document.myForm.Player" + Player + ".value = BtnLabel[0];");
	  if (Score[Player] < 0) {
	    endgame(changePlayers(Player));
	  } else {
	    Player = changePlayers(Player);
	    if (Pot <= 0) {
	      document.myForm.Ante.disabled = 0;
	      document.myForm.Ante.value = BtnLabel[3];
	      Move = "ante";
	    } else {
	      eval("document.myForm.Player" + Player + ".disabled = 0;");
	      eval("document.myForm.Player" + Player + ".value = BtnLabel[1];");
	      Move = "Spin";
	    }
	  }
      }
    }

    function changePlayers(From) {
	if (From==1) {
	  return 2;
	} else {
	  return 1;
	}
    }

    function processResults(Outcome) {
      if (Outcome == 0) {
	  //nothing happens for Nun
      } else if (Outcome == 1) {
	  //Gimmel
	  Score[Player] = Score[Player] + Pot;
	  Pot = 0;
      } else if (Outcome == 2) {
	  //Hei
	  Half = Math.ceil(Pot / 2);
	  Score[Player] = Score[Player] + Half;
	  Pot = Pot - Half;
      } else if (Outcome == 3) {
	  //Shin
	  Score[Player] = Score[Player] - 1;
	  Pot = Pot + 1;
      }
	document.myForm.Score1.value = Score[1];
	document.myForm.Score2.value = Score[2];
	document.myForm.Pot.value = Pot;
    }

    function endgame(Winner) {
	Ans = confirm("Player " + Winner + " Wins!\n\nPlay again?");
	if (Ans) {
	  startOver();
	  document.myForm.Replay.click();
	} else {
	  document.myForm.Rules.value=Outcome[4];
	}
    }

    function startOver() {
	Pot = 0;
	Player = 1;
	Score[1] = 10;
	Score[2] = 10;
	Move = "Ante";

      document.myForm.Score1.value = Score[1];
      document.myForm.Score2.value = Score[2];
      document.myForm.Pot.value = Pot;

	document.myForm.Rules.value = Outcome[5];

	document.myForm.Player1.value = BtnLabel[0];
	document.myForm.Player1.disabled = 1;

	document.myForm.Player2.value = BtnLabel[0];
	document.myForm.Player2.disabled = 1;

	document.myForm.Ante.value = BtnLabel[3];
	document.myForm.Ante.disabled = 0;
    }