// Functions (Legacy) Copyright 2004-2008 Productive Solutions, LLC
var isIE, isIE6, isIE7, isIE8, isFF, isOpera, isSafari, isMozilla, isWin, isMac;
var BrowserName="Unknown Browser";

function getBrowser(){
   var brwsrnm="";
   var isIE=(navigator.appName.indexOf("Internet Explorer")!=-1); 
   if(isIE){brwsrnm=navigator.appName;}
   var IE=(isIE);
   var ie6=(isIE && (navigator.appVersion.indexOf("MSIE 6")!=-1));
   var isIE6=ie6;
   var ie7=(isIE && (navigator.appVersion.indexOf("MSIE 7")!=-1));
   var isIE7=ie7;
   var ie8=(isIE && (navigator.appVersion.indexOf("MSIE 8")!=-1));
   var isIE8=ie8;
   var isOpera=false, Opera=false; //Opera
   if(brwsrnm==""){
      isOpera=(navigator.userAgent.indexOf("Opera")!=-1);
      if(isOpera){brwsrnm="Opera "+navigator.appVersion;}
      Opera=(isOpera);
   }   
   var isFF=false, FF=false; //Firefox
   if(brwsrnm==""){
      isFF=(navigator.userAgent.indexOf("Firefox")!=-1);
      if(isFF){brwsrnm="Firefox";}
      FF=(isFF);
   }   
   var isChrome=false, CHROME=false; //chrome
   if(brwsrnm==""){
      isChrome=(navigator.userAgent.indexOf("Chrome")!=-1);
      if(isChrome){brwsrnm="Chrome";}
      CHROME=(isChrome);
   }      
   //Safari and Mac
   var isSafari=false, SAFARI=false, isMac=false, MAC=false; 
   if(brwsrnm==""){
      //alert("appName="+navigator.appName+"\n\n"+"appVersion="+navigator.appVersion+'\n\n'+"Platform="+navigator.platform);
      isSafari=(navigator.appVersion.toUpperCase().indexOf("SAFARI") >= 0);
      if(isSafari){brwsrnm="Safari";}
      SAFARI=(isSafari);
      if(navigator.platform.toUpperCase()=="WIN32" && brwsrnm != ""){brwsrnm += " - Windows";}
      isMac=(navigator.platform.toUpperCase().indexOf("MAC")>0 && brwsrnm != "");
      if(isMac){brwsrnm += " - Mac";}
   } 
   if(brwsrnm==""){
      isMac=(navigator.platform.toUpperCase().indexOf("MAC") >= 0);
      if(isMac){brwsrnm="Mac Web Browser";}
      MAC=(isMac);
   } 
   var isNN=false, N6=false, N4=false, NN4P=false, NN6=false; //Netscape Navigator
   if(brwsrnm==""){
      isNN=(navigator.appName.indexOf("Netscape")!=-1);
      if(isNN){brwsrnm=navigator.appName;}
      N6=(isNN);
      N4=(!N6 && !IE && !FF);
      NN4P=(isNN && (navigator.appVersion.charAt(0)=="4"));
      NN6=(isNN && (navigator.appVersion.charAt(0)=="5"));
   }
   var isMozilla=false;
   if(brwsrnm==""){
       isMozilla=(navigator.appCodeName.indexOf("Mozilla")!=-1);
       if(isMozilla){brwsrnm="Generic Mozilla Browser";}
   }    
   if(brwsrnm==""){brwsrnm="Unknown Web Browser";}
   // Browser Done
   return brwsrnm
}

BrowserName=getBrowser();
window.defaultStatus='Sodexo Nutrition Calculator';
// text vars for popupwindows
var oldtext="", oldtextcolor="", oldbgcolor="";
//Mouseover images
var n_inactive=new Image;
n_inactive.src="images/nutfacts1.gif";
var n_over=new Image;
n_over.src="images/nutfacts2.gif";
var n_down=new Image;
n_down.src="images/nutfacts3.gif";
var n_sel=new Image;
n_sel.src="images/nutfacts2.gif";
// Selection List Size Limiter is sel_limit. (The count of existing size is in variable aa)
var xmlhttp=null;
var sel_limit=100;
var loading=1;
var selecting=0;
var aa=0;
var aSL=new Array();
// Cumulative Totals variables
var ntCalories=0;
var ntCalFat=0;
var ntFat=0;
var ntSatFat=0;
var ntTransFat=0;
var ntChol=0;
var ntSodium=0;
var ntCarbo=0;
var ntDfib=0;
var ntSugars=0;
var ntProtein=0;
var ntVitA=0;
var ntVitC=0;
var ntCalcium=0;
var ntIron=0;
var cQuery="";
var p;
var pvis=0;
var WinIds=new Array();
var CurrentWin=0;
var MAX_WAIT = 20000; // 20 seconds
var curitem;
var xmlhttp;
var discltxt='The nutrient information displayed for Sodexo recipes represent the known amount of a ';
    discltxt=discltxt+'particular nutrient in a recipe.  The recipes were analyzed using the CBORD Database and ' ;
    discltxt=discltxt+'additional information from food manufacturers.  The data are averages only, and should ';
    discltxt=discltxt+'be used as a guide.<br />&nbsp;<br />';
//  discltxt=discltxt+'be used as a guide.<br />&nbsp;<br /></span>';
    discltxt=discltxt+'The nutrient values are for the edible portion of the recipe.  The nutrient information ';
    discltxt=discltxt+'displayed for each item is the result of its exact preparation as stated in the recipe.  ';
    discltxt=discltxt+'Any deviation from the recipe such as product substitutions or changes to portion yield ';
    discltxt=discltxt+'will render the information, inaccurate. (Recipes are modified on occasion to better meet ';
    discltxt=discltxt+'local preference in taste, or to accommodate a variety of preparation methods.) Although ';
    discltxt=discltxt+'we strive to make the information as accurate as possible, nutrition analysis is not an ';
    discltxt=discltxt+'exact science. Various factors including diet of an animal, and food processing methods ';
    discltxt=discltxt+'influence the amounts of nutrients in food. However, we hope this information will be useful ';
    discltxt=discltxt+'to you, and assist you in your desire to achieve good health through healthful eating.';
var dvtxt="";
var ffhelptxt='The size and spacing of the Nutrition Facts tables require the use of fonts in sizes smaller than ';
    ffhelptxt=ffhelptxt+'default Firefox settings allow. To address this, please select the following from the ';
    ffhelptxt=ffhelptxt+'menu in the Firefox window:<br />&nbsp;<br />';
    ffhelptxt=ffhelptxt+'<b>Tools > Options > Content tab > Advanced button > Minimim Font Size</b> (change to "None") ';
    ffhelptxt=ffhelptxt+'and also be sure that the checkbox next to "Allow Pages to choose their own font" is checked.';
    
// *******************************************************    
function startUp(){
   var itm = document.getElementById("Items"); 
   if(itm.options){
      while (itm.options.length>0){itm.options[0]=null;}
      clearItems();
      clearSelItems();
      document.getElementById("btnAdd").disabled=true;
      document.getElementById("btnDel").disabled=true;
      document.getElementById("btnClear").disabled=true;
      document.getElementById("btnPrint").disabled=true;
      document.getElementById("searchField").focus();
      loading=0;
      cQuery="";
   } 
   window.status='Sodexo Nutrition Calculator ('+BrowserName+')'; 
   window.defaultStatus='Sodexo Nutrition Calculator ('+BrowserName+')'; 
   return true;
}
// *******************************************************
function winOpen(url,name,parms) {
    var handle = window.open(url,name,parms);
    if (!handle.opener) handle.opener = self;
    return handle;
}
// *******************************************************
function closeAll() {
   for (i=0; i<WinIds.length; i++) {
      if (WinIds[i] && !WinIds[i].closed) WinIds[i].close();
   }
   return true;
}
// *******************************************************
function makeArray() {for(var i=0; i<makeArray.arguments.length; i++){this[i+1]=makeArray.arguments[i];}}
// *******************************************************
function showYear(){
  // for footer in form
  var Today=new Date();
  return " "+Today.getYear()+" ";
}
// *******************************************************
function showDate() {
   var Today = new Date();
   var months= new Array('January','February','March','April','May','June','July','August','September','October','November','December');
   var days  = new Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
   var dow   = Today.getDay();
   var day   = Today.getDate();
   var month = Today.getMonth();
   var yy    = Today.getYear();
   var year  = ((yy < 1000) ? yy + 1900 : yy) ;
   return months[month]+" "+day+", "+year;
}
// *******************************************************
function Allergic(cc) {
  if(cc==""){return "";}
  var cstr=new String("");
  if(cc.indexOf("M") > -1){cstr+="milk, ";}
  if(cc.indexOf("E") > -1){cstr+="eggs, ";}
  if(cc.indexOf("F") > -1){cstr+="fish, ";}
  if(cc.indexOf("S") > -1){cstr+="shellfish, ";}
  if(cc.indexOf("H") > -1){cstr+="wheat, ";}
  if(cc.indexOf("N") > -1){cstr+="peanuts, ";}
  if(cc.indexOf("T") > -1){cstr+="tree nuts, ";}
  if(cc.indexOf("B") > -1){cstr+="soy, ";}
  cc=null;
  return cstr.substring(0, cstr.length - 2);
}
// *******************************************************
function swapText(ss) {
   var hdr=document.getElementById("leftheader");
   if(ss=="" && pvis==1){
      hdr.style.color=oldtextcolor;
      hdr.style.backgroundColor=oldbgcolor;
      hdr.innerHTML=oldtext;
      oldtext="";
      oldtextcolor="";
      oldbgcolor="";
      pvis=0;
   }
   else {
      var txt='<table style="height:29px; font-name:Arial; font-size:7.5pt; vertical-align:middle;">';
          txt+='<tr style="vertical-align:middle;">';
          txt+='<td style="vertical-align:middle;">Search text: <b>'+ss+'</b></td></tr></table>'; 
      oldtext=hdr.innerHTML;
      oldtextcolor=hdr.style.color;
      oldbgcolor=hdr.style.backgroundColor;
      hdr.style.color="black";
      hdr.style.backgroundColor="yellow";
      hdr.innerHTML=txt;
      pvis=1;
   }
   return false;
} 
// *******************************************************
function clearItems() {
  document.getElementById("iFull_Desc").innerHTML="";
  document.getElementById("iServing").innerHTML="" ;
  document.getElementById("iCalories").innerHTML=0 ;
  document.getElementById("iCalFat").innerHTML=0;
  document.getElementById("iFat").innerHTML=0;
  document.getElementById("iFatPcnt").innerHTML=0;
  document.getElementById("iSatFat").innerHTML=0
  document.getElementById("iSatFatPcnt").innerHTML=0;
  document.getElementById("iTransFat").innerHTML=0
  document.getElementById("tditfat").innerHTML="g";  
  document.getElementById("iChol").innerHTML=0;
  document.getElementById("iCholPcnt").innerHTML=0;
  document.getElementById("iSodium").innerHTML=0;
  document.getElementById("iSodiumPcnt").innerHTML=0;
  document.getElementById("iCarbo").innerHTML=0;
  document.getElementById("iCarboPcnt").innerHTML=0;
  document.getElementById("iDfib").innerHTML=0;
  document.getElementById("iDfibPcnt").innerHTML=0;
  document.getElementById("iSugars").innerHTML=0; 
  document.getElementById("tdisug").innerHTML="g";
  document.getElementById("iProtein").innerHTML=0;
  document.getElementById("iVitAPcnt").innerHTML=0;
  document.getElementById("iVitCPcnt").innerHTML=0;
  document.getElementById("iCalciumPcnt").innerHTML=0;
  document.getElementById("iIronPcnt").innerHTML=0;
}
// *******************************************************
function keychk(e, keylookfor){
   var keynum = 0;
   if(!isnull(e.which)) keynum=e.which;
   if(!isnull(e.keyCode)) keynum=e.keyCode;
   return (keynum==keylookfor);
}
// *******************************************************
function insertBeforeSelected(){
var x=document.getElementById("mySelect");
if (x.selectedIndex>=0)
  {
  var y=document.createElement('option');
  y.text='Kiwi';
  var sel=x.options[x.selectedIndex];  
  try
    {
    x.add(y,sel); // standards compliant
    }
  catch(ex)
    {
    x.add(y,x.selectedIndex); // IE only
    }
  }
}
// *******************************************************
function clearSelItems() {
   ntCalories=0;
   ntCalFat=0;
   ntFat=0;
   ntSatFat=0;
   ntTransFat=0;
   ntChol=0;
   ntSodium=0;
   ntCarbo=0;
   ntDfib=0;
   ntSugars=0;
   ntProtein=0;
   ntVitA=0;
   ntVitC=0;
   ntCalcium=0;
   ntIron=0;
   var sitm = document.getElementById("SelItems");
   if (loading==0 && sitm.options && sitm.length>0){sitm.options.length=0;}
   document.getElementById("btnDel").disabled=true;
   document.getElementById("btnClear").disabled=true;
   document.getElementById("btnPrint").disabled=true;
   document.getElementById("tCalories").innerHTML=0;
   document.getElementById("tCalFat").innerHTML=0;
   document.getElementById("tFat").innerHTML=0;
   document.getElementById("tFatPcnt").innerHTML=0;
   document.getElementById("tSatFat").innerHTML=0;
   document.getElementById("tSatFatPcnt").innerHTML=0;
   document.getElementById("tTransFat").innerHTML=0;
   document.getElementById("tdttfat").innerHTML="g";
   document.getElementById("tChol").innerHTML=0;
   document.getElementById("tCholPcnt").innerHTML=0;
   document.getElementById("tSodium").innerHTML=0;
   document.getElementById("tSodiumPcnt").innerHTML=0;
   document.getElementById("tCarbo").innerHTML=0;
   document.getElementById("tCarboPcnt").innerHTML=0;
   document.getElementById("tDfib").innerHTML=0;
   document.getElementById("tDfibPcnt").innerHTML=0;
   document.getElementById("tSugars").innerHTML=0; 
   document.getElementById("tdtsug").innerHTML="g";
   document.getElementById("tProtein").innerHTML=0;
   document.getElementById("tVitAPcnt").innerHTML=0;
   document.getElementById("tVitCPcnt").innerHTML=0;
   document.getElementById("tCalciumPcnt").innerHTML=0;
   document.getElementById("tIronPcnt").innerHTML=0;
   nSL=0;
   aSL.length=0;
   aa=0;
   document.getElementById("selCount").innerHTML=aa;
   selecting=0;
}
// *******************************************************
function showTotals() {
   var nVar=ntCalories;
   if(nVar<5){nVar=0;}
   if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0) * 5;}
   if(nVar>50) {nVar=round(nVar/10,0)*10;}
   document.getElementById("tCalories").innerHTML="" + nVar;
   ntCalories=nVar;
   
   nVar=ntFat;
   if(nVar<.5){nVar=0;}
   if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
   if(nVar>5){nVar=round(nVar,0);}                 
   ntFat=nVar;
   if(nVar==.5){nVar=".5";}              
   document.getElementById("tFat").innerHTML="" + nVar;
   
   var ntFatP=round(nVar/65*100, 0);
   document.getElementById("tFatPcnt").innerHTML="" + ntFatP;
   
   ntCalFat=round(ntFat*9,1)
   nVar=ntCalFat;
   if(nVar<5){nVar=0;}
   if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0)*5;}
   if(nVar>50){nVar=round(nVar/10,0)*10;}
   document.getElementById("tCalFat").innerHTML="" + nVar;
   ntCalFat=nVar;
   
   nVar=ntSatFat;
   if(nVar<.5){nVar=0;}
   if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
   if(nVar>5){nVar=round(nVar,0);}
   ntSatFat=nVar;   
   if(nVar==.5){nVar=".5";}              
   document.getElementById("tSatFat").innerHTML="" + nVar;
   
   var ntSatFatP=round(nVar/20*100, 0);
   document.getElementById("tSatFatPcnt").innerHTML="" + ntSatFatP;

   nVar=ntTransFat;
   if(nVar>=0 && nVar<.5){nVar=0;}
   if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
   if(nVar>5){nVar=round(nVar,0);}
   ntTransFat=nVar; 
   if(nVar==.5){nVar=".5";}                      
   var cTxt=((ntTransFat<0) ? "0" : "" + nVar);
   document.getElementById("tTransFat").innerHTML=cTxt;
   document.getElementById("tdttfat").innerHTML=((ntTransFat<0) ? "" : "g");

   nVar=ntChol;
   if(nVar<2){nVar=0;}
   if(nVar>=2 && nVar<5){nVar=2;}
   if(nVar>=5){nVar=round(nVar/5,0)*5;}                                                     
   cTxt=((nVar>0 && nVar<5) ? "< 5" : "" + nVar);
   document.getElementById("tChol").innerHTML=cTxt;
   ntChol=nVar;
   
   var ntCholP=round(nVar/300*100, 0);
   document.getElementById("tCholPcnt").innerHTML="" + ntCholP;
   
   nVar=ntSodium;
   if(nVar<5){nVar=0;}
   if(nVar>=5 && nVar<=140){nVar=round(nVar/5,0)*5;}
   if(nVar>140){nVar=round(nVar/10,0)*10;}
   document.getElementById("tSodium").innerHTML="" + nVar;
   ntSodium=nVar;    
   
   var ntSodiumP=round(nVar/2400*100, 0);
   document.getElementById("tSodiumPcnt").innerHTML="" + ntSodiumP;

   nVar=ntCarbo;
   if(nVar<.5){nVar=0;}
   if(nVar>=.5 && nVar<1.0){nVar=.90;}
   if(nVar>=1.0){nVar=round(nVar,0);}                                                      
   cTxt=((nVar>0 && nVar<1) ? "< 1" : "" + nVar);
   document.getElementById("tCarbo").innerHTML=cTxt;
   ntCarbo=nVar; 

   var ntCarboP=round(nVar/300*100, 0);
   document.getElementById("tCarboPcnt").innerHTML="" + ntCarboP;

   nVar=ntDfib;
   if(nVar<.5){nVar=0;}
   if(nVar>=.5 && nVar<1.0){nVar=.90;}
   if(nVar>=1.0){nVar=round(nVar,0);}                                                     
   cTxt=((nVar>0 && nVar<1) ? "< 1" : "" + nVar);
   document.getElementById("tDfib").innerHTML=cTxt;
   ntDfib=nVar;
   
   var ntDfibP=round(nVar/25*100, 0);
   document.getElementById("tDfibPcnt").innerHTML="" + ntDfibP;

   nVar=ntSugars;
   if(nVar>0 && nVar<.5){nVar=0;}
   if(nVar>=.5 && nVar<1.0){nVar=.90;}
   if(nVar>=1.0){nVar=round(nVar,0);}                                                     
   cTxt=((nVar>0 && nVar<1) ? "< 1" : "" + nVar);
   ntSugars=nVar;
   if(ntSugars<0){cTxt="(N/A)";}
   document.getElementById("tSugars").innerHTML=cTxt;
   document.getElementById("tdtsug").innerHTML=((ntSugars<0) ? "" : "g");
   
   nVar=ntProtein;   
   if(nVar<.5){nVar=0;}
   if(nVar>=.5 && nVar<1.0){nVar=1;}
   if(nVar>=1.0){nVar=round(nVar,0);}                                                                       
   document.getElementById("tProtein").innerHTML="" + nVar;
   ntProtein=nVar;

   nVar=round(ntVitA/5000*100, 0); // 5000IU std
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}
   document.getElementById("tVitAPcnt").innerHTML="" + nVar;
   
   nVar=round(ntVitC/60*100, 0);  // 60 mg std
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}                  
   document.getElementById("tVitCPcnt").innerHTML="" + nVar;

   nVar=round(ntCalcium/1000*100, 0); //1000mg std
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}                  
   document.getElementById("tCalciumPcnt").innerHTML="" + nVar;

   nVar=round(ntIron/18*100, 0); // 18 mg iron
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}                  
   document.getElementById("tIronPcnt").innerHTML="" + nVar; 
   document.getElementById("selCount").innerHTML=aa;
}
// *******************************************************
function RTrim(text){
   var entry=text;	
   while (entry.charAt(entry.length - 1) == ' ') {entry=entry.substring(0,entry.length - 1);}
   return entry;
}
// *******************************************************
function ltrim(text) {
   var entry=text;	
   while (entry.charAt(0) == ' ') {entry=entry.substring(1,entry.length);}
   return entry;
}
// *******************************************************
function trim(text){return RTrim(text);}
// *******************************************************
function alltrim(text){return ltrim(RTrim(text));}
// *******************************************************
function isalpha(s){return (chars.indexOf(s.charAt(0)) > -1);}
// *******************************************************
function isdigits(s){return (nums.indexOf(s.charAt(0)) > -1);} 
// *******************************************************
function isnull(s){return (s == null);}
// *******************************************************
function isblank(s){s=strtran(s," ",""); return ((s.length == 0) || (s == "  /  /  ") || (left(s, 4) == "//::") ); }
// *******************************************************
function strtran(s, fromStr, toStr){
   var nw_s=s;
   for (i=0; i < 100 && nw_s.indexOf (fromStr) != -1; i++){nw_s=nw_s.replace (fromStr, toStr);}
   return nw_s;
}
// *******************************************************
function right(s ,n){
   var cStr=new String(s);
   if (cStr.length < (n + 1)){return cStr;}
   return cStr.substring((cStr.length - n), cStr.length);
}
// *******************************************************
function round(number, X){ 
   X=(isNaN(X) ? 0 : X); 
   return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
// *******************************************************
//var days=14; 
//var today=new Date(); 
//var zero_date=new Date(0,0,0); 
//today.setTime(today.getTime() - zero_date.getTime()); 
//var todays_date=new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0); 
//var expires_date=new Date(todays_date.getTime() + (days * 86400000)); 
//var mainUrl='campus.asp';
// *******************************************************
function Get_Cookie(name) {
   var start=document.cookie.indexOf(name+"=");
   var len=start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) {return null;}
   if (start == -1) {return null;}
   var end=document.cookie.indexOf(";",len); 
   if (end == -1) {end=document.cookie.length;}
   return unescape(document.cookie.substring(len,end)); 
} 
// *******************************************************
function Set_Cookie(name,value,expires,path,domain,secure) {
   document.cookie=name+"="+escape(value)+
      ((expires)? ";expires="+expires.toGMTString():"")+
      ((path)   ? ";path="   +path  :"")+
      ((domain) ? ";domain=" +domain:"")+
      ((secure) ? ";secure" : "");
}
// *******************************************************
function Delete_Cookie(name,path,domain) {
   if (Get_Cookie(name)) {
      document.cookie=name + "=" +
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; 
   }
}
// *******************************************************
function isCookieEnabled() {
  if (document.all) return navigator.cookieEnabled; 
  Set_Cookie('testcookie', today.getTime() ); 
  var tc=Get_Cookie('testcookie'); 
  Delete_Cookie('testcookie'); 
  return (tc == today.getTime()); 
}
// *******************************************************
//var beenHere=Get_Cookie('beenHere'); 
//if (beenHere == 'yes') {
//   if (document.images) {window.location.replace(mainUrl);}
//   else {window.location=mainUrl; }
//} 
//else if (isCookieEnabled()) Set_Cookie('beenHere','yes',expires_date); 
// *******************************************************
function getreport(doc) {
   var d=showDate();
   // create inner html for printed doc
   var x='<table id="ptbl" class="ptbl">';
   // 22 columns, no item name
   //       item                        calories                cal from fat             fat                     
   x=x+'<col style="width:23px;"><col style="width:27px;"><col style="width:35px;"><col style="width:35px;">';
   //         fat%                     satfat                       sf%                   tfat                      
   x=x+'<col style="width:35px;"><col style="width:30px;"><col style="width:35px;"><col style="width:30px;">';
   //         chol                      chol%                      sodium                sodium%  
   x=x+'<col style="width:35px;"><col style="width:35px;"><col style="width:35px;"><col style="width:35px;">';
   //      carbs                       carbs%                        dfib                   dfib%                 
   x=x+'<col style="width:35px;"><col style="width:35px;"><col style="width:35px;"><col style="width:35px;">';
   //        sugars                    protein                      vita%                   vitc%                  
   x=x+'<col style="width:35px;"><col style="width:35px;"><col style="width:35px;"><col style="width:31px;">';
   //      calcium%                   iron%
   x=x+'<col style="width:39px;"><col style="width:35">';
   // heading
   var xstyle="height:44px; width:44px;"
   x=x+'<tr class="trhdr" style=" height:44px;"><th style="width:40px; padding:0px;" colspan="2">';
   if(div=="SCHL"){x = x+'<img class="noprint" src="images/report_schools.jpg" style="'+xstyle+'"></th>';}
   if(div=="HEAL"){x = x+'<img class="noprint" src="images/report_hc.jpg" style="'+xstyle+'"></th>';}
   if(div=="SSRV"){x = x+'<img class="noprint" src="images/report_ssrv.jpg" style="'+xstyle+'"></th>';}
   if(div=="EDUC"){x = x+'<img class="noprint" src="images/report_campus.jpg" style="'+xstyle+'"></th>';}
   if(div=="CORP"){x = x+'<img class="noprint" src="images/report_corp.gif" style="'+xstyle+'"></th>';}
   x=x+'<th colspan="3">';
   x=x+'<input class="noprint" type="button" name="prntIt" id="prntIt" style="font-size:7.5pt; margin:0,0,2px,0; width:65px; height:22px; padding-bottom:1px;" onclick="if(top.frames.length==3){top.frames[2].print(); return true;} else {window.print(); return true;}" value=" Print"></th>';
   x=x+'<th style="font-size:14pt; font-weight:bold;" colspan="12">Nutrition Summary';
   if(div=="EDUC" || div=="SCHL"){x=x+'<span style="font-size:7pt; vertical-align:middle;"><br /><img src="v.gif"> Vegetarian&nbsp;&nbsp;<img src="g.gif"> Vegan&nbsp;&nbsp;<img src="w.gif"> Well-Balanced</span>';}
   if(div=="CORP"){x=x+'<span style="font-size:7pt; vertical-align:middle;"><br /><img src="v.gif"> Vegetarian&nbsp;&nbsp;<img src="g.gif"> Vegan&nbsp;&nbsp;<img src="w.gif"> Your-Health-Your-Way</span>';}
   if(div=="HEAL" || div=="SSRV"){x=x+'<span style="font-size:7pt; vertical-align:middle;"><br /><img src="v.gif"> Vegetarian&nbsp;&nbsp;<img src="g.gif"> Vegan&nbsp;&nbsp;<img src="w1.gif"> Wellness</span>';}
   x=x+'</th><th style="font-size:11pt; font-weight:bold;" colspan="5">'+d+'</th></tr>';
   //subheaders with color
   x=x+'<tr><td class="thdata" colspan="2">Calories</td><td class="thdata">Fat<br />Cal</td>';
   x=x+'<td class="thdata">Fat</td><td class="thpct">Fat<br />%</td><td class="thdata">Sat Fat</td><td class="thpct">Sat<br />Fat%</td>';
   x=x+'<td class="thdata"><i>Trans</i> Fat</td>';
   x=x+'<td class="thdata">Chol</td><td class="thpct">Chol<br />%</td><td class="thdata">Sodium</td><td class="thpct">Sodium<br />%</td>';
   x=x+'<td class="thdata">Carbs</td><td class="thpct">Carbs<br />%</td><td class="thdata">DFib</td><td class="thpct">DFib<br />%</td>';
   x=x+'<td class="thdata">Sugars</td><td class="thdata">Protein</td><td class="thpct">Vit&nbsp;A<br />%</td><td class="thpct">Vit&nbsp;C<br />%</td>';
   x=x+'<td class="thpct">Calcium<br />%</td><td class="thpct">Iron<br />%</td></tr>';
   // selected item rows
   var pItems=document.getElementById("SelItems");
   var ntVitA=0;
   var ntVitC=0.0;
   var ntCalcium=0;
   var ntIron=0.0;
   var keystr="";

   for (var xx=0;xx<pItems.length;xx++) {
      x=x+'<tr style="background-color:#fefed8;"><td colspan="22" '+
          'style="font-size:7.5pt; font-style:italic; font-weight:normal; color:#c00000; text-align:left; vertical-align:middle;">'+
          '<b style="font-size:10pt; font-weight:x-bold; font-style:normal; color:#000000;">'+pItems.options[xx].text+' </b>';
      var cIcons = "" + getIcons(pItems.options[xx].value);
      x=x+cIcons+'  &nbsp;&nbsp;'+aSL[xx][15]+'</td></tr><tr>';  // menu item followed by allergens if any
      // x=x+pItems.options[xx].children[1].innerHTML+'  &nbsp;&nbsp;&nbsp;&nbsp;'+aSL[xx][15]+'</td></tr><tr>';  // menu item followed by allergens if any
      x=x+'<td colspan="2">'+aSL[xx][0]+'</td><td>'+aSL[xx][1]+'</td>';                          // calories and fat calories
      x=x+'<td>'+aSL[xx][2]+'g</td><td>'+round(parseFloat(aSL[xx][2])/65*100, 0)+'%</td>';     // fat
      x=x+'<td>'+aSL[xx][3]+'g</td><td>'+round(parseFloat(aSL[xx][3])/20*100, 0)+'%</td>';     // satfat
      x=x+'<td>'+((aSL[xx][4]<0) ? '(N/A)' : aSL[xx][4]+'g')+'</td>';                          //trans fat

      var nVal=(((aSL[xx][5]>0)&&(aSL[xx][5]<5)) ? '< 5mg' : aSL[xx][5]+'mg');
      x=x+'<td>'+nVal+'</td><td>'+round(parseFloat(aSL[xx][5])/300*100, 0)+'%</td>' ;          // chol
      x=x+'<td>'+aSL[xx][6]+'mg</td><td>'+round(parseFloat(aSL[xx][6])/2400*100, 0)+'%</td>' ; // sodium
      nVal=(((aSL[xx][7]>0)&&(aSL[xx][7]<1)) ? "< 1g" : aSL[xx][7]+'g');
      x=x+'<td>'+nVal+'</td><td>'+round(parseFloat(aSL[xx][7])/300*100, 0)+'%</td>' ;          // carbs
      nVal=(((aSL[xx][8]>0)&&(aSL[xx][8]<1)) ? "< 1g" : aSL[xx][8]+'g');
      x=x+'<td>'+nVal+'</td><td>'+round(parseFloat(aSL[xx][8])/25*100, 0)+'%</td>';            // dfib
      nVal=(((aSL[xx][9]>0)&&(aSL[xx][9]<1)) ? "< 1g" : aSL[xx][9]+'g');
      x=x+'<td>'+((aSL[xx][9]<0) ? '(N/A)' : nVal)+'</td>';                                    // sugars
      nVal=(((aSL[xx][10]>0)&&(aSL[xx][10]<1)) ? "< 1g" : aSL[xx][10]+'g');
      x=x+'<td>'+nVal+'</td>';                                                                 // protein

      var nVar=round(parseFloat(aSL[xx][11])/5000*100, 0);
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}    
      x=x+'<td>'+nVar+'%</td>';                          // vitA%
      ntVitA=ntVitA+parseFloat(aSL[xx][11]);
      
      nVar=round(parseFloat(aSL[xx][12])/60*100, 0);
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}
      x=x+'<td>'+nVar+'%</td>';                            // vitC%
      ntVitC=ntVitC+parseFloat(aSL[xx][12]);
      
      nVar=round(parseFloat(aSL[xx][13])/1000*100, 0);
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}
      x=x+'<td>'+nVar+'%</td>';                          // Calcium
      ntCalcium=ntCalcium+parseFloat(aSL[xx][13]);
      
      nVar=round(parseFloat(aSL[xx][14])/18*100, 0);
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}
      x=x+'<td>'+nVar+'%</td></tr>';                       // iron%
      ntIron=ntIron+parseFloat(aSL[xx][14]);

      keystr=keystr+((xx==0) ? "" : ",")+aSL[xx][16];
   }
   // Spacer line
   x=x+'<tr style="padding:0px; height:3px; border-style:none;">'+
       '<td colspan="22" style="height:3px; font-size:0px; border-style:none; line-height:1px; padding:0px;">'+
       '<img src="images/black1.gif" style="border-width:0px; width:100%; height:3px;"></td></tr>';
   // Totals Line
   x=x+'<tr style="background-color:#eed352;"><td class="totals">Totals</td>';                   // menu item
   x=x+'<td>'+ntCalories+'</td><td>'+ntCalFat+'</td>';
   x=x+'<td>'+ntFat+'g</td><td>'+round(parseFloat(ntFat)/65*100, 0)+'%</td>';            // fat
   x=x+'<td>'+ntSatFat+'g</td><td>'+round(parseFloat(ntSatFat)/20*100, 0)+'%</td>';      // satfat
   x=x+'<td>'+((ntTransFat<0) ? '(N/A)' : ntTransFat+'g')+'</td>';                       // trans fat
   x=x+'<td>'+ntChol+'mg</td><td>'+round(parseFloat(ntChol)/300*100, 0)+'%</td>';        // chol
   x=x+'<td>'+ntSodium+'mg</td><td>'+round(parseFloat(ntSodium)/2400*100, 0)+'%</td>' ;  // sodium
   x=x+'<td>'+ntCarbo+'g</td><td>'+round(parseFloat(ntCarbo)/300*100, 0)+'%</td>';       // carbs
   x=x+'<td>'+ntDfib+'g</td><td>'+round(parseFloat(ntDfib)/25*100, 0)+'%</td>';          // dfib
   x=x+'<td>'+((ntSugars<0) ? '(N/A)' : ntSugars+'g')+'</td>';                           // sugars
   x=x+'<td>'+ntProtein+'g</td>';                                                        // protein
                                                         
   nVar=round(parseFloat(ntVitA)/5000*100, 0);           // vita
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}    
   x=x+'<td>'+nVar+'%</td>';                            // vita%
   nVar=round(parseFloat(ntVitC)/60*100, 0);
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}    
   x=x+'<td>'+nVar+'%</td>';                              // vitc%
   nVar=round(parseFloat(ntCalcium)/1000*100, 0);
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}    
   x=x+'<td>'+nVar+'%</td>';                         // Calcium
   nVar=round(parseFloat(ntIron)/18*100, 0);
   if(nVar<1){nVar=0;}
   if(nVar>0 && nVar<=2){nVar=2;}
   if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
   if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
   if(nVar>50){nVar=round(nVar/10, 0)*10;}    
   x=x+'<td>'+nVar+'%</td></tr>';
   // Spacer line
   // x=x+'<tr class="noprint" style="background-color:black; height:3px;"><td class="ruleline5" colspan="22">&nbsp;</td></tr>';
   x=x+'<tr style="padding:0px; height:3px; border-style:none;">'+
       '<td colspan="22" style="height:3px; font-size:0px; border-style:none; line-height:1px; padding:0px;">'+
       '<img src="images/black1.gif" style="border-width:0px; width:100%; height:3px;"></td></tr>';
   x=x+'<tr class="noprint" style="background-color:#c0c0c0;"><td colspan="22" style="text-align:center;">';
   x=x+'<input class="btnplain" type="button" name="prtIt" id="prtIt" style="font-size:7.5pt; margin:0,0,2px,0; width:75px; " '+
       'onclick="if(top.frames.length==3){top.frames[2].print(); return true;} else {window.print(); return true;}" value="   Print   " />&nbsp;&nbsp;&nbsp;&nbsp;';
   x=x+'<input class="btnplain" type="button" name="closeIt" id="closeIt" style="font-size:7.5pt; margin:0,0,2px,0; width:75px;" onclick="return print_results(window.document);" value="   Close   " /></td></tr>';
   x=x+'<tr><td colspan="22" style="padding:8px; text-align:left; font-size:7.5pt;">'+
       '<span style="font-size:8pt; text-decoration:underline; margin-bottom:5px;"><b>Nutrient Information Disclaimer</b><br /></span>'+discltxt+'</td></tr></table>';
   // <%
   // Session("keystr")                      = keystr
   // Response.Cookies("VisitorID")          = Session("VisitorID")
   // Response.Cookies("VisitorID").Expires  = Date+14
   // Response.Cookies("VisitorID").Path     = "/balance"
   // Response.Cookies("keystr")             = keystr
   // Response.Cookies("keystr").Expires     = Date+14
   // Response.Cookies("keystr").Path        = "/balance"
   // %>
   // loop until window is created, then continue
   doc=null;
   return x
}
// *******************************************************
function print_results(doc) {
   var curstyle1='DIV.MAIN';
   var curstyle2='DIV.RPT';
   var sht=doc.styleSheets[0];
   var orules=((isIE) ? sht.rules : sht.cssRules);
   var rule_on=((isIE) ? 'inline-block' : '');
   var rule_off='none';
   var style1=0;
   var style2=0;   
   for (var i=0;i<orules.length;i++) {
      if (orules[i].selectorText.toUpperCase()==curstyle1) {style1=i;}
      if (orules[i].selectorText.toUpperCase()==curstyle2) {style2=i;}
   }
   if (orules[style1].style.display==rule_on || orules[style1].style.display=='') {
      // kill visibility of div.main, show div.rpt
      orules[style1].style.display=rule_off;
      orules[style2].style.display=rule_on;
      doc.body.style.leftmargin=1;
      doc.body.style.topmargin=1;
      doc.getElementById("rpt").innerHTML=getreport(doc);
   }
   else {
      orules[style2].style.display=rule_off;
      orules[style1].style.display=rule_on;
      doc.body.style.leftmargin=0;
      doc.body.style.topmargin=0;      
      doc.getElementById("rpt").innerHTML="<center>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p><h3>Working...</h3></center>"
   }  
   return true;
}
// *******************************************************
function getXML(url) {
   // calls createXMLHTTP, inprocess, and parseXML functions
   xmlhttp=null;
   if (isSafari || isChrome) {xmlhttp = createXMLHTTP2();}
   else {
      xmlhttp = createXMLHTTP();
   }
   if(!(typeof xmlhttp == 'object')){
      alert('Could not create the XML_HTTP data object.');
      return false; 
   }
   xmlhttp.open('GET', url, true);
   var requestTimer = setTimeout( function(){xmlhttp.abort(); alert("XML data request timed out.");}, MAX_WAIT ); 
   xmlhttp.onreadystatechange =  function() { inprocess(xmlhttp, requestTimer); };
   xmlhttp.send(null);
   return true;
}
// *******************************************************
function inprocess(xmlhttp, requestTimer) {
   if (xmlhttp.readyState == 4) {
      clearTimeout(requestTimer);        
      if (xmlhttp.status == 200) {
         var xmldoc = xmlhttp.responseXML;
         var xmlstr = xmlhttp.responseText;
         parseXML(xmldoc); 
      }
      else {
         var nerr = parseInt(xmlhttp.status);
         var cmsg = 'There was a problem with the XML request.';
         if (nerr >= 500 && nerr <= 599) cmsg = 'Server error. Cannot access data.';
         if (nerr == 404) cmsg = 'This computer is not allowed to access the data.';
         alert(cmsg); 
      }
   }    
}
// *******************************************************
function parseXML(xmldoc) {
   if (loading==1) {return true;}
   var useMoz = false;
   if (xmldoc.getElementsByTagName("row")[0] != null && xmldoc.getElementsByTagName("row")[0].nodeType ==1) {
      useMoz = true;  // FireFox & other Mozilla
      var nodelist = xmldoc.getElementsByTagName("row");
   } 
   else {var nodelist = xmldoc.firstChild.getElementsByTagName('z:row');}
   if(isSafari || isChrome){nodelist = xmldoc.getElementsByTagName("row");}
   var nodecount = nodelist.length;
   var itm = document.getElementById("Items");
   // clear first item - must check for 0 length later
   itm.options[0]=null;
   // clear nutrients to right of items list
   clearItems();  
   //alert(((useMoz)?'Using Mozilla/Firefox DOM':'Using IE DOM'));
   for (var ii=0; ii<nodecount; ii++){
      var node = nodelist[ii].attributes;      
      if (node != null) {
         var skey = node.getNamedItem("ckey").nodeValue;    //Case-Sensitive!
         var cGrams = new String(node.getNamedItem("weight").nodeValue);
         //cGrams = strtran(cGrams, " grams", "g");
         var stext = trim(node.getNamedItem("menu_desc").nodeValue) +" ("+ trim(cGrams) + ")";
         //var stext  = node.getNamedItem("menu_desc").nodeValue + " ("+node.getNamedItem("port_desc").nodeValue+")";
         var simg = "";
         if (node.getNamedItem("veg").nodeValue == "True"){simg+='v ';}  // simg+='<img src=v.gif>'
         if (node.getNamedItem("vegan").nodeValue == "True"){simg+='g ';}  //<img src=g.gif>';}
         var nwell  = parseInt(node.getNamedItem("wellness").nodeValue);
         if (nwell>0){
            if (div!="HEAL" && div!="SSRV"){simg+='w ';}  // <img src=w.gif>';} // educ=apple corp=yhyw in w.gif
            if (div=="HEAL" || div=="SSRV"){
               if (nwell==1){simg+='w1';}  // <img src=w1.gif>';} 
               // else {simg+='w2';}  // <img src=w2.gif>';}
            }
         }
         // if ((div=="EDUC" || div=="SCHL") && parseFloat(node.getNamedItem("carbo").nodeValue)<=20){simg+='c ';}  // <img src=c.gif>';}
         //if (simg==""){simg="&nbsp;";}           
         // add items here 
         var newitem = document.createElement('option');
         newitem.text = stext;
         newitem.value = simg;
         newitem.id = skey;
         try {itm.add(newitem,null);}
         catch(ex) {itm.add(newitem);} 
         //if(simg!=""){itm.options[itm.options.length-1].style.fontStyle="italic";}         
      }      
   } 
   // if nothing found...
   if (itm.options.length==0) {
      var newitem = document.createElement('option');
      newitem.text='No items found for selected search words/categories';
      newitem.value='';
      newitem.id='NONO';
      try {itm.add(newitem,null);}
      catch(ex) {itm.add(newitem);}           
   }
   document.getElementById("btnAdd").disabled = true; 
   curitem = null;
   itm.selectedIndex=-1;
   selecting=0; 
   return true;
}
// *******************************************************
function createXMLHTTP(){
   var oRequest = false;
   if (typeof XMLHttpRequest == 'undefined' && window.ActiveXObject){
      function XMLHttpRequest(){
         var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
         for (var i=0; i<arrSignatures.length; i++) {
            try { var oRequest = new ActiveXObject(arrSignatures[i]); return oRequest;}
            catch (e) { oRequest = false; }
         }
         throw new Error("MSXML is not installed and is required for this feature.");
      };  //end function
   } 
   else { oRequest = new XMLHttpRequest(); }
   // last resort for new Ice browser
   if (!oRequest && window.createRequest) {
      try {oRequest = window.createRequest();} 
      catch(e) {oRequest = false;}
   }
   // ensure xml delivery to pass security
   if (typeof oRequest == 'object' && oRequest.overrideMimeType) {oRequest.overrideMimeType("text/xml");}
   return oRequest;
}
// *******************************************************
function createXMLHTTP2(){
   var oRequest = false;
   if(window.XMLHttpRequest && !(window.ActiveXObject)) {
      try {
         oRequest = new XMLHttpRequest();
      }
      catch(e) {oRequest = false;}
      } 
      else {
         if(window.ActiveXObject) {
            try {oRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
            catch(e) {
               try {oRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
               catch(e) {oRequest=false;}
         }
      }
   }
   return oRequest;
}
// *******************************************************
function addURLParam(sURL, sParamName, sParamValue) {
   sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
   sURL += encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
   return sUrl;
}
// *******************************************************
function splangrp_dblclick() {
   document.getElementById("btnSrch").click();
   return true;
}
// *******************************************************
function splangrp_mouseover() {
   var cstr=document.getElementById("searchField").value;
   cstr=trim(cstr);
   if (cstr!="" && pvis==0){
      swapText(cstr);
   }
   else {window.status='Select categories and/or enter key words to search for';}
   return true;
}
// *******************************************************
function splangrp_mouseout() {
   if (pvis==1){swapText("");}
   window.status='';
   return true;
}
// *******************************************************
function Items_dblclick(itm) {
   if (itm.selectedIndex != -1) {
      if (selecting==1) {
         alert("An addition to your selection list is already in process.  ");  
         return false;         
      } 
      else {
         if (aa>=sel_limit){
            alert("The number of entries in the selection list is limited to " + sel_limit+".");
            return false;            
         } 
         else {
            selecting=1;
            document.getElementById("btnAdd").click();
         }
      }
   }
   return true;
}
// *******************************************************
function getIcons(cstr){
  // cstr is in pairs with "v g y w w1w2c "potential to split into images and insert text into iFullDesc or ViewReport
  if(cstr==""){return "";}
  var ss="";
  var cimg="";
  for (var ii=0;ii<=cstr.length/2;ii+=2){
     cimg=trim(cstr.substr(ii,2))+'.gif';
     ss+=((ss.length !=0) ? '&nbsp;' : '')+'<img src="'+cimg+'" />';
  }
  return ss;
}  
// *******************************************************
function Items_change(){ 
   var xmldoc = xmlhttp.responseXML;
   var itm = document.getElementById("Items"); 
   var nItem = itm.selectedIndex;
   var selItem = itm.options[nItem].id;
   if (document.getElementById("SelItems").selected!=null){
      var sitm = document.getElementById("SelItems");
      if (sitm.options[sitm.selectedIndex].id=="XX") {clearSelItems();}     
   }
   var useMoz = false;
   if (xmldoc.getElementsByTagName("row")[0] != null && xmldoc.getElementsByTagName("row")[0].nodeType ==1) {
      useMoz = true;  // FireFox & other Mozilla
      var nodelist = xmldoc.getElementsByTagName("row");
   } else {var nodelist = xmldoc.firstChild.getElementsByTagName('z:row');}
   
   var node = nodelist[nItem].attributes;      
   if (node != null) {
      var cDesc=trim(node.getNamedItem("full_desc").nodeValue);
      var cIcons=alltrim(getIcons(itm.options[nItem].value));
      var cAllergens = Allergic(trim(node.getNamedItem("allergens").nodeValue));
      if(cAllergens.length != 0 || cIcons.length !=0){
         if(cDesc.length != 0) {cDesc = cDesc + "<br />";}         
         if(cIcons.length !=0 ){cDesc = cDesc + cIcons;}
         if(cAllergens.length != 0){
            cDesc = cDesc + ' <div class="iAllergens">Contains '+cAllergens+'</div>';
         }
      }
      document.getElementById("iFull_Desc").innerHTML = cDesc;
      
      var cGrams=new String(node.getNamedItem("weight").nodeValue);
      cGrams=trim(cGrams);
      cGrams=strtran(cGrams, " grams", "g");
      document.getElementById("iServing").innerHTML = "" + trim(node.getNamedItem("port_desc").nodeValue)+" ("+ cGrams+")";
      
      var nCalories=parseInt(node.getNamedItem("calories").nodeValue);
      var nVar=nCalories;
      if(nVar<5){nVar=0;}
      if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0)*5;}
      if(nVar>50){nVar=round(nVar/10,0)*10;}
      document.getElementById("iCalories").innerHTML = "" + nVar;
      nCalories=nVar;
      
      var nFat=round(parseFloat(node.getNamedItem("fat").nodeValue), 1);
      nVar=nFat;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
      if(nVar>5){nVar=round(nVar,0);} 
      nFat=nVar;
      if(nVar==.5){nVar=".5";}                                    
      document.getElementById("iFat").innerHTML = "" + nVar; 
          
      var nFP = round(nVar/65*100, 0);
      document.getElementById("iFatPcnt").innerHTML = "" + nFP;
      
      var nCalFat=round(nFat*9,1);
      nVar=nCalFat;
      if(nVar<5){nVar=0;}
      if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0)*5;}
      if(nVar>50){nVar=round(nVar/10,0)*10;}
      document.getElementById("iCalFat").innerHTML = "" + nVar;
      nCalFat=nVar;
      
      var nSatFat=round(parseFloat(node.getNamedItem("satfat").nodeValue), 1);
      nVar=nSatFat;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
      if(nVar>5){nVar=round(nVar,0);}                 
      nSatFat=nVar;
      if(nVar==.5){nVar=".5";}                                    
      document.getElementById("iSatFat").innerHTML = "" + nVar;
      
      var nSF = round(nVar/20*100, 0);
      document.getElementById("iSatFatPcnt").innerHTML = "" + nSF;                 
      
      var nTransFat=round(parseFloat(node.getNamedItem("tfat").nodeValue), 1);
      nVar=nTransFat;
      if(nVar>=0 && nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
      if(nVar>5){nVar=round(nVar,0);}    
      nTransFat=nVar;             
      if(nVar==.5){nVar=".5";}                                                                   
      var cTxt=((nTransFat<0) ? "(N/A)" : "" + nVar);
      document.getElementById("iTransFat").innerHTML = cTxt; 
      document.getElementById("tditfat").innerHTML = ((nTransFat<0) ? "" : "g");
      
      var nChol=parseInt(node.getNamedItem("chol").nodeValue);
      nVar=nChol;
      if(nVar<2){nVar=0;}
      if(nVar>=2 && nVar<5){nVar=2;}
      if(nVar>=5){nVar=round(nVar/5,0)*5;}                                                     
      cTxt=((nVar>0 && nVar<5) ? "< 5" : "" + nVar);
      document.getElementById("iChol").innerHTML = cTxt;
      nChol=nVar;
      
      var nCh = round(nVar/300*100, 0);
      document.getElementById("iCholPcnt").innerHTML = "" + nCh;
      
      var nSod=parseInt(node.getNamedItem("sodium").nodeValue);
      nVar=nSod;
      if(nVar<5){nVar=0;}
      if(nVar>=5 && nVar<=140){nVar=round(nVar/5,0)*5;}
      if(nVar>140){nVar=round(nVar/10,0)*10;}                                   
      document.getElementById("iSodium").innerHTML = "" + nVar;
      nSod=nVar;
      
      var nSo = round(nVar/2400*100, 0);
      document.getElementById("iSodiumPcnt").innerHTML = "" + nSo;
      
      var nCarbo=round(parseFloat(node.getNamedItem("carbo").nodeValue), 1);
      nVar=nCarbo;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=.90;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                     
      cTxt=(((nVar>0)&&(nVar<1)) ? "< 1" : "" + nVar);
      document.getElementById("iCarbo").innerHTML = cTxt;
      nCarbo=nVar;
      
      var nCP = round(nVar/300*100, 0);
      document.getElementById("iCarboPcnt").innerHTML = "" + nCP;
      
      var nDfib=round(parseFloat(node.getNamedItem("dfib").nodeValue), 1);
      nVar=nDfib;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=.90;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                     
      cTxt=((nVar>0 && nVar<1) ? "< 1" : "" + nVar);
      document.getElementById("iDfib").innerHTML = cTxt;
      nDfib=nVar;
      
      var nDFP = round(nVar/25*100, 0);
      document.getElementById("iDfibPcnt").innerHTML = "" + nDFP;
      
      var nSugars=round(parseFloat(node.getNamedItem("sugars").nodeValue), 1);
      nVar=nSugars;
      if(nVar>0 && nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=.90;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                     
      cTxt=((nVar>0 && nVar<1) ? "< 1" : "" + nVar);
      if(nSugars<0){cTxt = "(N/A)";}
      document.getElementById("iSugars").innerHTML = cTxt; 
      document.getElementById("tdisug").innerHTML = ((nSugars<0) ? "" : "g");  
      nSugars=nVar;           
       
      var nProtein=round(parseFloat(node.getNamedItem("protein").nodeValue), 1);
      nVar=nProtein;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=1;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                                       
      document.getElementById("iProtein").innerHTML = "" + nVar;
      nProtein=nVar;
      
      var nVitA=round(parseFloat(node.getNamedItem("vit_a").nodeValue), 1);
      nVar=round(nVitA/5000*100, 0); // 5000IU std
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}
      document.getElementById("iVitAPcnt").innerHTML = "" + nVar;
      
      var nVitC=round(parseFloat(node.getNamedItem("vit_c").nodeValue), 1);
      nVar=round(nVitC/60*100, 0);  // 60 mg std
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}                  
      document.getElementById("iVitCPcnt").innerHTML = "" + nVar;
      
      var nCalcium=round(parseFloat(node.getNamedItem("calcium").nodeValue), 1);
      nVar=round(nCalcium/1000*100, 0); //1000mg std
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}                  
      document.getElementById("iCalciumPcnt").innerHTML = "" + nVar;
      
      var nIron=round(parseFloat(node.getNamedItem("iron").nodeValue), 1);
      nVar=round(nIron/18*100, 0); // 18 mg iron
      if(nVar<1){nVar=0;}
      if(nVar>0 && nVar<=2){nVar=2;}
      if(nVar>2 && nVar<=10){nVar=round(nVar/2, 0)*2;}
      if(nVar>10 && nVar<=50){nVar=round(nVar/5, 0)*5;}
      if(nVar>50){nVar=round(nVar/10, 0)*10;}                  
      document.getElementById("iIronPcnt").innerHTML = "" + nVar;
     // save curitem and use if add button or double click happens. 
      curitem = null;  
      curitem = document.createElement('option');
      curitem.text = itm.options[nItem].text;
      curitem.value = itm.options[nItem].value;
      curitem.id = itm.options[nItem].id; 
   } 
   document.getElementById('btnAdd').disabled = (itm.selectedIndex == -1);   
   return true;
}
// *******************************************************
function searchField_keypress(e){
   try {var keynum=e.which;}
   catch(ex){keynum=e.keyCode;}
   if(keynum==13){document.getElementById("btnSrch").click();}
   return true;
}
// *******************************************************
function btnSrch_click(){
   // Creates query string IIInnnAnnnAnnnAnnnAnnnAnnnAICccccccc20Ccccccccc20
   // where III=number of plan groups followed by codes with "A" separators
   // and I is: Phrase(1) All Words (2) or Any Words (3) Followed by search words
   // All pg and no pg = 000 for III, otherwise nCnt as 3-digit number
   // Rules: If III=000 and empty(Ccccc) = bad
   // Words under 3 chars in length are no good
   // Search Words Validation
   document.getElementById("iFull_Desc").innerHTML="";
   var cMsg = new String(""), qStr="", nCnt=0, sList="", aWords="", wType="";
   var wlist = new String(alltrim(document.getElementById("searchField").value));
   for (var ii=1;ii<4;ii++){
      crad="oRadio"+ii+"";
      if(document.getElementById(crad).checked){wType=document.getElementById(crad).value; break;}
   }
   var qStr="", nWordCnt=0;
   // clean up any weird charcters
   if (wlist.length!=0) {
      wlist = wlist.replace(/\ \ /, /\ /); // replace all two with one space
      wlist = wlist.toUpperCase();
      aWords = wlist.split(" ");
      nWordCnt = aWords.length;
      if (nWordCnt!=0) { qStr = aWords.join("x");}
      if (wType!="1" && nWordCnt!=0) {
         // check word length
         for (var i=0;i<nWordCnt;i++) {
            if(aWords[i].length<3){cMsg="Search words must be at least 3 characters in length."; break;}
         }
      }
   }
   // Category validation
   if (cMsg.length==0) {
      var plist = document.getElementById("splangrp");
      for (var i=0;i<plist.length;i++) {
         if(plist.options[i].selected==true){sList=sList+plist.options[i].value+"A"; nCnt=nCnt+1;}
      }
      var pCnt = ((nCnt==0 || nCnt==plist.length) ? "000" : right("000"+nCnt+"",3)) ;  
      if(nCnt==plist.length){sList=""; nCnt=-1; }
      plist=null;
   }
   if (nCnt<=0 && nWordCnt==0) {
      cMsg="Select at least one category and/or enter a search word or phrase.      ";
      if (nCnt==-1) {cMsg="At least one search word is required when searching all categories. "; document.getElementById("searchField").focus();}     
      alert(cMsg);
   }
   if (cMsg.length==0) {
      var itm=document.getElementById("Items");
      // clear the Items list
      while (itm.options.length>0){itm.options[0]=null;}
      clearItems();      
      var newitem=document.createElement('option');
      newitem.text='Searching - please wait...';
      newitem.id="TMP";
      newitem.value="";
      try {itm.add(newitem,null);}  //Standards compliant
      catch(e) {itm.add(newitem);} // IE only
   }
   // get the new items
   cQuery = "dag="+pCnt+sList+wType+qStr;
   getXML("items.xml.asp?"+cQuery);
   return true;
}  
// *******************************************************
function btnAdd_click() {
   var nItem = document.getElementById("Items").selectedIndex;
   if (selecting==1 && aa<sel_limit) {alert("An addition to your selection list is already in process.  "); return false;} 
   if (aa>=sel_limit){alert("The number of entries in the selection list is limited to " + sel_limit+"."); return false;} 
   if (nItem == -1) {alert("At least one item must be selected to add.    "); return false;} 
   selecting=1;
   var itm = document.getElementById("Items");  
   var sitm = document.getElementById("SelItems");
   var seldItem = itm.options[nItem].id;
   var xmldoc = xmlhttp.responseXML;
   var useMoz = false;
   if (xmldoc.getElementsByTagName("row")[0] != null && xmldoc.getElementsByTagName("row")[0].nodeType ==1) {
      useMoz = true;  // FireFox & other Mozilla
      var nodelist = xmldoc.getElementsByTagName("row");
   } else {var nodelist = xmldoc.firstChild.getElementsByTagName('z:row');} 
   if(isOpera){nodelist = xmldoc.firstChild.getElementsByTagName('z:row');}  
   var node = nodelist[nItem].attributes;      
   if (node != null) {
      var c_ckey = itm.options[nItem].id;     
      var nCalories=parseInt(node.getNamedItem("calories").nodeValue);
      var nVar=nCalories;
      if(nVar<5){nVar=0};
      if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0)*5;}
      if(nVar>50){nVar=round(nVar/10,0)*10;}
      nCalories=nVar;
      
      var nFat=round(parseFloat(node.getNamedItem("fat").nodeValue), 1);
      nVar=nFat;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
      if(nVar>5){nVar=round(nVar,0);}                 
      nFat=nVar;
      
      var nCalFat=round(nFat*9,1);
      nVar=nCalFat;
      if(nVar<5){nVar=0};
      if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0)*5;}
      if(nVar>50){nVar=round(nVar/10,0)*10;}
      nCalFat=nVar;
      
      var nSatFat=round(parseFloat(node.getNamedItem("satfat").nodeValue), 1);
      nVar=nSatFat;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
      if(nVar>5){nVar=round(nVar,0);}                 
      nSatFat=nVar;            
      
      var nTransFat=round(parseFloat(node.getNamedItem("tfat").nodeValue), 1);
      nVar=nTransFat;
      // This adds to totals only so kill the -1.0 used for N/A
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
      if(nVar>5){nVar=round(nVar,0);}                                   
      nTransFat=nVar;             
      
      var nChol=parseInt(node.getNamedItem("chol").nodeValue);
      nVar=nChol;
      if(nVar<2){nVar=0;}
      if(nVar>=2 && nVar<5){nVar=2;}
      if(nVar>=5){nVar=round(nVar/5,0)*5;}                                                     
      nChol=nVar;
      
      var nSodium=parseInt(node.getNamedItem("sodium").nodeValue);
      nVar=nSodium;
      if(nVar<5){nVar=0;}
      if(nVar>=5 && nVar<=140){nVar=round(nVar/5,0)*5;}
      if(nVar>140){nVar=round(nVar/10,0)*10;}                                   
      nSodium=nVar;
      
      var nCarbo=round(parseFloat(node.getNamedItem("carbo").nodeValue), 1);
      nVar=nCarbo;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=.90;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                     
      nCarbo=nVar;
      
      var nDfib=round(parseFloat(node.getNamedItem("dfib").nodeValue), 1);
      nVar=nDfib;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=.90;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                     
      nDfib=nVar;
      
      var nSugars=round(parseFloat(node.getNamedItem("sugars").nodeValue), 1);
      nVar=nSugars;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=.90;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                     
      nSugars=nVar;           
         
      var nProtein=round(parseFloat(node.getNamedItem("protein").nodeValue), 1);
      nVar=nProtein;
      if(nVar<.5){nVar=0;}
      if(nVar>=.5 && nVar<1.0){nVar=1;}
      if(nVar>=1.0){nVar=round(nVar,0);}                                                                       
      nProtein=nVar;
      
      var nVitA=round(parseFloat(node.getNamedItem("vit_a").nodeValue), 1);
      var nVitC=round(parseFloat(node.getNamedItem("vit_c").nodeValue), 1);
      var nCalcium=round(parseFloat(node.getNamedItem("calcium").nodeValue), 1);
      var nIron=round(parseFloat(node.getNamedItem("iron").nodeValue), 1);
         
      var nwell=parseInt(node.getNamedItem("wellness").nodeValue);
      var cAllergens=Allergic(node.getNamedItem("allergens").nodeValue);
      if(cAllergens.length>0){cAllergens="Contains "+cAllergens;}
      
      // 17 values with Key as last
      aSL[aa++] = new Array( nCalories, nCalFat, nFat, nSatFat, nTransFat, nChol, nSodium, nCarbo, nDfib, nSugars, nProtein, nVitA, nVitC, nCalcium, nIron, cAllergens, c_ckey );
         
      ntCalories=parseInt(ntCalories)+parseInt(nCalories);
      ntCalFat=parseInt(ntCalFat)+parseInt(nCalFat);
      ntFat=parseFloat(ntFat)+parseFloat(nFat);
      ntSatFat=parseFloat(ntSatFat)+parseFloat(nSatFat);
      ntTransFat=parseFloat(ntTransFat)+parseFloat(nTransFat);
      ntChol=parseInt(ntChol)+parseInt(nChol);
      ntSodium=parseInt(ntSodium)+parseInt(nSodium);
      ntCarbo=parseFloat(ntCarbo)+parseFloat(nCarbo);
      ntDfib=parseFloat(ntDfib)+parseFloat(nDfib);
      ntSugars=parseFloat(ntSugars)+parseFloat(nSugars);
      ntProtein=parseFloat(ntProtein)+parseFloat(nProtein);
      
      ntVitA=parseInt(ntVitA)+parseInt(nVitA);
      ntVitC=parseFloat(ntVitC)+parseFloat(nVitC);
      ntCalcium=parseFloat(ntCalcium)+parseFloat(nCalcium);
      ntIron=parseFloat(ntIron)+parseFloat(nIron);
      showTotals();
      
      var stext  = itm.options[nItem].text ;
      var simg   = itm.options[nItem].value;
    
      // add items here 
      var newitem = document.createElement('option');
      newitem.text=stext;
      newitem.value=simg;
      newitem.id=c_ckey;
      try {sitm.add(newitem,null);}
      catch(ex) {sitm.add(newitem);} 
      document.getElementById("btnDel").disabled=false;
      document.getElementById("btnClear").disabled=false;
      document.getElementById("btnPrint").disabled=false; 
      document.getElementById("selCount").innerHTML = aa; 
      if(sitm.length > 0) {sitm.selectedIndex = (parseInt(aa) - 1);}
      else {sitm.selectedIndex = -1;}
   }
   selecting=0;
   return true;   
}
// *******************************************************
function btnDel_click(){
   var sitem = document.getElementById("SelItems");
   if (sitem.selectedIndex == -1){alert("Select an item in the list above, then click the Delete button again."); return false;} 
   var ndelItem = sitem.selectedIndex;
   var delItemID = sitem.options[ndelItem].id;
   // Reduce the values
   if(sitem.options.length <=1 ){
      clearSelItems();
      return true;
   }
   // reduce totals
   var nIdx=ndelItem;
   ntCalories=parseInt(ntCalories)-parseInt(aSL[nIdx][0]);
   ntCalFat=parseInt(ntCalFat)-parseInt(aSL[nIdx][1]);
   ntFat=parseFloat(ntFat)-parseFloat(aSL[nIdx][2]);
   ntSatFat=parseFloat(ntSatFat)-parseFloat(aSL[nIdx][3]);
   ntTransFat=parseFloat(ntTransFat)-parseFloat(aSL[nIdx][4]);
   ntChol=parseInt(ntChol)-parseInt(aSL[nIdx][5]);
   ntSodium=parseInt(ntSodium)-parseInt(aSL[nIdx][6]);
   ntCarbo=parseFloat(ntCarbo)-parseFloat(aSL[nIdx][7]);
   ntDfib=parseFloat(ntDfib)-parseFloat(aSL[nIdx][8]);
   ntSugars=parseFloat(ntSugars)-parseFloat(aSL[nIdx][9]);
   ntProtein=parseFloat(ntProtein)-parseFloat(aSL[nIdx][10]);
   ntVitA=parseFloat(ntVitA)-parseFloat(aSL[nIdx][11]);
   ntVitC=parseFloat(ntVitC)-parseFloat(aSL[nIdx][12]);
   ntCalcium=parseFloat(ntCalcium)-parseFloat(aSL[nIdx][13]);
   ntIron=parseFloat(ntIron)-parseFloat(aSL[nIdx][14]);
   if (aa>0) {aa=aa-1;}
   var nEnd = sitem.options.length-1;
   if(ndelItem < nEnd) {
      // pull up the covers - contiguous array elements - no gaps            
      var nVar=3*1;
      for (var i=ndelItem; i<nEnd; i++) {
         // changed from 15 to 17 11/2/05  
         // array is 0-16 where aSL[xx][15] is allergens, aSL[16] is c_ckey
         for (var ii=0;ii<17;ii++) {
            nVar = aSL[i+1][ii]; // next row values
            aSL[i][ii]=nVar;
         }
      }
   }
   aSL.length=aSL.length-1;
   sitem.options[ndelItem] = null;
   showTotals();
   if(sitem.selectedIndex != -1) document.getElementById("btnDel").focus(); 
   if(sitem.length==1) sitem.selectedIndex=0;
   if(sitem.length>ndelItem){sitem.selectedIndex = ndelItem;}
   else {sitem.selectedIndex = sitem.length-1;}
   return true;
}
// *******************************************************
function xmlSelItems_hasdata() {
   if(loading != 1) {
      nodeList = document.getElementById("xmlSelItems").selectNodes("//z:row");
      // Add the Menu Item to Selected
      sitm = document.getElementById("SelItems");
      node = nodeList.nextNode;
      do {
   	   if (node != null) {
            var c_ckey = node.getNamedItem("ckey").nodeValue;
            var nCalories=parseInt(node.getNamedItem("calories").nodeValue);
            var nVar=nCalories;
            if(nVar<5){nVar=0};
            if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0)*5;}
            if(nVar>50){nVar=round(nVar/10,0)*10;}
            nCalories=nVar;
            
            var nFat=round(parseFloat(node.getNamedItem("fat").nodeValue), 1);
            nVar=nFat;
            if(nVar<.5){nVar=0;}
            if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
            if(nVar>5){nVar=round(nVar,0);}                 
            nFat=nVar;
            
            var nCalFat=round(nFat*9,1);
            nVar=nCalFat;
            if(nVar<5){nVar=0};
            if(nVar>=5 && nVar<=50){nVar=round(nVar/5,0)*5;}
            if(nVar>50){nVar=round(nVar/10,0)*10;}
            nCalFat=nVar;
            
            var nSatFat=round(parseFloat(node.getNamedItem("satfat").nodeValue), 1);
            nVar=nSatFat;
            if(nVar<.5){nVar=0;}
            if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
            if(nVar>5){nVar=round(nVar,0);}                 
            nSatFat=nVar;            
            
            var nTransFat=round(parseFloat(node.getNamedItem("tfat").nodeValue), 1);
            nVar=nTransFat;
            // This adds to totals only so kill the -1.0 used for N/A
            if(nVar<.5){nVar=0;}
            if(nVar>=.5 && nVar<=5.0){nVar=round(nVar/.5,0)*.5;}
            if(nVar>5){nVar=round(nVar,0);}                                   
            nTransFat=nVar;             
            
            var nChol=parseInt(node.getNamedItem("chol").nodeValue);
            nVar=nChol;
            if(nVar<2){nVar=0;}
            if(nVar>=2 && nVar<5){nVar=2;}
            if(nVar>=5){nVar=round(nVar/5,0)*5;}                                                     
            nChol=nVar;
            
            var nSodium=parseInt(node.getNamedItem("sodium").nodeValue);
            nVar=nSodium;
            if(nVar<5){nVar=0;}
            if(nVar>=5 && nVar<=140){nVar=round(nVar/5,0)*5;}
            if(nVar>140){nVar=round(nVar/10,0)*10;}                                   
            nSodium=nVar;
            
            var nCarbo=round(parseFloat(node.getNamedItem("carbo").nodeValue), 1);
            nVar=nCarbo;
            if(nVar<.5){nVar=0;}
            if(nVar>=.5 && nVar<1.0){nVar=.90;}
            if(nVar>=1.0){nVar=round(nVar,0);}                                                     
            nCarbo=nVar;
            
            var nDfib=round(parseFloat(node.getNamedItem("dfib").nodeValue), 1);
            nVar=nDfib;
            if(nVar<.5){nVar=0;}
            if(nVar>=.5 && nVar<1.0){nVar=.90;}
            if(nVar>=1.0){nVar=round(nVar,0);}                                                     
            nDfib=nVar;
            
            var nSugars=round(parseFloat(node.getNamedItem("sugars").nodeValue), 1);
            nVar=nSugars;
            if(nVar<.5){nVar=0;}
            if(nVar>=.5 && nVar<1.0){nVar=.90;}
            if(nVar>=1.0){nVar=round(nVar,0);}                                                     
            nSugars=nVar;           
               
            var nProtein=round(parseFloat(node.getNamedItem("protein").nodeValue), 1);
            nVar=nProtein;
            if(nVar<.5){nVar=0;}
            if(nVar>=.5 && nVar<1.0){nVar=1;}
            if(nVar>=1.0){nVar=round(nVar,0);}                                                                       
            nProtein=nVar;
            
            var nVitA=round(parseFloat(node.getNamedItem("vit_a").nodeValue), 1);
            var nVitC=round(parseFloat(node.getNamedItem("vit_c").nodeValue), 1);
            var nCalcium=round(parseFloat(node.getNamedItem("calcium").nodeValue), 1);
            var nIron=round(parseFloat(node.getNamedItem("iron").nodeValue), 1);
               
   	      var nwell=parseInt(node.getNamedItem("wellness").nodeValue);
            var cAllergens=Allergic(node.getNamedItem("allergens").nodeValue);
            if(cAllergens.length>0){cAllergens="Contains "+cAllergens;}
            
            // 17 values with Key as last
            aSL[aa++] = new Array( nCalories, nCalFat, nFat, nSatFat, nTransFat, nChol, nSodium, nCarbo, nDfib, nSugars, nProtein, nVitA, nVitC, nCalcium, nIron, cAllergens, c_ckey );
               
            ntCalories=parseInt(ntCalories)+parseInt(nCalories);
            ntCalFat=parseInt(ntCalFat)+parseInt(nCalFat);
            ntFat=parseFloat(ntFat)+parseFloat(nFat);
            ntSatFat=parseFloat(ntSatFat)+parseFloat(nSatFat);
            ntTransFat=parseFloat(ntTransFat)+parseFloat(nTransFat);
            ntChol=parseInt(ntChol)+parseInt(nChol);
            ntSodium=parseInt(ntSodium)+parseInt(nSodium);
            ntCarbo=parseFloat(ntCarbo)+parseFloat(nCarbo);
            ntDfib=parseFloat(ntDfib)+parseFloat(nDfib);
            ntSugars=parseFloat(ntSugars)+parseFloat(nSugars);
            ntProtein=parseFloat(ntProtein)+parseFloat(nProtein);
            
            ntVitA=parseInt(ntVitA)+parseInt(nVitA);
            ntVitC=parseFloat(ntVitC)+parseFloat(nVitC);
            ntCalcium=parseFloat(ntCalcium)+parseFloat(nCalcium);
            ntIron=parseFloat(ntIron)+parseFloat(nIron);
            showTotals();
            
   	      var stext  = node.getNamedItem("menu_desc").nodeValue+strtran(" ("+node.getNamedItem("weight").nodeValue+")"," grams","g");
   	      var simg   = "";
   	      if (node.getNamedItem("veg").nodeValue == "True"){simg+='v ';}  // "<img src=v.gif>";}
   	      if (node.getNamedItem("vegan").nodeValue == "True"){simg+='g ';}  // "<img src=g.gif>";}
   	      if (nwell>0){
   	         if (div!="HEAL" && div!="SSRV"){simg+='w ';}  //"<img src=w.gif>";} // educ=apple corp=yhyw in w.gif
   	         if (div=="HEAL" || div=="SSRV"){
   	            if (nwell==1){simg+='w1';}  // "<img src=w1.gif>";} 
   	           //  else {simg+='w2';}  // "<img src=w2.gif>";}
   	         }
   	      }
   	      // if ((div=="EDUC" || div=="SCHL") && parseInt(nCarbo)<=20){simg+='c ';}  // "<img src=c.gif>";}
            // add items here 
            var newitem = document.createElement('option');
            newitem.text=stext;
            newitem.value=simg;
            newitem.id=c_ckey;
            try {sitm.add(newitem,null);}
            catch(ex) {sitm.add(newitem);}           
            //sitm.appendChild(new Option(stext,simg));
            //sitm.options[sitm.length-1].id=c_ckey;           
           // document.getElementById("SelItems").addItem("<span class=s1 id="+c_ckey+">"+stext+" </span><span class=s2>"+simg+"</span>");
            document.getElementById("btnDel").disabled=false;
            document.getElementById("btnClear").disabled=false;
            document.getElementById("btnPrint").disabled=false; 
            document.getElementById("selCount").innerHTML = aa;                   
            }
   	   node = nodeList.nextNode;
      } while (node != null);
      selecting=0;
   }
}

// *******************************************************
function FFHelp() {
   // ffhelptxt is declared in jsfuncs.js, a pulic var
   var txt='<div style="height:100%; width:100%; text-align:left; vertical-align:middle; padding:2px; margin:0px; '+
      ' color:black; overflow:auto;">'+
      '<span style="font-size:12pt; margin-bottom:12px;"><b>Note for Firefox Users</b></span><p />'+
      ffhelptxt+'<div style="text-align:center; margin-top:4px;">'+
      '<input type="button" tabIndex="1" id="btnClose" name="btnClose"  style="font-size:8pt; margin-top:4px;" onclick="self.close(); return true;" value=" Close " /></div></div>'
   var nH=175;
   var nW=400;
   if(screen.availHeight){
      var nT=parseInt(screen.availHeight/2) - parseInt(nH/2);
      var nL=parseInt(screen.availWidth/2)  - parseInt(nW/2);
   } 
   else { 
      var nT=300; 
      var nL=400;
   }
   var nWin=CurrentWin++ ;
   var cWinName="discl_"+nWin+"";
   var cparams="height="+nH+",width="+nW+",top="+nT+",left="+nL+",titlebar=no,personalbar=no,status=no,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=no";
   WinIds[nWin]=null;
   WinIds[nWin]=window.open("",cWinName,cparams);
   if (!WinIds[nWin].opener) {WinIds[nWin].opener=self;}
   if(WinIds[nWin].document.body) {
      var sBody = WinIds[nWin].document.body;
      var sDoc = WinIds[nWin].document;  
      sDoc.title='Firefox Browser Note';
      sBody.style.margin="3px";
      sBody.style.fontFamily="Arial,Tahoma,Helvetica,sans-serif";
      sBody.style.fontSize="8pt";
      sBody.innerHTML=txt;
      sDoc.getElementById("btnClose").focus();
   }   
   return false  
}

// *******************************************************
function showDiscl() {
   // discltxt is declared in jsfuncs.js, a pulic var
   var txt='<div style="height:100%; width:100%; text-align:left; vertical-align:middle; padding:2px; margin:0px; '+
      ' color:black; overflow:auto;">'+
      '<span style="font-size:12pt; margin-bottom:12px;"><b>Nutrient Information Disclaimer</b></span><p />'+
      discltxt+'<div style="text-align:center; margin-top:4px;">'+
      '<input type="button" tabIndex="1" id="btnClose" name="btnClose"  style="font-size:8pt; margin-top:4px;" onclick="self.close(); return true;" value=" Close " /></div></div>'
   var nH=245;
   var nW=500;
   if(screen.availHeight){
      var nT=parseInt(screen.availHeight/2) - parseInt(nH/2);
      var nL=parseInt(screen.availWidth/2)  - parseInt(nW/2);
   } 
   else { 
      var nT=300; 
      var nL=400;
   }
   var nWin=CurrentWin++ ;
   var cWinName="discl_"+nWin+"";
   var cparams="height="+nH+",width="+nW+",top="+nT+",left="+nL+",titlebar=no,personalbar=no,status=no,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=no";
   WinIds[nWin]=null;
   WinIds[nWin]=window.open("",cWinName,cparams);
   if (!WinIds[nWin].opener) {WinIds[nWin].opener=self;}
   if(WinIds[nWin].document.body) {
      var sBody = WinIds[nWin].document.body;
      var sDoc = WinIds[nWin].document;  
      sDoc.title='Nutrient Information Disclaimer';
      sBody.style.margin="3px";
      sBody.style.fontFamily="Arial,Tahoma,Helvetica,sans-serif";
      sBody.style.fontSize="8pt";
      sBody.innerHTML=txt;
      sDoc.getElementById("btnClose").focus();
   }   
   return false  
}

// *******************************************************
function dvDiscl() {
   dvtxt='<ul style="margin: 8px 6px 2px 18px;"><li>';
   if(isFF || isSafari || isChrome){dvtxt='<ul style="margin: 8px 6px 2px -24px;"><li>';}
   dvtxt=dvtxt+'The values in the "CUMULATIVE RESULTS FOR SELECTED ITEMS" nutrition information panel contains ';
   dvtxt=dvtxt+'ONLY those foods you have selected, and in the portion size identified.</li><li>';
   dvtxt=dvtxt+'The percentages are based on a "Daily Value".  For this reason, one must be careful to consider ';
   dvtxt=dvtxt+'these percentages in the context of not only what food items have been selected for this analysis, ';
   dvtxt=dvtxt+'but all of the other items that one has consumed during the 24-hour day.</li><li>';
   dvtxt=dvtxt+'These values are for the recipes that are prepared and served in this establishment.  Foods that you ';
   dvtxt=dvtxt+'have consumed from other sources may not be included in this data set of nutrition information.  ';
   dvtxt=dvtxt+'This means the "% Daily Value" may be incomplete when this is viewed from a 24-hour day perspective.</li><li>';
   dvtxt=dvtxt+'The actual portion size (or amount of a serving) that you actually consume will affect your nutrient intake.  ';
   dvtxt=dvtxt+'If your portion size was larger than the amount stated, or you did not eat all of the portion, ';
   dvtxt=dvtxt+'these conditions need to be considered when evaluating the "% Daily Value."</li><li>';
   dvtxt=dvtxt+'The "% Daily Value" of the cumulative results is the percent of the defined standard used for the ';
   dvtxt=dvtxt+'Nutrition Facts labeling purposes.  Remember, your "100%" of the "% Daily Value" is likely to be ';
   dvtxt=dvtxt+'different - based on your body and activity level.</li></ul>';
  
   var txt='<div style="height:100%; width:100%; text-align:left; vertical-align:middle; padding:2px; margin:0px; color:black; overflow:auto;">'+
      '<span style="font-size:12pt; margin-bottom:0px;"><b>Interpreting Nutrient Values</b><br /></span>'+
      dvtxt+
      '<div style="text-align:center; margin-top:4px;">'+
      '<input type="button" tabIndex="1" id="btnClose" name="btnClose" style="font-size:8pt; margin-top:4px;" onclick="self.close(); return true;" value=" Close " /></div></div>'
   var nH=278;
   var nW=500;
   if(screen.availHeight){
      var nT=parseInt(screen.availHeight/2) - parseInt(nH/2);
      var nL=parseInt(screen.availWidth/2)  - parseInt(nW/2);
   } 
   else { 
      var nT=300; 
      var nL=400;
   }
   var nWin=CurrentWin++ ;
   var cWinName="discl_"+nWin+"";
   var cparams="height="+nH+",width="+nW+",top="+nT+",left="+nL+",titlebar=no,personalbar=no,status=no,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=no";
   WinIds[nWin]=null;
   WinIds[nWin]=window.open("",cWinName,cparams);
   if (!WinIds[nWin].opener) {WinIds[nWin].opener=self;}
   if(WinIds[nWin].document.body) {
      var sBody = WinIds[nWin].document.body;
      var sDoc = WinIds[nWin].document;
      sDoc.title='Interpreting Nutrient Values';
      sBody.style.margin="3px";
      sBody.style.fontFamily="Arial,Tahoma,Helvetica,sans-serif";
      sBody.style.fontSize="8pt";
      sBody.innerHTML=txt;
      sDoc.getElementById("btnClose").focus();
   }   
   return false  
}
