function showimage(theNewPictureName,thePictureObject)
{
	
	document.images.pictures.src=theNewPictureName;	
	var theParagraph = document.getElementById('left_writeup');
	theParagraph.innerHTML= 'DFdfdfdfdf';
	return;
	
}

//grab all the dropdown values, pull their values from the array
function updateForm() {
	
	// assuming variables on the page are named the same 'entree_writeup' this method will
	// update it.
	updateAMeal('entree');
	updateAMeal('sidedish');
	updateAMeal('veggies');
	
	//add up the nutrition stuff
	var this_select = document.getElementById('entree_select');
	theEntreeMeal = mealObjects[this_select.value];
	
	var this_select = document.getElementById('sidedish_select');
	theSideMeal = mealObjects[this_select.value];
	
	var this_select = document.getElementById('veggies_select');
	theVeggieMeal = mealObjects[this_select.value];
	
	if(parseInt(theEntreeMeal.calories) >0) {
		
		var theOutput = 'Calories ' + (parseInt(theEntreeMeal.calories) + parseInt(theSideMeal.calories) + parseInt(theVeggieMeal.calories));
		var theOutput = theOutput + '' + theEntreeMeal.calories_units;
	
		var theOutput = theOutput  + ' / Protein ' +  (parseInt(theEntreeMeal.protein) + parseInt(theSideMeal.protein) + parseInt(theVeggieMeal.protein));
		var theOutput = theOutput + '' + theEntreeMeal.protein_units;
	
		var theOutput = theOutput  + ' / Carbohydrates ' + (parseInt(theEntreeMeal.carbohydrates) + parseInt(theSideMeal.carbohydrates) + parseInt(theVeggieMeal.carbohydrates));
		var theOutput = theOutput + '' + theEntreeMeal.carbohydrates_units;
	
		var theOutput = theOutput  + ' / Fat ' + (parseInt(theEntreeMeal.fat) + parseInt(theSideMeal.fat) + parseInt(theVeggieMeal.fat));
		var theOutput = theOutput + '' + theEntreeMeal.fat_units;
	
		var this_select = document.getElementById('diabetic_add_message');
		this_select.innerHTML = theOutput;
	}
	
}

function updateAMeal(aMealPane) {
	//update a pane of info, entree sidedish or veggie
	//expects document emements with a convention like entree_select etc.
	
	var this_select = document.getElementById(aMealPane+'_select');
	theMeal = mealObjects[this_select.value];
	

	//var this_top_title = document.getElementById(aMealPane+'_top_title');
	//this_top_title.innerHTML = theMeal.title;

	var this_title = document.getElementById(aMealPane+'_title');
	this_title.innerHTML = theMeal.title;
	var this_writeup = document.getElementById(aMealPane+'_writeup');
	this_writeup.innerHTML = theMeal.write_up;	
	var this_meal_id = document.getElementById(aMealPane+'_meal_id');
	this_meal_id.innerHTML = theMeal.meal_id;	
	var this_price = document.getElementById(aMealPane+'_price');
	this_price.innerHTML = theMeal.price;
	var this_picture = document.getElementById(aMealPane+'_picture');
	this_picture.src = 'images/makeameal/'+theMeal.picture;
	var the_nutrition = document.getElementById(aMealPane+'_nutrition_info');
	if(the_nutrition) {
		the_nutrition.innerHTML = theMeal.nutrition;
	}
	
}


var mealObjects = new Array();

//a 'Class' which represents a meal
function Meal(	meal_id, 
				title,
				write_up,
				price,
				picture,
				nutrition,
				calories,
				protein,
				carbohydrates,
				fat,
				calories_units,
				protein_units,
				carbohydrates_units,
				fat_units) {
				
	this.meal_id = meal_id;
	this.title = title;
	this.write_up = write_up;
	this.price = price;
	this.picture = picture;
	this.getMealId = getMealId;
	this.nutrition = nutrition;
	this.calories = calories;
	this.protein = protein;
	this.carbohydrates = carbohydrates;
	this.fat = fat;
	this.calories_units = calories_units;
	this.protein_units = protein_units;
	this.carbohydrates_units = carbohydrates_units;
	this.fat_units = fat_units;
	
}

function getMealId() {
	with (this) return meal_id;
}

function getMealById(anId) {
	
	for(var x =0; x < mealObjects.length; x++) {
		
		//check for a match in ID
		myMeal = mealObjects[x];
		if(myMeal.getMealId(x) == anId) {
			return mealObjects[x];
		}
	}
	
}

function addMealObject(aMeal) {
	//concat new object to the end of the array based on its meal ID
	mealObjects[aMeal.meal_id] = aMeal;
}




