
mNumQuestions = 7;
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>";
now = new Date;
theYear=now.getYear();
if (theYear < 1900);
theYear=theYear+1900;
var mCopy = "<P>&nbsp;</P><DIV align='right'>&copy; 2002 - " + theYear + " by Mark A. Lane, Ph.D.</DIV>";

var mBlankRow = "<TR><TD>&nbsp;</TD></TR>\n";

var isNav = false;
var isIE = false;

// Common information
var mCI = "";

var mCash;
var mAccRec;
var mInv;
var mTCA;
var mNFA;
var mTA;
var mAccPay;
var mNotes;
var mTCL;
var mLTDebt;
var mTLTD;
var mCS;
var mRE;
var mTSE;
var mTL;

var mCash1;
var mAccRec1;
var mInv1;
var mTCA1;
var mNFA1;
var mTA1;
var mAccPay1;
var mNotes1;
var mTCL1;
var mLTDebt1;
var mTLTD1;
var mCS1;
var mRE1;
var mTSE1;
var mTL1;

var mGrowth;
var mSales;
var mCOGS;
var mTaxInc;
var mTaxes;
var mNI;
var mDiv;
var mAddRE;

var mEFN1;
var mEFN2;
var mEFN3;


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 || isNav6) {
		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() {
	getCommonInfo();
	mQue[0] = new getS1Problem();
	mQue[1] = new getPercentageProblem();
	mQue[2] = new getProFormaProblem();
	mQue[3] = new getREProblem();
	mQue[4] = new getEFNProblem();
	mQue[5] = new getEFN1Problem();
	mQue[6] = new getEFN2Problem();
	//mQue[6] = new getCFDSProblem(); redundant
}

function drawMCQuestions() {
	createQuestions();
	theOut = "<h1>Financial Forecasting Quiz</h1><hr>";
	allEssay = true;
	theNumQuestions = mNumQuestions;
	theOut += drawCommonInfo();
	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>Financial Forecasting Quiz: Results</H1></P><HR>";
	theOutStr1 += drawCommonInfo();
	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 getIncomeStatement(inNFA) {
  mSales = Math.round(Math.random()*((inNFA)/100)*(.5) + (inNFA/100))*100;
  //mDep = Math.round(Math.random()*(inNFA/100)*.20*100);
  //if (mDep < 50) {
  //	mDep = 50;
  //}
  mCOGS = Math.round(Math.random()*(mSales/100)*.30 + (mSales/100)*(.60))*100;
  //mAdmExp = Math.round(Math.random()*(mSales/100)*.1 + .5)*100;
  //mEBIT = mSales - mCOGS - mAdmExp - mDep;
  mTaxInc = mSales - mCOGS;
  //mInt = Math.round(((Math.random()*(20)+1)/100)*mLTDebt/10)*10;
  //mTaxInc = mEBIT - mInt;
  mTaxes = Math.round(((Math.random()*(40)+5)/100)*mTaxInc);
  mNI = mTaxInc - mTaxes;
  if (mNI > 0) {
  	mDiv = Math.round(((Math.random()*400)/1000)*mNI + .3*mNI);
  } else {
  	mDiv = 0;
  }
  mAddRE = mNI - mDiv;
}

function newFinancials() {
   mGrowth = Math.round(Math.random()*25+15);
  //var thePlug = Math.round(Math.random()*2);
  //if (thePlug == 0) {
  //	thePlug = 0;
  //} else if (thePlug == 1) {
  //	thePlug = 1;
  //} else {
  //	thePlug = 2;
  //}
  
  mCash = Math.round(Math.random()*6 + 1)*100;
  mAccRec = Math.round(Math.random()*6 + 1)*100;
  mInv = Math.round(Math.random()*10 + 1)*100;
  mTCA = mCash + mAccRec + mInv;
  mNFA = Math.round(Math.random()*18 + 4)*100;
  mTA = mTCA + mNFA;
  mLTDebt = Math.round(Math.random()*.4*(mTA/10) + .15*(mTA/10))*10;
  mTLTD = mLTDebt;
  
  getIncomeStatement(mNFA);
  
  mTA = mTCA + mNFA;
  mTL = mTA;
  mTCL = Math.round(Math.random()*.5*((mTA-mTLTD)/10) + .25*((mTA-mTLTD)/10))*10;
  mAccPay = Math.round((Math.random()*.6 + .2)*(mTCL/10))*10;
  mNotes = mTCL - mAccPay;
  mTSE = mTA - mTLTD - mTCL; 
  mCS = Math.round((Math.random()*.5 + .25)*(mTSE/10))*10;
  mRE = mTSE - mCS;
}

function getTRTitle(inTitleL,inVal1,inTitleR,inVal2) {
	var theTR = '<tr valign="top">';
    theTR += '<td class="ctitle" width="153">' + inTitleL + '</td>';
    theTR += '<td class="ctitle" width="46">' + inVal1 + '</td>';
    theTR += '<td class="ctitle" width="154">' + inTitleR + '</td>';
    theTR += '<td class="ctitle" width="47">' + inVal2 + '</td>';
    theTR += '</tr>\n';
	return theTR;
}

function getTR(inTitleL,inVal1,inTitleR,inVal2) {
	var theTR = '<tr valign="top">';
    theTR += '<td class="litem" width="153">' + inTitleL + '</td>';
    theTR += '<td class="litem" width="46">' + inVal1 + '</td>';
    theTR += '<td class="litem" width="154">' + inTitleR + '</td>';
    theTR += '<td class="litem" width="47">' + inVal2 + '</td>';
    theTR += '</tr>\n';
	return theTR;
}

function getTRIS(inTitle,inVal) {
	var theTR = '<tr valign="top">'; 
    theTR += '<td class="litem">' + inTitle + '</td>';
    theTR += '<td class="litem">' + inVal + '</td>';
    theTR += '</tr>\n';
    return theTR;
}

function getCommonInfo() {
	newFinancials();
    mCI = "<P>Use the Balance Sheet and Income Statement below to answer the following questions.</P>";
    mCI += '<table border="1" cellpadding="4" cellspacing="0">';
    mCI += '<tr valign="top"><td>';
      
    mCI += '<table border="0" cellspacing="4" cellpadding="0">';
    mCI += '<tr align="center" valign="top">';
    mCI += '<td class="ctitle" width="493" colspan="6">Balance Sheet ($ in Millions)</td>';
    mCI += '</tr>\n';
    mCI += getTRTitle("Assets", "1998", "Liabilities and Owners' Equity", "1998"); 
    mCI += getTR("Current Assets", "&nbsp;", "Current Liabilities", "&nbsp;"); 
    mCI += getTR("Cash", mCash, "Accounts Payable", mAccPay); 
    mCI += getTR("Accounts Receivable", mAccRec, "Notes Payable", mNotes); 
    mCI += getTR("Inventory", mInv, "<i>Total Current Liabilities</i>", mTCL); 
    mCI += getTR("<i>Total Current Assets</i>", mTCA, "Long Term Liabilities", "&nbsp;"); 
    mCI += getTR("&nbsp;", "&nbsp;", "Long Term Debt", mLTDebt); 
    mCI += getTR("Fixed Assets", "&nbsp;", "<i>Total Long Term Liabilities</i>", mTLTD);
    mCI += getTR("<i>Net Fixed Assets</i>", mNFA, "Owners' Equity", "&nbsp;");
    mCI += getTR("&nbsp;", "&nbsp;", "Common Stock", mCS); 
    mCI += getTR("&nbsp;", "&nbsp;", "Retained Earnings", mRE); 
    mCI += getTR("&nbsp;", "&nbsp;", "Total Owners' Equity", mTSE);
    mCI += getTR("<i>Total Assets</i>", mTA, "<i>Total Liabilities and Owners' Equity</i>", mTL);
    mCI += '</table></td>\n';
    mCI += '<td>'; 
    mCI += '<table border="0" cellspacing="4" cellpadding="0">';
    mCI += '<tr><td class="ctitle" colspan="2" align="center">Income Statement<br>($ in Millions)</td></tr>\n';
    mCI += '<tr><td class="litem">&nbsp;</td><td class="ctitle">1998</td></tr>\n';
    mCI += getTRIS("Sales",mSales);
    mCI += getTRIS("Costs",mCOGS);
    mCI += getTRIS("<i>Taxable Income</i>",mTaxInc);
    mCI += getTRIS("Taxes",mTaxes);
    mCI += getTRIS("<i>Net Income</i>",mNI);
    mCI += getTRIS("Dividends",mDiv);
    mCI += getTRIS("Addition to Ret. Earnings",mAddRE);
    mCI += getTRIS("&nbsp;","&nbsp;");
    mCI += getTRIS("Forecasted Growth Rate","" + mGrowth + "\%");
    
    mCI += '</table></td></tr></table>\n';
}

function drawCommonInfo() {
	return mCI;
}

function getEFNProblem() {
	var theQue = new Question();
	var theS1 = mSales*(1+mGrowth/100);
	var thePM = mNI/mSales;
	var theRR = mAddRE/mNI;
	var theAns = (mTA/mSales)*(mSales*mGrowth/100)-(mAccPay/mSales)*(mSales*mGrowth/100)-(mAddRE/mSales)*(theS1);
	theS1 = Math.round(theS1*100)/100;
	thePM = Math.round(thePM*100)/100;
	theRR = Math.round(theRR*100)/100;
	var theGrowth = Math.round(mGrowth*100)/10000;
	theAns = Math.round(theAns*100)/100;
  	theQue.mQ = "Find the External Financing Needed given that Fixed Assets are being utilized at full capacity.";
  	theQue.mE += "<p>First calculate the Sales Forecast (S<sub>1</sub>), Profit Margin (PM), and Retention Ratio (b).</p>";
  	theQue.mE += "<p>S<sub>1</sub> = S<sub>0</sub>(1 + g) = " + mSales + "(1 + " + theGrowth + ") = $" + theS1 + "</p>";
  	theQue.mE += drawFraction("PM","Net Income","S<sub>0</sub>",mNI,mSales,thePM);
  	theQue.mE += drawFraction("b","Addition to RE","Net Income",mAddRE,mNI,theRR);
    theQue.mE += "<p>Then, the <b>External Financing Needed</b> is calculated as follows:</p>";
	theQue.mE += "<p><img src='images/EFN.gif' alt='' width='284' height='41' border='0'></p>";
	theQue.mE += "<table cellspacing=0 cellpadding=0>";
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>EFN</td>";
	theQue.mE += "<td rowspan=3 valign='middle'> = <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mTA + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'><font size='+6'>]</font>(" + theS1 + " - " + mSales + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>&nbsp;</td>";
	theQue.mE += "<td rowspan=3 valign='middle'> - <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mAccPay + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'><font size='+6'>]</font>(" + theS1 + " - " + mSales + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr><td>&nbsp;</td>";
	theQue.mE += "<td colspan='4'> - (" + thePM + ")(" + theS1 + ")(" + theRR + ")</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
    theQue.mE += "<tr><td>EFN</td><td colspan='4'> = $" + theAns + "</td></tr></table>";
    theQue.mAns = theAns;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getEFN1Problem() {
	var theQue = new Question();
	var theS1 = mSales*(1+mGrowth/100);
	var thePC = (mSales/theS1)*100;
	thePC = Math.round(thePC - Math.random()*(thePC - 20) - 5);
	var theSFC = Math.round(mSales/(thePC/100)*100)/100;
	var thePM = mNI/mSales;
	var theRR = mAddRE/mNI;
	var theAns = (mTCA/mSales)*(mSales*mGrowth/100)-(mAccPay/mSales)*(mSales*mGrowth/100)-(mAddRE/mSales)*(theS1);
	theS1 = Math.round(theS1*100)/100;
	thePM = Math.round(thePM*100)/100;
	theRR = Math.round(theRR*100)/100;
	var theGrowth = Math.round(mGrowth*100)/10000;
	theAns = Math.round(theAns*100)/100;
  	theQue.mQ = "Find the External Financing Needed given that Fixed Assets are being utilized at " + thePC + "\% of capacity.";
  	theQue.mE += "<p>First calculate Full Capacity Sales (S<sub>FC</sub>), the Sales Forecast (S<sub>1</sub>), Profit Margin (PM), and Retention Ratio (b).</p>";
  	theQue.mE += drawFraction("S<sub>FC</sub>","S<sub>0</sub>","\% of Capacity",mSales,thePC/100,"$"+theSFC);
  	theQue.mE += "<p>S<sub>1</sub> = S<sub>0</sub>(1 + g) = " + mSales + "(1 + " + theGrowth + ") = $" + theS1 + "</p>";
  	theQue.mE += drawFraction("PM","Net Income","S<sub>0</sub>",mNI,mSales,thePM);
  	theQue.mE += drawFraction("b","Addition to RE","Net Income",mAddRE,mNI,theRR);
    theQue.mE += "<p>Since S<sub>FC</sub> is greater than S<sub>1</sub>, the <b>External Financing Needed</b> is calculated as follows:</p>";
	theQue.mE += "<p><img src='images/EFN.gif' alt='' width='284' height='41' border='0'></p>";
	theQue.mE += "<table cellspacing=0 cellpadding=0>";
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>EFN</td>";
	theQue.mE += "<td rowspan=3 valign='middle'> = <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mTCA + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'><font size='+6'>]</font>(" + theS1 + " - " + mSales + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>&nbsp;</td>";
	theQue.mE += "<td rowspan=3 valign='middle'> - <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mAccPay + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'><font size='+6'>]</font>(" + theS1 + " - " + mSales + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr><td>&nbsp;</td>";
	theQue.mE += "<td colspan='4'> - (" + thePM + ")(" + theS1 + ")(" + theRR + ")</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
    theQue.mE += "<tr><td>EFN</td><td colspan='4'> = $" + theAns + "</td></tr></table>";
	
    theQue.mAns = theAns;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
  function getEFN2Problem() {
	var theQue = new Question();
	var theS1 = mSales*(1+mGrowth/100);
	var thePC = (mSales/theS1)*100;
	thePC = Math.round(Math.random()*(98 - thePC) + thePC);
	var theSFC = Math.round(mSales/(thePC/100)*100)/100;
	var thePM = mNI/mSales;
	var theRR = mAddRE/mNI;
	var theEFN1 = (mTCA/mSales)*(theSFC-mSales)-(mAccPay/mSales)*(theSFC-mSales)-(mAddRE/mSales)*(theSFC);
	var theEFN2 = ((mTCA/mSales) + (mNFA/theSFC))*(theS1-theSFC)-(mAccPay/mSales)*(theS1-theSFC)-(mAddRE/mSales)*(theS1-theSFC);
	var theAns = theEFN1 + theEFN2;
	theS1 = Math.round(theS1*100)/100;
	thePM = Math.round(thePM*100)/100;
	theRR = Math.round(theRR*100)/100;
	var theGrowth = Math.round(mGrowth*100)/10000;
	theAns = Math.round(theAns*100)/100;
	theEFN1 = Math.round(theEFN1*100)/100;
	theEFN2 = Math.round(theEFN2*100)/100;
  	theQue.mQ = "Find the External Financing Needed given that Fixed Assets are being utilized at " + thePC + "\% of capacity.";
  	theQue.mE += "<p>First calculate Full Capacity Sales (S<sub>FC</sub>), the Sales Forecast (S<sub>1</sub>), Profit Margin (PM), and Retention Ratio (b).</p>";
  	theQue.mE += drawFraction("S<sub>FC</sub>","S<sub>0</sub>","\% of Capacity",mSales,thePC/100,"$"+theSFC);
  	theQue.mE += "<p>S<sub>1</sub> = S<sub>0</sub>(1 + g) = " + mSales + "(1 + " + theGrowth + ") = $" + theS1 + "</p>";
  	theQue.mE += drawFraction("PM","Net Income","S<sub>0</sub>",mNI,mSales,thePM);
  	theQue.mE += drawFraction("b","Addition to RE","Net Income",mAddRE,mNI,theRR);
    theQue.mE += "<p>Since S<sub>FC</sub> is less than S<sub>1</sub>, the <b>External Financing Needed</b> is calculated in two steps:</p>";
	theQue.mE += "<p><img src='images/EFN2.gif' alt='' width='410' height='109' border='0'></p>";
	
	theQue.mE += "<table cellspacing=0 cellpadding=0>";
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>EFN<sub>1</sub></td>";
	theQue.mE += "<td rowspan=3 valign='middle'> = <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mTCA + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'><font size='+6'>]</font>(" + theSFC + " - " + mSales + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>&nbsp;</td>";
	theQue.mE += "<td rowspan=3 valign='middle'> - <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mAccPay + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'><font size='+6'>]</font>(" + theSFC + " - " + mSales + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr><td>&nbsp;</td>";
	theQue.mE += "<td colspan='4'> - (" + thePM + ")(" + theSFC + ")(" + theRR + ")</td></tr>";
	theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr>";
	
    theQue.mE += "<tr><td>EFN<sub>1</sub></td><td colspan='4'> = $" + theEFN1 + "</td></tr>";
    theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr></table>";

    
    theQue.mE += "<table cellspacing=0 cellpadding=0>";
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>EFN<sub>2</sub></td>";
	theQue.mE += "<td rowspan=3 valign='middle'> = <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mTCA + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'> + </td>";
	theQue.mE += "<td align='center'>" + mNFA + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle'><font size='+6'>]</font>(" + theS1 + " - " + theSFC + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td>";
	theQue.mE += "<td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td>";
	theQue.mE += "<td align='center'>" + theSFC + "</td></tr>";
	theQue.mE += "<tr><td colspan='6'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr>";
	theQue.mE += "<td rowspan=3 valign='middle'>&nbsp;</td>";
	theQue.mE += "<td rowspan=3 valign='middle'> - <font size='+6'>[</font></td>";
	theQue.mE += "<td align='center'>" + mAccPay + "</td>";
	theQue.mE += "<td rowspan=3 valign='middle' colspan='3'><font size='+6'>]</font>(" + theS1 + " - " + theSFC + ")</td>";
	theQue.mE += "</tr>";
	theQue.mE += "<tr><td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td></tr>";
	theQue.mE += "<tr><td align='center'>" + mSales + "</td></tr>";
	theQue.mE += "<tr><td colspan='6'>&nbsp;</td></tr>";
	
	theQue.mE += "<tr><td>&nbsp;</td>";
	theQue.mE += "<td colspan='5'> - (" + thePM + ")(" + theS1 + " - " + theSFC + ")(" + theRR + ")</td></tr>";
	theQue.mE += "<tr><td colspan='6'>&nbsp;</td></tr>";
	
    theQue.mE += "<tr><td>EFN<sub>2</sub></td><td colspan='4'> = $" + theEFN2 + "</td></tr>";
    theQue.mE += "<tr><td colspan='5'>&nbsp;</td></tr></table>";
    
    theQue.mE += "<p>EFN = EFN<sub>1</sub> + EFN<sub>2</sub> = (" + theEFN1 + ") + (" + theEFN2 + ") = $" + theAns + "</p>";
    theQue.mAns = theAns;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getPercentageProblem() {
	var theQue = new Question();
	var theAccount = Math.round(Math.random()*3);
	var theAcc = "Cash";
	var theAccVal = 0;
	var theAns = 0;
	if (theAccount == 0) {
		theAcc = "Cash";
		theAccVal = mCash;
		theAns = Math.round((mCash/mSales)*10000)/100;
	} else if (theAccount == 1) {
		theAcc = "Accounts Receivable";
		theAccVal = mAccRec;
		theAns = Math.round((mAccRec/mSales)*10000)/100;
	} else if (theAccount == 2) {
		theAcc = "Inventory";
		theAccVal = mInv;
		theAns = Math.round((mInv/mSales)*10000)/100;
	} else if (theAccount == 3) {
		theAcc = "Accounts Payable";
		theAccVal = mAccPay;
		theAns = Math.round((mAccPay/mSales)*10000)/100;
	} 
  	theQue.mQ = "Express " + theAcc + " as a percentage of Sales.";
    theQue.mE = "<P><b>" + theAcc + "</b> as a percentage of Sales is calculated as follows:</P>";
	theQue.mE += drawFraction(theAcc + "\%",theAcc,"S<sub>0</sub>",theAccVal,mSales,theAns + "\%");
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, .5, "", "\%",2);
 	return theQue;
 }
 
 function getProFormaProblem() {
	var theQue = new Question();
	var theS1 = mSales*(1+mGrowth/100);
	var theGrowth = Math.round(mGrowth*100)/10000;
	var theAccount = Math.round(Math.random()*3);
	var theAcc = "Cash";
	var theAccVal = 0;
	var theAns = 0;
	var thePC = 0;
	if (theAccount == 0) {
		theAcc = "Cash";
		theAccVal = mCash;
		thePC = Math.round((mCash/mSales)*10000)/100;
	} else if (theAccount == 1) {
		theAcc = "Accounts Receivable";
		theAccVal = mAccRec;
		thePC = Math.round((mAccRec/mSales)*10000)/100;
	} else if (theAccount == 2) {
		theAcc = "Inventory";
		theAccVal = mInv;
		thePC = Math.round((mInv/mSales)*10000)/100;
	} else if (theAccount == 3) {
		theAcc = "Accounts Payable";
		theAccVal = mAccPay;
		thePC = Math.round((mAccPay/mSales)*10000)/100;
	} 
	//theAns = Math.round(thePC*theS1)/100;
	theAns = theAccVal*(1 + theGrowth);
  	theQue.mQ = "Find the Pro-Forma balance for " + theAcc + ".";
  	theQue.mE = "<p>First calculate the Sales Forecast (S<sub>1</sub>) and " + theAcc + " as a percentage of Sales.</p>";
    theQue.mE += "<p>S<sub>1</sub> = S<sub>0</sub>(1 + g) = " + mSales + "(1 + " + theGrowth + ") = $" + theS1 + "</p>";
    theQue.mE += drawFraction(theAcc + "\%",theAcc,"S<sub>0</sub>",theAccVal,mSales,thePC + "\%");
    theQue.mE += "<P>The Pro-Forma balance for <b>" + theAcc + "</b> is calculated as follows:</P>";
	theQue.mE += "<p>" + theAcc + "<sub>1</sub> = (" + theAcc + "\%)(S<sub>1</sub>) = (" + thePC + "\%)(" + theS1 + ") = $" + theAns + "</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 4, "$", "",2);
 	return theQue;
 }
 
 function getS1Problem() {
	var theQue = new Question();
	var theS1 = mSales*(1+mGrowth/100);
	var theGrowth = Math.round(mGrowth*100)/10000;
	theS1 = Math.round(theS1*100)/100;
  	theQue.mQ = "Calculate the forecasted Sales level.";
    theQue.mE = "<P><b>Forecasted Sales (S<sub>1</sub>)</b> is calculated as follows:</P>";
	theQue.mE += "<p>S<sub>1</sub> = S<sub>0</sub>(1 + g) = " + mSales + "(1 + " + theGrowth + ") = $" + theS1 + "</p>";
    theQue.mAns = theS1;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theS1, 5, "$", "",2);
 	return theQue;
 }
 
function getREProblem() {
	var theQue = new Question();
	var theS1 = mSales*(1+mGrowth/100);
	var thePM = mNI/mSales;
	var theRR = mAddRE/mNI;
	var theAns = mRE + (mAddRE/mSales)*(theS1);
	theS1 = Math.round(theS1*100)/100;
	thePM = Math.round(thePM*100)/100;
	theRR = Math.round(theRR*100)/100;
	var theGrowth = Math.round(mGrowth*100)/10000;
	theAns = Math.round(theAns*100)/100;
  	theQue.mQ = "Find the Pro-Forma balance for Retained Earnings on the Balance Sheet.";
  	theQue.mE += "<p>First calculate the Sales Forecast (S<sub>1</sub>), Profit Margin (PM), and Retention Ratio (b).</p>";
  	theQue.mE += "<p>S<sub>1</sub> = S<sub>0</sub>(1 + g) = " + mSales + "(1 + " + theGrowth + ") = $" + theS1 + "</p>";
  	theQue.mE += drawFraction("PM","Net Income","S<sub>0</sub>",mNI,mSales,thePM);
  	theQue.mE += drawFraction("b","Addition to RE","Net Income",mAddRE,mNI,theRR);
    theQue.mE += "<p>Then, the <b>Pro-Forma Retained Earnings</b> is calculated as follows:</p>";
	theQue.mE += "<p>RE<sub>1</sub> = RE<sub>0</sub> + (PM)(S<sub>1</sub>)(b) = " + mRE + " + (" + thePM + ")(" + theS1 + ")(" + theRR + ") = $" + theAns +"</p>";
    theQue.mAns = theAns;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",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 drawFraction(inLHS,inNum,inDen,inNum2,inDen2,inAnswer) {
	var theOut = "<table cellspacing='0' cellpadding='0'><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 valign='center' align='center'>" + inNum2 + "</td>";
	theOut += "<td rowspan='3' valign='center'>=</td>";
	theOut += "<td rowspan='3' valign='center'>" + inAnswer + "</td>";
	theOut += "</tr>";
	theOut += "<tr>";
	theOut += "<td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td>";
	theOut += "<td align='center' bgcolor='black'><img src='../images/space.gif' width=1 height=1></td>";
	theOut += "</tr>";
	theOut += "<tr>";
	theOut += "<td valign='center' align='center'>" + inDen + "</td>";
	theOut += "<td valign='center' align='center'>" + inDen2 + "</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;
}

