// Dessert Wizard
var notZeen = 1;

// construct an object of type Food
function Food(name, cal_per_g, dish, amtXSM, amtSM, amtMED, amtLG, amtXLG){
  // properties
  this.name = name;
  this.cal_per_g = cal_per_g;
  this.dish = dish;
  this.ozXSmall = amtXSM;
  this.ozSmall = amtSM;
  this.ozMedium = amtMED;
  this.ozLarge = amtLG;
  this.ozXLarge = amtXLG;
  // methods:
  this.getFoodArray = BuildFoodArray;
}

// 'cause this is a method of Food obj. "this" refers to Food
function BuildFoodArray () {
    // 1 oz =  28.34952g
    var FoodInfo = new Array(
    "('Tiny ("+this.ozXSmall+" oz.) "+this.dish+"','"+Math.round((this.ozXSmall * 28.34952) * this.cal_per_g)+"')",
    "('Small ("+this.ozSmall+" oz.) "+this.dish+"','"+Math.round((this.ozSmall * 28.34952) * this.cal_per_g)+"')",
    "('Medium ("+this.ozMedium+" oz.) "+this.dish+"','"+Math.round((this.ozMedium * 28.34952) * this.cal_per_g)+"')",
    "('Large ("+this.ozLarge+" oz.) "+this.dish+"','"+Math.round((this.ozLarge * 28.34952) * this.cal_per_g)+"')",
    "('Giant ("+this.ozXLarge+" oz.) "+this.dish+"','"+Math.round((this.ozXLarge * 28.34952) * this.cal_per_g)+"')"
    );
    return FoodInfo;
}

// build the object
//  Food Name                       Name               kcal/g   service   xsml sml  med  lrg   xlrg
var Jello               = new Food("Jello",              .97,   "cube",   "3", "6", "8", "12", "32");
//var Cheesecake          = new Food("Cheesecake",        3.57,   "piece",  "3", "5", "7",  "9", "14");
var Angel_Food_Cake     = new Food("Angel Food Cake",   2.58,   "slice",  "2", "6", "9", "12", "24");
var Apple_Crisp         = new Food("Apple Crisp",       1.63,   "bowl",   "2", "6", "9", "12", "24");
var Banana_Split        = new Food("Banana Split",      4.05,   "bowl",   "2", "6", "9", "12", "24");
var Bread_Pudding       = new Food("Bread Pudding",     1.68,   "bowl",   "2", "6", "9", "12", "24");
var Brownies            = new Food("Brownies",          4.05,   "brownie","2", "6", "9", "12", "24");
var Cheesecake          = new Food("Cheesecake",        3.21,   "slice",  "2", "6", "9", "12", "24");
var Chocolate_Cake      = new Food("Chocolate Cake",    3.67,   "piece",  "2", "6", "9", "12", "24");
var Chocolate_Mousse    = new Food("Chocolate Mousse",  2.21,   "bowl",   "2", "6", "9", "12", "24");
var Coffee_Cakes        = new Food("Coffee Cakes",      0.18,   "piece",  "2", "6", "9", "12", "24");
var Cream_Pie           = new Food("Cream Pie",         2.52,   "slice",  "2", "6", "9", "12", "24");
var Flan                = new Food("Flan",              1.44,   "bowl",   "2", "6", "9", "12", "24");
var FruitPie_apple      = new Food("Fruit Pie, apple",  2.37,   "slice",  "2", "6", "9", "12", "24");
var FruitPie_blueberry  = new Food("Fruit Pie, blueberry",2.32, "slice",  "2", "6", "9", "12", "24");
var FruitPie_cherry     = new Food("Fruit Pie, cherry", 2.6,    "slice",  "2", "6", "9", "12", "24");
var Pie_lemon_meringue  = new Food("Lemon meringue pie",2.68,   "slice",  "2", "6", "9", "12", "24");
var Fruit_Salad         = new Food("Fruit Salad",       0.3,    "bowl",   "2", "6", "9", "12", "24");
var Glazed_Pears        = new Food("Glazed Pears",      0.47,   "bowl",   "2", "6", "9", "12", "24");
var Gummy_Bears         = new Food("Gummy Bears",       1.82,   "amount", "2", "6", "9", "12", "24");
var Ice_Cream           = new Food("Ice Cream",         2.41,   "bowl",   "2", "6", "9", "12", "24");
var Ice_Cream_Sundae    = new Food("Ice Cream Sundae",  5.94,   "bowl",   "2", "6", "9", "12", "24");
var Truffles            = new Food("Truffles",          4.88,   "amount", "2", "6", "9", "12", "24");


function populateAmt(whichFood, obj) {
  if (navigator.appVersion.indexOf('MSIE 3') == -1) {

    var callerForm = obj.form;
    var whichItemSelected = callerForm.Lvl2.selectedIndex;

    if (!whichFood) { // in case they select "- Select... - "
	while (callerForm.Lvl2.options.length > 0) {
            callerForm.Lvl2.options[0] = null;
    	}
        callerForm.Lvl2.options[0]=new Option("------------------------------");
        return;
    }

    // Call up the food object
    var TheArray = eval(whichFood+".getFoodArray();");

    // get rid of the, now unneeded, elements in the options
    while (TheArray.length < callerForm.Lvl2.options.length) {
  	obj.form.Lvl2.options[(callerForm.Lvl2.options.length - 1)] = null;
    }

    // Populate the option with new values
    for (var i=0; i < TheArray.length; i++) {
  	eval("callerForm.Lvl2.options[i]=new Option" + TheArray[i]);
    }

    // Now be sure to select the previous selection
    callerForm.Lvl2.options[whichItemSelected].selected = true;

    notZeen = 0;
  } else { // you are in IE 3
    if (!whichFood) {return;} // in case they select "- Select... - "

    var callerForm = obj.form;
    var whichItemSelected = callerForm.Lvl2.selectedIndex;
    // Call up the food object
    var TheArray = eval(whichFood+".getFoodArray();");

    notZeen = 0;
  }
}

function calculateIt(obj) {
  var hour = 0;
  var callerForm    = obj.form;
  var amountOfCals  = callerForm.Lvl2.options[callerForm.Lvl2.selectedIndex].value;

  //RamaaCode: BUGno40691
  //gets rid of the NaN value in the results field(Netscape error)
  
  if(amountOfCals > 0) ; //continue
  else
  {
    // set to 0 and return
     callerForm.answertime.value = '0:00';
     return;
   }

  var activityBurn  = callerForm.activity.options[callerForm.activity.selectedIndex].value;

  var timeToBurn = Math.round(amountOfCals / activityBurn);

  while (timeToBurn >= 60) {
      timeToBurn = timeToBurn - 60;
      hour++;
  }

  timeToBurn+='';
  if(timeToBurn.length<2) timeToBurn='0'+timeToBurn;
  callerForm.answertime.value=hour+':'+timeToBurn;
}
// end Dessert Wizard
