// Load array for Years Certain factors
var YearsOnlyFactor = new Array()
// 1.60%
YearsOnlyFactor[0] = 84.05
YearsOnlyFactor[1] = 42.36
YearsOnlyFactor[2] = 28.46
YearsOnlyFactor[3] = 21.52
YearsOnlyFactor[4] = 17.35
YearsOnlyFactor[5] = 14.57
YearsOnlyFactor[6] = 12.59
YearsOnlyFactor[7] = 11.10
YearsOnlyFactor[8] = 9.94
YearsOnlyFactor[9] = 9.02
YearsOnlyFactor[10] = 8.26
YearsOnlyFactor[11] = 7.63
YearsOnlyFactor[12] = 7.10
YearsOnlyFactor[13] = 6.64
YearsOnlyFactor[14] = 6.25
YearsOnlyFactor[15] = 5.90
YearsOnlyFactor[16] = 5.60
YearsOnlyFactor[17] = 5.33
YearsOnlyFactor[18] = 5.08
YearsOnlyFactor[19] = 4.87
YearsOnlyFactor[20] = 4.67
YearsOnlyFactor[21] = 4.49
YearsOnlyFactor[22] = 4.33
YearsOnlyFactor[23] = 4.18
YearsOnlyFactor[24] = 4.04
YearsOnlyFactor[25] = 3.91
YearsOnlyFactor[26] = 3.80
YearsOnlyFactor[27] = 3.69
YearsOnlyFactor[28] = 3.59
YearsOnlyFactor[29] = 3.49

// Load array for Life Only and Life Plus Years Certain factors - 1.60%
// Ages 30-95
function LifePYCF(fiveF, tenF, fifteenF, twentyF, lifeonlyF){
        this.fiveF = fiveF
        this.tenF = tenF
        this.fifteenF = fifteenF
        this.twentyF = twentyF
        this.lifeonlyF = lifeonlyF
}
LifePYCFactorFemale = new Array(66)
LifePYCFactorFemale[0] = new LifePYCF(2.27,2.27,2.27,2.27,2.27)
LifePYCFactorFemale[1] = new LifePYCF(2.3,2.3,2.3,2.29,2.3)
LifePYCFactorFemale[2] = new LifePYCF(2.33,2.32,2.32,2.32,2.33)
LifePYCFactorFemale[3] = new LifePYCF(2.35,2.35,2.35,2.35,2.35)
LifePYCFactorFemale[4] = new LifePYCF(2.38,2.38,2.38,2.37,2.38)
LifePYCFactorFemale[5] = new LifePYCF(2.41,2.41,2.41,2.4,2.41)
LifePYCFactorFemale[6] = new LifePYCF(2.44,2.44,2.44,2.43,2.44)
LifePYCFactorFemale[7] = new LifePYCF(2.47,2.47,2.47,2.46,2.48)
LifePYCFactorFemale[8] = new LifePYCF(2.51,2.51,2.5,2.5,2.51)
LifePYCFactorFemale[9] = new LifePYCF(2.54,2.54,2.54,2.53,2.54)
LifePYCFactorFemale[10] = new LifePYCF(2.58,2.58,2.57,2.57,2.58)
LifePYCFactorFemale[11] = new LifePYCF(2.62,2.62,2.61,2.6,2.62)
LifePYCFactorFemale[12] = new LifePYCF(2.66,2.66,2.65,2.64,2.66)
LifePYCFactorFemale[13] = new LifePYCF(2.7,2.7,2.69,2.68,2.7)
LifePYCFactorFemale[14] = new LifePYCF(2.74,2.74,2.73,2.72,2.74)
LifePYCFactorFemale[15] = new LifePYCF(2.79,2.79,2.78,2.76,2.79)
LifePYCFactorFemale[16] = new LifePYCF(2.84,2.83,2.82,2.81,2.84)
LifePYCFactorFemale[17] = new LifePYCF(2.89,2.88,2.87,2.85,2.89)
LifePYCFactorFemale[18] = new LifePYCF(2.94,2.93,2.92,2.9,2.94)
LifePYCFactorFemale[19] = new LifePYCF(2.99,2.99,2.97,2.95,3)
LifePYCFactorFemale[20] = new LifePYCF(3.05,3.04,3.03,3,3.05)
LifePYCFactorFemale[21] = new LifePYCF(3.11,3.1,3.08,3.06,3.11)
LifePYCFactorFemale[22] = new LifePYCF(3.17,3.16,3.14,3.11,3.18)
LifePYCFactorFemale[23] = new LifePYCF(3.24,3.23,3.21,3.17,3.24)
LifePYCFactorFemale[24] = new LifePYCF(3.31,3.3,3.27,3.23,3.31)
LifePYCFactorFemale[25] = new LifePYCF(3.38,3.37,3.34,3.29,3.39)
LifePYCFactorFemale[26] = new LifePYCF(3.46,3.44,3.41,3.35,3.47)
LifePYCFactorFemale[27] = new LifePYCF(3.54,3.52,3.48,3.42,3.55)
LifePYCFactorFemale[28] = new LifePYCF(3.63,3.61,3.56,3.49,3.64)
LifePYCFactorFemale[29] = new LifePYCF(3.72,3.7,3.64,3.56,3.73)
LifePYCFactorFemale[30] = new LifePYCF(3.82,3.79,3.73,3.63,3.83)
LifePYCFactorFemale[31] = new LifePYCF(3.92,3.89,3.82,3.7,3.93)
LifePYCFactorFemale[32] = new LifePYCF(4.03,3.99,3.91,3.78,4.04)
LifePYCFactorFemale[33] = new LifePYCF(4.15,4.1,4.01,3.85,4.16)
LifePYCFactorFemale[34] = new LifePYCF(4.27,4.21,4.11,3.93,4.29)
LifePYCFactorFemale[35] = new LifePYCF(4.4,4.34,4.21,4.01,4.42)
LifePYCFactorFemale[36] = new LifePYCF(4.54,4.46,4.32,4.08,4.56)
LifePYCFactorFemale[37] = new LifePYCF(4.69,4.6,4.43,4.16,4.71)
LifePYCFactorFemale[38] = new LifePYCF(4.85,4.74,4.54,4.23,4.88)
LifePYCFactorFemale[39] = new LifePYCF(5.02,4.89,4.65,4.3,5.05)
LifePYCFactorFemale[40] = new LifePYCF(5.2,5.05,4.77,4.37,5.24)
LifePYCFactorFemale[41] = new LifePYCF(5.4,5.22,4.89,4.44,5.45)
LifePYCFactorFemale[42] = new LifePYCF(5.61,5.39,5.01,4.5,5.67)
LifePYCFactorFemale[43] = new LifePYCF(5.83,5.57,5.13,4.55,5.91)
LifePYCFactorFemale[44] = new LifePYCF(6.07,5.76,5.24,4.6,6.16)
LifePYCFactorFemale[45] = new LifePYCF(6.33,5.96,5.35,4.64,6.44)
LifePYCFactorFemale[46] = new LifePYCF(6.6,6.16,5.46,4.68,6.74)
LifePYCFactorFemale[47] = new LifePYCF(6.9,6.36,5.56,4.72,7.07)
LifePYCFactorFemale[48] = new LifePYCF(7.21,6.57,5.65,4.75,7.42)
LifePYCFactorFemale[49] = new LifePYCF(7.54,6.78,5.74,4.77,7.8)
LifePYCFactorFemale[50] = new LifePYCF(7.89,6.98,5.82,4.79,8.21)
LifePYCFactorFemale[51] = new LifePYCF(8.26,7.18,5.89,4.81,8.66)
LifePYCFactorFemale[52] = new LifePYCF(8.66,7.38,5.95,4.82,9.15)
LifePYCFactorFemale[53] = new LifePYCF(9.06,7.56,6,4.83,9.67)
LifePYCFactorFemale[54] = new LifePYCF(9.49,7.74,6.05,4.84,10.24)
LifePYCFactorFemale[55] = new LifePYCF(9.93,7.9,6.09,4.85,10.85)
LifePYCFactorFemale[56] = new LifePYCF(10.37,8.05,6.12,4.85,11.51)
LifePYCFactorFemale[57] = new LifePYCF(10.82,8.19,6.15,4.85,12.22)
LifePYCFactorFemale[58] = new LifePYCF(11.27,8.31,6.17,4.86,12.97)
LifePYCFactorFemale[59] = new LifePYCF(11.71,8.42,6.19,4.86,13.77)
LifePYCFactorFemale[60] = new LifePYCF(12.14,8.52,6.2,4.86,14.61)
LifePYCFactorFemale[61] = new LifePYCF(12.56,8.61,6.22,4.86,15.49)
LifePYCFactorFemale[62] = new LifePYCF(12.97,8.68,6.22,4.86,16.41)
LifePYCFactorFemale[63] = new LifePYCF(13.36,8.75,6.23,4.86,17.36)
LifePYCFactorFemale[64] = new LifePYCF(13.73,8.81,6.23,4.86,18.35)
LifePYCFactorFemale[65] = new LifePYCF(14.1,8.86,6.24,4.86,19.39)

// Load array for Life Only and Life Plus Years Certain factors - Male - 1.60%
// Ages 30-95
function LifePYCM(fiveM, tenM, fifteenM, twentyM, lifeonlyM){
        this.fiveM = fiveM
        this.tenM = tenM
        this.fifteenM = fifteenM
        this.twentyM = twentyM
        this.lifeonlyM = lifeonlyM
}
LifePYCFactorMale = new Array(66)
LifePYCFactorMale[0] = new LifePYCM(2.38,2.38,2.38,2.37,2.38)
LifePYCFactorMale[1] = new LifePYCM(2.41,2.41,2.41,2.4,2.41)
LifePYCFactorMale[2] = new LifePYCM(2.44,2.44,2.44,2.43,2.44)
LifePYCFactorMale[3] = new LifePYCM(2.48,2.47,2.47,2.46,2.48)
LifePYCFactorMale[4] = new LifePYCM(2.51,2.51,2.5,2.49,2.51)
LifePYCFactorMale[5] = new LifePYCM(2.54,2.54,2.54,2.53,2.54)
LifePYCFactorMale[6] = new LifePYCM(2.58,2.58,2.57,2.56,2.58)
LifePYCFactorMale[7] = new LifePYCM(2.62,2.61,2.61,2.6,2.62)
LifePYCFactorMale[8] = new LifePYCM(2.66,2.65,2.65,2.63,2.66)
LifePYCFactorMale[9] = new LifePYCM(2.7,2.69,2.69,2.67,2.7)
LifePYCFactorMale[10] = new LifePYCM(2.74,2.74,2.73,2.71,2.74)
LifePYCFactorMale[11] = new LifePYCM(2.79,2.78,2.77,2.75,2.79)
LifePYCFactorMale[12] = new LifePYCM(2.83,2.83,2.82,2.8,2.84)
LifePYCFactorMale[13] = new LifePYCM(2.88,2.88,2.86,2.84,2.88)
LifePYCFactorMale[14] = new LifePYCM(2.93,2.93,2.91,2.89,2.94)
LifePYCFactorMale[15] = new LifePYCM(2.99,2.98,2.96,2.93,2.99)
LifePYCFactorMale[16] = new LifePYCM(3.04,3.03,3.01,2.98,3.05)
LifePYCFactorMale[17] = new LifePYCM(3.1,3.09,3.07,3.03,3.1)
LifePYCFactorMale[18] = new LifePYCM(3.16,3.15,3.12,3.09,3.17)
LifePYCFactorMale[19] = new LifePYCM(3.23,3.21,3.18,3.14,3.23)
LifePYCFactorMale[20] = new LifePYCM(3.29,3.28,3.24,3.2,3.3)
LifePYCFactorMale[21] = new LifePYCM(3.36,3.34,3.31,3.25,3.37)
LifePYCFactorMale[22] = new LifePYCM(3.44,3.41,3.37,3.31,3.44)
LifePYCFactorMale[23] = new LifePYCM(3.51,3.49,3.44,3.37,3.52)
LifePYCFactorMale[24] = new LifePYCM(3.59,3.57,3.52,3.44,3.6)
LifePYCFactorMale[25] = new LifePYCM(3.68,3.65,3.59,3.5,3.69)
LifePYCFactorMale[26] = new LifePYCM(3.77,3.73,3.67,3.57,3.78)
LifePYCFactorMale[27] = new LifePYCM(3.86,3.82,3.75,3.63,3.88)
LifePYCFactorMale[28] = new LifePYCM(3.96,3.92,3.84,3.7,3.98)
LifePYCFactorMale[29] = new LifePYCM(4.07,4.02,3.92,3.77,4.09)
LifePYCFactorMale[30] = new LifePYCM(4.18,4.13,4.01,3.84,4.2)
LifePYCFactorMale[31] = new LifePYCM(4.3,4.24,4.11,3.91,4.32)
LifePYCFactorMale[32] = new LifePYCM(4.43,4.35,4.2,3.98,4.46)
LifePYCFactorMale[33] = new LifePYCM(4.57,4.48,4.3,4.05,4.6)
LifePYCFactorMale[34] = new LifePYCM(4.71,4.61,4.41,4.12,4.75)
LifePYCFactorMale[35] = new LifePYCM(4.87,4.74,4.51,4.19,4.9)
LifePYCFactorMale[36] = new LifePYCM(5.03,4.88,4.62,4.25,5.07)
LifePYCFactorMale[37] = new LifePYCM(5.2,5.03,4.72,4.32,5.26)
LifePYCFactorMale[38] = new LifePYCM(5.39,5.18,4.83,4.38,5.45)
LifePYCFactorMale[39] = new LifePYCM(5.58,5.34,4.94,4.43,5.65)
LifePYCFactorMale[40] = new LifePYCM(5.78,5.5,5.04,4.49,5.87)
LifePYCFactorMale[41] = new LifePYCM(6,5.67,5.15,4.54,6.11)
LifePYCFactorMale[42] = new LifePYCM(6.23,5.84,5.25,4.58,6.36)
LifePYCFactorMale[43] = new LifePYCM(6.47,6.01,5.35,4.63,6.62)
LifePYCFactorMale[44] = new LifePYCM(6.72,6.19,5.44,4.66,6.9)
LifePYCFactorMale[45] = new LifePYCM(6.99,6.37,5.53,4.7,7.21)
LifePYCFactorMale[46] = new LifePYCM(7.27,6.55,5.62,4.73,7.53)
LifePYCFactorMale[47] = new LifePYCM(7.57,6.74,5.7,4.75,7.88)
LifePYCFactorMale[48] = new LifePYCM(7.88,6.92,5.77,4.77,8.25)
LifePYCFactorMale[49] = new LifePYCM(8.21,7.1,5.84,4.79,8.65)
LifePYCFactorMale[50] = new LifePYCM(8.55,7.27,5.9,4.81,9.07)
LifePYCFactorMale[51] = new LifePYCM(8.9,7.44,5.96,4.82,9.53)
LifePYCFactorMale[52] = new LifePYCM(9.26,7.6,6,4.83,10.01)
LifePYCFactorMale[53] = new LifePYCM(9.64,7.76,6.05,4.84,10.53)
LifePYCFactorMale[54] = new LifePYCM(10.02,7.91,6.08,4.85,11.08)
LifePYCFactorMale[55] = new LifePYCM(10.42,8.04,6.12,4.85,11.67)
LifePYCFactorMale[56] = new LifePYCM(10.82,8.17,6.14,4.85,12.3)
LifePYCFactorMale[57] = new LifePYCM(11.22,8.29,6.17,4.86,12.97)
LifePYCFactorMale[58] = new LifePYCM(11.62,8.4,6.18,4.86,13.68)
LifePYCFactorMale[59] = new LifePYCM(12.02,8.49,6.2,4.86,14.43)
LifePYCFactorMale[60] = new LifePYCM(12.42,8.58,6.21,4.86,15.23)
LifePYCFactorMale[61] = new LifePYCM(12.81,8.66,6.22,4.86,16.07)
LifePYCFactorMale[62] = new LifePYCM(13.2,8.73,6.23,4.86,16.97)
LifePYCFactorMale[63] = new LifePYCM(13.58,8.79,6.23,4.86,17.92)
LifePYCFactorMale[64] = new LifePYCM(13.96,8.84,6.24,4.86,18.94)
LifePYCFactorMale[65] = new LifePYCM(14.32,8.88,6.24,4.86,20.03)


function format (expr, decplaces)
{
	// raise incoming value by power of 10 times the
	// number of decimal places; round to an integer; convert to string
	var str = "" + Math.round (eval(expr) * Math.pow(10, decplaces));

	// pad small value strings with zeros to the left of the rounded number
	while (str.length <= decplaces)
	{
		str = "0" + str;
	}

	// establish location of decimal point
	var decpoint = str.length - decplaces;

	// assemble final result from (a) the string up to the position of
	// the decimal point; (b) the decimal point; and (c) the balance
	// of the string.  Return finished product.
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);

}

// turn incoming expression into a dollar value
function dollarize (expr)
{
	var fmtAmt = format(expr,2)
	var decpoint = fmtAmt.indexOf(".")
	var wholePart = fmtAmt.substring(0,decpoint)
	var cents = fmtAmt.substring(decpoint,fmtAmt.length)

	var beforeComma = wholePart.substring(0,wholePart.length-3)

	if (wholePart.length > 5)
	{
		var afterComma = wholePart.substring(wholePart.length-beforeComma.length)
		var dlrFmtAmt = "$" + beforeComma + "," + afterComma + cents
	} else	if (wholePart.length > 4)
	{
		var afterComma = wholePart.substring(wholePart.length-beforeComma.length-1)
		var dlrFmtAmt = "$" + beforeComma + "," + afterComma + cents
	} else if (wholePart.length > 3)
		{
		var afterComma = wholePart.substring(wholePart.length-beforeComma.length-2)
		var dlrFmtAmt = "$" + beforeComma + "," + afterComma + cents
		} else
			{
			dlrFmtAmt = "$" + fmtAmt
			}
	return dlrFmtAmt
	
}

function isNumber(inputStr) 
{
	for (var i = 0; i < inputStr.length; i++)
	{
		var oneChar = inputStr.substring(i, i + 1)
		if (oneChar < "0" || oneChar > "9")
		{
			return false
		}
	}
	return true
}

function CalcIncome()
{
// errorSw values - 0=no errors; 1=error in amount; 2=error in field other than amount

	var errorSw = 0

	var quote = document.forms[0]
	var option = quote.PaymentOption.selectedIndex
	var nbrYears = quote.txtYear.value
	var custAge = quote.txtAge.value
	var custSex = quote.lstSex.selectedIndex

	var selState = quote.lstState.options[quote.lstState.selectedIndex].value
	var premTaxState = "N"

	if ((selState == "ZZ") || (selState == "  ") || (selState == ""))
	{
	    alert("Please select Resident State from the list.")
  	    errorSw = 2
	    return
	}	

	if ((selState == "CA") || (selState == "NV") || (selState == "WY"))
	{
	    premTaxState = "Y"
	} 
	else
	{
	    premTaxState = "N"
	}

	var premTaxRate = 0.00

	if (premTaxState == "Y")
	{
	    if (!(quote.qual[0].checked) && !(quote.qual[1].checked) && !(quote.qual[2].checked))
	    {
	        alert("Please indicate whether funds are qualified.")
//  	        quote.qual.focus()
//  	        quote.qual.select()
	        error = 2
		return
	    }
//
	    for (var i = 0; i < quote.qual.length; i++)
	    {
		if (quote.qual[i].checked)
		{
		    break
		}
	    }
//
	    if ((quote.qual[i].value == "IRA") || (quote.qual[i].value == "Q"))
	    {
		if (selState == "CA")
		{
		    premTaxRate = .0050
		}
		else
		{
		    premTaxRate = 0.00
		}
	    }
	    else
	    {
		if (selState == "CA")
		{
		    premTaxRate = .0235
		}
		else if (selState == "NV")
		{
		    premTaxRate = .0350
		}
		else
		{
		    premTaxRate = .01
		}	
	    }

	}
	else
	{
	    premTaxRate = 0.00
	}
	
	if (quote.CalcOption[0].checked)
	{
		calcOpt = "income"
		annAmount = quote.txtAmount1.value
		quote.txtIncome2.value = ""
		quote.txtAmount2.value = ""
		quote.txtPremTax2.value = ""
		quote.txtPremTaxRate2.value = ""
		quote.txtNetAnnuity2.value = ""
	} else
		{
			calcOpt = "annuity"
			incAmount = quote.txtIncome2.value
			quote.txtAmount1.value = ""
			quote.txtPremTax1.value = ""
			quote.txtPremTaxRate1.value = ""
			quote.txtNetAnnuity1.value = ""
			quote.txtIncome1.value = ""
		}

	// if there are any dollar signs or commas in the annamount field
	// (because of an uncleared previous quote) remove them
	if (calcOpt == "income")
	{
    	    if ((annAmount.charAt(0) == "$") || (annAmount.indexOf(",") != -1))
	    {
		var newAmt = ""
		for (var i = 0; i < annAmount.length; i++)
		{
			if ((annAmount.charAt(i) != "$") && (annAmount.charAt(i) != ","))
			{
				newAmt += annAmount.charAt(i)
			}
		}
		annAmount = newAmt
	    }
	}

	if (calcOpt == "annuity")
	{
    	    if ((incAmount.charAt(0) == "$") || (incAmount.indexOf(",") != -1))
	    {
		var newAmtInc = ""
		for (var i = 0; i < incAmount.length; i++)
		{
			if ((incAmount.charAt(i) != "$") && (incAmount.charAt(i) != ","))
			{
				newAmtInc += incAmount.charAt(i)
			}
		}
		incAmount = newAmtInc
	    }
	}

	if (calcOpt == "income")
	{
		if (annAmount == "")
		{
			alert("An annuity amount must be entered.")
			quote.txtAmount1.focus()
			quote.txtAmount1.select()
			errorSw = 1
			return
		}
	
		amt = parseFloat(annAmount)
	
		if ((amt < 20000) || (amt > 300000))
		{
			alert("Amount must be between $20,000 and $300,000, inclusive.")
			errorSw = 1
			return
		}
	}

	if (calcOpt == "annuity")
	{
		if (incAmount == "")
		{
			alert("An income amount must be entered.")
			quote.txtIncome2.focus()
			quote.txtIncome2.select()
			errorSw = 1
			return
		}
	}

	// Calculate income based on payment option selected

	// Years certain
	if (option == 0)
	{
		if (nbrYears == "")
		{
			alert("The number of years must be entered for this option.")
			quote.txtYear.focus()
			quote.txtYear.select()
			errorSw = 2
			return
		}

		if (isNumber(nbrYears))
		{
			yrs = parseInt(nbrYears)
		}
		else
		{
			alert("The number of years must be a number.")
			quote.txtYear.focus()
			quote.txtYear.select()
			errorSw = 2
			return
		}

		if (((yrs < 10) || (yrs > 30)))
		{
			alert("The number of years must be 10 through 30, inclusive.")
			quote.txtYear.focus()
			quote.txtYear.select()
			errorSw = 2
			return
		}

		var YCIdx = nbrYears - 1

		if (calcOpt == "income")
		{
			quote.txtAmount1.value = dollarize(annAmount)
			var premTaxAmount = annAmount * premTaxRate
			var displayTaxRate = premTaxRate * 100
			var netAnnAmount = annAmount - premTaxAmount
			var inc = netAnnAmount / 1000 * YearsOnlyFactor[YCIdx]
			if (errorSw == 2)
			{
				quote.txtPremTax1.value = ""
				quote.txtPremTaxRate1.value = ""
				quote.txtNetAnnuity1.value = ""
				quote.txtIncome1.value = ""
			} else if (errorSw == 1)
				{
					quote.txtPremTax1.value = ""
					quote.txtPremTaxRate1.value = ""
					quote.txtNetAnnuity1.value = ""
					quote.txtIncome1.value = ""
					quote.txtAmount1.focus()
				} else
					{
						quote.txtPremTax1.value = dollarize(premTaxAmount)
						quote.txtPremTaxRate1.value = format(displayTaxRate,2)
						quote.txtNetAnnuity1.value = dollarize(netAnnAmount)
						quote.txtIncome1.value = dollarize(inc)
					}
		}
		if (calcOpt == "annuity")
		{
			quote.txtIncome2.value = dollarize(incAmount)
			var inc = (incAmount / (1 - premTaxRate)) / YearsOnlyFactor[YCIdx] * 1000
			var premTaxAmount = inc * premTaxRate
			var displayTaxRate2 = premTaxRate * 100
			var netAnnAmount = inc - premTaxAmount
			annN = parseFloat(inc)
			if ((annN < 20000) || (annN > 300000))
			{
				alert("Calculated annuity amount of " + dollarize(annN) + " is not within the required limits ($20,000 through $300,000).")
				errorSw = 1
				quote.txtAmount2.value = ""
				quote.txtPremTax2.value = ""
				quote.txtPremTaxRate2.value = ""
				quote.txtNetAnnuity2.value = ""
				return
			}
			if (errorSw == 2)
			{
				quote.txtAmount2.value = ""
				quote.txtPremTax2.value = ""
				quote.txtPremTaxRate2.value = ""
				quote.txtNetAnnuity2.value = ""
			} else if (errorSw == 1)
				{
					quote.txtAmount2.value = ""
					quote.txtPremTax2.value = ""
					quote.txtPremTaxRate2.value = ""
					quote.txtNetAnnuity2.value = ""
					quote.txtIncome2.focus()
				} else
					{
						quote.txtAmount2.value = dollarize(inc)
						quote.txtPremTax2.value = dollarize(premTaxAmount)
						quote.txtPremTaxRate2.value = format(displayTaxRate2,2)
						quote.txtNetAnnuity2.value = dollarize(netAnnAmount)
					}
		}
	}

	// Life plus years certain
	if (option == 1)
	{
		if (nbrYears == "")
		{
			alert("The number of years must be entered for this option.")
			quote.txtYear.focus()
			quote.txtYear.select()
			errorSw = 2
			return
		}

		if (isNumber(nbrYears))
		{
			yrs = parseInt(nbrYears)
		}
		else
		{
			alert("The number of years must be a number.")
			quote.txtYear.focus()
			quote.txtYear.select()
			errorSw = 2
			return
		}

		if ((yrs != 10) && (yrs != 15) && (yrs != 20))
		{
			alert("The number of years must be 10, 15, or 20.")
			quote.txtYear.focus()
			quote.txtYear.select()
			errorSw = 2
			return
	}

		if (custAge == "")
		{
			alert("Age must be entered.")
			quote.txtAge.focus()
			quote.txtAge.select()
			errorSw = 2
			return
		}

		if (isNumber(custAge))
		{
			agex = parseInt(custAge)
		}
		else
		{
			alert("The age must be a number.")
			quote.txtAge.focus()
			quote.txtAge.select()
			errorSw = 2
			return
		}


	// Check for the accepted age ranges for male and female
	// if ((agex < 14) || (agex > 99))   used for 3% rate
	   if (((agex < 30) || (agex > 95)) && (custSex == "0")) 
	{
		alert("Valid ages are 30 through 95.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	   if (((agex < 30) || (agex > 95)) && (custSex == "1")) 
	{
		alert("Valid ages are 30 through 95.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	if (custSex == "1")	
			{
				ageIdx = agex - 30
			}
			else	
			{
				ageIdx = agex - 30 
			}				

	factor = 0
	if (ageIdx <= 65)	// was 85 for 3%
	{
		if (yrs == 5)
		{
			if (custSex == "1")
			{
				factor = LifePYCFactorFemale[ageIdx].fiveF
			}
			else
			{
				factor = LifePYCFactorMale[ageIdx].fiveM
			}
		}	else if (yrs == 10)
			{
				if (custSex == "1")
				{
					factor = LifePYCFactorFemale[ageIdx].tenF
				}
				else
				{
					factor = LifePYCFactorMale[ageIdx].tenM
				}
			}	else if (yrs == 15)
				{
					if (custSex == "1")
					{
						factor = LifePYCFactorFemale[ageIdx].fifteenF
					}
					else
					{
						factor = LifePYCFactorMale[ageIdx].fifteenM
					}
				} 	else
					{
						if (custSex == "1")
						{
							factor = LifePYCFactorFemale[ageIdx].twentyF
						}
						else
						{
							factor = LifePYCFactorMale[ageIdx].twentyM
						}
					}
	}

		if (calcOpt == "income")
		{
			quote.txtAmount1.value = dollarize(annAmount)
			var premTaxAmount = annAmount * premTaxRate
			var displayTaxRate = premTaxRate * 100
			var netAnnAmount = annAmount - premTaxAmount
			var inc = netAnnAmount / 1000 * factor
			if (errorSw == 2)
			{
				quote.txtPremTax1.value = ""
				quote.txtPremTaxRate1.value = ""
				quote.txtNetAnnuity1.value = ""
				quote.txtIncome1.value = ""
			} else if (errorSw == 1)
				{
					quote.txtPremTax1.value = ""
					quote.txtPremTaxRate1.value = ""
					quote.txtNetAnnuity1.value = ""
					quote.txtIncome1.value = ""
					quote.txtAmount1.focus()
				} else
					{
						quote.txtPremTax1.value = dollarize(premTaxAmount)
						quote.txtPremTaxRate1.value = format(displayTaxRate,2)
						quote.txtNetAnnuity1.value = dollarize(netAnnAmount)
						quote.txtIncome1.value = dollarize(inc)
					}
		}

		if (calcOpt == "annuity")
		{
			quote.txtIncome2.value = dollarize(incAmount)
			var inc = (incAmount / (1 - premTaxRate)) / factor * 1000
			var premTaxAmount = inc * premTaxRate
			var displayTaxRate2 = premTaxRate * 100
			var netAnnAmount = inc - premTaxAmount
			annN = parseFloat(inc)
			if ((annN < 20000) || (annN > 300000))
			{
				alert("Calculated annuity amount of " + dollarize(annN) + " is not within the required limits ($20,000 through $300,000).")
				errorSw = 1
				quote.txtAmount2.value = ""
				quote.txtPremTax2.value = ""
				quote.txtPremTaxRate2.value = ""
				quote.txtNetAnnuity2.value = ""
				return
			}
			if (errorSw == 2)
			{
				quote.txtAmount2.value = ""
				quote.txtPremTax2.value = ""
				quote.txtPremTaxRate2.value = ""
				quote.txtNetAnnuity2.value = ""
			} else if (errorSw == 1)
				{
					quote.txtAmount2.value = ""
					quote.txtPremTax2.value = ""
					quote.txtPremTaxRate2.value = ""
					quote.txtNetAnnuity2.value = ""
					quote.txtIncome2.focus()
				} else
					{
						quote.txtAmount2.value = dollarize(inc)
						quote.txtPremTax2.value = dollarize(premTaxAmount)
						quote.txtPremTaxRate2.value = format(displayTaxRate2,2)
						quote.txtNetAnnuity2.value = dollarize(netAnnAmount)
					}
		}
	}

	// Life only
	if (option == 2)
	{
		if (custAge == "")
		{
			alert("Age must be entered.")
			quote.txtAge.focus()
			quote.txtAge.select()
			errorSw = 2
			return
		}

		if (isNumber(custAge))
		{
			agex = parseInt(custAge)
		}
		else
		{
			alert("The age must be a number.")
			quote.txtAge.focus()
			quote.txtAge.select()
			errorSw = 2
			return
		}

		// Check for the accepted age ranges for male and female

	// Check for the accepted age ranges for male and female
	   if (((agex < 30) || (agex > 95)) && (custSex == "0"))
	{
		alert("Valid ages are 30 through 95.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	   if (((agex < 30) || (agex > 95)) && (custSex == "1"))
	{
		alert("Valid ages are 30 through 95.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	if (custSex == "1")
			{
				ageIdx = agex - 30
			}
			else	
			{
				ageIdx = agex - 30 
			}				

		factor = 0
		if (ageIdx <= 65)
		{
			if (custSex == "1")
			{
				factor = LifePYCFactorFemale[ageIdx].lifeonlyF
			}
			else
			{
				factor = LifePYCFactorMale[ageIdx].lifeonlyM
			}
		}	
	
		if (calcOpt == "income")
		{
			quote.txtAmount1.value = dollarize(annAmount)
			var premTaxAmount = annAmount * premTaxRate
			var displayTaxRate = premTaxRate * 100
			var netAnnAmount = annAmount - premTaxAmount
			var inc = netAnnAmount / 1000 * factor
			if (errorSw == 2)
			{
				quote.txtPremTax1.value = ""
				quote.txtPremTaxRate1.value = ""
				quote.txtNetAnnuity1.value = ""
				quote.txtIncome1.value = ""
			} else if (errorSw == 1)
				{
					quote.txtPremTax1.value = ""
					quote.txtPremTaxRate1.value = ""
					quote.txtNetAnnuity1.value = ""
					quote.txtIncome1.value = ""
					quote.txtAmount1.focus()
				} else
					{
						quote.txtPremTax1.value = dollarize(premTaxAmount)
						quote.txtPremTaxRate1.value = format(displayTaxRate,2)
						quote.txtNetAnnuity1.value = dollarize(netAnnAmount)
						quote.txtIncome1.value = dollarize(inc)
					}
		}

		if (calcOpt == "annuity")
		{
			quote.txtIncome2.value = dollarize(incAmount)
			var inc = (incAmount / (1 - premTaxRate)) / factor * 1000
			var premTaxAmount = inc * premTaxRate
			var displayTaxRate2 = premTaxRate * 100
			var netAnnAmount = inc - premTaxAmount
			annN = parseFloat(inc)
			if ((annN < 20000) || (annN > 300000))
			{
				alert("Calculated annuity amount of " + dollarize(annN) + " is not within the required limits ($20,000 through $300,000).")
				errorSw = 1
				quote.txtAmount2.value = ""
				quote.txtPremTax2.value = ""
				quote.txtPremTaxRate2.value = ""
				quote.txtNetAnnuity2.value = ""
				return
			}
			if (errorSw == 2)
			{
				quote.txtAmount2.value = ""
				quote.txtPremTax2.value = ""
				quote.txtPremTaxRate2.value = ""
				quote.txtNetAnnuity2.value = ""
		} else if (errorSw == 1)
				{
					quote.txtAmount2.value = ""
					quote.txtPremTax2.value = ""
					quote.txtPremTaxRate2.value = ""
					quote.txtNetAnnuity2.value = ""
					quote.txtIncome2.focus()
				} else
					{
						quote.txtAmount2.value = dollarize(inc)
						quote.txtPremTax2.value = dollarize(premTaxAmount)
						quote.txtPremTaxRate2.value = format(displayTaxRate2,2)
						quote.txtNetAnnuity2.value = dollarize(netAnnAmount)
					}
		}
	}
}

