function randomIRRProblem(form) { 	theCF0 = -1000 - (Math.round(Math.random()*2)*100);  	theCF1 = ((Math.round(Math.random()*5)) + 1)*100; 	theCF2 = ((Math.round(Math.random()*5)) + 1)*100;  	theCF3 = ((Math.round(Math.random()*5)) + 1)*100;  	theCF4 = ((Math.round(Math.random()*5)) + 1)*100;  	theCF5 = ((Math.round(Math.random()*5)) + 1)*100; 	form.Year0.value="" + theCF0; 	form.Year1.value="" + theCF1; 	form.Year2.value="" + theCF2; 	form.Year3.value="" + theCF3; 	form.Year4.value="" + theCF4; 	form.Year5.value="" + theCF5; 	form.IRROutput.value=""; } function calcPV(inFV, inNR, inNP, inC) {	var outPV = inFV*Math.pow((1 + inNR/(100*inC)),(-inNP)); 	return outPV;}function calcIRR(inCFs, inNum) { 	if (inNum == 0) return ""; 	if (inCFs[0] >= 0) return ""; 	var theSum = 0; 	var theGuess = 10; 	var theOldGuess = 10; 	var theH = 0.001; 	var thePV = 0; 	var thePVH = 0; 	var theDeriv = 0; 	var theCnt = 0; 	do { 		thePV = inCFs[0]; 		thePVH = inCFs[0]; 		theSum = inCFs[0];	 	for (i = 1; i <= inNum; i++) {	 		theSum += inCFs[i];	 		thePV += calcPV(inCFs[i],theGuess,i,1);	 		thePVH += calcPV(inCFs[i],(theGuess + theH),i,1);	 	}	 	if (theSum < 0) return "";	 	theDeriv = (thePVH - thePV)/theH;	 	if (theDeriv != 0) {	 		theOldGuess = theGuess;	 		theGuess = theGuess - thePV/theDeriv;	 	} else {	 		return "";	 	}		 	theCnt++;	 	if (theCnt > 50) return ""; 	} while (Math.abs(thePV) > 0.01) 	return theOldGuess;}  function findIRR(form) { 	theCF0Str = form.Year0.value; 	if (!isNegativeNumber(theCF0Str)) { 		return false; 	} 	theCF1Str = form.Year1.value; 	if (!isPositiveNumber(theCF1Str)) { 		return false; 	} 	theCF2Str = form.Year2.value; 	if (!isPositiveNumber(theCF2Str)) { 		return false; 	} 	theCF3Str = form.Year3.value; 	if (!isPositiveNumber(theCF3Str)) { 		return false; 	} 	theCF4Str = form.Year4.value; 	if (!isPositiveNumber(theCF4Str)) { 		return false; 	} 	theCF5Str = form.Year5.value; 	if (!isPositiveNumber(theCF5Str)) { 		return false; 	} 	var theCF = new Array(6); 	theCF[0] = parseFloat(theCF0Str); 	theCF[1] = parseFloat(theCF1Str); 	theCF[2] = parseFloat(theCF2Str); 	theCF[3] = parseFloat(theCF3Str); 	theCF[4] = parseFloat(theCF4Str); 	theCF[5] = parseFloat(theCF5Str); 	var theIRR = calcIRR(theCF,5); 	form.IRROutput.value = "" + Math.round(theIRR*100)/100; 	return true; }  function calcIRRHelp(form) { 	theCF0Str = form.Year0.value; 	if (!isNegativeNumber(theCF0Str)) { 		return false; 	} 	theCF1Str = form.Year1.value; 	if (!isPositiveNumber(theCF1Str)) { 		return false; 	} 	theCF2Str = form.Year2.value; 	if (!isPositiveNumber(theCF2Str)) { 		return false; 	} 	theCF3Str = form.Year3.value; 	if (!isPositiveNumber(theCF3Str)) { 		return false; 	} 	theCF4Str = form.Year4.value; 	if (!isPositiveNumber(theCF4Str)) { 		return false; 	} 	theCF5Str = form.Year5.value; 	if (!isPositiveNumber(theCF5Str)) { 		return false; 	} 	theCF = new Array(6); 	theCF2 = new Array(6); 	theF = new Array(6); 	theCF[0] = parseFloat(theCF0Str); 	theCF[1] = parseFloat(theCF1Str); 	theCF[2] = parseFloat(theCF2Str); 	theCF[3] = parseFloat(theCF3Str); 	theCF[4] = parseFloat(theCF4Str); 	theCF[5] = parseFloat(theCF5Str); 	var theIRR = calcIRR(theCF,5);; 	var theNum = 0; 	var theCNT = 1; 	for (i = 1; i <= 5; i++) {	 	if (i > 1) {	 		if (theCF[i] == theCF[i-1]) {	 			theCF2[theCNT] = theCF[i];	 			theF[theCNT]++;	 		} else {	 			theCNT++;	 			theCF2[theCNT] = theCF[i];	 			theF[theCNT] = 1;	 		}	 	} else {	 		theCF2[theCNT] = theCF[i];	 		theF[theCNT] = 1;	 	} 	} 	theIRR = "" + Math.round(theIRR*100)/100; 	var theOut = "<html><head><title>IRR Help</title></head><body bgcolor='white'>"; 	theOut += "<h3>IRR Help</h3>"; 	theOut += "<p>To solve using the Texas Instruments BA II Plus Calculator:</p>"; 	theOut += "<table><tr align='center'><td>[CF]</td><td>[2nd][CLR WORK]</td></tr>"; 	theOut +="<tr align='center'><td>" + theCF[0] + "</td><td>[Enter][Down Arrow]</td></tr>"; 	for (i=1; i<=theCNT; i++) {	 	theOut +="<tr align='center'><td>" + theCF2[i] + "</td><td>[Enter][Down Arrow]</td></tr>";	 	theOut +="<tr align='center'><td>" + theF[i] + "</td><td>[Enter][Down Arrow]</td></tr>"; 	} 	theOut +="<tr align='center'><td>[IRR]</td><td>[CPT]</td></tr></table>"; 	theOut += "<p><b>The IRR is " + theIRR + "\%</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; }