function calc_total(t){
var weight = parseInt(t.weight.value/2.2);
if (t.sex[0].checked) 
	var gender = "male";
else
	var gender = "female";
var veryLowActHours = t.veryLightActivity.value;
var lowActHours = t.lightActivity.value;
var modActHours = t.moderateActivity.value;
var heavyActHours = t.heavyActivity.value;
var sleepHours = t.hoursSleep.value;
var veryLowActCalories = 0;
var lowActCalories = 0;
var modActCalories = 0;
var heavyActCalories= 0;
var BMR = 0;
var totalHours = 0;
var totalCalories = 0;

switch (gender){
	case "male" :
		if ((weight>=55)&&(weight<=60))
		   BMR = weight * 27;
		else if ((weight>=61)&&(weight<=69))
		   BMR = weight * 26;
		else if ((weight>=70)&&(weight<=76))
		   BMR = weight * 25;
		else if ((weight>=77)&&(weight<=83))
		   BMR = weight * 24;
		else
		   BMR = weight * 23;
		 if (BMR > 2000)
		   	BMR = 2000;
		break;
	case "female" :
		if ((weight>=45)&&(weight<=50))
			BMR = weight * 28;
		else if ((weight>=51)&&(weight<=56))
		   BMR = weight * 27;
		else if ((weight>=57)&&(weight<=62))
			BMR = weight * 26;
		else if ((weight>=63)&&(weight<=68))
			BMR = weight * 25;
		else if ((weight>=69)&&(weight<=74))
			BMR = weight * 24;
		else
			BMR = weight * 23;
		  if (BMR > 1666)
		   	BMR = 1666;
		break;			
}

 
		if (gender == "male")
		   veryLowActCalories = veryLowActHours * 1.5 * weight;
		else
		   veryLowActCalories = veryLowActHours * 1.3 * weight;

		if (gender == "male")
		   lowActCalories = lowActHours * 2.9 * weight;
		else
		   lowActCalories = lowActHours* 2.6 * weight;

	 	if (gender == "male")
		   modActCalories = modActHours * 4.3 * weight;
		else
		   modActCalories = modActHours * 4.1 * weight;

		if (gender == "male")
		   heavyActCalories = heavyActHours * 8.4 * weight;
		else
		   heavyActCalories = heavyActHours * 8.0 * weight;
	
	totalHours = (veryLowActHours*1 + lowActHours*1 + modActHours*1 + heavyActHours*1 + sleepHours*1)


var e = .9 * BMR;
var e = e/24;
var e = e * sleepHours;
var f = 24 - (veryLowActHours*1 + sleepHours*1 + lowActHours*1 + modActHours*1 + heavyActHours*1 );
var f = f/24;
var f = f * BMR;
totalCalories = parseInt(e+f+veryLowActCalories+lowActCalories+modActCalories+heavyActCalories);

	   if (totalHours != 24)
	   		t.caloriesNeeded.value = "ERROR Activity Hours Must Total Up To 24. Current Hours = " + totalHours;
		else if (gender == "male")
			if (totalCalories > 4400)
				t.caloriesNeeded.value = "4400  daily calories expended through activity and metabolism";
			else							
	   		t.caloriesNeeded.value = totalCalories + "   daily calories expended through activity and metabolism";
		else if (gender == "female")
			if (totalCalories > 3400)
				t.caloriesNeeded.value = "3400  daily calories expended through activity and metabolism";
			else
				t.caloriesNeeded.value = totalCalories + "   daily calories expended through activity and metabolism";
  return true;
}
