// Parameters for the questions
// Parameters are (xLower, xUpper, yLower, yUpper, #ofQuestions, add, sub, mult, div)
 q1param = new Array(  1,   5,   1,   5, 10, 1, 0, 0, 0)
 q2param = new Array(  1,  10,   1,  10, 10, 1, 0, 0, 0)
 q3param = new Array(  1,   5,   1,   5, 10, 0, 1, 0, 0)
 q4param = new Array(  1,  10,   1,  10, 10, 0, 1, 0, 0)
 q5param = new Array(  1,  15,   1,   5, 10, 1, 0, 0, 0)
 q6param = new Array(  1,  15,   1,  10, 10, 1, 0, 0, 0)
 q7param = new Array(  1,  15,   1,  15, 10, 1, 0, 0, 0)
 q8param = new Array(  1,  15,   1,   5, 10, 0, 1, 0, 0)
 q9param = new Array(  1,  15,   1,  10, 10, 0, 1, 0, 0)
q10param = new Array(  1,  15,   1,  15, 10, 0, 1, 0, 0)
q11param = new Array(  1,  10,   1,  20, 10, 1, 0, 0, 0)
q12param = new Array(  1,  20,   1,  20, 10, 1, 0, 0, 0)
q13param = new Array(  1,  10,  11,  20, 10, 0, 1, 0, 0)
q14param = new Array(  1,  20,   1,  20, 10, 0, 1, 0, 0)
q15param = new Array(  1,  50,   1,  50, 10, 1, 0, 0, 0)
q16param = new Array(  1,  50,   1,  50, 10, 0, 1, 0, 0)
q17param = new Array(100, 120,   1,  50, 10, 1, 0, 0, 0)
q18param = new Array(100, 140, 100, 140, 10, 1, 0, 0, 0)



// Writes to the document
function makeQuestions(questionNumber)
{
	
	xLower = eval("q" + questionNumber + "param[0]")
	xUpper = eval("q" + questionNumber + "param[1]")
	yLower = eval("q" + questionNumber + "param[2]")
	yUpper = eval("q" + questionNumber + "param[3]")
	numberOfQuestions = eval("q" + questionNumber + "param[4]")

	possibilitiesForSign = new Array
	currentNumberOfSigns = 0
	if (eval("q" + questionNumber + "param[5]") == 1)
	{
		possibilitiesForSign[currentNumberOfSigns] = " &#043; "
		currentNumberOfSigns++
	}
	if (eval("q" + questionNumber + "param[6]") == 1)
	{
		possibilitiesForSign[currentNumberOfSigns] = " &#150; "
		currentNumberOfSigns++
	}
	if (eval("q" + questionNumber + "param[7]") == 1)
	{
		possibilitiesForSign[currentNumberOfSigns] = " &#215; "
		currentNumberOfSigns++
	}
	if (eval("q" + questionNumber + "param[8]") == 1)
	{
		possibilitiesForSign[currentNumberOfSigns] = " &#247; "
		currentNumberOfSigns++
	}

	xVar = new Array
	yVar = new Array
	zAns = new Array

	// Writes the questions themselves
	document.write("<FORM NAME='question'>")
	document.write("<TABLE BORDER=0>")
	currentCellIsEnd = 0
	xVar[0] = 0
	yVar[0] = 0
	zAns[0] = 0
	for (currentQuestion=1; currentQuestion<=numberOfQuestions; currentQuestion++)
	{
		newSign = possibilitiesForSign[Math.floor(Math.random() * possibilitiesForSign.length)]
		xVar[currentQuestion] = Math.floor(Math.random() * (xUpper - xLower + 1)) + xLower
		yVar[currentQuestion] = Math.floor(Math.random() * (yUpper - yLower + 1)) + yLower
		if (newSign == " &#043; "){
			zAns[currentQuestion] = xVar[currentQuestion] + yVar[currentQuestion]
		}
		if (newSign == " &#150; "){
			if (xVar[currentQuestion] < yVar[currentQuestion]){
				tempVariable = xVar[currentQuestion]
				xVar[currentQuestion] = yVar[currentQuestion]
				yVar[currentQuestion] = tempVariable
			}
			zAns[currentQuestion] = xVar[currentQuestion] - yVar[currentQuestion]
		}
		if (newSign == " &#215; "){
			zAns[currentQuestion] = xVar[currentQuestion] * yVar[currentQuestion]
		}
		if (newSign == " &#247; "){
			zAns[currentQuestion] = xVar[currentQuestion] / yVar[currentQuestion]
		}
		if (currentCellIsEnd == 0) document.write("<TR>")
		document.write("<TD>")
		document.write(xVar[currentQuestion] + newSign + yVar[currentQuestion] + " = ")
		document.write("<\/TD>")
		document.write("<TD>")
		document.write("<INPUT TYPE='text' NAME='answer" + currentQuestion + "' SIZE='5'>")
		document.write("<\/TD>")
		if (currentCellIsEnd == 1){
			document.write("<\/TR>")
			currentCellIsEnd = 0
		}
		else currentCellIsEnd = 1
	}
	document.write("<\/TABLE>")
	document.write("<A HREF='index.html' onClick='checkAnswers()'>Check Answers</A>")
	document.write("<\/FORM>")

	document.question.answer1.focus()
}



// Checks if the answer is right
function checkAnswers()
{
	numberRight = 0
	numberWrong = 0
	for (currentQuestion=1; currentQuestion<=numberOfQuestions; currentQuestion++)
	{
		if (eval("document.question.answer" + currentQuestion + ".value") == zAns[currentQuestion]) numberRight++;
		else numberWrong++;
	}
	alert("You got " + numberRight + " correct and " + numberWrong + " wrong.")
	return false
}