
mNumQuestions = 6;
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 mPPE;
var mAccDep;
var mNFA;
var mTA;
var mAccPay;
var mNotes;
var mTCL;
var mLTDebt;
var mTLTD;
var mCS;
var mCapSurp;
var mRE;
var mTSE;
var mTL;

var mCash1;
var mAccRec1;
var mInv1;
var mTCA1;
var mPPE1;
var mAccDep1;
var mNFA1;
var mTA1;
var mAccPay1;
var mNotes1;
var mTCL1;
var mLTDebt1;
var mTLTD1;
var mCS1;
var mCapSurp1;
var mRE1;
var mTSE1;
var mTL1;

var mSales;
var mCOGS;
var mAdmExp;
var mDep;
var	mEBIT;
var mInt;
var mTaxInc;
var mTaxes;
var mNI;
var mDiv;
var mAddRE;

var mOCF;
var mCapSpending;
var mANWC;
var mCFA;

var mCFDebt;
var	mCFStock;
var	mCFDS;

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 getOCFProblem();
	mQue[1] = new getCapSpendingProblem();
	mQue[2] = new getANWCProblem();
	mQue[3] = new getCFAProblem();
	mQue[4] = new getCFDebtProblem();
	mQue[5] = new getCFStockProblem();
	//mQue[6] = new getCFDSProblem(); redundant
}

function drawMCQuestions() {
	createQuestions();
	theOut = "<h1>Financial Cash Flow 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 Cash Flow 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(inPPE, inNFA) {
  mSales = Math.round(Math.random()*((inPPE)/100)*(.5) + (inPPE/100))*100;
  mDep = Math.round(Math.random()*(inNFA/100)*.20*100);
  if (mDep < 50) {
  	mDep = 50;
  }
  mCOGS = Math.round(Math.random()*(mSales/100)*.3 + (mSales/100)*(.5))*100;
  mAdmExp = Math.round(Math.random()*(mSales/100)*.1 + .5)*100;
  mEBIT = mSales - mCOGS - mAdmExp - mDep;
  mInt = Math.round(((Math.random()*(15)+1)/100)*mLTDebt/10)*10;
  mTaxInc = mEBIT - mInt;
  mTaxes = Math.round(((Math.random()*(35)+5)/100)*mTaxInc);
  mNI = mTaxInc - mTaxes;
  if (mNI > 0) {
  	mDiv = Math.round(((Math.random()*800)/1000)*mNI);
  } else {
  	mDiv = 0;
  }
  mAddRE = mNI - mDiv;
}

function newFinancials() {
  var theG = Math.round(Math.random()*4*100)/1000 + 1;
  mCash = Math.round(Math.random()*6 + 1)*100;
  mCash1 = Math.round(.85*(mCash/10)*theG + Math.random()*(.2*(mCash/10)))*10;
  mAccRec = Math.round(Math.random()*6 + 1)*100;
  mAccRec1 = Math.round(.85*(mAccRec/10)*theG + Math.random()*(.2*(mAccRec/10)))*10;
  mInv = Math.round(Math.random()*10 + 1)*100;
  mInv1 = Math.round(.85*(mInv/10)*theG + Math.random()*(.2*(mInv/10)))*10;
  mTCA = mCash + mAccRec + mInv;
  mTCA1 = mCash1 + mAccRec1 + mInv1;
  mPPE = Math.round(Math.random()*22 + 4)*100;
  mPPE1 = Math.round(.85*(mPPE/10)*theG + Math.random()*(.2*(mPPE/10)))*10;
  mAccDep = Math.round(Math.random()*((mPPE/10)*.3) + 1)*10;
  mNFA = mPPE - mAccDep;
  mTA = mTCA + mNFA;
  
  mLTDebt = Math.round(Math.random()*.4*(mTA/10) + .15*(mTA/10))*10;
  mTLTD = mLTDebt;
  
  getIncomeStatement(mPPE,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;
  mAccPay1 = Math.round(.85*(mAccPay/10)*theG + Math.random()*(.2*(mAccPay/10)))*10;
  mNotes1 = Math.round(.85*(mNotes/10)*theG + Math.random()*(.2*(mNotes/10)))*10;
  mTCL1 = mAccPay1 + mNotes1;
  
  mTSE = mTA - mTLTD - mTCL; 
  mCS = Math.round((Math.random()*.2 + .20)*(mTSE/10))*10;
  mCapSurp = Math.round((Math.random()*.3 + .20)*(mTSE/10))*10;
  mRE = mTSE - mCS - mCapSurp;

  mCS1 = mCS + Math.round(Math.random()*(.2*(mCS/10)))*10;
  mCapSurp1 = mCapSurp + Math.round(Math.random()*(.2*(mCapSurp/10)))*10;
  
  mAccDep1 = mAccDep + mDep;
  mNFA1 = mPPE1 - mAccDep1;
  mTA1 = mTCA1 + mNFA1;
  mRE1 = mRE + mAddRE;
  mTSE1 = mCS1 + mCapSurp1 + mRE1;
  mTL1 = mTA1;
  mLTDebt1 = mTA1 - mTSE1 - mTCL1;
  mTLTD1 = mLTDebt1;
  
  while((mTSE1 <= 0) || (mLTDebt1 < 0)) {
  	getIncomeStatement(mPPE, mNFA);
	mAccDep1 = mAccDep + mDep;
	mNFA1 = mPPE1 - mAccDep1;
	mTA1 = mTCA1 + mNFA1;
	mRE1 = mRE + mAddRE;
	mTSE1 = mCS1 + mCapSurp1 + mRE1;
	mTL1 = mTA1;
    mLTDebt1 = mTA1 - mTSE1 - mTCL1;
	mTLTD1 = mLTDebt1;	
  }
}

function getTRTitle(inTitleL,inVal1,inVal2,inTitleR,inVal3,inVal4) {
	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="46">' + inVal2 + '</td>';
    theTR += '<td class="ctitle" width="154">' + inTitleR + '</td>';
    theTR += '<td class="ctitle" width="47">' + inVal3 + '</td>';
    theTR += '<td class="ctitle" width="47">' + inVal4 + '</td>';
    theTR += '</tr>\n';
	return theTR;
}

function getTR(inTitleL,inVal1,inVal2,inTitleR,inVal3,inVal4) {
	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="46">' + inVal2 + '</td>';
    theTR += '<td class="litem" width="154">' + inTitleR + '</td>';
    theTR += '<td class="litem" width="47">' + inVal3 + '</td>';
    theTR += '<td class="litem" width="47">' + inVal4 + '</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", "1997", "Liabilities and Owners' Equity", "1998", "1997"); 
    mCI += getTR("Current Assets", "&nbsp;", "&nbsp;", "Current Liabilities", "&nbsp;", "&nbsp;"); 
    mCI += getTR("Cash", mCash1, mCash, "Accounts Payable", mAccPay1, mAccPay); 
    mCI += getTR("Accounts Receivable", mAccRec1, mAccRec, "Notes Payable", mNotes1, mNotes); 
    mCI += getTR("Inventory", mInv1, mInv, "<i>Total Current Liabilities</i>", mTCL1, mTCL); 
    mCI += getTR("<i>Total Current Assets</i>", mTCA1, mTCA, "Long Term Liabilities", "&nbsp;", "&nbsp;"); 
    mCI += getTR("&nbsp;", "&nbsp;", "&nbsp;", "Long Term Debt", mLTDebt1, mLTDebt); 
    mCI += getTR("Fixed Assets", "&nbsp;", "&nbsp;", "<i>Total Long Term Liabilities</i>", mTLTD1, mTLTD);
    mCI += getTR("Property, Plant, and Equipment", mPPE1, mPPE, "Owners' Equity", "&nbsp;", "&nbsp;");
    mCI += getTR("Less Accumulated Depreciation", mAccDep1, mAccDep, "Common Stock ($1 Par)", mCS1, mCS); 
    mCI += getTR("<i>Net Fixed Assets</i>", mNFA1, mNFA, "Capital Surplus", mCapSurp1, mCapSurp);
    mCI += getTR("&nbsp;", "&nbsp;", "&nbsp;", "Retained Earnings", mRE1, mRE); 
    mCI += getTR("&nbsp;", "&nbsp;", "&nbsp;", "Total Owners' Equity", mTSE1, mTSE);
    mCI += getTR("<i>Total Assets</i>", mTA1, mTA, "<i>Total Liabilities and Owners' Equity</i>", mTL1, 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 ($ 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("Cost of Goods Sold",mCOGS);
    mCI += getTRIS("Administrative Expenses",mAdmExp);
    mCI += getTRIS("Depreciation",mDep);
    mCI += getTRIS("<i>Earnings Before Interest and Taxes</i>",mEBIT);
    mCI += getTRIS("Interest Expense",mInt);
    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 Retained Earnings",mAddRE);
    
    mCI += '</table></td></tr></table>\n';
}

function drawCommonInfo() {
	return mCI;
}

function getOCFProblem() {
	var theQue = new Question();
	var theAns = mEBIT + mDep - mTaxes;
	mOCF = theAns;
  	theQue.mQ = "Find the Operating Cash Flow for 1998.";
    theQue.mE = "<p>The <b>Operating Cash Flow</b> is calculated as follows:</p>";
	theQue.mE += "<p>Operating Cash Flow = EBIT + Depreciation - Taxes</p>";
	theQue.mE += "<p>Operating Cash Flow = $" + mEBIT + " + $" + mDep + " - $" + mTaxes + " = $" + theAns +"</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getCapSpendingProblem() {
	var theQue = new Question();
	var theAns = mNFA1 - mNFA + mDep;
	mCapSpending = theAns;
  	theQue.mQ = "Find the Capital Spending for 1998.";
    theQue.mE = "<P>The <b>Capital Spending</b> is calculated as follows:</P>";
	theQue.mE += "<p>Capital Spending = Ending Net Fixed Assets - Beginning Net Fixed Assets + Depreciation</p>";
	theQue.mE += "<p>Capital Spending = $" + mNFA1 + " - $" + mNFA + " + $" + mDep + " = $" + theAns +"</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getANWCProblem() {
	var theQue = new Question();
	var theENWC = mTCA1 - mTCL1;
	var theBNWC = mTCA - mTCL;
	var theAns = theENWC - theBNWC;
	mANWC = theAns;
  	theQue.mQ = "Find the Additions to Net Working Capital for 1998.";
    theQue.mE = "<P>The <b>Additions to Net Working Capital</b> is calculated as follows:</P>";
	theQue.mE += "<p>Additions to Net Working Capital = Ending Net Working Capital - Beginning Net Working Capital</p>";
	theQue.mE += "<p>Where<br>";
	theQue.mE += "Ending Net Working Capital = Ending Current Assets - Ending Current Liabilities<br>";
	theQue.mE += "Ending Net Working Capital = $" + mTCA1 + " - " + mTCL1 + " = $" + theENWC + "<br>";
	theQue.mE += "Beginning Net Working Capital = Beginning Current Assets - Beginning Current Liabilities<br>";
	theQue.mE += "Beginning Net Working Capital = $" + mTCA1 + " - " + mTCL + " = $" + theBNWC + "</p>";
	theQue.mE += "<p>Additions to Net Working Capital = $" + theENWC + " - $" + theBNWC + " = $" + theAns +"</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getCFAProblem() {
	var theQue = new Question();
	var theAns = mOCF - mCapSpending - mANWC;
	mCFA = theAns;
  	theQue.mQ = "Find the Cash Flow from Assets for 1998.";
    theQue.mE = "<P>The <b>Cash Flow from Assets</b> is calculated as follows:</P>";
	theQue.mE += "<p>Cash Flow from Assets = Operating Cash Flow - Capital Spending - Additions to Net Working Capital</p>";
	theQue.mE += "<p>Using the results of the calculations above.</p>";
	theQue.mE += "<p>Cash Flow from Assets = $" + mOCF + " - $" + mCapSpending + " - $" + mANWC + " = $" + theAns +"</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getCFDebtProblem() {
	var theQue = new Question();
	var theAns = mInt - mLTDebt1 + mLTDebt;
	mCFDebt = theAns;
  	theQue.mQ = "Find the Cash Flow to Debtholders for 1998.";
    theQue.mE = "<p>The <b>Cash Flow to Debtholders</b> is calculated as follows:</p>";
	theQue.mE += "<p>Cash Flow to Debtholders = Interest Expense - Ending Long-Term Debt + Beginning Long-Term Debt</p>";
	theQue.mE += "<p>Cash Flow to Debtholders = $" + mInt + " - $" + mLTDebt1 + " + $" + mLTDebt + " = $" + mCFDebt +"</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getCFStockProblem() {
	var theQue = new Question();
	var theAns = mDiv - mCS1 - mCapSurp1 + mCS + mCapSurp;
	mCFStock = theAns;
  	theQue.mQ = "Find the Cash Flow to Stockholders for 1998.";
    theQue.mE = "<p>The <b>Cash Flow to Stockholders</b> is calculated as follows:</p>";
	theQue.mE += "<p>Cash Flow to Stockholders = Dividends - (Ending Common Stock + Ending Capital Surplus) + (Beginning Common Stock + Beginning Capital Surplus)</p>";
	theQue.mE += "<p>Cash Flow to Stockholders = $" + mDiv + " - ($" + mCS1 + " + $" + mCapSurp1 + ") + ($" + mCS + " + $" + mCapSurp + ") = $" + mCFStock +"</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, theAns, 2.5, "$", "",2);
 	return theQue;
 }
 
 function getCFDSProblem() {
	var theQue = new Question();
	var theAns = mCFDebt + mCFStock;
	mCFDS = theAns;
  	theQue.mQ = "Find the Cash Flow to Investors for 1998.";
    theQue.mE = "<P>The <b>Cash Flow to Investors</b> is calculated as follows:</P>";
	theQue.mE += "<p>Cash Flow to Investors = Cash Flow to Debtholders + Cash Flow to Stockholders</p>";
	theQue.mE += "<p>Using the results of the calculations above.</p>";
	theQue.mE += "<p>Cash Flow to Investors = $" + mCFDebt + " + $" + mCFStock + " = $" + mCFDS +"</p>";
    theQue.mAns = Math.round(theAns*100)/100;
    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 drawFractionNoF(inLHS,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'>" + 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 += "</tr>";
	theOut += "<tr>";
	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;
}

