function impl(pdescr,pminval,pmaxval)
{
	this.descr=pdescr;
	this.minval=pminval;
	this.maxval=pmaxval;
}

function custLog(x,base) {
	// Created 1997 by Brian Risk.  http://members.aol.com/brianrisk
	return (Math.log(x))/(Math.log(base));
}

function bodyfatanalyzer() {

//	alert("fat");
	//FOR MAN
	var h=document.getElementsByName("height")[0].value;
	var w=document.getElementsByName("waist")[0].value;
	var n=document.getElementsByName("neck")[0].value;
	var hips=document.getElementsByName("hips")[0].value;
	var bbbodyfat=0.0;
	var implicationsmen = new Array();
	implicationsmen.push(new impl("%, which shows you are in the acceptable range, but still have a good amount of excess fat to lose in order to reach the fitness or better levels.  For example, if you currently weigh 200 pounds with 20% body fat, you have about 40 pounds of fat on you.  To reach the point where you can clearly see six pack abs and a defined body, you would most likely need to lower your fat percentage to around 10%.  This would mean a fat loss of 20 pounds.  Rather than just focusing on weight loss, the fastest and most permanent way to do this would be to use the Fat Burning Furnace techniques to add 10 or more pounds of lean muscle to your body, while causing 10 or more pounds of fat loss.  Now you could potentially weigh close the same amount, but your body will be made up of just 10 pounds of fat and you've effectively cut your body fat percentage in half!",18,24)); //between 18 and 24 insert message here
	implicationsmen.push(new impl("%, which shows you are in the obese range and need to get started reducing your body fat as soon as possible (not only for appearance issues, but more importantly for your health). For example, if you currently weigh 250 pounds with 28% body fat, you have about 70 pounds of fat on you.  To reach the point where you can clearly see six pack abs and a defined body, you would most likely need to lower your fat percentage to around 10%.  This would mean a fat loss of 45 pounds.  Rather than just focusing on weight loss, the fastest and most permanent way to do this would be to use the Fat Burning Furnace techniques to add 15 or more pounds of lean muscle to your body, while causing 30 or more pounds of fat loss.  Now you could potentially weigh just 15 pounds less, but your body will be made up of just 25 pounds of fat and you've effectively cut your body fat by nearly 18%!",25,null));
	implicationsmen.push(new impl("%, which shows you are at least in the fitness range or better.  However, as with all methods of body fat testing, there is a chance for a few percent error in either direction.  This is important because it may mean that even though you have a fitness level or better reading from this analyzer, you would still do well to lower your body fat for maximum health and that lean fit look.",null,18));
	
	var implicationswomen = new Array();
	implicationswomen.push(new impl("%, which shows you are at least in the fitness range or better.  However, as with all methods of body fat testing, there is a chance for a few percent error in either direction.  This is important because it may mean that even though you have a fitness level or better reading from this analyzer, you would still do well to lower your body fat for maximum health and that lean fit look.",null,25));
	implicationswomen.push(new impl("%, which shows you are in the acceptable range, but still have a good amount of excess fat to lose in order to reach the fitness or better levels.  For example, if you currently weigh 150 pounds with 28% body fat, you have about 42 pounds of fat on you.  To reach the point where you can clearly see a tight belly, hips, thighs and a defined figure, you would most likely need to lower your fat percentage to around 18%.  This would mean a fat loss of 15 pounds.  Rather than just focusing on weight loss, the fastest and most permanent way to do this would be to use the Fat Burning Furnace techniques to add 5 or more pounds of lean and sexy muscle to your body, while causing 10 or more pounds of fat loss.  Now you could potentially weigh just 10 pounds less, but your body will be made up of just 27 pounds of fat and you've effectively cut your body fat percentage tremendously!",25,31));
	implicationswomen.push(new impl("%, which shows you are in the obese range and need to get started reducing your body fat as soon as possible (not only for appearance issues, but more importantly for your health). For example, if you currently weigh 200 pounds with 35% body fat, you have about 70 pounds of fat on you.  To reach the point where you can clearly see a tight belly, hips, thighs and a defined figure, you would most likely need to lower your fat percentage to around 18%.  This would mean a fat loss of 34 pounds.  Rather than just focusing on weight loss, the fastest and most permanent way to do this would be to use the Fat Burning Furnace techniques to add 10 or more pounds of lean muscle to your body, while causing 25 or more pounds of fat loss.  Now you could potentially weigh just 20 pounds less, but your body will be made up of just 36 pounds of fat and you've effectively cut your body fat in half!",32,null)); //above 32
	
	var pointertoarray;	
	
	if (document.getElementsByName("genre")[0].checked==true) {
		 bbbodyfat=(495/(1.0324-0.19077*(custLog(w*2.54-n*2.54,10))+0.15456*(custLog(h*2.54,10)))-450);
		pointertoarray = implicationsmen;

	}
	else {
		bbbodyfat=(495/(1.29579-0.35004*(custLog(w*2.54+hips*2.54-n*2.54,10))+0.221*(custLog(h*2.54,10)))-450);
		pointertoarray = implicationswomen;
	}
	
	bbbodyfat = roundNumber(bbbodyfat,2);
	document.getElementsByName("bodyfat")[0].value=bbbodyfat + " %";
	document.getElementsByName("implication")[0].value="";
	for (var ki=0;ki<pointertoarray.length;ki++) {
		if (pointertoarray[ki].minval!=null && pointertoarray[ki].maxval!=null && bbbodyfat >= pointertoarray[ki].minval && bbbodyfat <= pointertoarray[ki].maxval) {
			document.getElementsByName("implication")[0].value="Your body fat is between " + pointertoarray[ki].minval + " and " +  pointertoarray[ki].maxval;
			document.getElementsByName("implication")[0].value+=pointertoarray[ki].descr;
			break;
		}
		else if(pointertoarray[ki].minval==null && bbbodyfat <= pointertoarray[ki].maxval) {
			document.getElementsByName("implication")[0].value="Your body fat is lower than " + pointertoarray[ki].maxval;
			document.getElementsByName("implication")[0].value+=pointertoarray[ki].descr;
			break;
		}
		else if(pointertoarray[ki].maxval==null && bbbodyfat > pointertoarray[ki].minval){
			document.getElementsByName("implication")[0].value="Your body fat is above " + pointertoarray[ki].minval;
			document.getElementsByName("implication")[0].value+=pointertoarray[ki].descr;
			break;
		}
	}		
}

function metabolic_rate_calculator() {
	var h=document.getElementsByName("height")[0].value;
	var weight=document.getElementsByName("weight")[0].value;
	var age=document.getElementsByName("age")[0].value;
	var activitylevel=document.getElementsByName("activity")[0].value;

	if (document.getElementsByName("genre")[0].checked==true) {
//FOR MEN
		var metabolicrate=activitylevel*(66+(12.7*h)+(6.27*weight)-(6.8*age));
		var bodyfatloss1=metabolicrate-800;
		var bodyfatloss2=metabolicrate-500;
		
	}
	else {
		var metabolicrate=activitylevel*(655+(4.57*h)+(4.36*weight)-(4.7*age));
		var bodyfatloss1=metabolicrate-600;
		var bodyfatloss2=metabolicrate-400;
	}
	metabolicrate = roundNumber(metabolicrate,2);
	bodyfatloss1=roundNumber(bodyfatloss1,2);
	bodyfatloss2=roundNumber(bodyfatloss2,2);
	
	document.getElementsByName("metabolicrate")[0].value=metabolicrate;
	document.getElementsByName("bodyfatone")[0].value=bodyfatloss1;
	document.getElementsByName("bodyfattwo")[0].value=bodyfatloss2;
}

function togglegenre(g) {
	if (g.value=="woman") {
		document.getElementsByName("hips")[0].style.visibility="visible";
	}
	else {
		document.getElementsByName("hips")[0].style.visibility="hidden";
	}
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}