
mNumQuestions = 10;
mQue = new Array(mNumQuestions);


var mGreenCheckIMG = "<IMG SRC='darkGreenCheck.gif' WIDTH=22 HEIGHT=16>";
var mRedCheckIMG = "<IMG SRC='redCheck.gif' WIDTH=22 HEIGHT=16>";
var mBlankCheckIMG = "<IMG SRC='blankCheck.gif' WIDTH=22 HEIGHT=16>";
var mTStart = "<P><TABLE border=0 cellspacing=0 cellpadding=6>\n";
var mTDBegin = "<TD VALIGN='Top' ALIGN='Left'>";
var mTDBeginR = "<TD VALIGN='Top' ALIGN='Right'>";
var mTDBeginA = "<TD VALIGN='Top' ALIGN='Left'>&nbsp;</TD><TD VALIGN='Top' ALIGN='Left'>";
var mTDBeginB = "<TD VALIGN='Top' ALIGN='Left' BGCOLOR='lightGrey' COLSPAN=2>";
var mTDBeginC = "<TD VALIGN='Top' ALIGN='Left' BGCOLOR='lightGrey'>";
var mRadBeg = "<INPUT TYPE='RADIO' NAME='";
var mRadMid = "' VALUE='";
var mRadEnd = "'>";
var mTABeg = "<TEXTAREA NAME='";
var mTAEnd = "' ROWS='4' COLS='60' WRAP='Virtual'></TEXTAREA>";
var mCopy = "<P>&nbsp;</P><DIV align='right'>&copy; 2002 - 2007 by Mark A. Lane, Ph.D.</DIV>";

var mBlankRow = "<TR><TD>&nbsp;</TD></TR>\n";

var isNav = false;
var isIE = false;
var isNav6 = false;
var mVersion = parseInt(navigator.appVersion);

if (mVersion >= 4) {
	if (navigator.appName == "Netscape") {
		if (mVersion >= 5) {
			isNav6 = true;
		} else {
			isNav = true;
		}
	} else if (navigator.appName == "Microsoft Internet Explorer") {
		isIE = true;
	}
}

function Question() {
	this.mQ = "";
	this.mQA = "";
	this.mQB = "";
	this.mQC = "";
	this.mQD = "";
	this.mQE = "";
	this.mA = "";
	this.mR = "";
	this.mC = "";
	this.mT = "";
	this.mE = "";
	this.mG = "";
	this.mGW = "";
	this.mGH = "";
	this.mN = "";
	this.mAns = "";
}

function drawLayer() {
	var theLayerStr = "";
	if (isNav) {
		theLayerStr = "<layer name='theQuiz' left=150 top=110><form>"
		theLayerStr += drawMCQuestions();
		theLayerStr += "</form></layer>";
	} else if (isIE) {
		theLayerStr = "<div id='theQuiz'><form>";
		theLayerStr += drawMCQuestions();
		theLayerStr += "</form></div>";
	} else {
		theLayerStr = "" + navigator.appName + " " + navigator.appVersion + " " + isNav + isIE + "Netscape Communicator 4.0 or higher or Internet Explorer 4.0 or higher is required for the quiz.";
	}
	return theLayerStr;
}


function createQuestions() {
	for (i=0; i< mNumQuestions; i++) {
		theType = Math.round(Math.random()*5); 
		if (theType <= 2) {
			mQue[i] = new randomERProblem();
		} else if (theType <= 4) {
			mQue[i] = new randomSDProblem();
		} else if (theType == 5) {
			mQue[i] = new randomSD2Problem();
		}
	}
}

function drawMCQuestions() {
	createQuestions();
	theOut = "<h1>Two Asset Portfolio Quiz</h1><hr>";
	allEssay = true;
	theNumQuestions = mNumQuestions;
	theOut += "<form name='quiz'>";
	theOut += mTStart + "\n";
	for (i = 1; i <= theNumQuestions; i++) {
		if (mQue[i-1].mG != "") {
			theOut += mBlankRow;
			theOut += "<TR>\n" + mTDBegin + "&nbsp;</TD>\n";
			theOut += mTDBegin + "&nbsp;</TD>\n";
			if ((mQue[i-1].mGH != "") && (mQue[i-1].mGW != "")) {
				theOut += mTDBegin + "<IMG SRC='" + mQue[i-1].mG + "' WIDTH='" + mQue[i-1].mGW + "' HEIGHT='" + mQue[i-1].mGH + "'></TD></TR>\n";
			} else {
				theOut += mTDBegin + "<IMG SRC='" + mQue[i-1].mG + "'></TD></TR>\n";
			}
		}
			theOut += mBlankRow;
		theOut += "<TR>\n" + mTDBegin + "&nbsp;</TD>\n";
		theOut += mTDBegin  +  i  + ".</TD>\n";
		theOut += mTDBegin + mQue[i-1].mQ + "</TD>\n</TR>\n";
		if (mQue[i-1].mN >= 1) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "a" + mRadEnd + "</TD>";
			theOut += mTDBegin + "a. " + mQue[i-1].mQA + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN >= 2) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "b" + mRadEnd + "</TD>";
			theOut += mTDBegin + "b. " + mQue[i-1].mQB + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN >= 3) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "c" + mRadEnd + "</TD>";
			theOut += mTDBegin + "c. " + mQue[i-1].mQC + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN >= 4) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "d" + mRadEnd + "</TD>";
			theOut += mTDBegin + "d. " + mQue[i-1].mQD + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN >= 5) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "e" + mRadEnd + "</TD>";
			theOut += mTDBegin + "e. " + mQue[i-1].mQE + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mT == "Essay") {
			theOut += "<TR>\n" + mTDBeginA + "&nbsp;</TD>";
			theOut += mTDBegin +  mTABeg + "q" + i + mTAEnd  + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mT != "Essay") {
			allEssay = false;
		}
	}
		theOut += "</TABLE></P>\n";
	theOut += "<P><INPUT TYPE='button' Name='checkit' Value='How did I do?' onClick='checkMCAnswers(this.form)'></P>";
	theOut += "</form>";
	theOut += mCopy;
	if (isNav) {
		theOut += "<P><img src='space.gif' width='1' height='4000'></P>";
	}
	return theOut;
}

function checkMCAnswers(form) {
	theNumCorrect = 0;
	theNumToGrade = mNumQuestions;
	theOutStr = "";
	k = -1;
	for (i = 0; i < mNumQuestions; i++) {
		if (mQue[i].mT == "Essay") {
			k++;
			mQue[i].mR = "" + form.elements[k].value;
		} else {
			mQue[i].mR = "";
			for (j = 0; j < mQue[i].mN; j++) {
				k++;
				if (form.elements[k].checked) {
					if (j == 0) {
						mQue[i].mR = "a";
					}
					if (j == 1) {
						mQue[i].mR = "b";
					}
					if (j == 2) {
						mQue[i].mR = "c";
					}
					if (j == 3) {
						mQue[i].mR = "d";
					}
					if (j == 4) {
						mQue[i].mR = "e";
					}
				}
			}
		}
		if ((mQue[i].mT != "Essay") && (mQue[i].mA.toLowerCase() == mQue[i].mR)) {
			theNumCorrect++;
			mQue[i].mC = 1;
		} else {
			mQue[i].mC = 0;
		}
		if (mQue[i].mT == "Essay") {
			theNumToGrade--;
		}
	}
	if (theNumToGrade > 0) {
		theOutStr += " \nYou correctly answered " + theNumCorrect + " of " + theNumToGrade + " questions.\n \n";
		theOutStr += "Correct answers are indicated with a green checkmark. ";
		theOutStr += "Incorrect answers are indicated with a red X.";
		alert(theOutStr);
	}
	drawExplanation();
	scroll(0,0);
}

function drawExplanation() {
	theOutStr1 = "";
	theOutStr1 += "<P><H1>Two Asset Portfolio Quiz: Results</H1></P><HR>";
	if (isIE) {
		document.all.theQuiz.innerHTML = theOutStr1 + drawMCQuestions2();
	}
	if (isNav) {
		document.theQuiz.document.write(theOutStr1 + drawMCQuestions2());
		document.theQuiz.document.close();
	}
	if (isNav6) {
		document.getElementById("theQuiz").innerHTML = theOutStr1 + drawMCQuestions2();
	}
}

function drawMCQuestions2() {
	theOut = "";
	allEssay = true
	theNumQuestions = mNumQuestions;
	theOut += mTStart + "\n";
	for (i = 1; i <= theNumQuestions; i++) {
		if (mQue[i-1].mG != "") {
			theOut += mBlankRow;
			theOut += "<TR>\n" + mTDBegin + "&nbsp;</TD>\n";
			theOut += mTDBegin + "&nbsp;</TD>\n";
			if ((mQue[i-1].mGH != "") && (mQue[i-1].mGW != "")) {
				theOut += mTDBegin + "<IMG SRC='" + mQue[i-1].mG + "' WIDTH='" + mQue[i-1].mGW + "' HEIGHT='" + mQue[i-1].mGH + "'></TD></TR>\n";
			} else {
				theOut += mTDBegin + "<IMG SRC='" + mQue[i-1].mG + "'></TD></TR>\n";
			}
		}
		if (mQue[i-1].mT != "Essay") {
			theOut += mBlankRow;
			if (mQue[i-1].mC >= 1) {
				theOut += "<TR>\n" + mTDBeginR + mGreenCheckIMG + "</TD>\n";
			} else {
				theOut += "<TR>\n" + mTDBeginR + mRedCheckIMG + "</TD>\n";
			}
		} else {
			theOut += mBlankRow;
			theOut += "<TR>\n" + mTDBeginR + mBlankCheckIMG + "</TD>\n";
		}
		theOut += mTDBeginR  +  i  + ".</TD>\n";
		theOut += mTDBegin + mQue[i-1].mQ + "</TD>\n</TR>\n";
		if (mQue[i-1].mN >= 1) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "a. " + mQue[i-1].mQA + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN>= 2) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "b. " + mQue[i-1].mQB + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN >= 3) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "c. " + mQue[i-1].mQC + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN >= 4) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "d. " + mQue[i-1].mQD + "</TD>\n</TR>\n";
		}
		if (mQue[i-1].mN >= 5) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "e. " + mQue[i-1].mQE + "</TD>\n</TR>\n";
		}
		theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='red'>Your Answer:</FONT></TD>";
		theOut += mTDBeginC  + "<FONT COLOR='red'>" + mQue[i-1].mR + "</FONT>&nbsp;</TD>\n</TR>\n";
		if (mQue[i-1].mT != "Essay") {
			theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='green'>Correct Answer:</FONT></TD>";
			theOut += mTDBeginC  + "<FONT COLOR='green'>" + mQue[i-1].mA.toLowerCase() + "</FONT>&nbsp;</TD>\n</TR>\n";
		}
		if (mQue[i-1].mE != "") {
			if (mQue[i-1].mT != "Essay") {
				theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='green'>Explanation:</FONT></TD>";
				theOut += mTDBeginC  + mQue[i-1].mE + "&nbsp;</TD>\n</TR>\n";
			} else {
				theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='green'>Our Answer:</FONT></TD>";
				theOut += mTDBeginC  + mQue[i-1].mE + "&nbsp;</TD>\n</TR>\n";
			}
		}
	}
	theOut += "</TABLE></P>\n";
	theOut += mCopy;
	return theOut;
}

function randomERProblem() {
	var theQue = new Question();
  	var theRetA = Math.round(Math.random()*30) + 1; 
    var theRetB = Math.round(Math.random()*15) + theRetA; 
    var theSDA = Math.round(Math.random()*(theRetA*1.5)) + 1; 
    var theSDB = Math.round(Math.random()*15) + theSDA; 
    var theCorr = (Math.round(Math.random()*100))/100; 
    var theW = Math.round(Math.random()*8 + 1)*10;
    var isNeg = Math.random(); 
    if (isNeg < 0.3) theCorr *= -1;
    var theERP = (theW/100)*theRetA + (1 - theW/100)*theRetB;
    var theERPOut = "" + Math.round(theERP*100)/100;
  	var theRetAOut = "" + Math.round(theRetA*100)/100;
  	var theRetBOut = "" + Math.round(theRetB*100)/100;
  	var theSDAOut = "" + Math.round(theSDA*100)/100;
  	var theSDBOut = "" + Math.round(theSDB*100)/100;
  	var theSDAOut2 = "" + Math.round(theSDA*100)/10000;
  	var theSDBOut2 = "" + Math.round(theSDB*100)/10000;
 	var theCorrOut = "" + Math.round(theCorr*10000)/10000;
 	var theWOut = "" + Math.round(theW*100)/100;
 	var theWOut2 = "" + Math.round(theW*100)/10000;
  	theQue.mQ = "Find the Expected Return on a portfolio formed from stocks A and B given that ";
    theQue.mQ += "the Expected Return on Stock A is " + theRetAOut + "\%, ";
    theQue.mQ += "the Expected Return on Stock B is " + theRetBOut + "\%, ";
    theQue.mQ += "the Standard Deviation on Stock A is " + theSDAOut + "\%, ";
    theQue.mQ += "the Standard Deviation on Stock B is " + theSDBOut + "\%, ";
    theQue.mQ += "the Correlation Coefficient is " + theCorrOut + ", and ";
    theQue.mQ += "the Weight of Stock A is " + theWOut + "\%, ";
    theQue.mE = "<P>The <b>Expected Return on the Portfolio</b> is calculated as follows:</P>";
	theQue.mE += "<P>E[R<sub>p</sub>] = " + theWOut2 + "(" + theRetAOut + "\%) + (1 - " + theWOut2 + ")(" + theRetBOut + "\%) = " + theERPOut + "\%</P>";
    theQue.mAns = theERPOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theERP, .4, "", "\%",2);
 	return theQue;
 }
 
 function randomSDProblem() {
	var theQue = new Question();
  	var theRetA = Math.round(Math.random()*30) + 1; 
    var theRetB = Math.round(Math.random()*15) + theRetA; 
    var theSDA = Math.round(Math.random()*(theRetA*1.5)) + 1; 
    var theSDB = Math.round(Math.random()*15) + theSDA; 
    var theCorr = (Math.round(Math.random()*100))/100; 
    var theW = Math.round(Math.random()*8 + 1)*10;
    var isNeg = Math.random(); 
    if (isNeg < 0.3) theCorr *= -1;
    var theVarP = (theW/100)*(theW/100)*(theSDA/100)*(theSDA/100) + (1 - theW/100)*(1 - theW/100)*(theSDB/100)*(theSDB/100) + 2*(theW/100)*(1 - theW/100)*(theSDA/100)*(theSDB/100)*(theCorr);
    var theSDP = Math.sqrt(theVarP);
    var theVarPOut = "" + Math.round(theVarP*10000)/10000;
    var theSDPOut = "" + Math.round(theSDP*10000)/100;
    var theSDPOut2 = "" + Math.round(theSDP*10000)/10000;
  	var theRetAOut = "" + Math.round(theRetA*100)/100;
  	var theRetBOut = "" + Math.round(theRetB*100)/100;
  	var theSDAOut = "" + Math.round(theSDA*100)/100;
  	var theSDBOut = "" + Math.round(theSDB*100)/100;
  	var theSDAOut2 = "" + Math.round(theSDA*100)/10000;
  	var theSDBOut2 = "" + Math.round(theSDB*100)/10000;
 	var theCorrOut = "" + Math.round(theCorr*10000)/10000;
 	var theWOut = "" + Math.round(theW*100)/100;
 	var theWOut2 = "" + Math.round(theW*100)/10000;
  	theQue.mQ = "Find the Standard Deviation on a portfolio formed from stocks A and B given that ";
    theQue.mQ += "the Expected Return on Stock A is " + theRetAOut + "\%, ";
    theQue.mQ += "the Expected Return on Stock B is " + theRetBOut + "\%, ";
    theQue.mQ += "the Standard Deviation on Stock A is " + theSDAOut + "\%, ";
    theQue.mQ += "the Standard Deviation on Stock B is " + theSDBOut + "\%, ";
    theQue.mQ += "the Correlation Coefficient between the returns on stocks A and B is " + theCorrOut + ", and ";
    theQue.mQ += "the Weight of Stock A is " + theWOut + "\%, ";
    theQue.mE = "<P>First, the <b>Variance on the Portfolio</b> is calculated as follows:</P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sup>2</sup><sub>p</sub> = (" + theWOut2 + ")<sup>2</sup>(" + theSDAOut2 + ")<sup>2</sup> + (1 - " + theWOut2 + ")<sup>2</sup>(" + theSDBOut2 + ")<sup>2</sup> + 2(" + theWOut2 + ")(1 - " + theWOut2 + ")(" + theCorrOut + ")(" + theSDAOut2 + ")(" + theSDBOut2 + ") = " + theVarPOut + "</P>";
    theQue.mE += "<P>Then, the <b>Standard Deviation on the Portfolio</b> is calculated as the square root of the Variance.</P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sub>p</sub> = (" + theVarPOut + ")<sup>1/2</sup> = " + theSDPOut2 + " = " + theSDPOut + "\%</P>";
    theQue.mAns = theSDPOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theSDP*100, .4, "", "\%",2);
 	return theQue;
 }
 
 function randomSD2Problem() {
	var theQue = new Question();
  	var theRetA = Math.round(Math.random()*30) + 1; 
    var theRetB = Math.round(Math.random()*15) + theRetA; 
    var theSDA = Math.round(Math.random()*(theRetA*1.5)) + 1; 
    var theSDB = Math.round(Math.random()*15) + theSDA; 
    var theCorr = (Math.round(Math.random()*100))/100; 
    var theW = Math.round(Math.random()*8 + 1)*10;
    var isNeg = Math.random(); 
    if (isNeg < 0.3) theCorr *= -1;
    var theCov = theCorr*(theSDA/100)*(theSDB/100);
    var theVarP = (theW/100)*(theW/100)*(theSDA/100)*(theSDA/100) + (1 - theW/100)*(1 - theW/100)*(theSDB/100)*(theSDB/100) + 2*(theW/100)*(1 - theW/100)*(theCov);
    var theSDP = Math.sqrt(theVarP);
    var theVarPOut = "" + Math.round(theVarP*10000)/10000;
    var theSDPOut = "" + Math.round(theSDP*10000)/100;
    var theSDPOut2 = "" + Math.round(theSDP*10000)/10000;
  	var theRetAOut = "" + Math.round(theRetA*100)/100;
  	var theRetBOut = "" + Math.round(theRetB*100)/100;
  	var theSDAOut = "" + Math.round(theSDA*100)/100;
  	var theSDBOut = "" + Math.round(theSDB*100)/100;
  	var theSDAOut2 = "" + Math.round(theSDA*100)/10000;
  	var theSDBOut2 = "" + Math.round(theSDB*100)/10000;
 	var theCovOut = "" + Math.round(theCov*10000)/10000;
 	var theWOut = "" + Math.round(theW*100)/100;
 	var theWOut2 = "" + Math.round(theW*100)/10000;
  	theQue.mQ = "Find the Standard Deviation on a portfolio formed from stocks A and B given that ";
    theQue.mQ += "the Expected Return on Stock A is " + theRetAOut + "\%, ";
    theQue.mQ += "the Expected Return on Stock B is " + theRetBOut + "\%, ";
    theQue.mQ += "the Standard Deviation on Stock A is " + theSDAOut + "\%, ";
    theQue.mQ += "the Standard Deviation on Stock B is " + theSDBOut + "\%, ";
    theQue.mQ += "the Covariance between the returns on stocks A and B is " + theCovOut + ", and ";
    theQue.mQ += "the Weight of Stock A is " + theWOut + "\%, ";
    theQue.mE = "<P>First, the <b>Variance on the Portfolio</b> is calculated as follows:</P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sup>2</sup><sub>p</sub> = (" + theWOut2 + ")<sup>2</sup>(" + theSDAOut2 + ")<sup>2</sup> + (1 - " + theWOut2 + ")<sup>2</sup>(" + theSDBOut2 + ")<sup>2</sup> + 2(" + theWOut2 + ")(1 - " + theWOut2 + ")(" + theCovOut + ") = " + theVarPOut + "</P>";
    theQue.mE += "<P>Then, the <b>Standard Deviation on the Portfolio</b> is calculated as the square root of the Variance.</P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sub>p</sub> = (" + theVarPOut + ")<sup>1/2</sup> = " + theSDPOut2 + " = " + theSDPOut + "\%</P>";
    theQue.mAns = theSDPOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theSDP*100, .4, "", "\%",2);
 	return theQue;
 }
 
 function buildAnswers(inQue, inAns, inSpr, inPreSym, inPostSym, inDec) {
 	var theA = Math.round(Math.random()*3 + 1);
 	inDec = Math.pow(10,inDec);
 	var theAns = Math.round(inAns*inDec)/inDec;
 	var theLast = theAns;
	if (theA == 1) {
		inQue.mA = "a";
		inQue.mQA = "" + inPreSym + theAns + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQB = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQC = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQD = "" + inPreSym + theLast + inPostSym;
		inQue.mQE = "";
	} else if (theA == 2) {
		inQue.mA = "b";
		inQue.mQB = "" + inPreSym + theAns + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQC = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQD = "" + inPreSym + theLast + inPostSym;
		theLast = theAns;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQA = "" + inPreSym + theLast + inPostSym;
		inQue.mQE = "";
	} else if (theA == 3) {
		inQue.mA = "c";
		inQue.mQC = "" + inPreSym + theAns + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQD = "" + inPreSym + theLast + inPostSym;
		theLast = theAns;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQB = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQA = "" + inPreSym + theLast + inPostSym;
		inQue.mQE = "";
	} else if (theA == 4) {
		inQue.mA = "d";
		inQue.mQD = "" + inPreSym + theAns + inPostSym;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQC = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQB = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*inDec)/inDec;
		inQue.mQA = "" + inPreSym + theLast + inPostSym;
		inQue.mQE = "";
	}
	return inQue; 
 }

 function drawFractionNoF(inLHS,inNum,inDen,inAnswer) {
	var theOut = "<table cellspacing='1' cellpadding='1'><tr>";
	theOut += "<td rowspan='3' valign='center'>" + inLHS + "</td>";
	theOut += "<td rowspan='3' valign='center'>=</td>";
	theOut += "<td valign='center' align='center'>" + inNum + "</td>";
	theOut += "<td rowspan='3' valign='center'>=</td>";
	theOut += "<td rowspan='3' valign='center'>" + inAnswer + "</td>";
	theOut += "</tr>";
	theOut += "<tr>";
	theOut += "<td valign='center' align='center'><hr noshade></td>";
	theOut += "</tr>";
	theOut += "<tr>";
	theOut += "<td valign='center' align='center'>" + inDen + "</td>";
	theOut += "</tr></table>";
	return theOut;
}

function drawSimpleFraction(inNum,inDen) {
	var theOut = "<table cellspacing='1' cellpadding='1'>";
	theOut += "<tr><td valign='center' align='center'>" + inNum + "</td></tr>";
	theOut += "<tr><td valign='center' align='center'><hr noshade></td></tr>";
	theOut += "<tr><td valign='center' align='center'>" + inDen + "</td></tr>";
	theOut += "</table>";
	return theOut;
}
