// HangMan II script- By Chris Fortey (http://www.c-g-f.net/)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// Please keep notice intact

var can_play = true;
var words = new Array("ANANIAS", "CALEB", "NAZARETH", "ESTHER", "SHILOH", "UZZIAH", "HAGGAI", "DORCAS", "ELIJAH");
var details = new Array(
"Ananias, a member of the first Christian community, who dropped dead suddenly after attempting to deceive the Holy Spirit by withholding part of the profit from the sale of a piece of land A few moments later his wife, Sapphira also lied and also suffered the same fate. They both lied to Peter about the amount they had received and individually dropped dead after being rebuked by Peter. Acts 5:1-10. <br /><a href=http://en.wikipedia.org/wiki/Ananias>More...</a>",
"Caleb, the son of Jephunneh is an important figure in the Hebrew Bible, noted for his faith in God when the Hebrew nation refuses to enter the promised land of Canaan.<br /><br />When the Hebrews came to the outskirts of Canaan, the land they believed had been promised them by God, after having fled slavery in Egypt, Moses (the Hebrew leader) sent twelve scouts (or spies, meraglim in Hebrew) into Canaan to report on what was there. Ten of the scouts returned to say that the land would be impossible to claim, and that giants lived there who would crush the Hebrew army. Only two, Joshua and Caleb, returned and said that God would be able to deliver Canaan into the hands of the Hebrew nation.<br /><a href=http://en.wikipedia.org/wiki/Caleb>More...</a>",
"According to the New Testament, Nazareth was the home of Joseph and Mary and the site of the Annunciation, when Mary was told by the Angel Gabriel that she would have Jesus as her son. Nazareth is also assumed to be where Jesus grew up from his infancy to manhood.<br /><a href=http://en.wikipedia.org/wiki/Nazareth>More...</a>",
"Esther was the daughter of Abihail, a Benjamite. She resided with her cousin Mordecai, who held some office in the household of the Persian king at Shushan in the palace.<br /><br />Ahasuerus, having rid himself of Vashti, chose Esther to be his wife and queen. Soon after this he gave Haman the Agagite, his prime minister, power and authority. Haman, without the king's knowledge, plans to kill and extirpate all the Jews throughout the Persian empire. This attempted genocide was averted when Esther reveals this to the king and the king gives the Jews license to defend themselves against all who try to kill them. The king orders Haman and his 10 sons to be hanged on the gallows, just as Haman had planned for Mordecai. The fight begins on the 13th of Adar and thousands lost their lives from both sides across the empire, the other side being enemies of the Jews from various nations.<br /><br />Jews established an annual feast, the feast of Purim, in memory of their wonderful deliverance. According to traditional Jewish dating this took place about fifty-two years after the Return.<br /><br />Esther appears in the Bible as a woman of deep piety, faith, courage, patriotism, and caution, combined with resolution; a dutiful daughter to her adopted father, docile and obedient to his counsels, and anxious to share the favour of the king with him for the good of the Jewish people. That she was raised up as an instrument in the hand of God to avert the destruction of the Jewish people, and to afford them protection and forward their wealth and peace in their captivity, is manifest from the Scripture account.<br /><a href=http://en.wikipedia.org/wiki/Esther>More...</a>",
"Shiloh is mentioned in the Hebrew Bible as an assembly place for the people of Israel where there was a sanctuary containing the ark of the covenant until it was taken by the Philistines. According to the Book of Joshua 18:1, it was at Shiloh that the whole congregation of the children of Israel assembled...and set up the tabernacle of the congregation..., being the tent which housed the ark. Later on, the portable tent seems to have been enclosed within a compound or replaced with a standing structure with doors (1 Samuel 3:15) a precursor to the Temple, that survived until the time of Samuel.<br /><br />At Shiloh Samuel was raised by the priest Eli and later himself served as priest there. When the Israelites were defeated at the battle of Aphek, their Philistine foes (who already had captured the ark of the covenant) apparently destroyed the shrine (1 Samuel 4).<br /><br />The site of Shiloh is usually identified as modern Seilun, about eight miles north of Bethel. There is a tel and many impressive remains from the Caananite and Israelite eras, and till as late as the 8th century. During the following 12 centuries Shiloh is only noted as a station on sojourners' routes, usually having only its religious-historical significance to offer. Only in 1978 did it become residential again, as an eclectic group of Jews accompanying an archeological expedition at the ancient site rendered their tent-camp into the seed of a village.<br /><br />In 1979 Israel claimed the village as an Israeli settlement, and named it Shilo.<br /><a href=http://en.wikipedia.org/wiki/Shiloh_%28Biblical%29>More...</a>",
"His long reign of about fifty-two years was the most prosperous excepting that of Jehoshaphat since the time of Solomon. He was a vigorous and able ruler, and his name spread abroad, even to the entering in of Egypt (2 Chr. 26:8, 14). In the earlier part of his reign, under the influence of Zechariah, he was faithful to Yahweh, and did that which was right in the sight of the Lord (2 Kings 15:3; 2 Chr. 26:4, 5); but toward the close of his long life his heart was lifted up to his destruction, and he wantonly invaded the priest's office (2 Chr. 26:16), and entering the sanctuary proceeded to offer incense on the golden altar. Azariah the High Priest saw the tendency of such a daring act on the part of the king, and with a band of eighty priests he withstood him (2 Chr. 26:17), saying, It appertaineth not unto thee, Uzziah, to burn incense. Uzziah was suddenly struck with tzaraas while in the act of offering incense (26:19-21), and he was driven from the Temple and compelled to reside in a several house to the day of his death (2 Kings 15:5, 27; 2 Chr. 26:3).<br /><br />He was buried in a separate grave in the field of the burial which belonged to the kings (2 Kings 15:7; 2 Chr. 26:23). That lonely grave in the royal necropolis would eloquently testify to coming generations that all earthly monarchy must bow before the inviolable order of the divine will, and that no interference could be tolerated with that unfolding of the purposes of God...<br /><a href=http://en.wikipedia.org/wiki/Uzziah>More...</a>",
"Haggai was one of the twelve minor prophets and the author of the Book of Haggai. He was the first of three prophets (with Zechariah, his contemporary, and Malachi, who lived about one hundred years later), whose ministry belonged to the period of Jewish history which began after the return from captivity in Babylon.<br /><br />Scarcely anything is known of his personal history. He may have been one of the captives taken to Babylon by Nebuchadnezzar. He began his ministry about sixteen years after the return of the Jews to Judah. The work of rebuilding the temple had been put a stop to through the intrigues of the Samaritans. After having been suspended for fifteen years, the work was resumed through the efforts of Haggai and Zechariah (Ezra 6:14). They exhorted the people, which roused them from their lethargy, and induced them to take advantage of a change in the policy of the Persian government under Darius the Great.<br /><a href=http://en.wikipedia.org/wiki/Haggai>More...</a>",
"Dorcas is a female name of Greek origins, (in Aramaic - Tabitha), which means gazelle. There is a type of gazelle called the dorcas-gazelle. The biblical meaning is good woman, as the name appears in Acts 9:36-42. Dorcas was a disciple of Joppa found in the book of Acts. She was a dressmaker, who made clothes for the poor in her village. When she died, the people of the village called Saint Peter, also called Simon, of Galilee, who raised her from the dead.<br /><a href=http://en.wikipedia.org/wiki/Dorcas>More...</a>",
"Elijah is first introduced in 1 Kings 17:1 as delivering a message from God to Ahab, king of Israel in the first half of the ninth century BC. He is sometimes known as The Tishbite, being from the town of Tishbe.<br /><br />Having delivered his message to Ahab, he retired at the command of God to a hiding-place by the brook Cherith, beyond Jordan, where he was fed by ravens. When the brook dried up God sent him to the widow of Zarephath, a city of Zidon, from whose scanty store he was supported for the space of two years. During this period the son of the widow died, and was restored to life by Elijah (1 Kings 17:2-24).<br /><br />During these two years a famine prevailed in the land. At the close of this period of retirement and of preparation for his work, Elijah met Obadiah, one of Ahab's officers, whom he had sent out to seek for pasturage for the cattle, and bade him go and tell his master that Elijah was there. The king came and met Elijah, and reproached him as the troubler of Israel. It was then proposed that sacrifices should be publicly offered, for the purpose of determining whether Baal or the Israelite God was the true God. This was done on Mount Carmel; the result was that a miracle took place convincing those watching that Baal was false and that the Israelite God YHWH, was the true and only God. The prophets of Baal were then put to death by the order of Elijah.<br /><a href=http://en.wikipedia.org/wiki/Elijah>More...</a>");

var to_guess = "";
var display_word = "";
var used_letters = "";
var wrong_guesses = 0;
var random_number;

function letterTyped(element)
{
	selectLetter(element.value.substring(element.value.length-1).toUpperCase());
}

function selectLetter(l)
{
	document.aspnetForm.usedLetters.focus();
	if (can_play == false)
	{
		return;
	}

	if (used_letters.indexOf(l) != -1)
	{
		return;
	}
	
	used_letters += l;
	document.aspnetForm.usedLetters.value = used_letters;
	
	if (to_guess.indexOf(l) != -1)
	{
		pos = 0;
		temp_mask = display_word;
		while (to_guess.indexOf(l, pos) != -1)
		{
			pos = to_guess.indexOf(l, pos);			
			end = pos + 1;

			start_text = temp_mask.substring(0, pos);
			end_text = temp_mask.substring(end, temp_mask.length);

			temp_mask = start_text + l + end_text;
			pos = end;
		}

		display_word = temp_mask;
		document.aspnetForm.displayWord.value = display_word;
			
		if (display_word.indexOf("#") == -1)
		{
			document.all.result.innerHTML = "<br /><b>Well done, you have won!</b><br /><br />";
			document.all.title.innerHTML = "<b>" + words[random_number] + "</b><br />";
			document.all.details.innerHTML = details[random_number];
			can_play = false;
		}
	}
	else
	{
		wrong_guesses += 1;
		eval("document.hm.src=\"html/games/hm" + wrong_guesses + ".gif\"");
			
		if (wrong_guesses == 6)
		{
			document.all.result.innerHTML = "<br /><b>Sorry, you have lost!</b><br /><br />";
			document.all.title.innerHTML= "<b>" + words[random_number] + "</b><br />";
			document.all.details.innerHTML = details[random_number];
			can_play = false;
		}
	}
}

function reset()
{
	selectWord();
	document.aspnetForm.usedLetters.value = "";
	used_letters = "";
	wrong_guesses = 0;
	document.hm.src="html\\games\\hmstart.gif";
	document.aspnetForm.usedLetters.focus();
	document.all.result.innerHTML = "";
	document.all.title.innerHTML = "";
	document.all.details.innerHTML = "";
}

function selectWord()
{
	can_play = true;
	random_number = Math.round(Math.random() * (words.length - 1));
	to_guess = words[random_number];
		
	// display masked word
	masked_word = createMask(to_guess);
	document.aspnetForm.displayWord.value = masked_word;
	display_word = masked_word;
}

function createMask(m)
{
	mask = "";
	word_lenght = m.length;

	for (i = 0; i < word_lenght; i ++)
	{
		mask += "#";
	}
	return mask;
}
