function Dice () {
	this.die = new Array (4)
	for (var a=0; a<5; a++) {
		this.die[a] = new Die ()
	}
	this.rollCount = 0

	this.rolledYet = false
	this.roll = rollDice
	this.change = change
	this.rollsLeft = rollsLeft
	this.isHeld = isHeld
	this.reset = resetDice
	this.stats = stats
	this.isYahtzee = false
}

function stats (num) {
	var count = 0
	for (var a = 0; a < 5; a++) {
		if (this.die[a].val == num) {count ++}
	}
	return count
}

function rollsLeft () {
	return 3-this.rollCount
}

function rollDice () {
	this.rolledYet = true
	if (this.rollsLeft () > 0) {
		for (var a=0; a<5; a++) {
			if (!this.die[a].isHeld ()) {
				this.die[a].roll ()
				var img = eval("document.die" + a)
				img.src = this.die[a].val + ".gif"
			}
		}
		this.rollCount ++
		document.rolls_form.rolls.value = this.rollsLeft ()
	} else {
		alert ("Plus de lancers, vous devez marquer")
	}
}

function change (x) {
	var img = eval("document.die" + x)
	if (this.die[x].isHeld ()) {
		this.die[x].unHold ()
		document.dice_form.elements[x].value = "garde"
		img.src = this.die[x].val + ".gif"
	} else {
		this.die[x].hold ()
		document.dice_form.elements[x].value = "gardé."
		img.src = "h" + this.die[x].val + ".gif"
	}
}

function isHeld (x) {
	return this.die[x].isHeld ()
}

function resetDice () {
	this.rolledYet = false
	for (var a=0; a<5; a++) {
		this.die[a] = new Die ()
		var img = eval("document.die" + a)
		img.src = this.die[a].val + ".gif"
		this.rollCount = 0
		document.rolls_form.rolls.value = this.rollsLeft ()
		document.dice_form.elements[a].value = "garde"
	}
}
