var food_names = new Array("Banana","Burrito, Chicken","Burrito, Veggie","Cheeseburger","Cracker and Cheese","French Fries","Hot Dog","Pasta and Sauce","Pizza, 1 slice","Salad, Chicken Caesar","Salad, Cobb","Salad, Garden","Salad, Greek","Sandwich, Ham","Sandwich, Pulled Pork","Sandwich, Tuna","Sandwich, Turkey","Soup, Clam Chowder","Soup, Veggie Chili","Steak","Sub, Cheesesteak","Sub, Italian ","Sushi","Taco, Steak ","Taco, Veggie","---","Beer","Coffee, black","Coke","Hard Liqour","Milk, 1%","Orange Juice","Tea","Wine","---","Bagel + Cream Cheese","Cereal + Milk","Pancakes (3)","---","Apple Pie","Brownie","Cake","Cheesecake","Cookie, Choc Chip  ","Cookie, Oreo","Cupcake","Ice Cream");
var food_values = new Array("105","1030","970","400","70","500","365","428","290","621","708","35","517","520","640","540","690","660","225","300","740","720","240","303","287","0","145","2","150","97","102","95","2","95","0","330","240","400","0","410","112","235","257","120","55","250","282");
var activity_names = new Array("Rock Climbing","Kickboxing","Running","Swimming","Elliptical Trainer","Stair Running","Basketball","Bicycling","Football","Hockey","Aerobics","Bicycling Stationery","Soccer","Tennis","Hiking","Stair Step Machine","Golf","Softball","Walking","Tai Chi","Yoga","Bowling","Frisbee","Cooking","Desk Work","Standing in line","Reading","Watching TV","Sleeping");
var activity_names_verb = new Array("of Rock Climbing","of Kickboxing","of Running","of Swimming","on the Elliptical Trainer","of Stair Running","playing Basketball","of Bicycling","playing Football","playing Hockey","of Aerobics","on the stationary bike","playing Soccer","playing Tennis","Hiking","on the Stair Step Machine","playing Golf","playing Softball","of Walking","doing Tai Chi","doing Yoga","Bowling","playing Frisbee","of Cooking","doing Desk Work","of Standing in line","of Reading","of Watching TV","of Sleeping");
var activity_values = new Array(0.0829, 0.08, 0.08, 0.08, 0.072, 0.07, 0.064, 0.064, 0.064, 0.064, 0.056, 0.056, 0.056, 0.056, 0.048, 0.048, 0.044, 0.04, 0.036, 0.032, 0.032, 0.024, 0.024, 0.02, 0.012533333, 0.010133333, 0.009066667, 0.006133333, 0.005066667); // Calories multiplier for each of the above activities. This number times user's weight equals calories per minute of that activity.
// Function: load()
// Called by HTML body element's onload event when the web application is ready to start
//
function load()
{
  	window.scrollTo(0, 1);
    food_drop_down = document.getElementById("foods_id");
	activity_drop_down = document.getElementById("activities_id");
	weight_input = document.getElementById("weight_id");
	calculate_button = document.getElementById("calculate_id");
	for(i=0 ; i<food_names.length ; i++) {
	  addOption(food_drop_down,food_names[i],food_values[i]);
	}
	populate_activities();
	
}

function populate_activities() {
	for(i=0 ; i<activity_names.length ; i++) {
    	addOption(activity_drop_down,activity_names[i],activity_values[i]);
	}
}
function addOption(selectbox,text,value )
{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		selectbox.options.add(optn);
}
function calculate_values(event)
{
		food_drop_down = document.getElementById("foods_id");	
		activity_drop_down = document.getElementById("activities_id");   
		weight_input = document.getElementById("weight_id");
		units_kgs = document.getElementById("kgs_id")
		result_hours = document.getElementById("result_hours");
		result_minutes = document.getElementById("result_minutes");
		caption_hours = document.getElementById("caption_hours");
    	food_title = document.getElementById("food_title");
		more_info = document.getElementById("more_info");
		if(Number(weight_input.value)==0) {
			alert("Please enter your weight"); 
		} else if(String(Number(weight_input.value))=="NaN") {
			alert("Please enter a number for your weight");
		} else {
			if(units_kgs.checked) {
				// Convert kgs to lbs
				weight_in_lbs=weight_input.value*2.20462262;	
			} else {
				weight_in_lbs=weight_input.value;
			}
	 	food_name = food_names[food_drop_down.selectedIndex];
		activity_name = activity_names_verb[activity_drop_down.selectedIndex];
		
		
	  	var total_minutes = (food_drop_down.value/(activity_drop_down.value*weight_in_lbs)).toFixed(0);
		var hours = Math.floor(total_minutes/60);
		var minutes = total_minutes % 60;
		
		
		
		food_title.innerHTML = food_name;
	  	
		if(hours>1) {
			more_info.innerHTML = food_drop_down.value+" calories = "+hours+" hrs "+minutes+" mins <br />" +activity_name.toLowerCase();
			result_hours.style.display = 'block';
			caption_hours.style.display = 'block';
		} else {
			result_hours.style.display = 'none';
			caption_hours.style.display = 'none';
			more_info.innerHTML = food_drop_down.value+" calories = "+minutes+" mins <br />" +activity_name.toLowerCase();
		}
		
		
		result_minutes.innerHTML = minutes;
		result_hours.innerHTML = hours;
    }
    weight_input.blur();
}
function clear_input(input_box) {
  if(input_box.value == "150") {
		input_box.value = "";
	}
}




