
mNumQuestions = 10;
mQ = new Array(mNumQuestions);
mQA = new Array(mNumQuestions);
mQB = new Array(mNumQuestions);
mQC = new Array(mNumQuestions);
mQD = new Array(mNumQuestions);
mQE = new Array(mNumQuestions);
mA = new Array(mNumQuestions);
mR = new Array(mNumQuestions);
mC = new Array(mNumQuestions);
mT = new Array(mNumQuestions);
mE = new Array(mNumQuestions);
mG = new Array(mNumQuestions);
mGW = new Array(mNumQuestions);
mGH = new Array(mNumQuestions);
mN = new Array(mNumQuestions);
mAns = 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 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() {
	var thePV;
	var thePV2;
	var theH;
	var theAns = 0;
	var theType = 0;
	var theR;
	var theR2;
	var theA;
	var theCF = new Array(9);
	var theNumCF;
	var	theTemp;
	var theSumCF;
	var ii;
	for (i=0; i< mNumQuestions; i++) {
		theType = Math.round(Math.random()*2); // 0 -> NPV 1 -> IRR 2-> Payback
		if (theType == 0) {
			theR = Math.round(Math.random()*20 + 1);
			thePV = 0;
			mQ[i] = "<P>Find the NPV of the project with the following cash flows if the cost of capital is " + theR + "\%.</P>";
			theNumCF = Math.round(Math.random()*4 + 4);
			for (j = 0; j < (theNumCF+1); j++) {
				if (j == 0) {
					theCF[j] = Math.round(Math.random()*5)*(-100) - 1000;
					thePV += theCF[j];
				} else if (j > 1) {
					theTemp = Math.random();
					if (theTemp < 0.70) {
						theCF[j] = Math.round(Math.random()*5)*100;
					} else {
						theCF[j] = theCF[j-1];
					}
					if ((j == theNumCF) && (theCF[j] == 0)) {
						theCF[j] = 100;
					}
					if (j == theNumCF) { // check to see that sum of CFs is greater than CF[0]
						theSumCF = 0;
						for (jk = 0; jk < (theNumCF+1); jk++) {
							theSumCF += theCF[jk];
						}
						while (theSumCF <= 0) {
							theCF[j] += 100;
							theSumCF += 100;
						}
					}
					thePV += theCF[j]*Math.pow(1 + theR/100,-(j));
				} else {
					theCF[j] = Math.round(Math.random()*5)*100;
					if ((j == theNumCF) && (theCF[j] == 0)) {
						theCF[j] = 100;
					}
					if (j == theNumCF) { // check to see that sum of CFs is greater than CF[0]
						theSumCF = 0;
						for (jk = 0; jk < (theNumCF+1); jk++) {
							theSumCF += theCF[jk];
						}
						while (theSumCF <= 0) {
							theCF[j] += 100;
							theSumCF += 100;
						}
					}
					thePV += theCF[j]*Math.pow(1 + theR/100,-(j));
				}
			}
			mQ[i] += "<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0'><TR>";
			for (j = 0; j < (theNumCF+1); j++) {
				mQ[i] += "<TD ALIGN='CENTER'>" + j + "</TD>";
			}
			mQ[i] += "</TR><TR>";
			mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLineStart.gif'></TD>";
			for (j = 1; j < theNumCF; j++) {
				mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLine.gif'></TD>";
			}
			mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLineEnd.gif'></TD>";
			mQ[i] += "</TR><TR>";
			for (j = 0; j < (theNumCF+1); j++) {
				mQ[i] += "<TD ALIGN='CENTER'>$" + theCF[j] + "</TD>";
			}
			mQ[i] += "</TR></TABLE>";
			mE[i] = "To solve using the TI BAII Plus calculator:<BR><TABLE>";
			mE[i] += "<TR><TD ALIGN='CENTER'>[ CF ]</TD><TD ALIGN='CENTER'>[ 2nd ][CLR Work]</TD></TR>";
			mE[i] += "<TR><TD ALIGN='CENTER'>" + theCF[0] + "</TD><TD ALIGN='CENTER'>[ENTER][DOWN ARROW]</TD></TR>";
			for (j = 1; j < (theNumCF+1); j++) {
				ii = 1;
				mE[i] += "<TR><TD ALIGN='CENTER'>" + theCF[j] + "</TD><TD ALIGN='CENTER'>[ENTER][DOWN ARROW]</TD></TR>";
				while ((j < theNumCF) && (theCF[j] == theCF[j+1])) {
					ii++;
					j++;	
				}
				mE[i] += "<TR><TD ALIGN='CENTER'>" + ii + "</TD><TD ALIGN='CENTER'>[ENTER][DOWN ARROW]</TD></TR>";
			}
			mE[i] += "<TR><TD ALIGN='CENTER'>[ NPV ]</TD><TD ALIGN='CENTER'>&nbsp;</TD></TR>";
			mE[i] += "<TR><TD ALIGN='CENTER'>" + theR + "</TD><TD ALIGN='CENTER'>[ENTER][DOWN ARROW]</TD></TR>";
			mE[i] += "<TR><TD ALIGN='CENTER'>[ CPT ]</TD><TD ALIGN='CENTER'>&nbsp;</TD></TR></TABLE>";
	
			thePV = Math.round(thePV*100)/100;
			theAns = thePV;
		} else if (theType == 1) {
			theH = 0.01;
			theR = 10; // guess
			theR2 = theR + theH;
			thePV = 0;
			thePV2 = 0;
			mQ[i] = "<P>Find the IRR of the project with the following cash flows.</P>";
			theNumCF = Math.round(Math.random()*4 + 4);
			for (j = 0; j < (theNumCF+1); j++) {
				if (j == 0) {
					theCF[j] = Math.round(Math.random()*5)*(-100) - 1000;
				} else if (j > 1) {
					theTemp = Math.random();
					if (theTemp < 0.70) {
						theCF[j] = Math.round(Math.random()*5)*100;
					} else {
						theCF[j] = theCF[j-1];
					}
					if ((j == theNumCF) && (theCF[j] == 0)) {
						theCF[j] = 100;
					}
					if (j == theNumCF) { // check to see that sum of CFs is greater than CF[0]
						theSumCF = 0;
						for (jk = 0; jk < (theNumCF+1); jk++) {
							theSumCF += theCF[jk];
						}
						while (theSumCF <= 0) {
							theCF[j] += 100;
							theSumCF += 100;
						}
					}
				} else {
					theCF[j] = Math.round(Math.random()*5)*100;
					if ((j == theNumCF) && (theCF[j] == 0)) {
						theCF[j] = 100;
					}
					if (j == theNumCF) { // check to see that sum of CFs is greater than CF[0]
						theSumCF = 0;
						for (jk = 0; jk < (theNumCF+1); jk++) {
							theSumCF += theCF[jk];
						}
						while (theSumCF <= 0) {
							theCF[j] += 100;
							theSumCF += 100;
						}
					}
				}
			}
			// calc the IRR
			thePV = 0;
			thePV2 = 1;
			do {
				if (thePV2 == 0) {
					theR = -9999;
					break;
				}
				theR = theR - (thePV/thePV2);
				theR2 = theR + theH;
				thePV = 0;
				thePV2 = 0;
				for (j=0; j <= theNumCF; j++) {
					thePV += theCF[j]*Math.pow(1 + theR/100,-(j));
					thePV2 += theCF[j]*Math.pow(1 + theR2/100,-(j));
				}
				thePV2 = (thePV2 - thePV)/theH;
			} while ((thePV*thePV) > 0.01);
			// end calc
			mQ[i] += "<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0'><TR>";
			for (j = 0; j < (theNumCF+1); j++) {
				mQ[i] += "<TD ALIGN='CENTER'>" + j + "</TD>";
			}
			mQ[i] += "</TR><TR>";
			mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLineStart.gif'></TD>";
			for (j = 1; j < theNumCF; j++) {
				mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLine.gif'></TD>";
			}
			mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLineEnd.gif'></TD>";
			mQ[i] += "</TR><TR>";
			for (j = 0; j < (theNumCF+1); j++) {
				mQ[i] += "<TD ALIGN='CENTER'>$" + theCF[j] + "</TD>";
			}
			mQ[i] += "</TR></TABLE>";
			mE[i] = "To solve using the TI BAII Plus calculator:<BR><TABLE>";
			mE[i] += "<TR><TD ALIGN='CENTER'>[ CF ]</TD><TD ALIGN='CENTER'>[ 2nd ][CLR Work]</TD></TR>";
			mE[i] += "<TR><TD ALIGN='CENTER'>" + theCF[0] + "</TD><TD ALIGN='CENTER'>[ENTER][DOWN ARROW]</TD></TR>";
			for (j = 1; j < (theNumCF+1); j++) {
				ii = 1;
				mE[i] += "<TR><TD ALIGN='CENTER'>" + theCF[j] + "</TD><TD ALIGN='CENTER'>[ENTER][DOWN ARROW]</TD></TR>";
				while ((j < theNumCF) && (theCF[j] == theCF[j+1])) {
					ii++;
					j++;	
				}
				mE[i] += "<TR><TD ALIGN='CENTER'>" + ii + "</TD><TD ALIGN='CENTER'>[ENTER][DOWN ARROW]</TD></TR>";
			}
			mE[i] += "<TR><TD ALIGN='CENTER'>[ IRR ]</TD><TD ALIGN='CENTER'>&nbsp;</TD></TR>";
			mE[i] += "<TR><TD ALIGN='CENTER'>[ CPT ]</TD><TD ALIGN='CENTER'>&nbsp;</TD></TR></TABLE>";
	
			theR = Math.round(theR*100)/100;
			theAns = theR;
		} else if (theType == 2) { //Payback
			mQ[i] = "<P>Find the Payback Period for the project with the following cash flows.</P>";
			theNumCF = Math.round(Math.random()*4 + 4);
			for (j = 0; j < (theNumCF+1); j++) {
				if (j == 0) {
					theCF[j] = Math.round(Math.random()*5)*(-100) - 1000;
				} else if (j > 1) {
					theTemp = Math.random();
					if (theTemp < 0.70) {
						theCF[j] = Math.round(Math.random()*5)*100;
					} else {
						theCF[j] = theCF[j-1];
					}
					if ((j == theNumCF) && (theCF[j] == 0)) {
						theCF[j] = 100;
					}
					if (j == theNumCF) { // check to see that sum of CFs is greater than CF[0]
						theSumCF = 0;
						for (jk = 0; jk < (theNumCF+1); jk++) {
							theSumCF += theCF[jk];
						}
						while (theSumCF <= 0) {
							theCF[j] += 100;
							theSumCF += 100;
						}
					}
				} else {
					theCF[j] = Math.round(Math.random()*5)*100;
					if ((j == theNumCF) && (theCF[j] == 0)) {
						theCF[j] = 100;
					}
					if (j == theNumCF) { // check to see that sum of CFs is greater than CF[0]
						theSumCF = 0;
						for (jk = 0; jk < (theNumCF+1); jk++) {
							theSumCF += theCF[jk];
						}
						while (theSumCF <= 0) {
							theCF[j] += 100;
							theSumCF += 100;
						}
					}
				}
			}
			// calc the Payback
			var theNetCF = new Array(theNumCF + 1);
			theNetCF[0] = theCF[0];
			var theLastNeg = -1;
			for (j=1; j <= theNumCF; j++) {
				theNetCF[j] = theNetCF[j-1] + theCF[j];
				if ((theNetCF[j]) >= 0 && (theLastNeg < 0)) {
					theLastNeg = j - 1;
				}
			}
			var thePayback = theLastNeg + (-theNetCF[theLastNeg])/theCF[theLastNeg + 1];
			thePayback = Math.round(thePayback*100)/100;
			// end calc
			mQ[i] += "<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0'><TR>";
			for (j = 0; j < (theNumCF+1); j++) {
				mQ[i] += "<TD ALIGN='CENTER'>" + j + "</TD>";
			}
			mQ[i] += "</TR><TR>";
			mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLineStart.gif'></TD>";
			for (j = 1; j < theNumCF; j++) {
				mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLine.gif'></TD>";
			}
			mQ[i] += "<TD ALIGN='CENTER'><IMG SRC='TimeLineEnd.gif'></TD>";
			mQ[i] += "</TR><TR>";
			for (j = 0; j < (theNumCF+1); j++) {
				mQ[i] += "<TD ALIGN='CENTER'>$" + theCF[j] + "</TD>";
			}
			mQ[i] += "</TR></TABLE>";
			mE[i] = "<TABLE>";
			mE[i] += "<TR><TD ALIGN='CENTER'><b>Year</b></TD><TD ALIGN='CENTER'><b>Cash Flow</b></TD><TD ALIGN='CENTER'><b>Net Cash Flow</b></TD></TR>";
			for (j = 0; j < (theNumCF+1); j++) {
				mE[i] += "<TR><TD ALIGN='CENTER'>" + j +"</TD><TD ALIGN='CENTER'>" + theCF[j] + "</TD><TD ALIGN='CENTER'>" + theNetCF[j] + "</TD></TR>";
			}
			mE[i] += "<TR><TD COLSPAN='3'>" + drawSimpleFraction("Payback = " + theLastNeg + " + ",(-theNetCF[theLastNeg]),theCF[theLastNeg + 1]," = " + thePayback + " years") + "</TD></TR>";
			mE[i] += "</TABLE>";
			
			theAns = thePayback;
		}
		
		mAns[i] = theAns;
		mN[i] = 4;
		mT[i] = "MC";
		mG[i] = "";
		mGW[i] = "";
		mGH[i] = "";
		
		theA = Math.round(Math.random()*3 + 1);
		
		if (theType == 0) {
			if (theA == 1) {
				mA[i] = "a";
				mQA[i] = "$" + theAns;
				mQB[i] = "$" + Math.round((theAns + 1 + Math.random()*9)*100)/100;
				mQC[i] = "$" + Math.round((theAns + 11 + Math.random()*9)*100)/100;
				mQD[i] = "$" + Math.round((theAns + 21 + Math.random()*9)*100)/100;
				mQE[i] = "";
			} else if (theA == 2) {
				mA[i] = "b";
				mQB[i] = "$" + theAns;
				mQC[i] = "$" + Math.round((theAns + 1 + Math.random()*9)*100)/100;
				mQD[i] = "$" + Math.round((theAns + 11 + Math.random()*9)*100)/100;
				mQA[i] = "$" + Math.round((theAns - 1 - Math.random()*9)*100)/100;
				mQE[i] = "";
			} else if (theA == 3) {
				mA[i] = "c";
				mQC[i] = "$" + theAns;
				mQD[i] = "$" + Math.round((theAns + 1 + Math.random()*9)*100)/100;
				mQA[i] = "$" + Math.round((theAns - 11 - Math.random()*9)*100)/100;
				mQB[i] = "$" + Math.round((theAns - 1 - Math.random()*9)*100)/100;
				mQE[i] = "";
			} else if (theA == 4) {
				mA[i] = "d";
				mQD[i] = "$" + theAns;
				mQA[i] = "$" + Math.round((theAns - 21 - Math.random()*9)*100)/100;
				mQB[i] = "$" + Math.round((theAns - 11 - Math.random()*9)*100)/100;
				mQC[i] = "$" + Math.round((theAns - 1 - Math.random()*9)*100)/100;
				mQE[i] = "";
			}
		} else if (theType == 1) {
			if (theA == 1) {
				mA[i] = "a";
				mQA[i] = "" + theAns + "\%";
				mQB[i] = "" + Math.round((theAns + 1 + Math.random()*2)*100)/100 + "\%";
				mQC[i] = "" + Math.round((theAns + 4 + Math.random()*2)*100)/100 + "\%";
				mQD[i] = "" + Math.round((theAns + 7 + Math.random()*2)*100)/100 + "\%";
				mQE[i] = "";
			} else if (theA == 2) {
				mA[i] = "b";
				mQB[i] = "" + theAns + "\%";
				mQC[i] = "" + Math.round((theAns + 1 + Math.random()*2)*100)/100 + "\%";
				mQD[i] = "" + Math.round((theAns + 4 + Math.random()*2)*100)/100 + "\%";
				mQA[i] = "" + Math.round((theAns - 1 - Math.random()*2)*100)/100 + "\%";
				mQE[i] = "";
			} else if (theA == 3) {
				mA[i] = "c";
				mQC[i] = "" + theAns + "\%";
				mQD[i] = "" + Math.round((theAns + 1 + Math.random()*2)*100)/100 + "\%";
				mQA[i] = "" + Math.round((theAns - 4 - Math.random()*2)*100)/100 + "\%";
				mQB[i] = "" + Math.round((theAns - 1 - Math.random()*2)*100)/100 + "\%";
				mQE[i] = "";
			} else if (theA == 4) {
				mA[i] = "d";
				mQD[i] = "" + theAns + "\%";
				mQA[i] = "" + Math.round((theAns - 7 - Math.random()*2)*100)/100 + "\%";
				mQB[i] = "" + Math.round((theAns - 4 - Math.random()*2)*100)/100 + "\%";
				mQC[i] = "" + Math.round((theAns - 1 - Math.random()*2)*100)/100 + "\%";
				mQE[i] = "";
			}
		} else if (theType == 2) {
			var theLA = 0;
			if (theA == 1) {
				mA[i] = "a";
				mQA[i] = "" + theAns + " years";
				theLA = Math.round((theAns + .25 + Math.random()*2)*100)/100;
				mQB[i] = "" + theLA + " years";
				theLA = Math.round((theLA + .25 + Math.random()*2)*100)/100;
				mQC[i] = "" + theLA + " years";
				theLA = Math.round((theLA + .25 + Math.random()*2)*100)/100;
				mQD[i] = "" + theLA + " years";
				mQE[i] = "";
			} else if (theA == 2) {
				mA[i] = "b";
				mQB[i] = "" + theAns + " years";
				theLA = Math.round((theAns + .25 + Math.random()*2)*100)/100;
				mQC[i] = "" + theLA + " years";
				theLA = Math.round((theLA + .25 + Math.random()*2)*100)/100;
				mQD[i] = "" + theLA + " years";
				theLA = Math.round((theAns - .25 - Math.random()*2)*100)/100;
				mQA[i] = "" + theLA + " years";
				mQE[i] = "";
			} else if (theA == 3) {
				mA[i] = "c";
				mQC[i] = "" + theAns + " years";
				theLA = Math.round((theAns + .25 + Math.random()*2)*100)/100;
				mQD[i] = "" + theLA + " years";
				theLA = Math.round((theAns - .25 - Math.random()*2)*100)/100;
				mQB[i] = "" + theLA + " years";
				theLA = Math.round((theLA - .25 - Math.random()*2)*100)/100;
				mQA[i] = "" + theLA + " years";
				mQE[i] = "";
			} else if (theA == 4) {
				mA[i] = "d";
				mQD[i] = "" + theAns + " years";
				theLA = Math.round((theAns - .25 - Math.random()*2)*100)/100;
				mQC[i] = "" + theLA + " years";
				theLA = Math.round((theLA - .25 - Math.random()*2)*100)/100;
				mQB[i] = "" + theLA + " years";
				theLA = Math.round((theLA - .25 - Math.random()*2)*100)/100;
				mQA[i] = "" + theLA + " years";
				mQE[i] = "";
			}
		}
	}
}

function drawMCQuestions() {
	createQuestions();
	theOut = "<h1>Capital Budgeting Quiz</h1><hr>";
	allEssay = true;
	theNumQuestions = mNumQuestions;
	theOut += "<form name='quiz'>";
	theOut += mTStart + "\n";
	for (i = 1; i <= theNumQuestions; i++) {
		if (mG[i-1] != "") {
			theOut += mBlankRow;
			theOut += "<TR>\n" + mTDBegin + "&nbsp;</TD>\n";
			theOut += mTDBegin + "&nbsp;</TD>\n";
			if ((mGH[i-1] != "") && (mGW[i-1] != "")) {
				theOut += mTDBegin + "<IMG SRC='" + mG[i-1] + "' WIDTH='" + mGW[i-1] + "' HEIGHT='" + mGH[i-1] + "'></TD></TR>\n";
			} else {
				theOut += mTDBegin + "<IMG SRC='" + mG[i-1] + "'></TD></TR>\n";
			}
		}
			theOut += mBlankRow;
		theOut += "<TR>\n" + mTDBegin + "&nbsp;</TD>\n";
		theOut += mTDBegin  +  i  + ".</TD>\n";
		theOut += mTDBegin + mQ[i-1] + "</TD>\n</TR>\n";
		if (mN[i-1] >= 1) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "a" + mRadEnd + "</TD>";
			theOut += mTDBegin + "a. " + mQA[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 2) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "b" + mRadEnd + "</TD>";
			theOut += mTDBegin + "b. " + mQB[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 3) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "c" + mRadEnd + "</TD>";
			theOut += mTDBegin + "c. " + mQC[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 4) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "d" + mRadEnd + "</TD>";
			theOut += mTDBegin + "d. " + mQD[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 5) {
			theOut += "<TR>\n" + mTDBeginA + mRadBeg + "q" + i + mRadMid + "q" + i + "e" + mRadEnd + "</TD>";
			theOut += mTDBegin + "e. " + mQE[i-1] + "</TD>\n</TR>\n";
		}
		if (mT[i-1] == "Essay") {
			theOut += "<TR>\n" + mTDBeginA + "&nbsp;</TD>";
			theOut += mTDBegin +  mTABeg + "q" + i + mTAEnd  + "</TD>\n</TR>\n";
		}
		if (mT[i-1] != "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='6000'></P>";
	}
	return theOut;
}

function checkMCAnswers(form) {
	theNumCorrect = 0;
	theNumToGrade = mNumQuestions;
	theOutStr = "";
	k = -1;
	for (i = 0; i < mNumQuestions; i++) {
		if (mT[i] == "Essay") {
			k++;
			mR[i] = "" + form.elements[k].value;
		} else {
			mR[i] = "";
			for (j = 0; j < mN[i]; j++) {
				k++;
				if (form.elements[k].checked) {
					if (j == 0) {
						mR[i] = "a";
					}
					if (j == 1) {
						mR[i] = "b";
					}
					if (j == 2) {
						mR[i] = "c";
					}
					if (j == 3) {
						mR[i] = "d";
					}
					if (j == 4) {
						mR[i] = "e";
					}
				}
			}
		}
		if ((mT[i] != "Essay") && (mA[i].toLowerCase() == mR[i])) {
			theNumCorrect++;
			mC[i] = 1;
		} else {
			mC[i] = 0;
		}
		if (mT[i] == "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>Capital Budgeting 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 (mG[i-1] != "") {
			theOut += mBlankRow;
			theOut += "<TR>\n" + mTDBegin + "&nbsp;</TD>\n";
			theOut += mTDBegin + "&nbsp;</TD>\n";
			if ((mGH[i-1] != "") && (mGW[i-1] != "")) {
				theOut += mTDBegin + "<IMG SRC='" + mG[i-1] + "' WIDTH='" + mGW[i-1] + "' HEIGHT='" + mGH[i-1] + "'></TD></TR>\n";
			} else {
				theOut += mTDBegin + "<IMG SRC='" + mG[i-1] + "'></TD></TR>\n";
			}
		}
		if (mT[i-1] != "Essay") {
			theOut += mBlankRow;
			if (mC[i-1] >= 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 + mQ[i-1] + "</TD>\n</TR>\n";
		if (mN[i-1] >= 1) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "a. " + mQA[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 2) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "b. " + mQB[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 3) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "c. " + mQC[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 4) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "d. " + mQD[i-1] + "</TD>\n</TR>\n";
		}
		if (mN[i-1] >= 5) {
			theOut += "<TR>\n" + mTDBeginA  + "&nbsp;</TD>";
			theOut += mTDBegin + "e. " + mQE[i-1] + "</TD>\n</TR>\n";
		}
		theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='red'>Your Answer:</FONT></TD>";
		theOut += mTDBeginC  + "<FONT COLOR='red'>" + mR[i-1] + "</FONT>&nbsp;</TD>\n</TR>\n";
		if (mT[i-1] != "Essay") {
			theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='green'>Correct Answer:</FONT></TD>";
			theOut += mTDBeginC  + "<FONT COLOR='green'>" + mA[i-1].toLowerCase() + "</FONT>&nbsp;</TD>\n</TR>\n";
		}
		if (mE[i-1] != "") {
			if (mT[i-1] != "Essay") {
				theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='green'>Explanation:</FONT></TD>";
				theOut += mTDBeginC  + mE[i-1] + "&nbsp;</TD>\n</TR>\n";
			} else {
				theOut += "<TR>\n" + mTDBeginB + "<FONT COLOR='green'>Our Answer:</FONT></TD>";
				theOut += mTDBeginC  + mE[i-1] + "&nbsp;</TD>\n</TR>\n";
			}
		}
	}
	theOut += "</TABLE></P>\n";
	theOut += mCopy;
	//theOut += "<P><B>Click the close button on the button bar at the top of the screen to return to the lecture.</B></P>";
	return theOut;
}

function drawSimpleFraction(inLeft,inNum,inDen,inRight) {
	var theOut = "<table cellspacing='1' cellpadding='1'>";
	theOut += "<tr><td valign='center' align='right' rowspan='3'>" + inLeft + "</td>";
	theOut += "<td valign='center' align='center'>" + inNum + "</td>";
	theOut += "<td valign='center' align='left' rowspan='3'>" + inRight + "</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;
}

