// If you can see this, it means your web browser<br>
// is too old. Please upgrade to a newer browser.<br>
<!-- // hide the javascript on old browsers that don't support scripting.

// Please do not copy my scripts into your own page.  Its copyrighted.
// Although the javascript code below is based on published principles,
// the methods I have used to implement those principles are my own design.
// Therefore, copying my code, my method, is stealing.  I'll find out.
// (I am willing to discuss licensing my code.)
// The reason I haven't hidden my code on a server, is that some people
// may want to verify the logic of the methods, and suggest improvements
// to me.  I welcome all constructive comments!

//	document.standard_risk_factors.yAge.focus();


function CalcMenu(form) {
	var Age = Number(form.yAge.value);			// Make sure an age was
	if (!checkAgeMenu(Age)) {					// entered. Don't Alert
		ClearValues(form);
		return false;								// if not, are don't recalc.
	}
	CalcRisk(form);
	return true;
}

function CalcButton(form) {
	var Age = Number(form.yAge.value);		// Make sure an age was
	if (!checkAgeButton(Age)){				// entered. Show an alert
		ClearValues(form);
		form.yAge.focus();					// if not.
		return false;
	}
	CalcRisk(form);
	return true;
}

function ClearValues(form) {
	form.five.value = "";
	form.ten.value = "";
	form.twenty.value = "";
	form.thirty.value = "";
	form.life.value = "";
	return false;
}

function CalcRisk(form) {
	var Age = Number(form.yAge.value);

// Set A, B, C and D variables, using the relative risk factors from
// the Gail model 1.
	
	var A = 1.00;												// default is 14 or over.
	if (form.yMenarche.selectedIndex == 1) A = 1.10;	// age 12-13 yrs menarche
	if (form.yMenarche.selectedIndex == 2) A = 1.21;	// under 12 years menarche
	
	var B = 1.00;
	if (Age < 50) {	
		if (form.nBiopsy.selectedIndex == 1) B = 1.70;
		if (form.nBiopsy.selectedIndex == 2) B = 2.88;
	} else {
		if (form.nBiopsy.selectedIndex == 1) B = 1.27;
		if (form.nBiopsy.selectedIndex == 2) B = 1.62;
	}
	
	var C = 1.00;
	if ( (form.yFLB.selectedIndex == 4)  || (form.yFLB.selectedIndex == 2)) {
		if (form.nRel.selectedIndex == 0) C = 1.55;
		if (form.nRel.selectedIndex == 1) C = 2.76;
		if (form.nRel.selectedIndex == 2) C = 4.91;
	} else {
		if (form.yFLB.selectedIndex == 0) {
			if (form.nRel.selectedIndex == 0) C = 1.00;
			if (form.nRel.selectedIndex == 1) C = 2.61;
			if (form.nRel.selectedIndex == 2) C = 6.80;
		} else {
			if (form.yFLB.selectedIndex == 1) {
				if (form.nRel.selectedIndex == 0) C = 1.24;
				if (form.nRel.selectedIndex == 1) C = 2.68;
				if (form.nRel.selectedIndex == 2) C = 5.78;
			} else {
				if (form.nRel.selectedIndex == 0) C = 1.93;
				if (form.nRel.selectedIndex == 1) C = 2.83;
				if (form.nRel.selectedIndex == 2) C = 4.17;
			}
		}
	}

	var D = 1.00;
	if (form.nBiopsy.selectedIndex > 0) {				// If she's had a biopsy, and
		if (form.atypical.selectedIndex == 2) {		// if a biopsy had atypical hyperplasia,
			D = 1.82;										// increase the risk.
		} else {											// And if she's had a biopsy, and
			if (form.atypical.selectedIndex == 1) {	// specifically stated that it wasn't
				D = 0.93;									// atypical hyperplasia, then decrease the risk.
			}												// Otherwise, leave it alone (1.00).
		}
	}
	// Calculate the basic summary relative risk, a la Gail model 1.
	var basicRisk = A * B * C * D;


	// Emulate NSABP's model 2.  (used for P-1 and P-2 trial eligibility).	
	var Anci = 1.00 * 1.00;													// default is 14 or over.
	if (form.yMenarche.selectedIndex == 1) Anci = 1.10 * 0.9985;		// age 12-13 yrs menarche
	if (form.yMenarche.selectedIndex == 2) Anci = 1.21 * 0.982;		// under 12 years menarche

	var Bnci = 1.00;
	if (Age < 50) {	
		if (form.nBiopsy.selectedIndex == 1) Bnci = 1.70 * 0.752;
		if (form.nBiopsy.selectedIndex == 2) Bnci = 2.88 * 0.572;
	} else {
		if (form.nBiopsy.selectedIndex == 1) Bnci = 1.27 * 0.974;
		if (form.nBiopsy.selectedIndex == 2) Bnci = 1.62 * 0.950;
	}
	var Cnci = 1.00;
	if ( (form.yFLB.selectedIndex == 4)  || (form.yFLB.selectedIndex == 2)) {
		if (form.nRel.selectedIndex == 0) Cnci = 1.55;
		if (form.nRel.selectedIndex == 1) Cnci = 2.76 * 0.980;
		if (form.nRel.selectedIndex == 2) Cnci = 4.91 * 0.935;
	} else {
		if (form.yFLB.selectedIndex == 0) {
			if (form.nRel.selectedIndex == 0) Cnci = 1.00;
			if (form.nRel.selectedIndex == 1) Cnci = 2.61 * 0.981;
			if (form.nRel.selectedIndex == 2) Cnci = 6.80 * 0.907;
		} else {
			if (form.yFLB.selectedIndex == 1) {
				if (form.nRel.selectedIndex == 0) Cnci = 1.24;
				if (form.nRel.selectedIndex == 1) Cnci = 2.68 * 0.985;
				if (form.nRel.selectedIndex == 2) Cnci = 5.78 * 0.920;
			} else {
				if (form.nRel.selectedIndex == 0) Cnci = 1.93;
				if (form.nRel.selectedIndex == 1) Cnci = 2.83 * 0.982;
				if (form.nRel.selectedIndex == 2) Cnci = 4.17 * 0.948;
			}
		}
	}
	var Dnci = 1.00;
	if (form.nBiopsy.selectedIndex > 0) {				// If she's had a biopsy, and
		if (form.atypical.selectedIndex == 2) {		// if a biopsy had atypical hyperplasia,
			Dnci = 1.82;									// increase the risk.
		} else {											// And if she's had a biopsy, and
			if (form.atypical.selectedIndex == 1) {	// specifically stated that it wasn't
				Dnci = 0.93;								// atypical hyperplasia, then decrease the risk.
			}												// Otherwise, leave it alone (1.00).
		}
	}
	var NCIbasicRisk = Anci * Bnci * Cnci * Dnci;

//	window.defaultStatus = "ignore this debug info:  " + rounding(A,2) + " * " + rounding(B,2) + " * " + rounding(C,2) + " * " + rounding(D,2) + " = " + rounding(basicRisk,2) + "   //   " + rounding(Anci,2) + " * " + rounding(Bnci,2) + " * " + rounding(Cnci,2) + " * " + rounding(Dnci,2) + " = " + rounding(NCIbasicRisk,2);

	var modRisk = basicRisk;
	if (form.CalcMethod.selectedIndex == 1) modRisk = NCIbasicRisk;



// Now, add in some extra relative risk modifiers that weren't
// part of Gail Model 1.  (These make my predictions less
// scientifically provable, but hopefully a little more accurate.

	// Adjust for Breast Density						// 3 = Unknown.
	if (form.Dense.selectedIndex == 1) { 				// 1 = 0% fatty.
		modRisk = modRisk * 0.4048583;  				// Odds Ratio = 1.0
	} else {
		if (form.Dense.selectedIndex == 2) {			// 2 = 1% to 24%
			modRisk = modRisk * 0.635627;				// Odds Ratio = 1.57
		} else {											// 3 = 25% to 49%.  OR = 2.47.
			if (form.Dense.selectedIndex == 4) {		// 4 = 50% to 74%
				modRisk = modRisk * 1.121457;   		// Odds Ratio = 2.77
			} else {
				if (form.Dense.selectedIndex == 5) {	// 5 = 75% to 100%
					modRisk = modRisk * 1.761134; 		// Odds Ratio = 4.35
				}
			}
		}
	}
// Although the reference doesn't support it, I'm thinking I should add some code
// to minimize the effect of breast density for women under 40, because:
// a) they don't undergo screening, so referenced data is sparce,
// b) most young women have dense breast tissue,  so the referenced data probably
// takes that density into account, and assumes it is "normal".
// (note to self,  improve this part in the future.)



	// Adjust for Tamoxifen. Ref 7.  But, I'm uncertain if this should
	// apply to women whose basicRisk is low,  because the NSAPB P-1 study
	// proved benefit by studying high risk women only.  I'm making a guess
	// that it will benefit even women whose risk is inherently low.
	if (form.Tamox.selectedIndex == 1) {
		if (Age < 50) {
			modRisk = modRisk * 0.56;
		} else {
			if (Age < 60) {
				modRisk = modRisk * 0.49;
			} else {
				modRisk = modRisk * 0.45;
			}		// Actually, tamoxifen reduces risk even more
		}			// for women with atypical hyperplasia, but I
	}				// didn't implement that. Maybe I should.



	// Adjust for alcohol.  Ref 9.
	if (form.Alcohol.selectedIndex == 2) modRisk = modRisk * 1.07;
	if (form.Alcohol.selectedIndex == 3) modRisk = modRisk * 0.99;
	if (form.Alcohol.selectedIndex == 4) modRisk = modRisk * 1.06;
	if (form.Alcohol.selectedIndex == 5) modRisk = modRisk * 1.16;
	if (form.Alcohol.selectedIndex == 6) modRisk = modRisk * 1.41;
	if (form.Alcohol.selectedIndex == 7) modRisk = modRisk * 1.31;

	// Adjust for LCIS.  I used table 3 from Ref 10, and did a weighted linear
	// regression of its Relative risk values, to smooth out its behavior.
	if (form.nBiopsy.selectedIndex > 0) {
		if (form.LCIS.selectedIndex == 1) modRisk = modRisk * 8.7;		// was 10.5;
		if (form.LCIS.selectedIndex == 2) modRisk = modRisk * 6.8;		// was 6.6;
		if (form.LCIS.selectedIndex == 3) modRisk = modRisk * 5.6;		// was 5.0;
		if (form.LCIS.selectedIndex == 4) modRisk = modRisk * 4.5;		// was 5.4;
		if (form.LCIS.selectedIndex == 5) modRisk = modRisk * 3.1;		// was3.2;
	}

	// Adjust for Birth Control Pills.  Used table 3b from Ref 11.
	if (form.BCPs.selectedIndex > 0 && form.startBCPs.selectedIndex > 0) {
		if (form.BCPs.selectedIndex == 1) {	// Current User.
			if (form.startBCPs.selectedIndex == 1) {	// start age <20 yrs
				modRisk = modRisk * 1.59;
			} else {
				if (form.startBCPs.selectedIndex == 2) {	// start age 20-24yrs
					modRisk = modRisk * 1.17;
				} else {
					if (form.startBCPs.selectedIndex == 3) {	// start age 25-29 yrs
						modRisk = modRisk * 1.16;
					} else {										// start age 30 + yrs
						modRisk = modRisk * 1.25;
					}
				}
			}
		} else {
			if (form.BCPs.selectedIndex == 2) {  // Last use 1-4 yrs ago.
				if (form.startBCPs.selectedIndex == 1) {	// start age <20 yrs
					modRisk = modRisk * 1.49;
				} else {
					if (form.startBCPs.selectedIndex == 2) {	// start age 20-24yrs
						modRisk = modRisk * 1.15;
					} else {
						if (form.startBCPs.selectedIndex == 3) {	// start age 25-29 yrs
							modRisk = modRisk * 1.09;
						} else {										// start age 30 + yrs
							modRisk = modRisk * 1.11;
						}
					}
				}
			} else {
				if (form.BCPs.selectedIndex == 3) {	// Last use 5-9 yrs ago.
					if (form.startBCPs.selectedIndex == 1) {	// start age <20 yrs
						modRisk = modRisk * 1.07;
					} else {
						if (form.startBCPs.selectedIndex == 2) {	// start age 20-24yrs
							modRisk = modRisk * 1.09;
						} else {
							if (form.startBCPs.selectedIndex == 3) {	// start age 25-29 yrs
								modRisk = modRisk * 1.01;
							} else {										// start age 30 + yrs
								modRisk = modRisk * 1.18;
							}
						}
					}
				} else {
					if (form.BCPs.selectedIndex == 4) {	// Last use 10-14 yrs ago.
						if (form.startBCPs.selectedIndex == 1) {	// start age <20 yrs
							modRisk = modRisk * 1.13;
						} else {
							if (form.startBCPs.selectedIndex == 2) {	// start age 20-24yrs
								modRisk = modRisk * 0.93;
							} else {
								if (form.startBCPs.selectedIndex == 3) {	// start age 25-29 yrs
									modRisk = modRisk * 1.06;
								} else {										// start age 30 + yrs
									modRisk = modRisk * 0.95;
								}
							}
						}
					} else {										// Last use 15+ yrs ago.
						if (form.startBCPs.selectedIndex == 1) {	// start age <20 yrs
							modRisk = modRisk * 1.14;
						} else {
							if (form.startBCPs.selectedIndex == 2) {	// start age 20-24yrs
								modRisk = modRisk * 1.01;
							} else {
								if (form.startBCPs.selectedIndex == 3) {	// start age 25-29 yrs
									modRisk = modRisk * 1.01;
								} else {										// start age 30 + yrs
									modRisk = modRisk * 0.99;
								}
							}
						}
					}
				}
			}
		}	
	}

	// Adjust for effect of Black Race, emulating behavior of NCI's Tool.
	var raceModfive = 1;
	var raceModlife = 1;
	var raceModten = 1;
	var raceModtwenty = 1;
	var raceModthirty = 1;
	var m = 1;
	var b = 0;
	if (form.Race.selectedIndex == 1) {	// For black race.
		// 5-year race modification
		if (Age < 50) {
			// y = -8E-05x2 + 0.0038x + 0.5774
			raceModlife = -0.00008371*Age*Age + 0.0037974*Age + 0.57738;
			// y = -0.001x2 + 0.0469x + 0.4435
			raceModfive = -0.00095462*Age*Age + 0.046916*Age + 0.44353;
		} else {
			// y = 0.0001x2 - 0.0147x + 0.9565 (old y = 9E-05x2 - 0.0088x + 0.7681 )
			raceModlife = 0.00013558*Age*Age - 0.01467*Age + 0.95651;
			// y = -0.0004x2 + 0.0411x - 0.5312
			raceModfive = -0.00036536*Age*Age + 0.041145*Age - 0.53121;
		}

	// Interpolate between 5yr and lifetime raceMods,
	// to find the 10,20 and 30 year raceMods.
	m = (raceModlife-raceModfive) / (90-(Age+5));
	b = raceModfive - (m * (Age+5));  				//  y=mx+b.   b=y-mx
	raceModten = (m * (Age+10)) + b;
	raceModtwenty = (m * (Age+20)) + b;
	raceModthirty = (m * (Age+30)) + b;
	}

	if (modRisk > 90) {
		alert("Unfortunately, by choosing so many high risk factors, their combined" +  
			" relative risk exceeds the safe operating range of the curves that predict" +
			" the absolute chance of getting cancer. Sorry about that.");
		ClearValues(form);
		return false;
	}

// I use 2nd-order polynomial expressions to characterize the
// graphical absolute risk curves published by Gail. Ref 1.
	var lowD = 0;
	var highD = 0;
	var lowE = 0;
	var highE = 0;
	var lowF = 0;
	var highF = 0;
	var lowRisk = 0;
	var highRisk = 0;
	var lowPoint = 20;
	var tenRisk = 0;
	var twentyRisk = 0;
	var thirtyRisk = 0;
	var fiveRisk = 0;
	var lifeRisk = 0;
	var distance = 10;
	var fixRisk = 0;

if (form.CalcMethod.selectedIndex == 0) {  // Gail model 1.

	fixRisk = modRisk * raceModten;

// 10 year risk.
	if (Age < 30) {	// OK. New method slightly increased (about +0.2% AR) vs Old.
		lowPoint = 20;		// curves for age 20, 10yr chance of cancer.
		lowD =  0.00028727;	// y=0.0003x2 + 0.0426x + 0.0045
		lowE =  0.042587;		// Original curves will work to modRisk < 90.
		lowF =  0.004463;	
		highD = -0.000966;	// y=-0.001x2 + 0.4558x - 0.0615
		highE =  0.45581;		// curves for age 30, 10yr chance of cancer.
		highF = -0.061461;
		if (fixRisk > 25) {	// 
			highD = -0.0023;	// y = -0.0023x2 + 0.4417x + 1.0
			highE =  0.4417;	// This alternate curve for age 30, 10yr for
			highF =  1.0; 	// modRisk > 25, is lower than the original.
		}
	} else {
		if (Age < 40) {	// OK. gets almost equal to old near 49 and big RR factors.
			lowPoint = 30;
			lowD = -0.000966;
			lowE =  0.45581;
			lowF =  0.061461;
			if (fixRisk > 25) {
				lowD = -0.0023;
				lowE =  0.4417;
				lowF =  1.0;
			}
			highD = -0.007138;	// y=-0.0071x2 + 1.2564x -0.0781
			highE =  1.2564;
			highF = -0.078126;
			if (fixRisk > 20) {
				highD = -0.0041; 	// extra: y = -0.005x2 + 0.95x + 5
				highE =  0.9986;	// new extra: y = -0.0041x2 + 0.9986x + 3.6857
				highF =  3.6857;
			}
		} else {	// ages 40 - 50, then beyond by extrapolation.
			lowPoint = 40;
			lowD = -0.007138;
			lowE =  1.2564;
			lowF = -0.078126;
			if (fixRisk > 20) {
				lowD = -0.0041;
				lowE =  0.9986;
				lowF =  3.6857;
			}
			highD = -0.010061;	// y=-0.0101x2 + 1.5667x + 0.0033
			highE =  1.5667;
			highF =  0.0033184;
			if (fixRisk > 27) {
				highD = -0.0058;	// extra: y = -0.0056x2 + 1.0432x + 8.3714
				highE =  1.2351; // new extra: y = -0.0058x2 + 1.2351x + 5.8864
				highF =  5.8864;
			}
		}
	}
	lowRisk = (lowD * fixRisk * fixRisk) + (lowE * fixRisk) + lowF;
	highRisk = (highD * fixRisk * fixRisk) + (highE * fixRisk) + highF;
	tenRisk =(Age-lowPoint)/10 * (highRisk-lowRisk) + lowRisk;

// Twenty Year Risk.
	fixRisk = modRisk * raceModtwenty;

	if (Age < 30) {	
		lowPoint = 20;
		lowD = -0.0016617;	// y=-0.0017x2 + 0.4948x +0
		lowE =  0.49476;		// these 20yr age 20 curves are fine to 100.
		lowF =  0;
		highD = -0.010241;	// y=-0.0102x2 + 1.619x + 0.1418
		highE =  1.6190;
		highF =  0.14179; 
		if (fixRisk > 24) {
			highD = -0.0054;	// extra: y = -0.0054x2 + 1.0893x + 9.987
			highE =  1.0893;
			highF =  9.9870;
		}
	} else {
		if (Age < 40) {
			lowPoint = 30;
			lowD = -0.010241;
			lowE =  1.6190;
			lowF =  0.14179;
			if (fixRisk > 24) {
				lowD = -0.0054;	// extra y = -0.0054x2 + 1.0893x + 9.987
				lowE =  1.0893;
				lowF =  9.9870;
			}
			if (form.nBiopsy.selectedIndex == 2) {
				highD = -0.012414;	// y = -0.0124x2 + 1.8969x + 1.2952
				highE =  1.8969;  
				highF =  1.2952;
				if (fixRisk > 25) {	// extra: y = -0.0059x2 + 1.2042x + 14.596
					highD = -0.0059;
					highE =  1.2042;
					highF = 14.5960;
				}
			} else {
				highD = -0.025755;	// y = -0.0258x2 + 2.3648x + 0.6164
				highE =  2.3648;
				highF =  0.61644;
				if (fixRisk > 15) {
					highD = -0.007;	// extra: y = -0.007x2 + 1.3844x + 11.8
					highE =  1.3844;
					highF = 11.8;
				}
			}
		} else {	// age is 40 or over.
			lowPoint = 40;
			if (form.nBiopsy.selectedIndex == 2) {
				lowD = -0.012414;		// y = -0.0124x2 + 1.8969x + 1.2952
				lowE =  1.8969;  
				lowF =  1.2952;
				if (fixRisk > 25) {	// extra: y = -0.0059x2 + 1.2042x + 14.596
					lowD = -0.0059;
					lowE =  1.2042;
					lowF = 14.5960;
				}
			} else {
				lowD = -0.025755;		// y = -0.0258x2 + 2.3648x + 0.6164
				lowE =  2.3648;
				lowF =  0.61644;
				if (fixRisk > 15) {
					lowD = -0.007;	// extra: y = -0.007x2 + 1.3844x + 11.8
					lowE =  1.3844;
					lowF = 11.8;
				}
			}
			highD = -0.039537;	// y = -0.0395x2 + 3.1427x + 0.2516
			highE =  3.1427;		// Near age 50, these numbers were slightly
			highF =  0.25161;		// lower in the mid risks. (thats good I think)
			if (fixRisk > 16) {
				highD = -0.0077;	// extra y = -0.0077x2 + 1.4639x + 18.547
				highE =  1.4639;
				highF = 18.547;
			}
		}
	}
	lowRisk = (lowD * fixRisk * fixRisk) + (lowE * fixRisk) + lowF;
	highRisk = (highD * fixRisk * fixRisk) + (highE * fixRisk) + highF;
	twentyRisk =(Age-lowPoint)/10 * (highRisk-lowRisk) + lowRisk;

// 30 year risk
	fixRisk = modRisk * raceModthirty;

	if (Age < 30) {	
		lowPoint = 20;	// y = -0.0107x2 + 1.6493x + 0.339
		lowD = -0.010721;
		lowE =  1.6493;
		lowF =  0.33903;
		if (fixRisk > 25) {
			lowD = -0.0063;	// extra y = -0.0063x2 + 1.2331x + 7.1154
			lowE =  1.2331;
			lowF =  7.1154;
		}
		if (form.nBiopsy.selectedIndex == 2) {  
			highD = -0.019108;		// y = -0.0191x2 + 2.2942x + 1.35
			highE =  2.2942;
			highF =  1.3500;
			if (fixRisk > 27) {
				highD = -0.0050;	// extra: y = -0.005x2 + 1.1231x + 23.312
				highE =  1.1231;
				highF = 23.312;
			}
		} else {
			highD = -0.028327;	// y = -0.0283x2 + 2.637x + 1.2923
			highE =  2.6370;
			highF =  1.2923;
			if (fixRisk > 25) {
				highD = -0.0064;	// extra: y = -0.0064x2 + 1.1987x + 24.038
				highE =  1.1987;
				highF = 24.038;
			}
		}
	} else {
		if (Age < 40) {
			lowPoint = 30;
			if (form.nBiopsy.selectedIndex == 2) {  
				lowD = -0.019108;		// y = -0.0191x2 + 2.2942x + 1.35
				lowE =  2.2942;
				lowF =  1.3500;
				if (fixRisk > 27) {
					lowD = -0.0050;	// extra: y = -0.005x2 + 1.1231x + 23.312
					lowE =  1.1231;
					lowF = 23.312;
				}
			} else {
				lowD = -0.028327;	// y = -0.0283x2 + 2.637x + 1.2923
				lowE =  2.6370;		// 
				lowF =  1.2923;		//
				if (fixRisk > 25) {
					lowD = -0.0064;	// extra: y = -0.0064x2 + 1.1987x + 24.038
					lowE =  1.1987;
					lowF = 24.038;
				}
			}
			if (form.nBiopsy.selectedIndex == 2) {
				highD = -0.024583;	// y = -0.0246x2 + 2.6349x + 2.3411
				highE =  2.6349;	
				highF =  2.3411;
				if (fixRisk > 30) {
					highD = -0.0058;	// extra: y = -0.0058x2 + 1.1667x + 30.25
					highE =  1.1667;
					highF = 30.25;
				}
			} else {
				highD = -0.039893;	// y = -0.0399x2 + 3.2326x + 2.7527
				highE =  3.2326;	// 
				highF =  2.7527;
				if (fixRisk > 25) {
					highD = -0.0072;	// extra: y = -0.0072x2 + 1.3765x + 29.058
					highE =  1.3765;
					highF = 29.058;
				}
			}
		} else {	// age 40 and above.
			lowPoint = 40;
			if (form.nBiopsy.selectedIndex == 2) {
				lowD = -0.024583;	// y = -0.0246x2 + 2.6349x + 2.3411
				lowE =  2.6349;	
				lowF =  2.3411;
				if (fixRisk > 30) {
					lowD = -0.0058;	// extra: y = -0.0058x2 + 1.1667x + 30.25
					lowE =  1.1667;
					lowF = 30.25;
				}
			} else {
				lowD = -0.039893;	// y = -0.0399x2 + 3.2326x + 2.7527
				lowE =  3.2326;	// 
				lowF =  2.7527;
				if (fixRisk > 25) {
					lowD = -0.0072;	// extra: y = -0.0072x2 + 1.3765x + 29.058
					lowE =  1.3765;
					lowF = 29.058;
				}
			}
			highD = -0.059953;	// y = -0.059953x2 + 3.9732x + 1.6088
			highE =  3.9732;
			highF =  1.6088;
			if (fixRisk > 20) {
				highD = -0.0104; // new extra y=-0.0104x2 +1.925x +22.643
				highE =  1.925;
				highF = 22.643;
			}
		}
	}
	lowRisk = (lowD * fixRisk * fixRisk) + (lowE * fixRisk) + lowF;
	highRisk = (highD * fixRisk * fixRisk) + (highE * fixRisk) + highF;
	thirtyRisk =(Age-lowPoint)/10 * (highRisk-lowRisk) + lowRisk;

	fiveRisk = tenRisk / 2;  // Not really.  fix this in the future.

} 

if (form.CalcMethod.selectedIndex == 1) { // NSABP model 2.

	distance = 10;		// Use a 10 year distance for linear interpolations.

// Do the 5 year risk calculation,
	fixRisk = modRisk * raceModfive;

	if (Age < 50) {
		// Must fix a problem with NCIs tool.  They use different risk multipliers
		// in the <50 ages than the >50 ages, for 0,1 and 2 biopsies.  So here, I
		// must "undo/fix" something done above.  This "fix" only seems to be
		// necessary for calculating 5-year risk,  but not lifetime risk. go figure.

		if (form.nBiopsy.selectedIndex == 1) fixRisk = fixRisk * 0.990 / 0.752;
		if (form.nBiopsy.selectedIndex == 2) fixRisk = fixRisk * 0.955 / 0.572;


		// Another thing to fix:  When Race is Black, age under 50 uses
		// different numbers.
		if (Age < 30) {
			lowPoint = 20;
			lowD = 0;				// Age 20.
			lowE = 0.0051;		// Note, this linear equation for age 20, doesn't
			lowF = 0;				// need range protection like the others.
			highD =  0.00034822;			// Age 30.
			highE =  0.08278;
			highF = -0.019199;
			if (fixRisk > 20) {		// Protect for extra high risk ranges.
				highD = -0.0005;		// by using a different curve that performs
				highE =  0.0984;		// better at higher risks.
				highF = -0.0270;
			}

		} else {
			if (Age < 40) {
				lowPoint = 30;
				lowD =  0.00034822;	// Age 30.
				lowE =  0.08278;
				lowF = -0.019199;
				if (fixRisk > 20) {
					lowD = -0.0005;
					lowE =  0.0984;
					lowF = -0.0270;
				}
				highD =  0.0018583;	// Age 40.
				highE =  0.37656;
				highF = -0.030994;
				if (fixRisk > 20) {
					highD = -0.0022;
					highE =  0.4635;
					highF = -0.1929;
				}
			} else {	// age 40 to 50.
				lowPoint = 40;
				lowD =  0.0018583;		// Age 40.
				lowE =  0.37656;
				lowF = -0.030994;
				if (fixRisk > 20) {
					lowD = -0.0022;
					lowE =  0.4635;
					lowF = -0.1929;
				}
				highD =  0.0059;			// Age 50.  (note, age 50 doesn't use
				highE =  0.6559;			// the fixRisk adjustment.  There is an
				highF = -0.0467;			// "if" statement in the calculation of
				if ( (modRisk*raceModfive) > 18) {		// highRisk below, that takes care of this
					highD = -0.0038;		// special case,  only when lowPoint = 40.
					highE =  0.7864;
					highF = -0.2830;
				}
			}
		}
	} else {
		if (Age < 60) {
			lowPoint = 50;
			lowD =  0.0059;		// Age 50.
			lowE =  0.6559;
			lowF = -0.0467;
			if (fixRisk > 18) {			// Its OK to refer to fixRisk in the 50 -70 year
				lowD = -0.0038;			// range, because fixRisk will equal modRisk in
				lowE =  0.7864;			// this age range.
				lowF = -0.2830;
			}
			highD =  0.0098;		// Age 60.
			highE =  0.9388;
			highF = -0.0190;
			if (fixRisk > 11) {
				highD = -0.0060;
				highE =  1.0910;
				highF =  0.1203;
			}
		} else {
			lowPoint = 60;
			lowD =  0.0098;		// Age 60.
			lowE =  0.9388;
			lowF = -0.0190;
			if (fixRisk > 11) {
				lowD = -0.0060;
				lowE =  1.0910;
				lowF =  0.1203;
			}
			highD =  0.0072;		// Age 70.
			highE =  1.1722;
			highF = -0.0693;
			if (fixRisk > 12) {
				highD = -0.0052;
				highE =  1.1771;
				highF =  1.25;
			}
		}
	}
	lowRisk = (lowD * fixRisk * fixRisk) + (lowE * fixRisk) + lowF;
	if (lowPoint == 40) {
		highRisk = (highD*modRisk*raceModfive*modRisk*raceModfive) + (highE*modRisk*raceModfive) + highF;
	} else {
		highRisk = (highD * fixRisk * fixRisk) + (highE * fixRisk) + highF;
	}
	fiveRisk = (Age-lowPoint)/distance * (highRisk-lowRisk) + lowRisk;

}



// Do the lifetime calculation.
if(form.CalcMethod.selectedIndex == 0) {
	var lifeLeft = (90-Age);
	// eg, age 71 has 19 years of life left.
	if (lifeLeft < 20) {  // 5 to 19 or less years left.  (ages 71 to 85)
		lifeRisk = ((lifeLeft - 10)/10 * (twentyRisk-tenRisk)) + tenRisk;
	} else {
		lifeRisk = ((lifeLeft - 20)/10 * (thirtyRisk-twentyRisk)) + twentyRisk;
	}
} else {
	distance = 10;		// Reset this, just in case.
	fixRisk = modRisk * raceModlife;

	if (Age < 30) {
		lowPoint = 20;
		lowD = -0.1527;		// Age 20.
		lowE =  7.0808;
		lowF =  0.3652;
		if (fixRisk > 15) {
			lowD = -0.0186;
			lowE =  3.2665;
			lowF = 27.483;
		}
		highD = -0.1619;		// Age 30.
		highE =  7.2326;
		highF =  0.0195;
		if (fixRisk > 15) {
			highD = -0.0186;
			highE =  3.2665;
			highF = 27.483;
		}
	} else {
		if (Age < 40) {
			lowPoint = 30;
			lowD = -0.1619;		// Age 30.
			lowE =  7.2326;
			lowF =  0.0195;
			if (fixRisk > 15) {
				lowD = -0.0186;
				lowE =  3.2665;
				lowF = 27.483;
			}
			highD = -0.1547;		// Age 40.
			highE =  6.9880;
			highF = -0.0231;
			if (fixRisk > 18) {
				highD = -0.0148;  // new extra y = -0.0148x2 + 2.8021x + 29.344
				highE =  2.8021;
				highF = 29.344;
			}
		} else {
			if (Age < 50) {
				lowPoint = 40;
				lowD = -0.1547;		// Age 40.
				lowE =  6.9880;
				lowF = -0.0231;
				if (fixRisk > 18) {
					lowD = -0.0148;	// new extra y = -0.0148x2 + 2.8021x + 29.344
					lowE =  2.8021;
					lowF = 29.344;
				}
				highD = -0.1338;		// Age 50.
				highE =  6.3051;
				highF = -0.3276;
				if (fixRisk > 15) {
					highD = -0.0135;
					highE =  2.5629;
					highF = 28.8510;
				}
			} else {
				if (Age < 60) {
					lowPoint = 50;
					lowD = -0.1338;		// Age 50.
					lowE =  6.3051;
					lowF = -0.3276;
					if (fixRisk > 15) {
						lowD = -0.0135;
						lowE =  2.5629;
						lowF = 28.8510;
					}
					highD = -0.0737;		// Age 60.
					highE =  4.9825;
					highF = -0.0697;
					if (fixRisk > 25) {
						highD = -0.0117;	// new extra y = -0.0117x2 + 2.3906x + 24.766
						highE =  2.3906;
						highF = 24.766;
					}
				} else {
					lowPoint = 60;
					lowD = -0.0737;		// Age 60.
					lowE =  4.9825;
					lowF = -0.0697;
					if (fixRisk > 25) {
						lowD = -0.0117;	// new extra y = -0.0117x2 + 2.3906x + 24.766
						lowE =  2.3906;
						lowF = 24.766;
					}
					highD = -0.0313;		// Age 70.
					highE =  3.5062;
					highF = -0.1732;
					if (fixRisk > 13) {
						highD = -0.0142;
						highE =  2.7076;
						highF =  6.4363;
					}
				}
			}
		}
	}
	lowRisk =  (lowD * fixRisk * fixRisk) + (lowE * fixRisk) + lowF;
	highRisk = (highD * fixRisk * fixRisk) + (highE * fixRisk) + highF;
	lifeRisk = (Age-lowPoint)/distance * (highRisk-lowRisk) + lowRisk;
}



// For NSABP model 2, interpolate between 5yr and lifetime,
// to find the 10,20 and 30 year risks.
if (form.CalcMethod.selectedIndex == 1) {
	m = (lifeRisk-fiveRisk) / (90-(Age+5));
	b = fiveRisk - (m * (Age+5));  				//  y=mx+b.   b=y-mx
	tenRisk = (m * (Age+10)) + b;
	twentyRisk = (m * (Age+20)) + b;
	thirtyRisk = (m * (Age+30)) + b;
}



// Finished calculating fiveRisk,tenRisk, twentyRisk, thirtyRisk and lifeRisk.


// Plus increase by 24.38% for DCIS incidence in screened populations.  * 1.2438;
//
//if (form.DCIS.checked == 1 && form.CalcMethod.selectedIndex == 1) {
//	if (form.Screen.selectedIndex == 0) {
//		tenRisk = tenRisk * 1.2438;			// In Alberta, 24% of cancers are DCIS.
//		twentyRisk = twentyRisk * 1.2438;	// Thats a little higher than average in
//		thirtyRisk = thirtyRisk * 1.2438;	// North America.  I'm looking for a better
//		fiveRisk = fiveRisk * 1.2438;		// estimate for screened populations.
//		lifeRisk = lifeRisk * 1.2438;
//	} else {
//		tenRisk = tenRisk * 1.12;			// In North America,  in non-screened
//		twentyRisk = twentyRisk * 1.12;	// women,  about 12% of cancers are DCIS.
//		thirtyRisk = thirtyRisk * 1.12;
//		fiveRisk = fiveRisk * 1.12;
//		lifeRisk = lifeRisk * 1.12;
//	}
//}


// Compensate for model 1 underpredicing cancer rates in women over 60.
//  (see Ref 5, page 1544.)  (and slightly underpredicting in under 60.)
if (form.CalcMethod.selectedIndex == 0) {
	if (Age < 50) {
		tenRisk = tenRisk * 1.098901099;  // 1/0.91;
		twentyRisk = twentyRisk * 1.098901099;
		thirtyRisk = thirtyRisk * 1.098901099;
		fiveRisk = fiveRisk * 1.098901099;
		lifeRisk = lifeRisk * 1.098901099;
	} else {
		if (Age < 60 ) {
			tenRisk = tenRisk * 1.041666667;  // 1/0.96;
			twentyRisk = twentyRisk * 1.041666667;
			thirtyRisk = thirtyRisk * 1.041666667;
			fiveRisk = fiveRisk * 1.041666667;
			lifeRisk = lifeRisk * 1.041666667;
		} else {
			tenRisk = tenRisk * 1.515151515;  // 1/0.66;
			twentyRisk = twentyRisk * 1.515151515;
			thirtyRisk = thirtyRisk * 1.515151515;
			fiveRisk = fiveRisk * 1.515151515;
			lifeRisk = lifeRisk * 1.515151515;
		}
	}
}


// Compensate for model 1 overpredicting cancer rates in women who do not undergo
// regular mammographic screening.  ( I also do the same thing for model 2.)
	if (form.Screen.selectedIndex == 1) {	
		tenRisk = tenRisk * 0.81300813;  // 1/1.23		// Instead of choosing to use the
		twentyRisk = twentyRisk * 0.81300813;				// age-specific E/O ratios available in
		thirtyRisk = thirtyRisk * 0.81300813;				// ref 8, I instead used the simpler
		fiveRisk = fiveRisk * 0.81300813;					// E/0 ratio from 1982-1987,  which is
		lifeRisk = lifeRisk * 0.81300813;					// likely more pertinent to modern lifestyles.
	}

// Not yet implemented,  Ref 5 says that risk is underestimated in the lowest quintiles
// of predicted 5-year risk, and overestimated in the highest quintiles.  Ie.
// It might be good to scale low and high risks towards the middle slightly for model 1.


	// Display the results.
	if (fiveRisk < 0.2) {
		form.five.value = "<0.2%";
	} else {
		form.five.value = rounding(fiveRisk, 1) + "%";
	}



	if (tenRisk < 0.2) { 
		form.ten.value = "<0.2%";
	} else {
		if (tenRisk > 85) {
			form.ten.value = ">85%*";
		} else {
			if (tenRisk > 30) {
				form.ten.value = rounding( tenRisk,0) + "%*";
			} else {
				form.ten.value = rounding( tenRisk,1) + "%";
			}
		}		
	}


	if (Age < 80.5) {
		if (twentyRisk < 0.2) {
			form.twenty.value = "<0.2%";
		} else {
			if (twentyRisk > 85) {
				form.twenty.value = ">85%*";
			} else {
				if (twentyRisk > 40) {
					form.twenty.value = rounding( twentyRisk,0) + "%*";
				} else {
					form.twenty.value = rounding( twentyRisk,1) + "%";
				}
			}		
		}
	} else {
		form.twenty.value = "";
	}



	if (Age < 70) {
		if (thirtyRisk > 85) {
			form.thirty.value = ">85%*";
		} else {
			if (thirtyRisk > 50) {
				form.thirty.value = rounding( thirtyRisk,0) + "%*";
			} else {
				form.thirty.value = Math.max( rounding( thirtyRisk,1),0) + "%";
			}
		}		
	} else {
		form.thirty.value = "";
	}


	if (Age < 40 && form.CalcMethod.selectedIndex == 0) {
		form.life.value = "";
	} else {
		if (lifeRisk > 85) {
			form.life.value = ">85%*";
		} else {
			if (lifeRisk > 50) {
				form.life.value = rounding( lifeRisk,0) + "%*";
			} else {
				form.life.value = rounding( lifeRisk,1) + "%";
			}
		}
	}

	return true;
}

function checkAgeMenu(val) {
	if ((isNaN(val)) || (val == null)  || (val == "") || (val < 0)) return false;
	if ( val < 20) return false;
	if ( val > 75) return false;
	if (document.standard_risk_factors.LCIS.selectedIndex > 0 && document.standard_risk_factors.nBiopsy.selectedIndex == 0) return false;
	if (document.standard_risk_factors.yFLB.selectedIndex == 1 && val < 20) return false;
	if (document.standard_risk_factors.yFLB.selectedIndex == 2 && val < 25) return false;
	if (document.standard_risk_factors.yFLB.selectedIndex == 3 && val < 30) return false;
	
	if (document.standard_risk_factors.LCIS.selectedIndex == 2 && val < 40) return false;
	if (document.standard_risk_factors.LCIS.selectedIndex == 3 && val < 45) return false;
	if (document.standard_risk_factors.LCIS.selectedIndex == 4 && val < 50) return false;
	if (document.standard_risk_factors.LCIS.selectedIndex == 5 && val < 55) return false;

	if (document.standard_risk_factors.startBCPs.selectedIndex == 3 && val < 25) return false;
	if (document.standard_risk_factors.startBCPs.selectedIndex == 4 && val < 30) return false;

	if (document.standard_risk_factors.BCPs.selectedIndex == 4 && val < 25) return false;
	if (document.standard_risk_factors.BCPs.selectedIndex == 5 && val < 30) return false;

	return true;
}

function checkAgeButton(val) {
	if ((isNaN(val)) || (val == null)  || (val == "") || (val < 0)) {
	alert("Please enter a value for age.");
	return false;
	}
	if ( val < 20) {
	alert("Ages less than 20 years have results too low to calculate accurately.");
	return false;
	}
	if ( val > 75) {
	alert("Ages greater than 70 years have results too inaccurate to calculate.");
	return false;
	}
	if (document.standard_risk_factors.LCIS.selectedIndex > 0 && document.standard_risk_factors.nBiopsy.selectedIndex == 0) {
		alert("How can you have a biopsy showing LCIS (in question 11) when you've had no biopsies (in question 2)?");
		return false;
	}
//	if (document.standard_risk_factors.yFLB.selectedIndex == 4) return true;

	var sayWhat = 0;
	
	if (document.standard_risk_factors.yFLB.selectedIndex == 1 && val < 20) sayWhat = 1;
	if (document.standard_risk_factors.yFLB.selectedIndex == 2 && val < 25) sayWhat = 1;
	if (document.standard_risk_factors.yFLB.selectedIndex == 3 && val < 30) sayWhat = 1;
	
	if (document.standard_risk_factors.LCIS.selectedIndex == 2 && val < 40) sayWhat = 2;
	if (document.standard_risk_factors.LCIS.selectedIndex == 3 && val < 45) sayWhat = 2;
	if (document.standard_risk_factors.LCIS.selectedIndex == 4 && val < 50) sayWhat = 2;
	if (document.standard_risk_factors.LCIS.selectedIndex == 5 && val < 55) sayWhat = 2;

	if (document.standard_risk_factors.startBCPs.selectedIndex == 3 && val < 25) sayWhat = 3;
	if (document.standard_risk_factors.startBCPs.selectedIndex == 4 && val < 30) sayWhat = 3;

	if (document.standard_risk_factors.BCPs.selectedIndex == 4 && val < 25) sayWhat = 4;
	if (document.standard_risk_factors.BCPs.selectedIndex == 5 && val < 30) sayWhat = 4;
	
	if (sayWhat == 1) {
		alert("Your stated age (in question 5) is lower than the age you first gave birth (in question 4).");
		return false;
	}
	if (sayWhat == 2) {
		alert("Your stated age (in question 5) is lower than the age of a biopsy showing LCIS (in question 11).");
		return false;
	}
	if (sayWhat == 3) {
		alert("Your stated age (in question 5) is lower than the age you started taking Birth Control Pills (in question 12).");
		return false;
	}
	if (sayWhat == 4) {
		alert("Your age (in question 5) seems too young in relation to when you stopped taking Birth Control Pills (in question 12).");
		return false;
	}
	return true;
}


function rounding(number,decimal) {  
	multi = Math.pow(10,decimal);
	number = Math.round(number * multi) / multi;
	return number;
}


// -->
