
mNumQuestions = 8;
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;

// Common information
var mCI = "";
var mP = new Array(4);
var mRA = new Array(4);
var mRB = new Array(4);
var mPOut = new Array(4);
var mPOut2 = new Array(4);
var mRAOut = new Array(4);
var mRBOut = new Array(4);
var mRAOut2 = new Array(4);
var mRBOut2 = new Array(4);
var mERA;
var mERB;
var mVarA;
var mVarB;
var mSDA;
var mSDB;
var mCov;
var mCorr;
var mERAOut;
var mERBOut;
var mERAOut2;
var mERBOut2;
var mVarAOut;
var mVarBOut;
var mSDAOut;
var mSDBOut;
var mSDAOut2;
var mSDBOut2;
var mCovOut;
var mCorrOut;

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() {
	getCommonInfo();
	mQue[0] = new getERAProblem();
	mQue[3] = new getERBProblem();
	mQue[1] = new getVarAProblem();
	mQue[4] = new getVarBProblem();
	mQue[2] = new getSDAProblem();
	mQue[5] = new getSDBProblem();
	mQue[6] = new getCovProblem();
	mQue[7] = new getCorrProblem();
}

function drawMCQuestions() {
	createQuestions();
	theOut = "<h1>Expected Return 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>Expected Return 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 getCommonInfo() {
	mP[0] = Math.round(Math.random()*60) + 1;
    mP[1] = Math.round(Math.random()*(98-mP[0])) + 1;
    mP[2] = Math.round(Math.random()*(98-mP[0]-mP[1])) + 1;
    mP[3] = 100 - mP[0] - mP[1] - mP[2];
    var isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRA[0] = isNeg*Math.round(Math.random()*50); 
    isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRA[1] = isNeg*Math.round(Math.random()*50); 
    isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRA[2] = isNeg*Math.round(Math.random()*50); 
    isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRA[3] = isNeg*Math.round(Math.random()*50); 
    isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRB[0] = isNeg*Math.round(Math.random()*50); 
    isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRB[1] = isNeg*Math.round(Math.random()*50); 
    isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRB[2] = isNeg*Math.round(Math.random()*50); 
    isNeg = Math.random();   
    if (isNeg < 0.20) {
    	isNeg = -1;
    } else {
    	isNeg = 1;
    }
    mRB[3] = isNeg*Math.round(Math.random()*50); 
    mERA = 0;
    mERB = 0;
    for (i=0; i<4; i++) {
    	mERA += mP[i]*mRA[i]/100;
    	mERB += mP[i]*mRB[i]/100;
    	mRAOut[i] = "" + Math.round(mRA[i]*100)/100;
    	mRBOut[i] = "" + Math.round(mRB[i]*100)/100;
    	mRAOut2[i] = "" + Math.round(mRA[i]*100)/10000;
    	mRBOut2[i] = "" + Math.round(mRB[i]*100)/10000;
    	mPOut[i] = "" + Math.round(mP[i]*100)/10000;
    	mPOut2[i] = "" + Math.round(mP[i]*100)/100;
    }
    mVarA = 0;
    mVarB = 0;
    mCov = 0;
    for (i=0; i<4; i++) {
    	mVarA += mP[i]*(mRA[i]-mERA)*(mRA[i]-mERA)/1000000;
    	mVarB += mP[i]*(mRB[i]-mERB)*(mRB[i]-mERB)/1000000;
    	mCov += mP[i]*(mRA[i]-mERA)*(mRB[i]-mERB)/1000000;
    }
    mSDA = Math.sqrt(mVarA)*100;
    mSDB = Math.sqrt(mVarB)*100;
    mCorr = mCov/(mSDA*mSDB/10000);
    mERAOut = "" + Math.round(mERA*100)/100;
    mERBOut = "" + Math.round(mERB*100)/100;
    mERAOut2 = "" + Math.round(mERA*100)/10000;
    mERBOut2 = "" + Math.round(mERB*100)/10000;
    mVarAOut = "" + Math.round(mVarA*10000)/10000;
    mVarBOut = "" + Math.round(mVarB*10000)/10000;
    mSDAOut = "" + Math.round(mSDA*100)/100;
    mSDBOut = "" + Math.round(mSDB*100)/100;
    mSDAOut2 = "" + Math.round(mSDA*100)/10000;
    mSDBOut2 = "" + Math.round(mSDB*100)/10000;
    mCorrOut = "" + Math.round(mCorr*1000)/1000;
    mCovOut = "" + Math.round(mCov*10000)/10000;
    mCI = "<P>Use the information below to answer the following questions.</P>";
    mCI += "<center><table><tr valign='bottom' align='center'><td><b>State</b></td><td><b>Probability</b></td><td><b>Return on<br>Stock A</b></td><td><b>Return on<br>Stock B</b></td></tr>";
    for (i=1; i<=4; i++) {
    	mCI += "<tr align='center'><td>" + i + "</td><td>" + mPOut2[i-1] + "\%</td><td>" + mRAOut[i-1] + "\%</td><td>" + mRBOut[i-1] + "\%</td><td></tr>"
    }
    mCI += "</table></center>";
}

function drawCommonInfo() {
	return mCI;
}

function getERAProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Expected Return on Stock A.";
    theQue.mE = "<P>The <b>Expected Return on Stock A</b> is calculated as follows:</P>";
	theQue.mE += "<P>E[R<sub>A</sub>] = ";
	theQue.mE += "" + mPOut[0] + "(" + mRAOut[0] + "\%) + ";
	theQue.mE += "" + mPOut[1] + "(" + mRAOut[1] + "\%) + ";
	theQue.mE += "" + mPOut[2] + "(" + mRAOut[2] + "\%) + ";
	theQue.mE += "" + mPOut[3] + "(" + mRAOut[3] + "\%) = " + mERAOut + "\%";
    theQue.mAns = mERAOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mERA, .4, "", "\%",2);
 	return theQue;
 }
 
 function getERBProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Expected Return on Stock B.";
    theQue.mE = "<P>The <b>Expected Return on Stock B</b> is calculated as follows:</P>";
	theQue.mE += "<P>E[R<sub>B</sub>] = ";
	theQue.mE += "" + mPOut[0] + "(" + mRBOut[0] + "\%) + ";
	theQue.mE += "" + mPOut[1] + "(" + mRBOut[1] + "\%) + ";
	theQue.mE += "" + mPOut[2] + "(" + mRBOut[2] + "\%) + ";
	theQue.mE += "" + mPOut[3] + "(" + mRBOut[3] + "\%) = " + mERBOut + "\%";
    theQue.mAns = mERBOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mERB, .4, "", "\%",2);
 	return theQue;
 }
 
 function getVarAProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Variance of the returns on Stock A.";
    theQue.mE = "<P>The <b>Variance on Stock A</b> is calculated as follows:</P>";
    theQue.mE += "<P><I>Using the Expected Return on Stock A from the previous problem.</I></P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sup>2</sup><sub>A</sub> = ";
	theQue.mE += "" + mPOut[0] + "(" + mRAOut2[0] + " - " + mERAOut2 + ")<sup>2</sup> + ";
	theQue.mE += "" + mPOut[1] + "(" + mRAOut2[1] + " - " + mERAOut2 + ")<sup>2</sup> + ";
	theQue.mE += "" + mPOut[2] + "(" + mRAOut2[2] + " - " + mERAOut2 + ")<sup>2</sup> + ";
	theQue.mE += "" + mPOut[3] + "(" + mRAOut2[3] + " - " + mERAOut2 + ")<sup>2</sup> = " + mVarAOut + "";
    theQue.mAns = mVarAOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mVarA, .04, "", "",4);
 	return theQue;
 }
 
 function getVarBProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Variance of the returns on Stock B.";
    theQue.mE = "<P>The <b>Variance on Stock B</b> is calculated as follows:</P>";
    theQue.mE += "<P><I>Using the Expected Return on Stock B from the previous problem.</I></P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sup>2</sup><sub>B</sub> = ";
	theQue.mE += "" + mPOut[0] + "(" + mRBOut2[0] + " - " + mERBOut2 + ")<sup>2</sup> + ";
	theQue.mE += "" + mPOut[1] + "(" + mRBOut2[1] + " - " + mERBOut2 + ")<sup>2</sup> + ";
	theQue.mE += "" + mPOut[2] + "(" + mRBOut2[2] + " - " + mERBOut2 + ")<sup>2</sup> + ";
	theQue.mE += "" + mPOut[3] + "(" + mRBOut2[3] + " - " + mERBOut2 + ")<sup>2</sup> = " + mVarBOut + "";
    theQue.mAns = mVarBOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mVarB, .04, "", "",4);
 	return theQue;
 }
 
 function getSDAProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Standard Deviation of the returns on Stock A.";
    theQue.mE = "<P>The <b>Standard Deviation on Stock A</b> is calculated as the square root of the Variance.</P>";
    theQue.mE += "<P><I>Using the Variance on Stock A from the previous problem.</I></P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sub>A</sub> = (" + mVarAOut + ")<sup>1/2</sup> = " + mSDAOut2 + " = " + mSDAOut + "\%";
    theQue.mAns = mSDAOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mSDA, .4, "", "\%",2);
 	return theQue;
 }
 
 function getSDBProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Standard Deviation of the returns on Stock B.";
    theQue.mE = "<P>The <b>Standard Deviation on Stock B</b> is calculated as the square root of the Variance.</P>";
    theQue.mE += "<P><I>Using the Variance on Stock B from the previous problem.</I></P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sub>B</sub> = (" + mVarBOut + ")<sup>1/2</sup> = " + mSDBOut2 + " = " + mSDBOut + "\%";
    theQue.mAns = mSDBOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mSDB, .4, "", "\%",2);
 	return theQue;
 }
 
 function getCovProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Covariance between the returns on Stock A and Stock B.";
    theQue.mE = "<P>The <b>Covariance</b> is calculated as follows:</P>";
    theQue.mE += "<P><I>Using information from the above problems.</I></P>";
	theQue.mE += "<P><FONT FACE='symbol'>s</FONT><sub>AB</sub> = ";
	theQue.mE += "" + mPOut[0] + "(" + mRAOut2[0] + " - " + mERAOut2 + ")(" + mRBOut2[0] + " - " + mERBOut2 + ") + ";
	theQue.mE += "" + mPOut[1] + "(" + mRAOut2[1] + " - " + mERAOut2 + ")(" + mRBOut2[1] + " - " + mERBOut2 + ")<br> + ";
	theQue.mE += "" + mPOut[2] + "(" + mRAOut2[2] + " - " + mERAOut2 + ")(" + mRBOut2[2] + " - " + mERBOut2 + ") + ";
	theQue.mE += "" + mPOut[3] + "(" + mRAOut2[3] + " - " + mERAOut2 + ")(" + mRBOut2[3] + " - " + mERBOut2 + ") = " + mCovOut + "";
    theQue.mAns = mCovOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mCov, .04, "", "",4);
 	return theQue;
 }
 
 function getCorrProblem() {
	var theQue = new Question();
  	theQue.mQ = "Find the Correlation Coefficient between the returns on Stock A and Stock B.";
    theQue.mE = "<P>The <b>Correlation Coefficient</b> is calculated as follows:</P>";
    theQue.mE += "<P><I>Using information from the above problems.</I></P>";
	theQue.mE += drawFractionNoF("<FONT FACE='symbol'>r</FONT><sub>AB</sub>",mCovOut,"(" + mSDAOut2 + ")(" + mSDBOut2 + ")",mCorrOut);
    theQue.mAns = mCorrOut;
    theQue.mN = 4;
	theQue.mT = "MC";
	theQue = buildAnswers(theQue, mCorr, .01, "", "",3);
 	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;
}
