<!--
function makeSound4IE(index)
{
	//if (navigator.appName != "Netscape")
		document.soundBox.makeSound(index);   
}

function getNextTargetNumber()
{
	document.formWitzzle.txtTargetNumber.value = Math.floor(Math.random() * 30) + 1;
	document.formWitzzle.txtFormula.value = "";   // clear
	document.formWitzzle.txt3Positions.value = "";
	document.formWitzzle.txt3Numbers.value = "";
	makeSound4IE(16);   // ding sound

}

function WitzzleClicked(number, pos)
{
	var nLength = document.formWitzzle.txtFormula.value.length;
	//alert("Length = " + nLength);
	if (nLength != 0) 
	{
		var oldString = document.formWitzzle.txtFormula.value;
		var lastInput = oldString.substr(nLength-1, 1);
		if (lastInput > "0" && lastInput <= "9" || lastInput == ")")
		{
			alert("You need to click on an operator at this time!");
			return;
		}
	}
	var strFormula = document.formWitzzle.txtFormula.value;
	var pos2 = strFormula.indexOf(number);
	if (pos2 >= 0)
	{
		alert("You can click on this number once and only once!");
		return;
	}
	document.formWitzzle.txt3Positions.value = document.formWitzzle.txt3Positions.value + pos;
	document.formWitzzle.txt3Numbers.value = document.formWitzzle.txt3Numbers.value + number;
	document.formWitzzle.txtFormula.value = document.formWitzzle.txtFormula.value + number;
	makeSound4IE(number);
}

function addOperator(op)
{
	var nLength = document.formWitzzle.txtFormula.value.length;
	if (nLength == 0) 
	{
		if (op == "x" || op == "÷" || op == ")")
		{
			alert("You can not start with an operator 'x', '÷' or ')'!");
			return;
		}
	}
	else
	{
		var oldString = document.formWitzzle.txtFormula.value;
		var lastInput = oldString.substr(nLength-1, 1);
		if ((lastInput == "+" || lastInput == "-" || lastInput == "x" || 
			lastInput == "÷" || lastInput == "(" )
			&& (op == "+" || op == "-" || op == "x" || op == "÷" || op == ")") )
		{
			alert("You can not click on one of the +, -, x, ÷, ) operator at this time!");
			return;
		}
		if (lastInput > "0" && lastInput <= "9" && op == "(")
		{
			alert("You can not click on the '(' operator at this time!");
			return;
		}
	}
	document.formWitzzle.txtFormula.value = document.formWitzzle.txtFormula.value + op;
	if (op == "+")
		makeSound4IE(101);
	if (op == "-")
		makeSound4IE(102);
	if (op == "x")
		makeSound4IE(103);
	if (op == "÷")
		makeSound4IE(104);
}

function checkMyAnswer()
{
	// Verify the 3 positions
	var strPos = document.formWitzzle.txt3Positions.value;
	var strPos1 = strPos.substr(0,1);
	var strPos2 = strPos.substr(1,1);
	var strPos3 = strPos.substr(2,1);
	var strTemp = "";
	if (strPos2 < strPos1)
	{
		strTemp = strPos1;
		strPos1 = strPos2;
		strPos2 = strTemp;
	}
	if (strPos3 < strPos2)
	{
		strTemp = strPos2;
		strPos2 = strPos3;
		strPos3 = strTemp;
	}
	if (strPos2 < strPos1)
	{
		strTemp = strPos1;
		strPos1 = strPos2;
		strPos2 = strTemp;
	}
	if (strPos3 < strPos2)
	{
		strTemp = strPos2;
		strPos2 = strPos3;
		strPos3 = strTemp;
	}
	strPos = strPos1 + strPos2 + strPos3;
	//alert("Position = " + strPos);
	if (strPos != "123" &&
		strPos != "456" &&
		strPos != "789" &&
		strPos != "147" &&
		strPos != "258" &&
		strPos != "369" &&
		strPos != "159" &&
		strPos != "357")
	{
		alert("Bad Combo. Numbers are not in a row, a column etc.");
		var nBadCombo = document.formWitzzle.txtBadCombo.value;
		document.formWitzzle.txtBadCombo.value = parseInt(nBadCombo) + 1;
		document.formWitzzle.txtResult.value = document.formWitzzle.txtFormula.value + " ? ";
		makeSound4IE(13);
		clear();
		return;
	}

	if (document.formWitzzle.txt3Positions.value.length != 3)
	{
		alert("Bad Combo, Only can enter exactly 3 numbers!");
		var nBadCombo = document.formWitzzle.txtBadCombo.value;
		document.formWitzzle.txtBadCombo.value = parseInt(nBadCombo) + 1;
		document.formWitzzle.txtResult.value = document.formWitzzle.txtFormula.value + " ? ";
		makeSound4IE(13);
		clear();
		return;
	}

	strFormula = document.formWitzzle.txtFormula.value;
	var pos = strFormula.indexOf("÷");
	if (pos >=0)
		strFormula = strFormula.substr(0, pos) + "/" + strFormula.substr(pos + 1);
	// you have to see if there is another one	
	pos = strFormula.indexOf("÷");
	if (pos >=0)
		strFormula = strFormula.substr(0, pos) + "/" + strFormula.substr(pos + 1);
	
	pos = strFormula.indexOf("x");
	if (pos >=0)
		strFormula = strFormula.substr(0, pos) + "*" + strFormula.substr(pos + 1);
	// you have to see if there is another one	
	pos = strFormula.indexOf("x");
	if (pos >=0)
		strFormula = strFormula.substr(0, pos) + "*" + strFormula.substr(pos + 1);
		
	//alert ("Formula = " + strFormula);
	eval ("result = " + strFormula);
	//alert("Result = " + result);
	//document.soundBox.makeSound(105);
	
	document.formWitzzle.txtResult.value = document.formWitzzle.txtFormula.value + " = " + result;
	if (result == parseInt(document.formWitzzle.txtTargetNumber.value, 10))
	{
		var nWitzzles = document.formWitzzle.txtWitzzles.value;
		document.formWitzzle.txtWitzzles.value = parseInt(nWitzzles,10) + 1;
		makeSound4IE(11);
	}
	else 
	{
		var nOops = document.formWitzzle.txtOops.value;
		document.formWitzzle.txtOops.value = parseInt(nOops, 10) + 1;
		//alert("Oops count after " + parseInt(nOops,10));
		//alert("Oops value after " + document.formWitzzle.txtOops.value);
		makeSound4IE(12);
	}

	//alert("before Clear = ");
	clear();
}

function clear()
{
	var nTotal = document.formWitzzle.txtTotalAttempts.value;
	document.formWitzzle.txtTotalAttempts.value = parseInt(nTotal, 10) + 1;
	document.formWitzzle.txtFormula.value = "";   // clear
	document.formWitzzle.txt3Positions.value = "";
	document.formWitzzle.txt3Numbers.value = "";

}

function getSampleSolution(nIndex)
{
	nTarget = parseInt(document.formWitzzle.txtTargetNumber.value, 10);
	alert("Sample solution for target number " + nTarget + ":\n\r\n\r        "
			+ arraySolutions[nIndex][nTarget] + "\n\r\n\r" + "The target number will be reset." );

	var nSolutions = document.formWitzzle.txtSolutions.value;
	document.formWitzzle.txtSolutions.value = parseInt(nSolutions, 10) + 1;
	getNextTargetNumber();
}

function resetResult()
{
	document.formWitzzle.txtFormula.value = "";   // clear
	document.formWitzzle.txt3Positions.value = "";
	document.formWitzzle.txt3Numbers.value = "";
	makeSound4IE(14);
}

function undo()
{
	var nLength = document.formWitzzle.txtFormula.value.length;
	//alert("Length = " + nLength);
	if (nLength == 0) return;
	
	var oldString = document.formWitzzle.txtFormula.value;
	var lastInput = oldString.substr(nLength-1, 1);
	if (lastInput> "0" && lastInput <= "9")
	{
		var strPos = document.formWitzzle.txt3Positions.value;
		document.formWitzzle.txt3Positions.value = strPos.substr(0, strPos.length - 1);
		
		var strNum = document.formWitzzle.txt3Numbers.value;
		document.formWitzzle.txt3Numbers.value = strNum.substr(0, strNum.length - 1);
	}
		
	var strFormula = document.formWitzzle.txtFormula.value;
	document.formWitzzle.txtFormula.value = strFormula.substr(0, strFormula.length - 1);
	makeSound4IE(15);
}
// -->
