NutrientCounter is a quick and easy way to calculate menu-based calories and nutrients.
Copyright (C) 2005 Christopher Theberge

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Terms: The link to nafwa.org must remain in place.

Instructions:
1. I have copied and pasted much of the script where editing is needed here, but did not go through each page and leave markup-Sorry.
2. To edit the source code, open each of the menus in your browser and select View-Source. A notepad txt file should open with code that looks like the code in here. I pasted the code that you should be concerned with to edit here. The code in this doc is from calbreakfast.html, but the premise is the same for all files. 
3. This is the array for the foods: name = foodname, choper, protper, fatper, kcalper, namgper, and kmgper=carbohydrates, protein, fat, calories, sodium, and potassium per serving). Feel free to add more variables to calculate, just be sure to include them in the function food () and as variables. 

foodgroup = new Array;

function food(name,choper,protper,fatper,kcalper,namgper,kmgper)
{
   this.name=name;
   this.servings=0;
   this.choper=choper;
   this.protper=protper;
   this.fatper=fatper;
   this.kcalper=kcalper;
   this.namgper=namgper;
   this.kmgper=kmgper;
   this.cho=1;
   this.prot=0;
   this.fat=0;
   this.kcal=0;
   this.namg=0;
   this.kmg=0;
}

4. This is the array from above. Each food has a number 1-n. Looking at the variables above, you see we have (name, choper, protper, etc..) If you look at the array below for foodgroup[1], orange juice = name, 13 = choper serving, etc..) Here you can add all the foods that you want to and the other nutrients.

function setup()
{
// Breakfast Juices & Fruits

   foodgroup[1]=new food("Orange Juice",13,0.5,0.5,59,0,251);
   foodgroup[2]=new food("Apple Juice",15,0,0,59,0,125);
   foodgroup[3]=new food("Prune Juice",24,0,0,99,3,301);
   foodgroup[4]=new food("Grapefruit Juice",11,0,0,44,0,208);
   foodgroup[5]=new food("Cranberry Juice",19,0,0,76,0,15);
   foodgroup[6]=new food("Applesauce",11,0,0,44,2,78);
   foodgroup[7]=new food("Stewed Prunes",27,0,0,112,3,277);
   foodgroup[8]=new food("Apple",20,1,1,89,1,152);
   foodgroup[9]=new food("Banana",17,0,0,72,1,288);
   foodgroup[10]=new food("Orange (navel)",18,0,0,80,1,272);


5. Here is where you want to write your variables. If you add other things like say, copperper, be sure to write it below.

function adjust(x)
{
   foodgroup[x].servings=0;

   foodgroup[x].cho= foodgroup[x].servings*foodgroup[x].choper;
   foodgroup[x].prot=foodgroup[x].servings*foodgroup[x].protper;
   foodgroup[x].fat= foodgroup[x].servings*foodgroup[x].fatper;
   foodgroup[x].kcal=foodgroup[x].servings*foodgroup[x].kcalper;
   foodgroup[x].namg=foodgroup[x].servings*foodgroup[x].namgper;
   foodgroup[x].kmg= foodgroup[x].servings*foodgroup[x].kmgper;

   document.diet.name[x-1].value=foodgroup[x].name;
   document.diet.cho[x-1].value=foodgroup[x].cho;
   document.diet.prot[x-1].value=foodgroup[x].prot;
   document.diet.fat[x-1].value=foodgroup[x].fat;
   document.diet.kcal[x-1].value=foodgroup[x].kcal;
   document.diet.na[x-1].value=foodgroup[x].namg;
   document.diet.k[x-1].value=foodgroup[x].kmg;

}

6. Be sure to write the same here as above.

function adjust1(x)
{
   foodgroup[x].servings=document.diet.oneserving[x-1].value;

   foodgroup[x].cho= foodgroup[x].servings*foodgroup[x].choper;
   foodgroup[x].prot=foodgroup[x].servings*foodgroup[x].protper;
   foodgroup[x].fat= foodgroup[x].servings*foodgroup[x].fatper;
   foodgroup[x].kcal=foodgroup[x].servings*foodgroup[x].kcalper;
   foodgroup[x].namg=foodgroup[x].servings*foodgroup[x].namgper;
   foodgroup[x].kmg= foodgroup[x].servings*foodgroup[x].kmgper;

   document.diet.name[x-1].value=foodgroup[x].name;
   document.diet.cho[x-1].value=foodgroup[x].cho;
   document.diet.prot[x-1].value=foodgroup[x].prot;
   document.diet.fat[x-1].value=foodgroup[x].fat;
   document.diet.kcal[x-1].value=foodgroup[x].kcal;
   document.diet.na[x-1].value=foodgroup[x].namg;
   document.diet.k[x-1].value=foodgroup[x].kmg;
   findtotal();
}

7. Below, LastBreakFastNum is equal to the total number of foods you have.

function findtotal()
{
    brkcho=0;
    brkprot=0;
    brkfat=0;
    brkkcal=0;
    brkna=0;
    brkk=0;
    LastBreakFastNum = 10;

8. I broke this script up to write into different forms based on the type of foods. You will need to change 
(i=1;i<x;i++) based on how you decide to use this script. If you just want to include all foods to calculate, then (i=1;i<11;i++) would be what you would write (based on the example here). You have to write it as i is less than 1 number greater than the total number of foods you have.  

9. This script will calculate each meal separately, but if you click the links, it will add the totals into the next page. For example, breakfast totals will be put in the lunch totals and then as you add up lunch, it will add to that.

10. If you find this script useful, please provide a link to nafwa. <A HREF="http://www.nafwa.org" target="_blank" title="NAFWA.org">Form Provided By The Nutrition and Food Web Archive</A> 
