
//Javascript written by Veronica Noone
//Points and the points formula are owned by Weight Watchers 


function calculatePoints(fiber,cals,fat){
	var points;
	if (fiber > 4) {
		fiber=4;
	}
	points = (cals/50) + (fat/12) - (fiber/5);
	points = decimalRound(points, 1)
	//alert(points);
	document.getElementById('displayPoints').innerHTML=points;
}
function decimalRound(num, d) { 
//rounds to however many decimal places you want (d) got formula from a site (can't remeber URL)
   n = Math.pow(10, !d ? 2 : d);
   return Math.round(num*n) / n;
}


function calculateTargetPoints(type,age,weight,height,activity){
	
//function has an error if weight is below 100 - too lazy to fix right now.

	var points;
	var w; //need to account for under 100 pounds
	if (weight.length<3){
		w=parseInt(weight.substring(0,1));
	} else {
		w=parseInt(weight.substring(0,2));
	}
	points = parseInt(type)+parseInt(age)+w+parseInt(height)+parseInt(activity);
	
	//alert(points);
	if (points<18){
		points=18;
	}
	if (points>44){
		points=44;
	}

	//
	document.getElementById('displayTargetPoints').innerHTML=points;
}


