function Food(id,cat_id,name,image,desc,size,cal,pro,carbo,fibers,tfat,sfat,cholesterol,sodium){
	var id=id;
	var category_id=cat_id;
	var option_name=name;
	var option_image=image;
	var option_desc=desc;
	var serving_size=size;
	var calories=cal;
	var protein=pro;
	var carbohydrates=carbo;
	var dietary_fibers=fibers;
	var total_fat=tfat;
	var saturated_fat=sfat;
	var cholesterol=cholesterol;
	var sodium=sodium;
	
	this.getID=function(){ return id;}
	this.getCatID=function(){ return category_id;}
	this.getName=function(){ return option_name;}
	this.getImage=function(){ return option_image;}
	this.getDesc=function(){ return option_desc;}
	this.getSize=function(){ return serving_size;}
	this.getCalories=function(){ return calories;}
	this.getProtein=function(){ return protein;}
	this.getCarbohydrate=function(){ return carbohydrates;}
	this.getFibers=function(){ return dietary_fibers;}
	this.getTFat=function(){ return total_fat;}
	this.getSFat=function(){ return saturated_fat;}
	this.getCholesterol=function(){ return cholesterol;}
	this.getSodium=function(){ return sodium;}
}


function Bowl(){
	var foods=new Array();
	var selectedCatIds;
	var selectedFoodIds;

	this.getFoodsByCategory=function(categoryId){
		var tempArray=new Array();
		for(var i=0;i<foods.length;i++){
			if(categoryId==foods[i].getID()){
				tempArray.push(foods[i]);
			}
		}
		if(tempArray.length>0){
			return tempArray.join(",");
		}
	}
	
	this.displaySummary=function(){
		
	}

	this.addFood=function(food){
		foods.push(food);
		this.updateFoods();
		this.updateNutri();
	}
	
	this.removeFood=function(ind){
		foods.splice(ind,1);
		this.updateFoods();
		this.updateNutri();
		if(this.selectedCatIds){
			submitFoods(this.selectedCatIds);
		}
	}
	
	this.updateFoods=function(){
		var str="";
		selectedFoodIds=new Array();
		for(var i=0;i<foods.length;i++){
			str=str+foods[i].getName()+" - <i><a href='javascript:removeFood("+i+")'>remove</a></i><br />";
			selectedFoodIds.push(foods[i].getCatID()+"~#~"+foods[i].getID());
		}
		//document.getElementById("selectedFoods").value=selectedFoodIds.join(",");
		document.getElementById("AddedFoods").innerHTML=str;
	}
	
	this.submitFoods=function(cat){
		this.selectedCatIds=cat;
		var categories=cat.split(",");
		var str="";
		str='<img src="imgs/hdr_summary.gif" width="480" height="62"><br />';
		for(var i=0;i<categories.length;i++){
			str=str+'<img src="imgs/step'+categories[i]+'_hdr_b.gif" width="480" height="62"><br>';
			
			str=str+"<table width='100%' border=0 cellpadding=0 margin=0>";
			for(var j=0;j<foods.length;j++){
				if(foods[j].getCatID()==categories[i]){
					str=str+"<tr><td width='10%'>&nbsp;</td>";
					str=str+"<td width='45%' style='face:Gotham, Tahoma, Helvetica, Arial; font-size:12px;'>"+foods[j].getName()+"</td><td width='45%' style='face:Gotham, Tahoma, Tahoma, Helvetica, Arial; font-size:12px;'>"+foods[j].getDesc()+"</td></tr>";	
				}
			}
			str=str+"</table>";
		}
		
		var strPrint="";

		
		//alert(strPrint);
		str=str+"<div style='text-align:right;width:100%'>";
		str=str+"<a href='#' onClick='javascript:printBowl();'><img src=imgs/btn_print_mybowls.gif border=0 /></a><br />";
		str=str+"<a href='#' onClick='javascript:emailBowl();'><img src=imgs/btn_email_mybowls.gif border=0 /></a><br />";
str=str+"</div>";
//str=str+"<a href='#' onClick='javascript:saveBowl();'><img src=imgs/btn_add_mybowls.gif border=0 /></a></div>";
		
		//document.write(strPrint);
		
		document.getElementById("Accordion").style.display='none';
		document.getElementById("summary").innerHTML=str;
		document.getElementById("finishBowl").style.display='none';
		
		//document.getElementById("printBowl").style.display='block';
		
		if(foods.length==0){
			document.getElementById("Accordion").style.display='block';
			document.getElementById("summary").innerHTML="";
			document.getElementById("finishBowl").style.display='block';
		}
	}
	
	this.printBowl=function(){
		strPrint="<html><head><title>Genghis Bowl</title>";
		str=strPrint+="<script>function Print(){alert('printing');document.body.offsetHeight;window.print();}</script></head>";		
		str=strPrint+="<body style='font-family:Gotham, Tahoma, Helvetica, Arial;' onload=\"javascript:Print();\" >";
		strPrint=strPrint+'<img src=imgs/hdr_summary.gif width=480 height=62><br />';
		
		for(var i=1;i<=5;i++){
			strPrint=strPrint+'<img src=imgs/step'+(i)+'_hdr_b.gif width=480 height=62><br>';			
			strPrint=strPrint+'<table width=480 border=0 cellpadding=0 margin=0>';
			for(var j=0;j<foods.length;j++){
				if(foods[j].getCatID()==i){
					strPrint=strPrint+"<tr><td width='10%'>&nbsp;</td>";
					strPrint=strPrint+"<td width='45%' style='font-size:12px; font-family:Gotham, Tahoma, Tahoma, Helvetica, Arial;'>"+foods[j].getName()+"</td><td width='45%' style='font-size:12px;'>"+foods[j].getDesc()+"</td></tr>";	
				}
			}
			
			strPrint=strPrint+"</table>";
		}
		
		strPrint=strPrint+"<div style='margin-left:25px;'><br/><font size='4' face='Gotham, Tahoma, Helvetica, Arial'><b>Nutritional Facts:</b></font><font size='2' face='Gotham, Tahoma, Tahoma, Helvetica, Arial' color='#000'><br/><br/>"+document.getElementById("Nutri").innerHTML+"</font></div><div align='center'> <form> <input type='button' value='Print' onClick='window.print()'></form></div></body></html>";
		var defaultWidth=430;
		var defaultHeight=600;
		var PositionX=100;
		var PositionY=100;
		var imgWin = window.open('','_blank');//,'width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
		imgWin.document.write(strPrint);
		imgWin.focus();
	}
	
	this.emailBowl=function(){
		var strPrint="";
		strPrint=strPrint+'<img src=http://www.idealgrowthclients.com/genghis/imgs/hdr_summary.gif width=480 height=62><br />';
		
		for(var i=1;i<=5;i++){
			strPrint=strPrint+'<img src=http://www.idealgrowthclients.com/genghis/imgs/step'+(i)+'_hdr_b.gif width=480 height=62><br>';			
			strPrint=strPrint+'<table width=480 border=0 cellpadding=0 margin=0>';
			for(var j=0;j<foods.length;j++){
				if(foods[j].getCatID()==i){
					strPrint=strPrint+"<tr><td width='10%'>&nbsp;</td>";
					strPrint=strPrint+"<td width='45%' style='font-size:12px;'>"+foods[j].getName()+"</td><td width='45%' style='font-size:12px;'>"+foods[j].getDesc()+"</td></tr>";	
				}
			}
			strPrint=strPrint+"</table>";
		}
		strPrint=strPrint+"<div style='margin-left:25px;'><br/><font size='4'><b>Nutritional Facts:</b></font><font size='2' color='#000' face='Gotham, Tahoma, Tahoma, Helvetica, Arial'><br/><br/>"+document.getElementById("Nutri").innerHTML+"</font></div>";
		var str="<form method='post' action='email_bowl2.php' id='frmBowlEmail' name='frmBowlEmail' target='_blank'>";		
		str=str+"<textarea name='message'>"+strPrint+"</textarea>";
		str=str+"</form>";
		document.getElementById("emailBowl").innerHTML=str;
		document.frmBowlEmail.submit();
	}
	
	this.saveBowl=function(){
		//alert("saving bowl now...");
		var ids=selectedFoodIds.join(",");
		str="<form method='post' action='saveBowl.php' id='frmBowlSubmit' name='frmBowlSubmit'>";
		str=str+"<input type='hidden' name='selectedFoodIds' value='"+ids+"' />";
		str=str+"</form>";
		document.getElementById("submitBowl").innerHTML=str;
		document.frmBowlSubmit.submit();
	}
	
	this.updateNutri=function(){
		
		var str="";
		var cal=0;
		var pro=0;
		var carbo=0;
		var fibers=0;
		var tfat=0;
		var sfat=0;
		var cholesterol=0;
		var sodium=0;
		
		for(var i=0;i<foods.length;i++){
			cal+=Number(foods[i].getCalories());
			pro+=Number(foods[i].getProtein());
			carbo+=Number(foods[i].getCarbohydrate());
			fibers+=Number(foods[i].getFibers());
			tfat+=Number(foods[i].getTFat());
			sfat+=Number(foods[i].getSFat());
			cholesterol+=Number(foods[i].getCholesterol());
			sodium+=Number(foods[i].getSodium());

}
		str=str+"Calories:         "+Math.round(cal*100)/100+"<br />";
		str=str+"Protein (g):"+Math.round(pro*100)/100+"<br />";
		str=str+"Carbohydrates (g):"+Math.round(carbo*100)/100+"<br />";
		str=str+"Dietary Fiber (g):"+Math.round(fibers*100)/100+"<br />";
		str=str+"Total Fat (g):"+Math.round(tfat*100)/100+"<br />";
		str=str+"Saturated Fat (g):"+Math.round(sfat*100)/100+"<br />";
		str=str+"Cholesterol (mg):"+Math.round(cholesterol*100)/100+"<br />";
		str=str+"Sodium (mg):"+Math.round(sodium*100)/100+"<br />";
		document.getElementById("Nutri").innerHTML=str;
	}
}

var fs=new Array();

var b=new Bowl();

function removeFood(ind){
	b.removeFood(ind);	
}
function addFood(id){
	var f=fs[id];
	b.addFood(f);
}

function submitFoods(categories){
	b.submitFoods(categories);
}
function saveBowl(){
	b.saveBowl();
}

function printBowl(){
	b.printBowl();	
}

function emailBowl(){
	b.emailBowl();	
}
