// Load array for Years Certain factors
var YearsOnlyFactor = new Array()
// 3.00%
YearsOnlyFactor[0] = 84.68		
YearsOnlyFactor[1] = 42.96		
YearsOnlyFactor[2] = 29.06		
YearsOnlyFactor[3] = 22.12		
YearsOnlyFactor[4] = 17.95
YearsOnlyFactor[5] = 15.18
YearsOnlyFactor[6] = 13.2
YearsOnlyFactor[7] = 11.71
YearsOnlyFactor[8] = 10.56
YearsOnlyFactor[9] = 9.64
YearsOnlyFactor[10] = 8.88
YearsOnlyFactor[11] = 8.26
YearsOnlyFactor[12] = 7.73
YearsOnlyFactor[13] = 7.28
YearsOnlyFactor[14] = 6.89
YearsOnlyFactor[15] = 6.54
YearsOnlyFactor[16] = 6.24
YearsOnlyFactor[17] = 5.98
YearsOnlyFactor[18] = 5.74
YearsOnlyFactor[19] = 5.53
YearsOnlyFactor[20] = 5.33
YearsOnlyFactor[21] = 5.16
YearsOnlyFactor[22] = 5
YearsOnlyFactor[23] = 4.85
YearsOnlyFactor[24] = 4.72
YearsOnlyFactor[25] = 4.6
YearsOnlyFactor[26] = 4.49
YearsOnlyFactor[27] = 4.38
YearsOnlyFactor[28] = 4.28
YearsOnlyFactor[29] = 4.19

// Load array for Life Only and Life Plus Years Certain factors - 3.00%
// Ages 14-99
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(86)
LifePYCFactorFemale[0] = new LifePYCF(2.87,2.87,2.87,2.87,2.87)
LifePYCFactorFemale[1] = new LifePYCF(2.89,2.89,2.88,2.88,2.89)
LifePYCFactorFemale[2] = new LifePYCF(2.9,2.9,2.9,2.9,2.9)
LifePYCFactorFemale[3] = new LifePYCF(2.92,2.91,2.91,2.91,2.92)
LifePYCFactorFemale[4] = new LifePYCF(2.93,2.93,2.93,2.92,2.93)
LifePYCFactorFemale[5] = new LifePYCF(2.95,2.95,2.94,2.94,2.95)
LifePYCFactorFemale[6] = new LifePYCF(2.96,2.96,2.96,2.96,2.96)
LifePYCFactorFemale[7] = new LifePYCF(2.98,2.98,2.98,2.97,2.98)
LifePYCFactorFemale[8] = new LifePYCF(3,3,2.99,2.99,3)
LifePYCFactorFemale[9] = new LifePYCF(3.02,3.01,3.01,3.01,3.02)
LifePYCFactorFemale[10] = new LifePYCF(3.03,3.03,3.03,3.03,3.04)
LifePYCFactorFemale[11] = new LifePYCF(3.05,3.05,3.05,3.05,3.06)
LifePYCFactorFemale[12] = new LifePYCF(3.08,3.07,3.07,3.07,3.08)
LifePYCFactorFemale[13] = new LifePYCF(3.1,3.09,3.09,3.09,3.1)
LifePYCFactorFemale[14] = new LifePYCF(3.12,3.12,3.11,3.11,3.12)
LifePYCFactorFemale[15] = new LifePYCF(3.14,3.14,3.14,3.13,3.14)
LifePYCFactorFemale[16] = new LifePYCF(3.17,3.16,3.16,3.15,3.17)
LifePYCFactorFemale[17] = new LifePYCF(3.19,3.19,3.19,3.18,3.19)
LifePYCFactorFemale[18] = new LifePYCF(3.22,3.22,3.21,3.2,3.22)
LifePYCFactorFemale[19] = new LifePYCF(3.25,3.24,3.24,3.23,3.25)
LifePYCFactorFemale[20] = new LifePYCF(3.28,3.27,3.27,3.26,3.28)
LifePYCFactorFemale[21] = new LifePYCF(3.31,3.3,3.3,3.29,3.31)
LifePYCFactorFemale[22] = new LifePYCF(3.34,3.33,3.33,3.32,3.34)
LifePYCFactorFemale[23] = new LifePYCF(3.37,3.37,3.36,3.35,3.37)
LifePYCFactorFemale[24] = new LifePYCF(3.41,3.4,3.39,3.38,3.41)
LifePYCFactorFemale[25] = new LifePYCF(3.44,3.44,3.43,3.41,3.44)
LifePYCFactorFemale[26] = new LifePYCF(3.48,3.48,3.46,3.45,3.48)
LifePYCFactorFemale[27] = new LifePYCF(3.52,3.51,3.5,3.48,3.52)
LifePYCFactorFemale[28] = new LifePYCF(3.56,3.56,3.54,3.52,3.57)
LifePYCFactorFemale[29] = new LifePYCF(3.61,3.6,3.58,3.56,3.61)
LifePYCFactorFemale[30] = new LifePYCF(3.65,3.64,3.63,3.6,3.66)
LifePYCFactorFemale[31] = new LifePYCF(3.7,3.69,3.67,3.64,3.71)
LifePYCFactorFemale[32] = new LifePYCF(3.75,3.74,3.72,3.68,3.76)
LifePYCFactorFemale[33] = new LifePYCF(3.81,3.79,3.77,3.73,3.81)
LifePYCFactorFemale[34] = new LifePYCF(3.86,3.85,3.82,3.77,3.87)
LifePYCFactorFemale[35] = new LifePYCF(3.92,3.9,3.87,3.82,3.93)
LifePYCFactorFemale[36] = new LifePYCF(3.98,3.96,3.92,3.87,3.99)
LifePYCFactorFemale[37] = new LifePYCF(4.05,4.02,3.98,3.92,4.05)
LifePYCFactorFemale[38] = new LifePYCF(4.11,4.09,4.04,3.97,4.12)
LifePYCFactorFemale[39] = new LifePYCF(4.18,4.15,4.1,4.03,4.19)
LifePYCFactorFemale[40] = new LifePYCF(4.26,4.22,4.17,4.08,4.27)
LifePYCFactorFemale[41] = new LifePYCF(4.33,4.29,4.23,4.14,4.34)
LifePYCFactorFemale[42] = new LifePYCF(4.41,4.37,4.3,4.2,4.43)
LifePYCFactorFemale[43] = new LifePYCF(4.5,4.45,4.37,4.26,4.51)
LifePYCFactorFemale[44] = new LifePYCF(4.59,4.54,4.45,4.32,4.6)
LifePYCFactorFemale[45] = new LifePYCF(4.68,4.62,4.53,4.39,4.7)
LifePYCFactorFemale[46] = new LifePYCF(4.78,4.72,4.61,4.45,4.8)
LifePYCFactorFemale[47] = new LifePYCF(4.89,4.82,4.69,4.51,4.91)
LifePYCFactorFemale[48] = new LifePYCF(5,4.92,4.78,4.58,5.03)
LifePYCFactorFemale[49] = new LifePYCF(5.12,5.03,4.87,4.64,5.15)
LifePYCFactorFemale[50] = new LifePYCF(5.25,5.14,4.96,4.71,5.28)
LifePYCFactorFemale[51] = new LifePYCF(5.39,5.26,5.06,4.78,5.42)
LifePYCFactorFemale[52] = new LifePYCF(5.53,5.39,5.16,4.84,5.57)
LifePYCFactorFemale[53] = new LifePYCF(5.69,5.52,5.26,4.9,5.74)
LifePYCFactorFemale[54] = new LifePYCF(5.85,5.66,5.36,4.96,5.91)
LifePYCFactorFemale[55] = new LifePYCF(6.03,5.81,5.46,5.02,6.1)
LifePYCFactorFemale[56] = new LifePYCF(6.21,5.96,5.56,5.08,6.29)
LifePYCFactorFemale[57] = new LifePYCF(6.41,6.11,5.66,5.13,6.5)
LifePYCFactorFemale[58] = new LifePYCF(6.62,6.28,5.76,5.18,6.73)
LifePYCFactorFemale[59] = new LifePYCF(6.84,6.44,5.86,5.23,6.97)
LifePYCFactorFemale[60] = new LifePYCF(7.07,6.61,5.96,5.27,7.23)
LifePYCFactorFemale[61] = new LifePYCF(7.32,6.78,6.05,5.31,7.51)
LifePYCFactorFemale[62] = new LifePYCF(7.58,6.96,6.14,5.35,7.8)
LifePYCFactorFemale[63] = new LifePYCF(7.85,7.14,6.23,5.38,8.12)
LifePYCFactorFemale[64] = new LifePYCF(8.14,7.32,6.31,5.4,8.45)
LifePYCFactorFemale[65] = new LifePYCF(8.44,7.49,6.39,5.43,8.82)
LifePYCFactorFemale[66] = new LifePYCF(8.76,7.67,6.47,5.45,9.21)
LifePYCFactorFemale[67] = new LifePYCF(9.1,7.86,6.53,5.46,9.62)
LifePYCFactorFemale[68] = new LifePYCF(9.44,8.05,6.59,5.48,10.07)
LifePYCFactorFemale[69] = new LifePYCF(9.81,8.23,6.64,5.49,10.55)
LifePYCFactorFemale[70] = new LifePYCF(10.24,8.4,6.69,5.49,11.07)
LifePYCFactorFemale[71] = new LifePYCF(10.67,8.55,6.73,5.5,11.69)
LifePYCFactorFemale[72] = new LifePYCF(11.11,8.7,6.76,5.5,12.36)
LifePYCFactorFemale[73] = new LifePYCF(11.55,8.83,6.78,5.51,13.08)
LifePYCFactorFemale[74] = new LifePYCF(11.99,8.95,6.8,5.51,13.84)
LifePYCFactorFemale[75] = new LifePYCF(12.43,9.05,6.82,5.51,14.65)
LifePYCFactorFemale[76] = new LifePYCF(12.85,9.15,6.84,5.51,15.5)
LifePYCFactorFemale[77] = new LifePYCF(13.26,9.23,6.85,5.51,16.38)
LifePYCFactorFemale[78] = new LifePYCF(13.66,9.3,6.85,5.51,17.31)
LifePYCFactorFemale[79] = new LifePYCF(14.03,9.36,6.86,5.51,18.26)
LifePYCFactorFemale[80] = new LifePYCF(14.4,9.42,6.86,5.51,19.26)
LifePYCFactorFemale[81] = new LifePYCF(14.75,9.47,6.87,5.51,20.3)
LifePYCFactorFemale[82] = new LifePYCF(14.76,9.46,6.87,5.51,20.29)
LifePYCFactorFemale[83] = new LifePYCF(15.11,9.5,6.87,5.51,21.42)
LifePYCFactorFemale[84] = new LifePYCF(15.45,9.53,6.87,5.51,22.64)
LifePYCFactorFemale[85] = new LifePYCF(15.77,9.56,6.87,5.51,23.96)

// Load array for Life Only and Life Plus Years Certain factors - Male - 3.00%
// Ages 10-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(86)
LifePYCFactorMale[0] = new LifePYCM(2.87,2.87,2.87,2.87,2.87)
LifePYCFactorMale[1] = new LifePYCM(2.89,2.89,2.88,2.88,2.89)
LifePYCFactorMale[2] = new LifePYCM(2.9,2.9,2.9,2.9,2.9)
LifePYCFactorMale[3] = new LifePYCM(2.92,2.91,2.91,2.91,2.92)
LifePYCFactorMale[4] = new LifePYCM(2.93,2.93,2.93,2.92,2.93)
LifePYCFactorMale[5] = new LifePYCM(2.95,2.95,2.94,2.94,2.95)
LifePYCFactorMale[6] = new LifePYCM(2.96,2.96,2.96,2.96,2.96)
LifePYCFactorMale[7] = new LifePYCM(2.98,2.98,2.98,2.97,2.98)
LifePYCFactorMale[8] = new LifePYCM(3,3,2.99,2.99,3)
LifePYCFactorMale[9] = new LifePYCM(3.02,3.01,3.01,3.01,3.02)
LifePYCFactorMale[10] = new LifePYCM(3.03,3.03,3.03,3.03,3.04)
LifePYCFactorMale[11] = new LifePYCM(3.05,3.05,3.05,3.05,3.06)
LifePYCFactorMale[12] = new LifePYCM(3.08,3.07,3.07,3.07,3.08)
LifePYCFactorMale[13] = new LifePYCM(3.1,3.09,3.09,3.09,3.1)
LifePYCFactorMale[14] = new LifePYCM(3.12,3.12,3.11,3.11,3.12)
LifePYCFactorMale[15] = new LifePYCM(3.14,3.14,3.14,3.13,3.14)
LifePYCFactorMale[16] = new LifePYCM(3.17,3.16,3.16,3.15,3.17)
LifePYCFactorMale[17] = new LifePYCM(3.19,3.19,3.19,3.18,3.19)
LifePYCFactorMale[18] = new LifePYCM(3.22,3.22,3.21,3.2,3.22)
LifePYCFactorMale[19] = new LifePYCM(3.25,3.24,3.24,3.23,3.25)
LifePYCFactorMale[20] = new LifePYCM(3.28,3.27,3.27,3.26,3.28)
LifePYCFactorMale[21] = new LifePYCM(3.31,3.3,3.3,3.29,3.31)
LifePYCFactorMale[22] = new LifePYCM(3.34,3.33,3.33,3.32,3.34)
LifePYCFactorMale[23] = new LifePYCM(3.37,3.37,3.36,3.35,3.37)
LifePYCFactorMale[24] = new LifePYCM(3.41,3.4,3.39,3.38,3.41)
LifePYCFactorMale[25] = new LifePYCM(3.44,3.44,3.43,3.41,3.44)
LifePYCFactorMale[26] = new LifePYCM(3.48,3.48,3.46,3.45,3.48)
LifePYCFactorMale[27] = new LifePYCM(3.52,3.51,3.5,3.48,3.52)
LifePYCFactorMale[28] = new LifePYCM(3.56,3.56,3.54,3.52,3.57)
LifePYCFactorMale[29] = new LifePYCM(3.61,3.6,3.58,3.56,3.61)
LifePYCFactorMale[30] = new LifePYCM(3.65,3.64,3.63,3.6,3.66)
LifePYCFactorMale[31] = new LifePYCM(3.7,3.69,3.67,3.64,3.71)
LifePYCFactorMale[32] = new LifePYCM(3.75,3.74,3.72,3.68,3.76)
LifePYCFactorMale[33] = new LifePYCM(3.81,3.79,3.77,3.73,3.81)
LifePYCFactorMale[34] = new LifePYCM(3.86,3.85,3.82,3.77,3.87)
LifePYCFactorMale[35] = new LifePYCM(3.92,3.9,3.87,3.82,3.93)
LifePYCFactorMale[36] = new LifePYCM(3.98,3.96,3.92,3.87,3.99)
LifePYCFactorMale[37] = new LifePYCM(4.05,4.02,3.98,3.92,4.05)
LifePYCFactorMale[38] = new LifePYCM(4.11,4.09,4.04,3.97,4.12)
LifePYCFactorMale[39] = new LifePYCM(4.18,4.15,4.1,4.03,4.19)
LifePYCFactorMale[40] = new LifePYCM(4.26,4.22,4.17,4.08,4.27)
LifePYCFactorMale[41] = new LifePYCM(4.33,4.29,4.23,4.14,4.34)
LifePYCFactorMale[42] = new LifePYCM(4.41,4.37,4.3,4.2,4.43)
LifePYCFactorMale[43] = new LifePYCM(4.5,4.45,4.37,4.26,4.51)
LifePYCFactorMale[44] = new LifePYCM(4.59,4.54,4.45,4.32,4.6)
LifePYCFactorMale[45] = new LifePYCM(4.68,4.62,4.53,4.39,4.7)
LifePYCFactorMale[46] = new LifePYCM(4.78,4.72,4.61,4.45,4.8)
LifePYCFactorMale[47] = new LifePYCM(4.89,4.82,4.69,4.51,4.91)
LifePYCFactorMale[48] = new LifePYCM(5,4.92,4.78,4.58,5.03)
LifePYCFactorMale[49] = new LifePYCM(5.12,5.03,4.87,4.64,5.15)
LifePYCFactorMale[50] = new LifePYCM(5.25,5.14,4.96,4.71,5.28)
LifePYCFactorMale[51] = new LifePYCM(5.39,5.26,5.06,4.78,5.42)
LifePYCFactorMale[52] = new LifePYCM(5.53,5.39,5.16,4.84,5.57)
LifePYCFactorMale[53] = new LifePYCM(5.69,5.52,5.26,4.9,5.74)
LifePYCFactorMale[54] = new LifePYCM(5.85,5.66,5.36,4.96,5.91)
LifePYCFactorMale[55] = new LifePYCM(6.03,5.81,5.46,5.02,6.1)
LifePYCFactorMale[56] = new LifePYCM(6.21,5.96,5.56,5.08,6.29)
LifePYCFactorMale[57] = new LifePYCM(6.41,6.11,5.66,5.13,6.5)
LifePYCFactorMale[58] = new LifePYCM(6.62,6.28,5.76,5.18,6.73)
LifePYCFactorMale[59] = new LifePYCM(6.84,6.44,5.86,5.23,6.97)
LifePYCFactorMale[60] = new LifePYCM(7.07,6.61,5.96,5.27,7.23)
LifePYCFactorMale[61] = new LifePYCM(7.32,6.78,6.05,5.31,7.51)
LifePYCFactorMale[62] = new LifePYCM(7.58,6.96,6.14,5.34,7.8)
LifePYCFactorMale[63] = new LifePYCM(7.85,7.14,6.23,5.37,8.12)
LifePYCFactorMale[64] = new LifePYCM(8.14,7.32,6.31,5.4,8.45)
LifePYCFactorMale[65] = new LifePYCM(8.44,7.49,6.38,5.42,8.82)
LifePYCFactorMale[66] = new LifePYCM(8.76,7.67,6.45,5.44,9.21)
LifePYCFactorMale[67] = new LifePYCM(9.1,7.84,6.51,5.45,9.62)
LifePYCFactorMale[68] = new LifePYCM(9.44,8.01,6.57,5.47,10.07)
LifePYCFactorMale[69] = new LifePYCM(9.8,8.17,6.62,5.48,10.55)
LifePYCFactorMale[70] = new LifePYCM(10.17,8.33,6.66,5.49,11.06)
LifePYCFactorMale[71] = new LifePYCM(10.55,8.48,6.7,5.49,11.61)
LifePYCFactorMale[72] = new LifePYCM(10.94,8.61,6.73,5.5,12.19)
LifePYCFactorMale[73] = new LifePYCM(11.33,8.74,6.76,5.5,12.81)
LifePYCFactorMale[74] = new LifePYCM(11.72,8.86,6.79,5.51,13.46)
LifePYCFactorMale[75] = new LifePYCM(12.12,8.97,6.81,5.51,14.16)
LifePYCFactorMale[76] = new LifePYCM(12.51,9.06,6.82,5.51,14.89)
LifePYCFactorMale[77] = new LifePYCM(12.9,9.15,6.83,5.51,15.66)
LifePYCFactorMale[78] = new LifePYCM(13.28,9.23,6.84,5.51,16.47)
LifePYCFactorMale[79] = new LifePYCM(13.66,9.3,6.85,5.51,17.33)
LifePYCFactorMale[80] = new LifePYCM(14.04,9.36,6.86,5.51,18.25)
LifePYCFactorMale[81] = new LifePYCM(14.4,9.42,6.86,5.51,19.24)
LifePYCFactorMale[82] = new LifePYCM(14.76,9.46,6.87,5.51,20.29)
LifePYCFactorMale[83] = new LifePYCM(15.11,9.5,6.87,5.51,21.42)
LifePYCFactorMale[84] = new LifePYCM(15.45,9.53,6.87,5.51,22.64)
LifePYCFactorMale[85] = new LifePYCM(15.77,9.56,6.87,5.51,23.96)


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 < 5) || (yrs > 30)))
		{
			alert("The number of years must be 5 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 != 5) && (yrs != 10) && (yrs != 15) && (yrs != 20))
		{
			alert("The number of years must be 5, 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 < 10) || (agex > 95)) && (custSex == "0")) // clr 4/30/09 male ages 10-95 for 3.5%
	{
		alert("Valid ages are 10 through 95.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	   if (((agex < 14) || (agex > 99)) && (custSex == "1")) // clr 4/30/09 female ages 14-99 for 3.5%
	{
		alert("Valid ages are 14 through 99.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	if (custSex == "1")	//clr 4/29/09 for combined 3%-3.5% table females only due to 4-yr setback for females
			{
				ageIdx = agex - 14
			}
			else	
			{
				ageIdx = agex - 10 // was 14 for 3% table; for males in combined table
			}				

	factor = 0
	if (ageIdx <= 85)	// 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 < 14) || (agex > 99))   used for 3% rate
	   if (((agex < 10) || (agex > 95)) && (custSex == "0")) // clr 4/30/09 male ages 10-95 for 3.5%
	{
		alert("Valid ages are 10 through 95.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	   if (((agex < 14) || (agex > 99)) && (custSex == "1")) // clr 4/30/09 female ages 14-99 for 3.5%
	{
		alert("Valid ages are 14 through 99.")
		quote.txtAge.focus()
		quote.txtAge.select()
		errorSw = 2
		return
	}

	if (custSex == "1")	//clr 4/29/09 for combined 3%-3.5% table females only due to 4-yr setback for females
			{
				ageIdx = agex - 14
			}
			else	
			{
				ageIdx = agex - 10 // was 14 for 3% table; for males in combined table
			}				

		factor = 0
		if (ageIdx <= 85)	// was 85 for 3%
		{
			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)
					}
		}
	}
}
