function mbrEvent(someval) {
	tierChange(1);
	buildAge(1);
}

function buildAge(someval){
	var mbr = parseInt(document.ERABenCalc.mbrClass.value);
	var Tier = parseInt(document.ERABenCalc.mbrTier.value);

	if (mbr == -1 || Tier == -1)
	{
		document.ERABenCalc.Age.value = -1;
		
		return(false);
	}
	
	document.ERABenCalc.Age.length=0;  //this clears the select box
	//if generalmember =1, start = 50
	//is safety member = 2, start = 41
	
	var start = 0;
	var end = 0;
	var range = 0;
	if (mbr == 0)
	{
		if (Tier == 3)
		{
			start = 55;
		}
		else
		{
			start = 50;
		}
	}
	if (mbr == 1)
	{
		if (Tier == 3)
		{
			return(false);
		}
		else
		{
			start = 41;
		}
	}
	
	if(Tier == -1)
	{
		return(false);
	}
	document.ERABenCalc.Age.options[0] = new Option("<Select One>","-1",true,true);
	end = 65;
	range = 4 * (end - start);
	for (var i=0; i <= range;i++)
	{
		document.ERABenCalc.Age.options[i+1] = new Option(start, start);
		start= start + 0.25;
	}
}
//-----------------------------------------------------------------
function tierChange(Tier){
	var mbr = parseInt(document.ERABenCalc.mbrClass.value);
	var input = parseInt(document.ERABenCalc.mbrTier.value, 10);
	if (mbr == 0)
	{
		if (input == 3)
		{
			document.ERABenCalc.SSat65.value = "";
			document.ERABenCalc.SSat65.disabled = false;
		}
		else
		{
			document.ERABenCalc.SSat65.value = "";
			document.ERABenCalc.SSat65.disabled = true;
		}
	}
	else
	{
		document.ERABenCalc.SSat65.value = "";
		document.ERABenCalc.SSat65.disabled = true;
			
		if (input == 3)
		{
			alert("No tier 3 safety.");
			document.ERABenCalc.mbrTier.value = 1;
		}
	
	}
	
	buildAge(document.ERABenCalc.mbrClass);
}
// --------------------------------------------------------

function CalculateComp() {
var theFactor = 0.0;
var mbr = parseInt(document.ERABenCalc.mbrClass.value);
var tier = parseInt(document.ERABenCalc.mbrTier.value);
var retAge = parseFloat(document.ERABenCalc.Age.value);
var yearsService = parseFloat(document.ERABenCalc.Service.value);
var retFinAvgMoComp = parseFloat(document.ERABenCalc.FinComp.value);
var boolErrorCheck = "TRUE";
boolErrorCheck = isEmpty(retAge);
if(boolErrorCheck)
alert("Empty Field: Age at Retirement");
boolErrorCheck = isEmpty(yearsService);
if(boolErrorCheck)
alert("Empty Field: Years of Service");
boolErrorCheck = isEmpty(retFinAvgMoComp);
if(boolErrorCheck)
alert("Empty Field: Final Average Monthly Salary");
//OK, lets calculate the value
var divisor = new Array(new Array(75,90,-1,90,90), new Array(75,75,-1,50,50));
var divisor2 = new Array(new Array(50,60,-1,60,60), new Array(50,50,-1,33.33,33.33));
if(!boolErrorCheck) {
var msg = "going to calc\n"
var theFactor = getFactor(tier, retAge, mbr);
var theAnswer1 = 0;
var theAnswer2 = 0;
if (tier != 3)
{
	//msg = msg + "factor is " + theFactor + "\n";
	var tmpVal = 350;
	var div = 75;
	if(retFinAvgMoComp < 350)
	{
	tmpVal = retFinAvgMoComp;
	}
	//msg = msg + "tmpval is " + tmpVal + "\n";
	div = divisor[mbr][tier-1];
	//msg = msg + "div is " + div + "\n";
	theAnswer1 = tmpVal/div;
	//msg = msg + "ans1= " + theAnswer1+ "\n";
	theAnswer1 = theAnswer1 *theFactor * yearsService;
	//msg = msg + "svc= " + yearsService+ "\n";
	//msg = msg + "ans1= " + theAnswer1+ "\n";
	tmpVal = retFinAvgMoComp - 350;
	if(tmpVal < 0)
	{
	tmpVal = 0;
	}
	//msg = msg + "tmpval2= " + tmpVal+ "\n";
	div = divisor2[mbr][tier-1];
	//msg = msg + "div2= " + div + "\n";
	theAnswer2 = tmpVal/div;
	//msg = msg + "ans2= " + theAnswer2+ "\n";
	theAnswer2 = theAnswer2 *theFactor * yearsService;
	theAnswer1 = theAnswer1 + theAnswer2;
}
if (tier == 3)
{
	var SSat65 = parseFloat(document.ERABenCalc.SSat65.value);
	//msg = msg + "SSat65= " + SSat65+ "\n";
	var yearsServiceUpTo35 = yearsService;
	var yearsServiceOver35 = yearsService - 35;
	
	if (yearsServiceOver35 < 0)
	{
		yearsServiceOver35 = 0;
	}
	if (yearsServiceOver35 > 20)
	{
		yearsServiceOver35 = 20;
	}
	
	if (yearsService > 35)
	{
		yearsServiceUpTo35 = 35;
	}
	
	//msg = msg + "yearsServiceUpTo35= " + yearsServiceUpTo35+ "\n";
	//msg = msg + "yearsServiceOver35= " + yearsServiceOver35+ "\n";

	theAnswer1 = (((.02 * retFinAvgMoComp * yearsServiceUpTo35) + (.01 * retFinAvgMoComp * yearsServiceOver35)) - (SSat65*yearsServiceUpTo35/35));
	msg = msg + "theAnswer1= " + theAnswer1+ "\n";
	if (retAge < 65)
	{
		theAnswer1 = theAnswer1 * theFactor;
	}
	//msg = msg + "retAge= " + retAge+ "\n";
	//msg = msg + "theFactor= " + theFactor+ "\n";
	//msg = msg + "theAnswer1*ERF= " + theAnswer1+ "\n";
}

if (theAnswer1 < 0)
{
	theAnswer1 = 0;
	alert("Please call (209) 525-6393 for an estimate.");
}

document.ERABenCalc.MoRetAllow.value = "$" + parseInt(theAnswer1);
//alert(msg);
}
}
//----------------------------------------------------------------------------------
function isEmpty(inputStr) {
if (inputStr == "" || inputStr == null) {
return true;
}
return false;
}
//----------------------------------------------------------------------------------
function getFactor(tier, age, mbr) {
var ndx = 0;
var ndx2 = 0;
if(mbr == 0)
{
if(tier == 1)
ndx=0;
if(tier == 2)
ndx=1;
if(tier == 3)
ndx=5;
if(tier == 4)
ndx=2;
if(tier == 5)
ndx=2;
}
if(mbr==1)
{
if(tier == 1)
ndx=3;
if(tier == 2)
ndx=3;
if(tier == 4)
ndx=4;
if(tier == 5)
ndx=4;
}
age = age-41;
ndx2 = Math.floor(age);
age = age - ndx2; //ie, give me float part w/o integer part
ndx2 = ndx2 *4;
while(age > 0)
{
ndx2 = ndx2 + 1;
age = age - .25;
}
rates = new Array();
rates.push( new Array(-1, -1,0.6258 ,0.6258, 0.6258 , 0.0000 ));  // 41
rates.push( new Array(-1, -1,0.6350 ,0.6350, 0.6350 , 0.0000 ));
rates.push( new Array(-1, -1,0.6442 ,0.6442, 0.6442 , 0.0000 ));
rates.push( new Array(-1, -1,0.6533 ,0.6533, 0.6533 , 0.0000 ));
rates.push( new Array(-1, -1,0.6625 ,0.6625, 0.6625 , 0.0000 ));  // 42
rates.push( new Array(-1, -1,0.6720 ,0.6720, 0.6720 , 0.0000 ));
rates.push( new Array(-1, -1,0.6814 ,0.6814, 0.6814 , 0.0000 ));
rates.push( new Array(-1, -1,0.6909 ,0.6909, 0.6909 , 0.0000 ));
rates.push( new Array(-1, -1,0.7004 ,0.7004, 0.7004 , 0.0000 ));  // 43
rates.push( new Array(-1, -1,0.7102 ,0.7102, 0.7102 , 0.0000 ));
rates.push( new Array(-1, -1,0.7200 ,0.7200, 0.7200 , 0.0000 ));
rates.push( new Array(-1, -1,0.7299 ,0.7299, 0.7299 , 0.0000 ));
rates.push( new Array(-1, -1,0.7397 ,0.7397, 0.7397 , 0.0000 ));  // 44
rates.push( new Array(-1, -1,0.7499 ,0.7499, 0.7499 , 0.0000 ));
rates.push( new Array(-1, -1,0.7601 ,0.7601, 0.7601 , 0.0000 ));
rates.push( new Array(-1, -1,0.7703 ,0.7703, 0.7703 , 0.0000 ));
rates.push( new Array(-1, -1,0.7805 ,0.7805, 0.7805 , 0.0000 ));  // 45
rates.push( new Array(-1, -1,0.7910 ,0.7910, 0.7910 , 0.0000 ));
rates.push( new Array(-1, -1,0.8016 ,0.8016, 0.8016 , 0.0000 ));
rates.push( new Array(-1, -1,0.8121 ,0.8121, 0.8121 , 0.0000 ));
rates.push( new Array(-1, -1,0.8226 ,0.8226, 0.8226 , 0.0000 ));  // 46
rates.push( new Array(-1, -1,0.8339 ,0.8339, 0.8339 , 0.0000 ));
rates.push( new Array(-1, -1,0.8452 ,0.8452, 0.8452 , 0.0000 ));
rates.push( new Array(-1, -1,0.8586 ,0.8586, 0.8586 , 0.0000 ));
rates.push( new Array(-1, -1,0.8678 ,0.8678, 0.8678 , 0.0000 ));  // 47
rates.push( new Array(-1, -1,0.8780 ,0.8780, 0.8780 , 0.0000 ));
rates.push( new Array(-1, -1,0.8882 ,0.8882, 0.8882 , 0.0000 ));
rates.push( new Array(-1, -1,0.8983 ,0.8983, 08983 , 0.0000 ));
rates.push( new Array(-1, -1,0.9085 ,0.9085, 0.9085 , 0.0000 ));  // 48
rates.push( new Array(-1, -1,0.9194 ,0.9194, 0.9194 , 0.0000 ));
rates.push( new Array(-1, -1,0.9304 ,0.9304, 0.9304 , 0.0000 ));
rates.push( new Array(-1, -1,0.9413 ,0.9413, 0.9413 , 0.0000 ));
rates.push( new Array(-1, -1,0.9522 ,0.9522, 0.9522 , 0.0000 ));  // 49
rates.push( new Array(-1, -1,0.9641 ,0.9641, 0.9641 , 0.0000 ));
rates.push( new Array(-1, -1,0.9761 ,0.9761, 0.9761 , 0.0000 ));
rates.push( new Array(-1, -1,0.9880 ,0.9880, 0.9880 , 0.0000 ));
rates.push( new Array(0.6681 ,0.7091 ,0.8850 ,1.0000 ,1.0000, 0.000 ));  // 50
rates.push( new Array(0.6775 ,0.7183 ,0.8987 ,1.0130 ,1.0000, 0.000 ));
rates.push( new Array(0.6869 ,0.7274 ,0.9125 ,1.0259 ,1.0000, 0.000 ));
rates.push( new Array(0.6962 ,0.7366 ,0.9262 ,1.0387 ,1.0000, 0.000 ));
rates.push( new Array(0.7056 ,0.7457 ,0.9399 ,1.0516 ,1.0000, 0.000 )); // 51
rates.push( new Array(0.7156 ,0.7547 ,0.9549 ,1.0656 ,1.0000, 0.000 ));
rates.push( new Array(0.7255 ,0.7637 ,0.9699 ,1.0796 ,1.0000, 0.000 ));
rates.push( new Array(0.7355 ,0.7726 ,0.9849 ,1.0937 ,1.0000, 0.000 ));
rates.push( new Array(0.7454 ,0.7816 ,1.0000 ,1.1078 ,1.0000, 0.000 ));  // 52
rates.push( new Array(0.7561 ,0.7907 ,1.0111 ,1.1231 ,1.0000, 0.000 ));
rates.push( new Array(0.7668 ,0.7999 ,1.0223 ,1.1384 ,1.0000, 0.000 ));
rates.push( new Array(0.7775 ,0.8090 ,1.0335 ,1.1538 ,1.0000, 0.000 ));
rates.push( new Array(0.7882 ,0.8181 ,1.0447 ,1.1692 ,1.0000, 0.000 ));  // 53
rates.push( new Array(0.7998 ,0.8275 ,1.0597 ,1.1859 ,1.0000, 0.000 ));
rates.push( new Array(0.8114 ,0.8369 ,1.0747 ,1.2028 ,1.0000, 0.000 ));
rates.push( new Array(0.8230 ,0.8462 ,1.0898 ,1.2195 ,1.0000, 0.000 ));
rates.push( new Array(0.8346 ,0.8556 ,1.1048 ,1.2366 ,1.0000, 0.000 ));  // 54
rates.push( new Array(0.8472 ,0.8656 ,1.1207 ,1.2547 ,1.0000, 0.000 ));
rates.push( new Array(0.8598 ,0.8755 ,1.1367 ,1.2730 ,1.0000, 0.000 ));
rates.push( new Array(0.8724 ,0.8855 ,1.1526 ,1.2915 ,1.0000, 0.000 ));
rates.push( new Array(0.8850 ,0.8954 ,1.1686 ,1.3099 ,1.0000, 0.3700 )); // 55
rates.push( new Array(0.8987 ,0.9061 ,1.1855 ,1.3099 ,1.0000, 0.3700 ));
rates.push( new Array(0.9125 ,0.9168 ,1.2025 ,1.3099 ,1.0000, 0.3700 ));
rates.push( new Array(0.9262 ,0.9275 ,1.2195 ,1.3099 ,1.0000, 0.3700 ));
rates.push( new Array(0.9399 ,0.9382 ,1.2365 ,1.3099 ,1.0000, 0.4000 ));  // 56
rates.push( new Array(0.9549 ,0.9498 ,1.2547 ,1.3099 ,1.0000, 0.4000 ));
rates.push( new Array(0.9699 ,0.9614 ,1.2729 ,1.3099 ,1.0000, 0.4000 ));
rates.push( new Array(0.9849 ,0.9730 ,1.2911 ,1.3099 ,1.0000, 0.4000 ));
rates.push( new Array(1.0000 ,0.9846 ,1.3093 ,1.3099 ,1.0000, 0.4400 ));  // 57
rates.push( new Array(1.0111 ,0.9972 ,1.3221 ,1.3099 ,1.0000, 0.4400 ));
rates.push( new Array(1.0223 ,1.0098 ,1.3350 ,1.3099 ,1.0000, 0.4400 ));
rates.push( new Array(1.0335 ,1.0224 ,1.3479 ,1.3099 ,1.0000, 0.4400 ));
rates.push( new Array(1.0447 ,1.0350 ,1.3608 ,1.3099 ,1.0000, 0.4899 ));
rates.push( new Array(1.0597 ,1.0487 ,1.3736 ,1.3099 ,1.0000, 0.4899 ));
rates.push( new Array(1.0747 ,1.0625 ,1.3865 ,1.3099 ,1.0000, 0.4899 ));
rates.push( new Array(1.0898 ,1.0762 ,1.3994 ,1.3099 ,1.0000, 0.4899 ));
rates.push( new Array(1.1048 ,1.0899 ,1.4123 ,1.3099 ,1.0000, 0.5400 ));
rates.push( new Array(1.1207 ,1.1049 ,1.4251 ,1.3099 ,1.0000, 0.5400 ));
rates.push( new Array(1.1367 ,1.1199 ,1.4380 ,1.3099 ,1.0000, 0.5400 ));
rates.push( new Array(1.1526 ,1.1349 ,1.4509 ,1.3099 ,1.0000, 0.5400 ));
rates.push( new Array(1.1686 ,1.1500 ,1.4638 ,1.3099 ,1.0000, 0.5999 ));
rates.push( new Array(1.1855 ,1.1611 ,1.4766 ,1.3099 ,1.0000, 0.5999 ));
rates.push( new Array(1.2025 ,1.1723 ,1.4895 ,1.3099 ,1.0000, 0.5999 ));
rates.push( new Array(1.2195 ,1.1835 ,1.5024 ,1.3099 ,1.0000, 0.5999 ));
rates.push( new Array(1.2365 ,1.1947 ,1.5153 ,1.3099 ,1.0000, 0.6600 ));
rates.push( new Array(1.2547 ,1.2097 ,1.5281 ,1.3099 ,1.0000, 0.6600 ));
rates.push( new Array(1.2729 ,1.2247 ,1.5410 ,1.3099 ,1.0000, 0.6600 ));
rates.push( new Array(1.2911 ,1.2398 ,1.5539 ,1.3099 ,1.0000, 0.6600 ));
rates.push( new Array(1.3093 ,1.2548 ,1.5668 ,1.3099 ,1.0000, 0.7299 ));
rates.push( new Array(1.3093 ,1.2707 ,1.57,1.3099 ,1.0000, 0.7299 ));
rates.push( new Array(1.3093 ,1.2867 ,1.57,1.3099 ,1.0000, 0.7299 ));
rates.push( new Array(1.3093 ,1.3026 ,1.57,1.3099 ,1.0000, 0.7299 ));
rates.push( new Array(1.3093 ,1.3186 ,1.57,1.3099 ,1.0000, 0.8100 ));
rates.push( new Array(1.3093 ,1.3355 ,1.57,1.3099 ,1.0000, 0.8100 ));
rates.push( new Array(1.3093 ,1.3525 ,1.57,1.3099 ,1.0000, 0.8100 ));
rates.push( new Array(1.3093 ,1.3695 ,1.57,1.3099 ,1.0000, 0.8100 ));
rates.push( new Array(1.3093 ,1.3865 ,1.57,1.3099 ,1.0000, 0.9000 ));
rates.push( new Array(1.3093 ,1.4047 ,1.57,1.3099 ,1.0000, 0.9000 ));
rates.push( new Array(1.3093 ,1.4229 ,1.57,1.3099 ,1.0000, 0.9000 ));
rates.push( new Array(1.3093 ,1.4411 ,1.57,1.3099 ,1.0000, 0.9000 ));
rates.push( new Array(1.3093 ,1.4593 ,1.57,1.3099 ,1.0000, 1.0000 ));
return(rates[ndx2][ndx]);
}
//----------------------------------------------------------------------------------
function ageCheck(Age){
var input = parseInt(document.ERABenCalc.Age.value, 10);
if (isNaN(input)){
alert("You may only enter numbers in the Age box.");
return false;
} else {
if (document.ERABenCalc.Age.value.length > 5) {
alert("Please enter a number that is no larger than 5 digits in the Age box.");
return false;
} else {
if (!inRange(input,50,70)) {
alert("Please enter an age between 50 and 70 in the Age box.");
return false;
}
return true;
}
}
}
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
function serviceCheck(Service){
var input = parseInt(document.ERABenCalc.Service.value, 10);
if (isNaN(input)){
alert("You may only enter numbers in the Years of Service box.");
return false;
} else {
if (document.ERABenCalc.Service.value.length > 5) {
alert("You may only enter a number no longer than 5 digits in length. (Range: 1.00 thru 45.99)");
return false;
} else {
if (!inRange(input,1,45.99)) {
alert("Please enter Years of Service between 1.00 and 45.99");
return false;
}
return true;
}
}
}
//----------------------------------------------------------------------------------
function compCheck(FinComp) {
var input = parseInt(document.ERABenCalc.FinComp.value, 10);
if (isNaN(input)){
alert("You may only enter numbers in the Monthly Salary box. Do not use dollar signs or commas.");
return false;
} else {
if (document.ERABenCalc.FinComp.value.length >10) {
alert("You may only enter a number that is no longer than 10 digits in length. (Range: 1 thru 9999999.99)");
return false;
}
}
return true;
}
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
function ssCheck(SSat65) {
var input = parseInt(document.ERABenCalc.SSat65.value, 10);
if (isNaN(input)){
alert("You may only enter numbers in the SS at 65 box. Do not use dollar signs or commas.");
return false;
} else {
if (document.ERABenCalc.SSat65.value.length >10) {
alert("You may only enter a number that is no longer than 10 digits in length. (Range: 1 thru 9999999.99)");
return false;
}
}
return true;
}
//----------------------------------------------------------------------------------
function inRange(inputStr, lo, hi) {
var num =parseInt(inputStr, 10);
if (num < lo || num > hi) {
return false;
}
return true;
}

window.onload = function(){document.ERABenCalc.SSat65.disabled = true;}