
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() {
	//var thePV;
	//var theFV;
	//var theN;
	//var theAns = 0;
	//var theType = 0;
	//var theR;
	//var theA;
	//var theCF = new Array(8);
	//var theNumCF;
	//var	theTemp;
	//var ii;
	for (i=0; i< mNumQuestions; i++) {
		theType = Math.round(Math.random()*5); 
		if (theType <= 2) {
			mQue[i] = new randomPProblem();
		} else if ((theType == 3) || (theType == 4)) {
			mQue[i] = new randomYTMProblem();
		} else if (theType == 5) {
			mQue[i] = new randomYTCProblem();
		} 
	}
}

function drawMCQuestions() {
	createQuestions();
	theOut = "<h1>Bond 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='5000'></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>Bond 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 randomPProblem(form) {
	var theQue = new Question();
 	var theCR = (Math.round(Math.random()*10)) + 5; 
 	var theR = (Math.round(Math.random()*15)) + 5; 
 	var theFV = 1000; 
 	var theM = (Math.round(Math.random()*29)) + 1;
 	theCR = Math.round(theCR*10)/10;
 	theR = Math.round(theR*10)/10;
 	var theCROut = "" + Math.round(theCR*10)/10;
 	var theCouponOut = "" + Math.round(theCR*theFV*100/200)/100;
 	var theROut = "" + Math.round(theR*10)/10;
 	var theFVOut = "1000";
 	var theMOut = "" + Math.round(theM);
 	var theNPOut = "" + Math.round(theM*2);
 	var theP = calcPV(theCR*theFV/200,theFV,theR,theM*2,2);
 	var thePOut = Math.round(theP*100)/100;
 	theQue.mQ = "Find the price of a semiannual coupon bond given that the coupon rate = " + theCROut + "\%";
 	theQue.mQ += ", the face value = $" + theFVOut;
 	theQue.mQ += ", the required return = " + theROut + "\%";
 	theQue.mQ += ", and there are " + theMOut + " years remaining until maturity.";
 	theQue.mE = "<P>The <b>Bond Price</b> is calculated as follows:</P>";
	theQue.mE += "<TABLE><TR><TD colspan='2'>First make sure that your calculator is set up for semiannual compounding.</TD></TR>";
	theQue.mE += "<TR><TD align='center'>" + theCouponOut + "</TD><TD align='center'>[ PMT ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>" + theFVOut + "</TD><TD align='center'>[ FV ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>" + theROut + "</TD><TD align='center'>[ I/Y ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>" + theNPOut + "</TD><TD align='center'>[ N ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>[ CPT ]</TD><TD align='center'>[ PV ]</TD></TR>";
 	theQue.mE += "<TR><TD colspan='2'>The Bond Price is $" + thePOut + "</TD></TR></TABLE>";
 	theQue.mAns = thePOut;
	theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theP, 2, "$", "");
 	return theQue;
 }
 
 function randomYTMProblem(form) {
	var theQue = new Question();
 	var theCR = (Math.round(Math.random()*10)) + 5;
 	var theMode = Math.round(Math.random()); 
 	var theP = 1000;
 	if (theMode == 1) {
 		theP = (Math.round(Math.random()*250)) + 1000; 
 	} else {
 		theP = -(Math.round(Math.random()*250)) + 1000; 
 	}
 	var theFV = 1000; 
 	var theM = (Math.round(Math.random()*29)) + 1;
 	theCR = Math.round(theCR*10)/10;
 	theR = Math.round(theR*10)/10;
 	var theCROut = "" + Math.round(theCR*10)/10;
 	var theCouponOut = "" + Math.round(theCR*theFV*100/200)/100;
 	var thePOut = "" + Math.round(theP*100)/100;
 	var theFVOut = "1000";
 	var theMOut = "" + Math.round(theM);
 	var theNPOut = "" + Math.round(theM*2);
 	var theR = calcNR(theCR*theFV/200,-theP,theFV,theM*2,2);
 	var theROut = Math.round(theR*100)/100;
 	theQue.mQ = "Find the yield to maturity on a semiannual coupon bond given that the bond price = $" + thePOut;
 	theQue.mQ += ", the coupon rate = " + theCROut + "\%";
 	theQue.mQ += ", the face value = $" + theFVOut;
 	theQue.mQ += ", and there are " + theMOut + " years remaining until maturity.";
 	theQue.mE = "<P>The <b>Yield to Maturity</b> is calculated as follows:</P>";
	theQue.mE += "<TABLE><TR><TD colspan='2'>First make sure that your calculator is set up for semiannual compounding.</TD></TR>";
	theQue.mE += "<TR><TD align='center'>-" + thePOut + "</TD><TD align='center'>[ PV ]</TD></TR>";
	theQue.mE += "<TR><TD align='center'>" + theCouponOut + "</TD><TD align='center'>[ PMT ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>" + theFVOut + "</TD><TD align='center'>[ FV ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>" + theNPOut + "</TD><TD align='center'>[ N ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>[ CPT ]</TD><TD align='center'>[ I/Y ]</TD></TR>";
 	theQue.mE += "<TR><TD colspan='2'>The Yield to Maturity is " + theROut + "\%</TD></TR></TABLE>";
 	theQue.mAns = theROut;
	theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theR, .4, "", "\%");
 	return theQue;
 } 
 
 function randomYTCProblem(form) {
	var theQue = new Question();
 	var theCR = (Math.round(Math.random()*10)) + 5; 
 	var theP = (Math.round(Math.random()*250)) + 1000; 
 	var theFV = 1000; 
 	var theCP = theFV + theCR*theFV/100;
 	var theCM = (Math.round(Math.random()*8)) + 2;
 	var theM = (Math.round(Math.random()*19)) + 5 + theCM;
 	theCR = Math.round(theCR*10)/10;
 	theR = Math.round(theR*10)/10;
 	var theCROut = "" + Math.round(theCR*10)/10;
 	var theCouponOut = "" + Math.round(theCR*theFV*100/200)/100;
 	var thePOut = "" + Math.round(theP*100)/100;
 	var theFVOut = "1000";
 	var theCPOut = "" + Math.round(theCP);
 	var theMOut = "" + Math.round(theM);
 	var theNPOut = "" + Math.round(theCM*2);
 	var theCMOut = "" + Math.round(theCM);
 	var theR = calcNR(theCR*theFV/200,-theP,theCP,theCM*2,2);
 	var theROut = Math.round(theR*100)/100;
 	theQue.mQ = "Find the yield to call on a semiannual coupon bond given that the bond price = $" + thePOut;
 	theQue.mQ += ", the coupon rate = " + theCROut + "\%";
 	theQue.mQ += ", the face value = $" + theFVOut;
 	theQue.mQ += ", the call price = $" + theCPOut;
 	theQue.mQ += ", there are " + theMOut + " years remaining until maturity.";
 	theQue.mQ += ", and there are " + theCMOut + " years remaining until the call date.";
 	theQue.mE = "<P>The <b>Yield to Call</b> is calculated as follows:</P>";
	theQue.mE += "<TABLE><TR><TD colspan='2'>First make sure that your calculator is set up for semiannual compounding.</TD></TR>";
	theQue.mE += "<TR><TD align='center'>-" + thePOut + "</TD><TD align='center'>[ PV ]</TD></TR>";
	theQue.mE += "<TR><TD align='center'>" + theCouponOut + "</TD><TD align='center'>[ PMT ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>" + theCPOut + "</TD><TD align='center'>[ FV ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>" + theNPOut + "</TD><TD align='center'>[ N ]</TD></TR>";
 	theQue.mE += "<TR><TD align='center'>[ CPT ]</TD><TD align='center'>[ I/Y ]</TD></TR>";
 	theQue.mE += "<TR><TD colspan='2'>The Yield to Call is " + theROut + "\%</TD></TR></TABLE>";
 	theQue.mAns = theROut;
	theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theR, .4, "", "\%");
 	return theQue;
 } 
 
 function buildAnswers(inQue, inAns, inSpr, inPreSym, inPostSym) {
 	var theA = Math.round(Math.random()*3 + 1);
 	var theAns = Math.round(inAns*100)/100;
 	var theLast = theAns;
	if (theA == 1) {
		inQue.mA = "a";
		inQue.mQA = "" + inPreSym + theAns + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*100)/100;
		inQue.mQB = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*100)/100;
		inQue.mQC = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*100)/100;
		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))*100)/100;
		inQue.mQC = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast + inSpr + Math.random()*(inSpr*2))*100)/100;
		inQue.mQD = "" + inPreSym + theLast + inPostSym;
		theLast = theAns;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*100)/100;
		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))*100)/100;
		inQue.mQD = "" + inPreSym + theLast + inPostSym;
		theLast = theAns;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*100)/100;
		inQue.mQB = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*100)/100;
		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))*100)/100;
		inQue.mQC = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*100)/100;
		inQue.mQB = "" + inPreSym + theLast + inPostSym;
		theLast = Math.round((theLast - inSpr - Math.random()*(inSpr*2))*100)/100;
		inQue.mQA = "" + inPreSym + theLast + inPostSym;
		inQue.mQE = "";
	}
	return inQue; 
 }

 function drawFraction(inLHS,inNumFormula,inDenFormula,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'>" + inNumFormula + "</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 += "<td valign='center' align='center'><hr noshade></td>";
	theOut += "</tr>";
	theOut += "<tr>";
	theOut += "<td valign='center' align='center'>" + inDenFormula + "</td>";
	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;
}

function calcPV(inPMT, inFV, inNR, inNP, inC) {
	var outPV = inFV*Math.pow((1 + inNR/(100*inC)),(-inNP));
 	if (inNR == 0) {
 		outPV = outPV + inPMT*inNP;
 	} else {
 		outPV = outPV + inPMT*((1-(Math.pow((1 + inNR/(100*inC)),(-inNP))))/(inNR/(100*inC)));
 	}
 	return outPV;
}

function calcNR(inPMT, inPV, inFV, inNP, inC) {
	var	outNR = 0.1; // initial guess
	var	thePV1, thePV2, theDeriv;
	var	theH = 0.00001;
	var	i = 1;
	var	theZeros = 0;
	var lastNR = outNR;
	//alert("PV " + inPV + " PMT " + inPMT + " FV " + inFV + " NP " + inNP);
	if (inNP <= 0) { // should throw an exception
		alert("The Nominal Rate cannot be computed.");
		return outNR = "";
	}
	if (inFV == 0) {
		theZeros++;
	}	
	if (inPMT == 0) {
		theZeros++;
	}	
	if (inPV == 0) {
		theZeros++;
		// inFV *= -1;
	}
	if (theZeros >= 2) { // should throw an exception
		alert("The Nominal Rate cannot be computed.");
		return outNR = "";
	}
	if ((inPV > 0) && (inPMT >= 0) && (inFV >= 0)) {
		alert("The Nominal Rate cannot be computed.");
		return outNR = "";
	}
	if ((inPV == 0) && (inPMT >= 0) && (inFV >= 0)) {
		alert("The Nominal Rate cannot be computed.");
		return outNR = "";
	}
	inPV *= -1;
	//thePV1 = calcPV(inPMT,inFV,outNR*100,inNP,inC);
	//alert("thePV1 " + thePV1 + " " + inPV);
	do {
		thePV1 = calcPV(inPMT,inFV,(outNR*100),inNP,inC) - inPV;
		theDeriv = ((calcPV(inPMT,inFV,((outNR+theH)*100),inNP,inC) - inPV) - thePV1)/theH;
		thePV2 = thePV1;
		//if ((theDeriv == 0) && (Math.abs(thePV2) > 0)) { // should throw an exception
		//	alert("The Nominal Rate cannot be computed. 5");
		//	return outNR = "";
		//}
		lastNR = outNR;
		outNR = outNR - thePV1/theDeriv;
		if (i > 200) { // should throw an exception
			alert("The Nominal Rate cannot be computed.");
			return outNR = "";
		}
		i++;
		if (thePV2 < 0) thePV2 *= -1;
	} while (thePV2 > 0.0001);
	return (lastNR*100); // maybe should change to give the previous rate	
}
