<!--

  function crapsGame() {
	this.gameStatus			= 2;					//GAME STATUS FLAG (2 = CONTINUE ROLLING)
	this.firstRoll			= true;					//FIRST ROLL FLAG
	this.balance			= 0;					//USER'S CURRENT BALANCE
	this.die1				= '';					//FACE OF DIE 1
	this.die2				= '';					//FACE OF DIE 2
	this.sumOfDice			= 0;					//SUM OF DICE ROLLED
	this.myPoint			= '';					//SHOOTER'S POINT VALUE
	this.comePoint			= '';					//COME & DONT COME BETTER'S POINT VALUE
	this.totalMessage		= '';					//MESSAGE STRING TO PASS TO USER

	this.MAXBET				= 500;					//MAX BET ALLOWED
	this.currentBetTotal	= 0;					//CURRENT TOTAL OF BETS PLACED
	
	
	//CLASS METHODS
	this.updateBalance		= updateBalance;
	this.updateBet			= updateBet;
	this.checkBet			= checkBet;
	this.checkPassLine		= checkPassLine;
	this.resetPassLine		= resetPassLine;
	this.checkDontPassBar	= checkDontPassBar;
	this.resetDontPassBar	= resetDontPassBar;
	this.checkComeBets		= checkComeBets;
	this.wonCome			= wonCome;
	this.lostCome			= lostCome;
	this.resetCome			= resetCome;
	this.wonDontCome		= wonDontCome;
	this.lostDontCome		= lostDontCome;
	this.resetDontCome		= resetDontCome;
	this.isComePoint		= isComePoint;
	this.setComePoint		= setComePoint;
	this.resetComePoint		= resetComePoint;
	this.checkField			= checkField;
	this.resetField			= resetField;
	this.checkBigSix		= checkBigSix;
	this.resetBigSix		= resetBigSix;
	this.checkBigEight		= checkBigEight;
	this.resetBigEight		= resetBigEight;
	this.checkAnySeven		= checkAnySeven;
	this.resetAnySeven		= resetAnySeven;
	this.checkAnyEleven		= checkAnyEleven;
	this.resetAnyEleven		= resetAnyEleven;
	this.checkAnyCraps		= checkAnyCraps;
	this.resetAnyCraps		= resetAnyCraps;
	this.checkHorn			= checkHorn;
	this.resetHorn			= resetHorn;
	this.message			= message;
	this.showMessage		= showMessage;
	this.isReady			= isReady;
	this.rollDice			= rollDice;
	this.setMyPoint			= setMyPoint;
	this.checkBetTotal		= checkBetTotal;
	this.showRule			= showRule;
  }


  //UPDATES THE USER'S BALANCE BASED ON PASSED IN AMOUNT
  function updateBalance(amount) {
	document.craps.balance.value = parseInt(document.craps.balance.value) + parseInt(amount);
  }
  
  
  //INCREASE USER'S BET AMOUNT BASED ON PASSED IN VALUE
  function updateBet(type, amount) {
	if(this.checkBet(amount) ) {
		switch(type) {
			case "Pass Line":
				if(this.myPoint == 0) {
					document.craps.passLine.value = parseInt(document.craps.passLine.value) + amount;
				} else {
					this.showMessage("Pass Line bets can not be placed at this time");
				}
				break;
			case "Dont Pass Bar":
				if(this.myPoint == 0) {
					document.craps.dontPassBar.value = parseInt(document.craps.dontPassBar.value) + amount;
				} else {
					this.showMessage("Don't Pass Bar bets can not be placed at this time");
				}
				break;
			case "Come":
				if(this.myPoint != 0) {
					document.craps.come.value = parseInt(document.craps.come.value) + amount;
				} else {
					this.showMessage("Come bets can not be placed at this time");
				}
				break;
			case "Dont Come":
				if(this.myPoint != 0) {
					document.craps.dontCome.value = parseInt(document.craps.dontCome.value) + amount;
				} else {
					this.showMessage("Don't Come bets can not be placed at this time");
				}
				break;
			case "Field":
				document.craps.field.value = parseInt(document.craps.field.value) + amount;
				break;
			case "Big 6":
				document.craps.bigSix.value = parseInt(document.craps.bigSix.value) + amount;
				break;
			case "Big 8":
				document.craps.bigEight.value = parseInt(document.craps.bigEight.value) + amount;
				break;
			case "Any 7":
				document.craps.anySeven.value = parseInt(document.craps.anySeven.value) + amount;
				break;
			case "Any 11":
				document.craps.anyEleven.value = parseInt(document.craps.anyEleven.value) + amount;
				break;
			case "Any Craps":
				document.craps.anyCraps.value = parseInt(document.craps.anyCraps.value) + amount;
				break;
			case "Horn":
				document.craps.horn.value = parseInt(document.craps.horn.value) + amount;
				break;
		}
		
		this.currentBetTotal += amount;
	}
  }


  //TEST USER'S BET AMOUNT TO MAKE SURE IT HASN'T EXCEEDED THE MAX BET OR THEIR BALANCE
  function checkBet(amount) {
	if(this.currentBetTotal + amount <= this.MAXBET) {
		if(this.currentBetTotal + amount <= parseInt(document.craps.balance.value)) {
			return true;
		} else {
			this.showMessage("Total bet cannot exceed balance.");
		}
	} else {
		this.showMessage("Max bet allowed is $" + this.MAXBET);
	}

	return false;
  }


  //UPDATES MESSAGE FOR USER TO BE PRINTED LATER
  function message(string) {
	if(string == '')
		this.totalMessage = string;
	else
		this.totalMessage += string;
  } 


  //DISPLAYS GIVEN MESSAGE TO USER
  function showMessage(message) {
	if(message == null)
		message = this.totalMessage

	document.craps.message.value = message;
  }
  
  
  //CHECKS TO MAKE SURE BALANCE AND BET ARE VALID
  function isReady() {
	if(document.craps.balance.value != 0 && this.currentBetTotal != 0)
		return true;
	else
		if(document.craps.balance.value == 0)
			this.showMessage("Your broke.\nClick Start Over to play again.");
		else
			this.showMessage("Please place your bets.\nClick Roll Dice to play.");
		
	return false;
  }
  
  
  //GET THE VALUES FOR THE DICE AND SUM
  function rollDice() {
	//ROLL THE DICE
	this.die1 = Math.floor(1 + Math.random() * 6);
	this.die2 = Math.floor(1 + Math.random() * 6);
	this.sumOfDice = this.die1 + this.die2;

	//SHOW USER THE RESULTS
	document.craps.firstDie.value	= this.die1;
	document.craps.secondDie.value	= this.die2;
	document.craps.sum.value		= this.sumOfDice;
  }
  
  
  //FUNCTION USED TO ASSIGN PASSED IN VALUE TO myPoint
  function setMyPoint(value) {
	this.myPoint = value;
	document.craps.point.value = this.myPoint;
  } 


  //CHECKS FOR BETS PLACED ON PASS LINE
  function checkPassLine() {
	if(parseInt(document.craps.passLine.value) != 0) {
		switch(this.gameStatus) {
			case 0:													//VALUE OF WON FLAG
				this.updateBalance(document.craps.passLine.value);
				this.message("Won: $" + document.craps.passLine.value + " on Pass Line\n");
				this.resetPassLine();
				break;
			case 1:													//VALUE OF LOST FLAG
				this.updateBalance(-document.craps.passLine.value);
				this.message("Lost: $" + document.craps.passLine.value + " on Pass Line\n");
				this.resetPassLine();
				break;
		}
	}
  } 


  //RESETS PASS LINE BET VALUE
  function resetPassLine() {
	this.currentBetTotal -= document.craps.passLine.value
	document.craps.passLine.value = 0;
  } 


  //CHECKS FOR BETS PLACED ON DONT PASS BAR
  function checkDontPassBar() {
	if(document.craps.dontPassBar.value != 0) {
		if(this.sumOfDice != 12) {
			switch(this.gameStatus) {
				case 0:													//VALUE OF WON FLAG
					this.updateBalance(-document.craps.dontPassBar.value);
					this.message("Lost: $" + document.craps.dontPassBar.value + " on Don't Pass Bar\n");
					this.resetDontPassBar();
					break;
				case 1:													//VALUE OF LOST FLAG
					this.updateBalance(document.craps.dontPassBar.value);
					this.message("Won: $" + document.craps.dontPassBar.value + " on Don't Pass Bar\n");
					this.resetDontPassBar();
					break;
			}
		} else {
			this.message("Rolled " + this.sumOfDice + ".\nStandoff for Don't Pass Bar.\n");
			this.resetDontPassBar();
		}
	}
  } 


  //RESETS DONT PASS BAR BET VALUE
  function resetDontPassBar() {
	this.currentBetTotal -= document.craps.dontPassBar.value;
	document.craps.dontPassBar.value = 0;
  }
  
  
  //CHECKS FOR BETS PLACED ON COME & DON'T COME
  function checkComeBets() {
	if(document.craps.come.value != 0 || document.craps.dontCome.value != 0) {
		if(this.comePoint != '') {
			if(this.sumOfDice == 7) {
				this.message("Rolled 7 before meeting Come Point.\n");
				
				if(document.craps.come.value != 0) {
					this.message("Lost: $" + document.craps.come.value + " on Come\n");
					this.lostCome();
				}
				
				if(document.craps.dontCome.value != 0) {
					this.message("Won: $" + document.craps.dontCome.value + " on Don't Come\n");
					this.wonDontCome();
				}
			} else if(this.sumOfDice == 12 && document.craps.dontCome.value != 0) {
				this.message("Rolled " + this.sumOfDice + ".\nStandoff on Don't Come.\n");
				this.resetDontCome();
			} else if(this.sumOfDice == this.comePoint) {
				this.message("Rolled come point " + this.comePoint + "\n");
				
				if( document.craps.come.value != 0) {
					this.message("Won: $" + document.craps.come.value + " on Come\n");
					this.wonCome();
				}
				
				if(document.craps.dontCome.value != 0) {
					this.message("Lost: $" + document.craps.dontCome.value + " on Don't Come\n");
					this.lostDontCome();
				}
			}
			
			//CHECK TO SEE IF COME POINT NEEDS TO BE RESET
			this.resetComePoint();
		} else {
			switch(this.sumOfDice) {
				case 7: case 11:
					this.message("Rolled " + this.sumOfDice + ".\n");
					
					if(document.craps.come.value != 0) {
						this.message("Won: $" + document.craps.come.value + " on Come\n");
						this.wonCome();
					}
					
					if(document.craps.dontCome.value != 0) {
						this.message("Lost: $" + document.craps.dontCome.value + " on Don't Come\n");
						this.lostDontCome();
					}
					break;
				case 2: case 3: case 12:
					this.message("Rolled " + this.sumOfDice + ".\n");
					
					if(document.craps.come.value != 0) {
						this.message("Lost: $" + document.craps.come.value+ " on Come\n");
						this.lostCome();
					}
					
					if(document.craps.dontCome.value != 0) {
						if(this.sumOfDice == 12) {
							this.message("Standoff on Don't Come.\n");
							this.resetDontCome();
						} else {
							this.message("Won: $" + document.craps.dontCome.value + " on Don't Come\n");
							this.wonDontCome();
						}
					}
					break;
				default:
					//CHECK TO SEE IF COME POINT IS NEEDED
					this.isComePoint();
			}
		}
	}
  } 





  //STEPS TO PERFORM AFTER WINNING COME BET
  function wonCome() {
	this.updateBalance(document.craps.come.value);
	this.resetCome();
  }


  //STEPS TO PERFORM AFTER LOSING COME BET
  function lostCome() {
	this.updateBalance(-document.craps.come.value);
	this.resetCome();
  } 


  //RESETS COME BET VALUE
  function resetCome() {
	this.currentBetTotal -= document.craps.come.value;
	document.craps.come.value = 0;
  }


  //STEPS TO PERFORM AFTER WINNING DON'T COME BET
  function wonDontCome() {
	this.updateBalance(document.craps.dontCome.value);
	this.resetDontCome();
  }


  //STEPS TO PERFORM AFTER LOSING DON'T COME BET
  function lostDontCome() {
	this.updateBalance(-document.craps.dontCome.value);
	this.resetDontCome();
  } 


  //RESETS DON'T COME BET VALUE
  function resetDontCome() {
	this.currentBetTotal -= document.craps.dontCome.value;
	document.craps.dontCome.value = 0;
  }


  //CHECKS TO SEE IF CURRENT ROLL WILL BE COME POINT
  function isComePoint() {
	if(document.craps.come.value != 0 || document.craps.dontCome.value != 0) {
		switch(this.sumOfDice) {
			case 4: case 5: case 6: case 8: case 9: case 10:
				this.setComePoint(this.sumOfDice);
				this.message("Come point is " + this.comePoint + ".\n");
				break;
		}
	}
  }
  
  
  
  //RESET COME POINT IF NEEDED
  function resetComePoint() {
	if(document.craps.come.value == 0 && document.craps.dontCome.value == 0) {
		this.setComePoint('');
	}
  }
  
  
  //FUNCTION USED TO ASSIGN PASSED IN VALUE TO comePoint
  function setComePoint(value) {
	this.comePoint = value;
	document.craps.comePoint.value = this.comePoint;
  } 


  //CHECKS FOR BETS PLACED ON FIELD
  function checkField() {
	if(document.craps.field.value != 0) {
		switch(this.sumOfDice) {
			case 3: case 4: case 9: case 10: case 11:
				this.updateBalance(document.craps.field.value);
				this.message("Won: $" + document.craps.field.value + " on Field\n");
				this.resetField();
				break;
			case 2: case 12:
				this.updateBalance(document.craps.field.value * 2);
				this.message("Won: $" + (document.craps.field.value * 2) + " on Field\n");
				this.resetField();
				break;
			default:
				this.updateBalance(-document.craps.field.value);
				this.message("Lost: $" + document.craps.field.value + " on Field\n");
				this.resetField();
				break;
		}
	}
  }


  //RESETS FIELD BET VALUE
  function resetField() {
	this.currentBetTotal -= document.craps.field.value;
	document.craps.field.value = 0;
  }


  //CHECKS FOR BETS PLACED ON BIG 6
  function checkBigSix() {
	if(document.craps.bigSix.value != 0) {
		if(this.sumOfDice == 7) {
			this.updateBalance(-document.craps.bigSix.value);
			this.message("Lost: $" + document.craps.bigSix.value + " on Big 6\n");
			this.resetBigSix();
		} else if(this.sumOfDice == 6) {
			this.updateBalance(document.craps.bigSix.value);
			this.message("Won: $" + document.craps.bigSix.value + " on Big 6\n");
			this.resetBigSix();
		}
	}
  }


  //RESETS BIG 6 BET VALUE
  function resetBigSix() {
	this.currentBetTotal -= document.craps.bigSix.value;
	document.craps.bigSix.value = 0;
  }
  
  
  //CHECKS FOR BETS PLACED ON BIG 8
  function checkBigEight() {
	if(document.craps.bigEight.value != 0) {
		if(this.sumOfDice == 7) {
			this.updateBalance(-document.craps.bigEight.value);
			this.message("Lost: $" + document.craps.bigEight.value + " on Big 8\n");
			this.resetBigEight();
		} else if(this.sumOfDice == 8) {
			this.updateBalance(document.craps.bigEight.value);
			this.message("Won: $" + document.craps.bigEight.value + " on Big 8\n");
			this.resetBigEight();
		}
	}
  }


  //RESETS BIG 8 BET VALUE
  function resetBigEight() {
	this.currentBetTotal -= document.craps.bigEight.value;
	document.craps.bigEight.value = 0;
  }
  
  
  //CHECKS FOR BETS PLACED ON ANY 7
  function checkAnySeven() {
	if(document.craps.anySeven.value != 0 && this.sumOfDice == 7) {
		this.updateBalance(document.craps.anySeven.value * 4);
		this.message("Won: $" + (document.craps.anySeven.value * 4) + " on Any 7\n");
		this.resetAnySeven();
	} else if(document.craps.anySeven.value != 0) {
		this.updateBalance(-document.craps.anySeven.value);
		this.message("Lost: $" + document.craps.anySeven.value + " on Any 7\n");
		this.resetAnySeven();
	}
  }


  //RESETS ANY 7 BET VALUE
  function resetAnySeven() {
	this.currentBetTotal -= document.craps.anySeven.value;
	document.craps.anySeven.value = 0;
  } 
  
  
  //CHECKS FOR BETS PLACED ON ANY 11
  function checkAnyEleven() {
	if(document.craps.anyEleven.value != 0) {
		if(this.sumOfDice == 11) {
			this.updateBalance(document.craps.anyEleven.value * 15);
			this.message("Won: $" + (document.craps.anyEleven.value * 15) + " on Any 11\n");
			this.resetAnyEleven();
		} else {
			this.updateBalance(-document.craps.anyEleven.value);
			this.message("Lost: $" + document.craps.anyEleven.value + " on Any 11\n");
			this.resetAnyEleven();
		}
	}
  }


  //RESETS ANY 11 BET VALUE
  function resetAnyEleven() {
	this.currentBetTotal -= document.craps.anyEleven.value;
	document.craps.anyEleven.value = 0;
  } 
  
  
  //CHECKS FOR BETS PLACED ON ANY CRAPS
  function checkAnyCraps() {
	if(document.craps.anyCraps.value != 0) {
		switch(this.sumOfDice) {
			case 2: case 3: case 12:
				this.updateBalance(document.craps.anyCraps.value * 7);
				this.message("Won: $" + (document.craps.anyCraps.value * 7) + " on Any Craps\n");
				this.resetAnyCraps();
				break;
			default:
				this.updateBalance(-document.craps.anyCraps.value);
				this.message("Lost: $" + document.craps.anyCraps.value + " on Any Craps\n");
				this.resetAnyCraps();
		}
	}
  }


  //RESETS ANY 7 BET VALUE
  function resetAnyCraps() {
	this.currentBetTotal -= document.craps.anyCraps.value;
	document.craps.anyCraps.value = 0;
  } 
  
  
  //CHECKS FOR BETS PLACED ON HORN
  function checkHorn() {
	if(document.craps.horn.value != 0) {
		switch(this.sumOfDice) {
			case 2: case 12:
				this.updateBalance(document.craps.horn.value * 30);
				this.message("Won: $" + (document.craps.horn.value * 30) + " on Horn\n");
				this.resetHorn();
				break;
			case 3: case 11:
				this.updateBalance(document.craps.horn.value * 15);
				this.message("Won: $" + (document.craps.horn.value * 15) + " on Horn\n");
				this.resetHorn();
				break;
			default:
				this.updateBalance(-document.craps.horn.value);
				this.message("Lost: $" + document.craps.horn.value + " on Horn\n");
				this.resetHorn();
		}
	}
  }


  //RESETS HORN BET VALUE
  function resetHorn() {
	this.currentBetTotal -= document.craps.horn.value;
	document.craps.horn.value = 0;
  }
  
  
  //UPDATE currentBetTotal TO MAKE SURE IT IS CORRECT
  function checkBetTotal() {
	this.currentBetTotal = parseInt(document.craps.passLine.value) + parseInt(document.craps.dontPassBar.value) + parseInt(document.craps.come.value) + parseInt(document.craps.dontCome.value) + parseInt(document.craps.field.value) + parseInt(document.craps.bigSix.value) + parseInt(document.craps.bigEight.value) + parseInt(document.craps.anySeven.value) + parseInt(document.craps.anyEleven.value) +  parseInt(document.craps.anyCraps.value) + parseInt(document.craps.horn.value);
  }


  
  //DISPLAYS THE RULE FOR THE PASSED IN BET TYPE
  function showRule(type) {
  	switch(type) {
  		case 'Pass Line':
  			this.showMessage("Pass Line bets are placed before the first roll of the dice in a new craps round.\n\nPass Line bets win immediately if the first roll is 7 or 11, and loses if the roll is 2, 3, or 12 (craps numbers). If any other number (4, 5, 6, 8, 9, or 10) is rolled, that number becomes the shooter's \"point.\"\n\nIf the shooter rolls the \"point\" again before rolling a 7, Pass Line bets win. If the shooter rolls a 7 before rolling the \"point\" again, your Pass Line bets lose.\n\nPayoff is 1 to 1.");
			break;
		case 'Dont Pass Bar':
  			this.showMessage("Don't Pass Bar bets are essentially the reverse of the Pass Line, and are also placed before the first roll of the dice in a new craps round.\n\nDon't Pass Bar bets win immediately if the first roll is 2 or 3, and lose if the roll is 7 or 11. If 12 is rolled, it's a standoff, nobody wins. If any other number (4, 5, 6, 8, 9, or 10) is rolled, that number becomes the shooter's \"point.\"\n\nIf the shooter rolls the \"point\" again before rolling a 7, your Don't Pass Bar bets lose. If the shooter rolls a 7 before rolling the \"point\" again, your Don't Pass Bar bets win.\n\nPayoff is 1 to 1.");
			break;
		case 'Come':
  			this.showMessage("Come bets are placed after the shooter's \"point\" has been made.\n\nOn the next roll, if the sum is 7 or 11, Come bets win. If the shooter rolls a 2, 3, or 12, Come bets lose. If a 4, 5, 6, 8, 9, or 10 is rolled, that number becomes your \"come point.\"\n\nAfter the \"come point\" is established, Come bets win if the shooter rolls the \"come point\" again before rolling a 7. If a 7 is rolled before the \"come point\", Come bets lose.");
			break;
		case 'Dont Come':
  			this.showMessage("Don't Come bets are essentially the reverse of Come Bets, and are also placed after the shooter's \"point\" has been made.\n\nDon't Come bets win immediately when the shooter's next roll is 2 or 3, and lose if the roll is 7 or 11. If the shooter rolls a 12, it's a standoff, nobody wins. If a 4, 5, 6, 8, 9, or 10 is rolled, that number becomes your \"come point.\"\n\nAfter the \"come point\" is established, Don't Come bets win if 7 is rolled before the \"come point\" is rolled again. If the shooter rolls the \"come point\" before a 7, Don't Come bets lose.\n\nPayoff is 1 to 1.");
			break;
		case 'Field':
			this.showMessage("Field bets win if the next roll is 2, 3, 4, 9, 10, 11, or 12, and lose if anything else is rolled.\n\nPayoff is 1 to 1 on 3, 4, 9, 10, or 11.  2 to 1 on 2 or 12");
			break;
		case 'Big 6':
			this.showMessage("A Big 6 bet is a bet that 6 will be rolled before 7.\n\nPayoff is 1 to 1.");
			break;
		case 'Big 8':
			this.showMessage("A Big 8 bet is a bet that 8 will be rolled before 7.\n\nPayoff is 1 to 1.");
			break;
		case 'Any 7':
			this.showMessage("Any 7 bets win if the next roll is 7, and lose if anything else is rolled.\n\nPayoff is 4 to 1.");
			break;
		case 'Any 11':
			this.showMessage("Any 11 bets win if the next roll is 11, and lose if anything else is rolled.\n\nPayoff is 15 to 1.");
			break;
		case 'Any Craps':
			this.showMessage("Any Craps bets win if the next roll is 2, 3, or 12, and lose if anything else is rolled.\n\nPayoff is 7 to 1.");
			break;
		case 'Horn':
			this.showMessage("Horn bets win if the next roll is 2, 3, 11, or 12, and lose if anything else is rolled.\n\nPayoff is 30 to 1 on 2 or 12. 15 to 1 on 3 or 11");
			break;
  	}
  }

//-->