// Copyright (c) 1999 by R. E. Mathis, III// All rights reserved.// Unauthorized use or duplication is prohibited.var gD = 0;var gP = 0;var gG = 0;var gR = 0;var gDivNum = 0;var gType = 0; // P =1, D =2, R =3, G =4 if 0 => no problemfunction myAlert(inDivNum, inD, inG, inR, inP) {   var ETF = "\nEnter the Following:\n";   var Div = "\nD0 = ";   if (inDivNum == 1) {  	Div = "\nD1 = ";  }   var P = "\nPrice = ";   var G = "\nGrowth Rate = ";   var R = "\nRequired Return = ";   var TPress = "\nThen Press the ";  if (gType == 0) {     alert("Please click the New Problem button.");  } else if (gType == 1) {           alert(ETF+Div+inD+G+inG+R+inR+P+inP+TPress+"Po Button");   } else if (gType == 2) {           alert(ETF+Div+inD+G+inG+R+inR+P+inP+TPress+"Div Button");   } else if (gType == 3) {           alert(ETF+Div+inD+G+inG+R+inR+P+inP+TPress+"r Button");   } else if (gType == 4) {           alert(ETF+Div+inD+G+inG+R+inR+P+inP+TPress+"g Button");   } }function newProblem(form) {  gType = Math.round(Math.random()*3)+1;   if (gType == 1) {     randomPProblem(form);  } else if (gType == 2) {     randomDProblem(form);  } else if (gType == 3) {     randomRProblem(form);  }  else if (gType == 4) {     randomGProblem(form);  } }function doProblem() {  if (gType == 0) {     alert("Please click the New Problem button.");  } else if (gType == 1) {    scriptP(gDivNum,gD,gG,gR,gP);  } else if (gType == 2) {    scriptD(gDivNum,gD,gG,gR,gP);  }  else if (gType == 3) {    scriptR(gDivNum,gD,gG,gR,gP);  } else if (gType == 4) {    scriptG(gDivNum,gD,gG,gR,gP);  } }function randomPProblem(form) {	gP = 0;	gD = Math.round((Math.random()*5 + 1)*100)/100;	gDivNum = Math.round(Math.random());	gG = Math.round((Math.random()*9 + 1)*100)/100;	gR = Math.round((Math.random()*9 + 2 + gG)*100)/100;	var theOut = "Find the price for a stock given that ";	if (gDivNum == 0) {		theOut += "the current dividend is $" + gD + " per share, ";	} else {		theOut += "the next dividend is $" + gD + " per share, ";	}	theOut += "the required return is " + gR + "\%, ";	theOut += "the growth rate is dividends is " + gG + "\% per year.";	form.RandomProb.value = theOut;} function randomGProblem(form) {	gD = Math.round((Math.random()*5 + 1)*100)/100;	gDivNum = Math.round(Math.random());	gG = Math.round((Math.random()*9 + 1)*100)/100;	gR = Math.round((Math.random()*9 + 2 + gG)*100)/100;	if (gDivNum == 0) {		gP = Math.round(((gD*(1+gG/100))/((gR - gG)/100))*100)/100;	} else {		gP = Math.round((gD/((gR - gG)/100))*100)/100;	}	gG = 0;	var theOut = "Find the dividend growth rate for a stock given that ";	if (gDivNum == 0) {		theOut += "the current dividend is $" + gD + " per share, ";	} else {		theOut += "the next dividend is $" + gD + " per share, ";	}	theOut += "the required return is " + gR + "\%, and ";	theOut += "the stock price is $" + gP + " per share.";	form.RandomProb.value = theOut;}function randomRProblem(form) {	gD = Math.round((Math.random()*5 + 1)*100)/100;	gDivNum = Math.round(Math.random());	gG = Math.round((Math.random()*9 + 1)*100)/100;	gR = Math.round((Math.random()*9 + 2 + gG)*100)/100;	if (gDivNum == 0) {		gP = Math.round(((gD*(1+gG/100))/((gR - gG)/100))*100)/100;	} else {		gP = Math.round((gD/((gR - gG)/100))*100)/100;	}	gR = 0;	var theOut = "Find the required return for a stock given that ";	if (gDivNum == 0) {		theOut += "the current dividend is $" + gD + " per share, ";	} else {		theOut += "the next dividend is $" + gD + " per share, ";	}	theOut += "the dividend growth rate is " + gG + "\%, and ";	theOut += "the stock price is $" + gP + " per share.";	form.RandomProb.value = theOut;}function randomDProblem(form) {	gD = Math.round((Math.random()*5 + 1)*100)/100;	gDivNum = Math.round(Math.random());	gG = Math.round((Math.random()*9 + 1)*100)/100;	gR = Math.round((Math.random()*9 + 2 + gG)*100)/100;	if (gDivNum == 0) {		gP = Math.round(((gD*(1+gG/100))/((gR - gG)/100))*100)/100;	} else {		gP = Math.round((gD/((gR - gG)/100))*100)/100;	}	gD = 0;	var theOut = "";	if (gDivNum == 0) {		theOut += "Find the current dividend on a stock given that ";	} else {		theOut += "Find the next dividend on a stock given that ";	}	theOut += "the required return is " + gR + "\%, ";	theOut += "the dividend growth rate is " + gG + "\%, and ";	theOut += "the stock price is $" + gP + " per share.";	form.RandomProb.value = theOut;}//end pastefunction calcP(inDNum, inD, inG, inR) {	var outP = "";	inG = inG/100;	inR = inR/100;	if (inG >= inR) {		alert("Cannot compute the stock price (r must be greater than g).");		return outP;	}	 	if (inDNum == 0) { 		outP = inD*(1 + inG)/(inR - inG); 	} else { 		outP = inD/(inR - inG); 	} 	return outP;}function calcD(inDNum, inG, inR, inP) {	var outD = "";	inG = inG/100;	inR = inR/100;	if (inG >= inR) {		alert("Cannot compute the dividend (r must be greater than g).");		return outD;	}		if (inG <= -1) {		alert("Cannot compute the dividend (g must be greater than -100\%).");		return outD;	}	 	if (inDNum == 0) { 		outD = (inP*(inR - inG))/(1 + inG); 	} else { 		outD = (inP*(inR - inG)); 	} 	return outD;}function calcG(inDNum, inD, inR, inP) {	var outG = "";	inR = inR/100;	if (inP == 0) {		alert("Cannot compute the growth rate (Po must be positive).");		return outG;	}	 	if (inDNum == 0) { 		if ((inD/inP) == -1) { 			alert("Cannot compute the growth rate."); 			return outG; 		}	 		outG = (inR - (inD/inP))/((inD/inP)+1); 	} else { 		outG = inR - (inD/inP); 	}	return outG*100;}function calcR(inDNum, inD, inG, inP) {	var outR = "";	inG = inG/100;	if (inP <= 0) {		alert("Cannot compute the required return (Po must be positive).");		return outR;	}	 	if (inDNum == 0) { 		outR = (inD*(1 + inG))/(inP) + inG; 	} else { 		outR = (inD)/(inP) + inG; 	}	return outR*100;	}function findP(form) { 	var theG = form.GInput.value; 	if (!isNumber(theG)) { 		return false; 	} 	if (theG == "") theG = 0; 	var theR = form.RInput.value; 	if (!isPositiveNumber(theR)) { 		return false; 	} 	if (theR == "") theR = 0; 	var theD = form.DInput.value; 	if (!isPositiveNumber(theD)) { 		return false; 	} 	if (theD == "") theD = 0; 	var theDNum; 	var theDNum = form.DivNum.selectedIndex; 	if (theDNum == 0) { 		theDNum = 0; 	} else { 		theDNum = 1; 	} 	var theP = calcP(theDNum, theD, theG, theR); 	form.PInput.value = "" + Math.round(theP*100)/100; 	return true;} function findD(form) {	var theG = form.GInput.value; 	if (!isNumber(theG)) { 		return false; 	} 	if (theG == "") theG = 0; 	var theR = form.RInput.value; 	if (!isPositiveNumber(theR)) { 		return false; 	} 	if (theR == "") theR = 0; 	var theP = form.PInput.value; 	if (!isPositiveNumber(theP)) { 		return false; 	} 	if (theP == "") theP = 0; 	var theDNum; 	var theDNum = form.DivNum.selectedIndex; 	if (theDNum == 0) { 		theDNum = 0; 	} else { 		theDNum = 1; 	} 	var theD = calcD(theDNum, theG, theR, theP);	form.DInput.value = "" + Math.round(theD*100)/100;	form.DivNum.selectedIndex = theDNum;	return true;}function findG(form) { 	var theD = form.DInput.value; 	if (!isPositiveNumber(theD)) { 		return false; 	} 	if (theD == "") theD = 0; 	var theR = form.RInput.value; 	if (!isPositiveNumber(theR)) { 		return false; 	} 	if (theR == "") theR = 0; 	var theP = form.PInput.value; 	if (!isPositiveNumber(theP)) { 		return false; 	} 	if (theP == "") theP = 0; 	var theDNum; 	var theDNum = form.DivNum.selectedIndex; 	if (theDNum == 0) { 		theDNum = 0; 	} else { 		theDNum = 1; 	} 	var theG = calcG(theDNum, theD, theR, theP); 	form.GInput.value = "" + Math.round(theG*100)/100; 	return true; }  function findR(form) { 	var theD = form.DInput.value; 	if (!isPositiveNumber(theD)) { 		return false; 	} 	if (theD == "") theD = 0; 	var theG = form.GInput.value; 	if (!isNumber(theG)) { 		return false; 	} 	if (theG == "") theG = 0; 	var theP = form.PInput.value; 	if (!isPositiveNumber(theP)) { 		return false; 	} 	if (theP == "") theP = 0; 	var theDNum; 	var theDNum = form.DivNum.selectedIndex; 	if (theDNum == 0) { 		theDNum = 0; 	} else { 		theDNum = 1; 	} 	var theR = calcR(theDNum, theD, theG, theP);	form.RInput.value = "" + Math.round(theR*100)/100; 	return true;}  function isPositiveNumber(inputStr) { 	var decFlag = false; 	if (inputStr == ".") { 		alert("Please make sure that only numbers are input."); 		return false; 	} 	for (var i = 0; i < inputStr.length; i++) { 		var oneChar = inputStr.substring(i,i+1); 		if (((oneChar >= "0") && (oneChar <= "9")) || ((oneChar == ".") && (decFlag == false))) { 		 		} else { 			alert("Please make sure that only numbers are input."); 			return false; 		} 		if (oneChar == ".") {	 		decFlag = true;	 	} 	}	return true; }  function isNumber(inputStr) { 	var decFlag = false; 	if (inputStr == ".") { 		alert("Please make sure that only numbers are input."); 		return false; 	} 	for (var i = 0; i < inputStr.length; i++) { 		var oneChar = inputStr.substring(i,i+1); 		if ((i == 0) && (inputStr.length > 1)) {	 		if (((oneChar >= "0") && (oneChar <= "9")) || ((oneChar == ".") && (decFlag == false)) || (oneChar == "-")) {	 			 		} else {	 			alert("Please make sure that only numbers are input.");	 			return false;	 		}	 	} else {	 		if (((oneChar >= "0") && (oneChar <= "9")) || ((oneChar == ".") && (decFlag == false))) {	 			 		} else {	 			alert("Please make sure that only numbers are input.");	 			return false;	 		}	 	}	 	if (oneChar == ".") {	 		decFlag = true;	 	}	 	}	return true; } function launchCGStockCalc() {    window.open("CGStockCalcWindow.html","Win2","menubar,resizable,height=205,width=315");}function scriptP(inDivNum,inD,inG,inR,inP) {	document.CGStockCalc.DInput.value = inD;	document.CGStockCalc.GInput.value = inG;	document.CGStockCalc.RInput.value = inR;	document.CGStockCalc.PInput.value = inP;	document.CGStockCalc.DivNum.selectedIndex = inDivNum;	findP(document.CGStockCalc);	}function scriptG(inDivNum,inD,inG,inR,inP) {	document.CGStockCalc.DInput.value = inD;	document.CGStockCalc.GInput.value = inG;	document.CGStockCalc.RInput.value = inR;	document.CGStockCalc.PInput.value = inP;	document.CGStockCalc.DivNum.selectedIndex = inDivNum;	findG(document.CGStockCalc);	}function scriptD(inDivNum,inD,inG,inR,inP) {	document.CGStockCalc.DInput.value = inD;	document.CGStockCalc.GInput.value = inG;	document.CGStockCalc.RInput.value = inR;	document.CGStockCalc.PInput.value = inP;	document.CGStockCalc.DivNum.selectedIndex = inDivNum;	findD(document.CGStockCalc);	}function scriptR(inDivNum,inD,inG,inR,inP) {	document.CGStockCalc.DInput.value = inD;	document.CGStockCalc.GInput.value = inG;	document.CGStockCalc.RInput.value = inR;	document.CGStockCalc.PInput.value = inP;	document.CGStockCalc.DivNum.selectedIndex = inDivNum;	findR(document.CGStockCalc);	}