// Body Fat Calculator (c) 2004 Golden Summit, Inc.
// Create a div with id of "npForm"  
// then include this file! 

function funcCalcBF(ppFrm) {
							var chest = ppFrm.ppChest.value * 1;
							var supra = ppFrm.ppSupra.value*1; 
							var triceps = ppFrm.ppTriceps.value*1;
							var ab = ppFrm.ppAb.value*1;
							var thigh = ppFrm.ppThigh.value*1; 
							var age = ppFrm.ppAge.value * 1;
							var gender = ppFrm.ppGender.value;  
							
							if ( ab > 0 && supra > 0 && triceps > 0 && thigh > 0 ) {
								 
								 var sum = ab + supra + triceps + thigh;
								 var sumsq = sum * sum; 
								 
								 if ( gender == 0 ) {
								 		var cof1 = 0.29288;
										var cof2 = 0.0005;
										var cof3 = 0.15845;
										var cof4 = -5.76377;
							   }
								 else {
								    var cof1 = 0.29669;
										var cof2 = 0.00043; 
										var cof3 = 0.02963;
										var cof4 = 1.4072; 
								 }
								 var bodyfat = cof1 * sum - cof2 * sumsq + cof3 * age + cof4;   
							}
							else {
									 if ( gender == 0 ) { 
									 		var sum = chest + ab + thigh; 
											var sumsq = sum * sum; 
											var density = 1.1093800 - 0.0008267 * sum + 0.0000016 * sumsq - 0.000257 * age;
									    var bodyfat = 495/density - 450; 
									 }
									 else {
									    var sum = triceps + ab + supra; 
											var sumsq = sum * sum;
											var density = 1.089733 - 0.0009245 * sum + 0.0000025 * sumsq - 0.0000979 * age;
											var bodyfat = 495/density -450; 
									 }
							}
							var weight = ppFrm.ppWeight.value; 
							var fat = weight * ( bodyfat / 100 ); 
							var lean = weight - fat; 
							bodyfat = Math.ceil(bodyfat * 1000.0); 
							ppFrm.ppBodyfat.value = bodyfat / 1000;
							ppFrm.ppFat.value = Math.ceil( fat );
							ppFrm.ppLean.value = Math.ceil( lean );
}
function genForm() {

strForm = "<form id=\"ppFrm\" name=\"ppFrm\"><p>Instructions: there is a 3-site method and a 4-site method. Both methods";
strForm += "are similar in accuracy. Pick whichever method you like, ";
strForm += "and key in the appropriate values.</p><p><b>For the 4-site method, the sites are the same for men ";
strForm += "and women: Abdomen, Suprailiac, Triceps, and Thigh.</b><br>For the 3-site method, use this guide:<br>";
strForm += "<b>Male 3-site: Chest, Abdomen, Thigh.</b><br>";
strForm += "<b>Female 3-site: Triceps, Abdomen, Suprailiac.</b></p>";
strForm += "<p><b>NOTE:</b> When taking your actual measurements, you should stand ";
strForm += "relaxed with your arms hanging comfortably by your sides - do <i>not</i> flex!";
strForm += "When taking the thigh measurement, keep both feet on the ground, but shift ";
strForm += "your weight to the leg that you are <i>not</i> measuring.</p>";
strForm += "<table border=\"0\" width=\"400\" align=\"center\">"; 
strForm += "<tr valign=\"top\" bgcolor=\"#e0e0e0\"><td align=\"right\"><div style=\"font-size: 11px;\"><b>Chest</b>: a diagonal fold taken midway between the nipple and the crease of the under arm</div></td><td><input size=\"5\" type=\"text\" id=\"ppChest\" name=\"ppChest\" value=\"0\">mm</td></tr>";
strForm += "<tr valign=\"top\"><td align=\"right\"><div style=\"font-size: 11px;\"><b>Suprailiac</b>: a diagonal fold";
strForm += "		taken midway between the hip joint and the bottom of the rib cage. Hint: place forefinger on";
strForm += "		hip bone, thumb at the bottom of the rib cage, then draw fingers together to the mid-point";
strForm += "		and pinch for suprailiac</div></td><td><input size=\"5\" type=\"text\" id=\"ppSupra\" name=\"ppSupra\""; 
strForm += "		value=\"0\">mm</td></tr>";
strForm += "<tr valign=\"top\" bgcolor=\"#e0e0e0\"><td align=\"right\"><div style=\"font-size: 11px;\"><b>Abdomen</b>: a vertical fold taken one inch to the";
strForm += "    side of the umbilicus (belly button)</div></td>";
strForm += "		<td><input size=\"5\" type=\"text\" id=\"ppAb\" name=\"ppAb\" value=\"0\">mm</td></tr>";
strForm += "<tr valign=\"top\"><td align=\"right\"><div style=\"font-size: 11px;\"><b>Thigh</b>: a vertical fold taken halfway between the knee"; 
strForm += " joint and the hip joint</div>";
strForm += "</td><td><input size=\"5\" type=\"text\" id=\"ppThigh\" name=\"ppThigh\" value=\"0\">mm</td></tr>"; 
strForm += "<tr valign=\"top\" bgcolor=\"#e0e0e0\"><td align=\"right\"><div style=\"font-size: 11px;\"><b>Triceps</b>: a vertical fold taken halfway between the";
strForm += " elbow joint and the shoulder joint</div></td><td><input size=\"5\" type=\"text\" id=\"ppTriceps\" name=\"ppTriceps\"";
strForm += " value=\"0\">mm</td></tr></table>";
strForm += "<table align=center>";
strForm += "<tr valign=\"top\"><td align=\"right\"><b>Gender:</b></td><td align=\"right\"><b>Weight:</b></td><td><input size=\"5\" type=\"text\" id=\"ppWeight\""; 
strForm += " name=\"ppWeight\" value=\"150\">lbs</td></tr>";
strForm += " <tr><td align=\"right\">";
strForm += " <select id=\"ppGender\" name=\"ppGender\">";
strForm += " <option id=\"male\"  value=\"0\">Male</option>";
strForm += " <option id=\"female\" value=\"1\">Female</option>";
strForm += " </select></td><td align=\"right\"><b>Age:</b></td><td><input size=\"5\" type=\"text\" id=\"ppAge\" name=\"ppAge\"";
strForm += "   value=\"25\">yrs</td></tr>";
strForm += "<tr><td colspan=\"3\" align=\"center\"><input type=\"button\" onClick=\"funcCalcBF(this.form);\" value=\"CALCULATE\"></td></tr>";
strForm += "<tr><td align=\"center\">Body fat:</td><td align=\"center\">Fat weight:</td><td align=\"center\">Lean weight:</td></tr>";
strForm += "<tr><td align=\"center\"><input type=\"text\" size=\"8\" id=\"ppBodyfat\" name=\"ppBodyfat\" value=\"???\">%</td>";
strForm += "<td align=\"center\"><input type=\"text\" size=\"5\" id=\"ppFat\" name=\"ppFat\" value=\"???\">lbs</td>";
strForm += "<td align=\"center\"><input type=\"text\" size=\"5\" id=\"ppLean\" name=\"ppLean\" value=\"???\">lbs</td>";
strForm += "</tr>";
strForm += " </table></form>";
strForm += "<font face=arial size=1>Courtesy of <a href=\"http://www.naturalphysiques.com\" target=\"_blank\">NaturalPhysiques.com</a> &copy; 2004 Golden Summit, Inc.</font></div>";
document.getElementById("npForm").innerHTML = strForm; 

}

genForm(); 


