function BVHelp(form) {	alert("This feature is not yet implemented.");}function randomBVProblem(form) { 	theF = 1000;  	theCR = Math.round((Math.random()*16+4)*10)/10; 	theB = Math.round((Math.random()*400+800)*100)/100;  	theM = Math.round(Math.random()*29+1);  	form.BInput.value="" + theB; 	form.FInput.value="" + theF; 	form.CRInput.value="" + theCR; 	form.MInput.value="" + theM; 	form.ROutput.value=""; }  function findBV(form) { 	theFStr = form.FInput.value; 	if (!isPositiveNumber(theFStr)) { 		return false; 	} 	theCRStr = form.CRInput.value; 	if (!isPositiveNumber(theCRStr)) { 		return false; 	} 	theBStr = form.BInput.value; 	if (!isPositiveNumber(theBStr)) { 		return false; 	} 	theMStr = form.MInput.value; 	if (!isPositiveNumber(theMStr)) { 		return false; 	} 	theF = parseFloat(theFStr); 	theCR = parseFloat(theCRStr); 	theB = parseFloat(theBStr); 	theM = parseInt(theMStr); 	var theR = calcNR((theCR*theF/200),-theB,theF,theM*2,2); 	form.MInput.value = "" + Math.round(theM); 	form.ROutput.value = "" + Math.round(theR*100)/100; 	return true; }  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	}  function calcBVHelp(form) { 	theFStr = form.FInput.value; 	if (!isPositiveNumber(theFStr)) { 		return false; 	} 	theCRStr = form.CRInput.value; 	if (!isPositiveNumber(theCRStr)) { 		return false; 	} 	theBStr = form.BInput.value; 	if (!isPositiveNumber(theBStr)) { 		return false; 	} 	theMStr = form.MInput.value; 	if (!isPositiveNumber(theMStr)) { 		return false; 	} 	theF = parseFloat(theFStr); 	theCR = parseFloat(theCRStr); 	theB = parseFloat(theBStr); 	theM = parseInt(theMStr); 	var theR = calcNR((theCR*theF/200),-theB,theF,theM*2,2); 	 	form.ROutput.value = "" + Math.round(theR*100)/100; 	var theOut = "<html><head><title>Yield to Maturity Help</title></head><body bgcolor='white'>"; 	theOut += "<h3>Yield to Maturity Help</h3>"; 	theOut += "<p>To solve using the Texas Instruments BA II Plus Calculator:</p>"; 	theOut += "<p><i>Make sure that the calculator is set up for semiannual compounding before beginning.</i></p>"; 	theOut += "<table><tr align='center'><td>-" + Math.round(theB*100)/100 + "</td><td>[PV]</td></tr>"; 	theOut += "<tr align='center'><td>" + Math.round(theF*100)/100 + "</td><td>[FV]</td></tr>"; 	theOut += "<tr align='center'><td>" + Math.round((theCR*theF/200)*100)/100 + "</td><td>[PMT]</td></tr>"; 	theOut += "<tr align='center'><td>" + Math.round(theM*2) + "</td><td>[N]</td></tr>"; 	theOut += "<tr align='center'><td>&nbsp;</td><td>[CPT][I/Y]</td></tr></table>"; 	theOut += "<p><b>The Yield to Maturity is " + Math.round(theR*100)/100 + "\%</b></p>"; 	theOut += "<CENTER>";	theOut += "<P><FORM NAME=\"Form1\">";	theOut += "<INPUT TYPE=\"button\" VALUE=\"   OK   \" onClick=\"window.close();\"></FORM></P></CENTER>"; 	theOut += "</body></html>"; 	var newWin = window.open("","","scrollbars,resizable,width=400,height=420"); 	if (newWin != null) { 		newWin.document.write(theOut); 		newWin.document.close(); 		newWin.focus(); 	} 	return true; }  function isPositiveNumber(inputStr) { 	for (var i = 0; i < inputStr.length; i++) { 		var oneChar = inputStr.substring(i,i+1); 		if (((oneChar >= "0") && (oneChar <= "9")) || (oneChar == ".")) { 		 		} else { 			alert("Please make sure that only numbers are input."); 			return false; 		}  	}	return true; }  function isNegativeNumber(inputStr) { 	if (inputStr.length < 2) { 		alert("Please input a negative number."); 		return false; 	} 	var oneChar = inputStr.substring(0,1); 	if (oneChar != '-') { 		alert("Please make sure that only negative numbers are input."); 		return false; 	} 	for (var i = 1; i < inputStr.length; i++) { 		oneChar = inputStr.substring(i,i+1); 		if (((oneChar >= "0") && (oneChar <= "9")) || (oneChar == ".")) { 		 		} else { 			alert("Please make sure that only numbers are input."); 			return false; 		}  	}	return true; }
