var a303592=0;var a418433="";var a339127="";var a244663=false;var a096265=false;var a552265="";var a861621=false;var a690841=0;var a784726=false;var a096182=false;var a057421=0;var a606327=1;var a554072=2;var a239003=3;function ClearValues(){iSetStr("Title","");oSetStr("Error","");iSetStr("Food","");iSetStr("Serving","");iSetSelIdx("Portion",-1);oSetStr("CountShown","");oSetStr("Matches","");oSetStr("FoodLabel","");a757855();SetDisplay("trError",false);SetFocus("Food");}function a757855(){a325123(a057421);var a633902=GetDocObj("FoodList");if(a633902){while(a633902.rows.length>0){a633902.deleteRow(0);}}}function ShowSearch(){HideSearch(false,3);var a386867=false;if(!GetDisplay("Foods")){var a633902=GetDocObj("FoodList");if(a633902){if(a633902.rows.length>0){SetDisplay("Foods",true);}else{a386867=true;}}}else{a386867=true;}if(a386867){SearchChange(0);}}function CheckFoodBlur(a811737){var a050151=9;var a107914=a603174(a811737);if(a107914==a050151){HideSearch(true,2);}}function HideSearch(a160012,a594322){if(a690841<=a594322){a690841=a594322;a861621=a160012;}if(!a784726){setTimeout("TestHideSearch();",100);a784726=true;}}function TestHideSearch(){if(a861621){SetDisplay('Foods',false);}a784726=a861621=false;a690841=0;}function a325123(a135685){SetDisplay("FoodLabel",a135685==a606327);SetDisplay("DataRefresh",a135685==a554072);SetDisplay("SendButton",a135685==a239003);}function SearchChange(a630006){var a306156=iGetStr("Food");if(a306156!=a418433||a630006>0){if(a306156.length>0){if(a630006==0){a096182=false;a630006=20;}a339127=a306156;SetDisplay("trError",false);var a899956="../FoodLabel.aspx?Command=Search&Food="+a306156+"&MaxRecs="+a630006;new a664029(a899956,a771638,a481144);}a418433=a306156;}}function a771638(a070041,a800452){if(a070041){if(a070041.documentElement){var a115217=0;var a359059=a700570(a070041.documentElement,"TotalCount");oSetStr("Matches",FmtNum(a359059));var a005039=GetDocObj("Food");var a671834=GetDocObj("Foods");if(a671834&&a005039){a671834.style.left=GetX(a005039)+"px";a671834.style.top=GetY(a005039)+a005039.offsetHeight+"px";a671834.style.height="auto";}SetDisplay("Foods",true);var a633902=GetDocObj("FoodList");if(a633902){var a353130=-1;a422571(a070041.documentElement,"Matches",function (a897108){a422571(a897108,"Food",function (a306156){var a109239=a700570(a306156,"FoodRno");var a556771=a700570(a306156,"Desc");var a707175=a700570(a306156,"AltDesc");if(a556771!=a707175){a556771+=" <span style='font-size: 80%;'>("+a707175+")</span>";}var a313431=(++a353130>=a633902.rows.length);var a489703=(a313431?a633902.insertRow(a633902.rows.length):a633902.rows[a353130]);var a553968=(a313431?a489703.insertCell(0):a489703.cells[0]);a553968.innerHTML=a556771;a553968.onmouseover=a505096;a553968.onmouseout=a528924;a553968.onclick=function (){a141637(a109239,a556771);};if(a115217==0){a115217=a109239;}});});oSetStr("CountShown",FmtNum(a353130+1));if(a096182){setTimeout("WatchFoodListHeight();",100);}SetDisplay("ShowMore",!a096182);if(a353130+1==a359059){SetDisplay("ShowMore",false);}while(a353130+1<a633902.rows.length){a633902.deleteRow(a353130+1);}}if(a096265&&a115217!=0){SetDisplay("Foods",false);a725078(a115217);a503855(a115217);a096265=false;}}}else{a488633(a800452)}a609033();}function a505096(){this.className="OverFood";}function a528924(){this.className="";}function a141637(a109239,a306156){a096182=false;HideSearch(true,3);a725078(a109239);a503855(a109239);a244663=true;a854989(a109239);SetFocus("Serving");}function a725078(a109239){a303592=a109239;iSetStr("FoodRno",a109239);}function ShowMoreFood(){var a136911=oGetNum("CountShown");var a718513=Math.min(500,oGetNum("Matches"));if(a718513>a136911){SetDisplay("ShowMore",false);HideSearch(false,3);SetFocus("Food");iSetStr("Food",a339127);a096182=true;a028137();SearchChange(a718513);}}function WatchFoodListHeight(){var a671834=GetDocObj("Foods");if(a671834){a671834.style.height=(a671834.offsetHeight>=400?"400px":"auto");}}function a157041(a572835){var a629704=a572835;var a426719=true;while(a426719){a426719=false;var a439467=a629704.indexOf("<");if(a439467>=0){var a526413=a629704.indexOf(">",a439467);if(a526413>=0){a629704=a629704.substring(0,a439467)+a629704.substring(a526413+1);a426719=true;}}}return a629704;}function a503855(a109239){a303592=a109239;SetDisplay("trError",false);var a648847="../FoodLabel.aspx?Command=Food&FoodRno="+a109239;new a664029(a648847,a337833,a481144);}function a337833(a070041,a800452){if(a070041){if(a070041.documentElement){var a556771=a700570(a070041.documentElement,"Desc");iSetStr("Food",a556771);a418433=a556771;if(a244663){a854989(a303592);}}}else{a488633(a800452);}}function a854989(a109239){a303592=a109239;SetDisplay("trError",false);var a648847="../FoodLabel.aspx?Command=Portions&FoodRno="+a109239;new a664029(a648847,a100443,a481144);}function a100443(a070041,a800452){var a255234=new Array();var a840470=-1;if(a070041){if(a070041.documentElement){var a292854=GetDocObj("Portion");if(a292854){a422571(a070041.documentElement,"Portions",function (a552579){a422571(a552579,"Portion",function (a073125){var a342040=a700570(a073125,"FoodPortionRno");var a217563=Num(a700570(a073125,"Qty"));var a658131=a700570(a073125,"Unit");a255234[++a840470]=new a336955(a217563,a658131,a342040,1,true);});});var a129064=a255234.length;for(a840470=0;a840470<a129064;a840470++){switch(a255234[a840470].Unit){case "oz":a299920(a255234,a255234[a840470].Qty,"lb",a255234[a840470].FoodPortionRno,1/16);break;case "lb":a299920(a255234,a255234[a840470].Qty,"oz",a255234[a840470].FoodPortionRno,16);break;case "gallon":a299920(a255234,a255234[a840470].Qty,"quart",a255234[a840470].FoodPortionRno,4);a299920(a255234,a255234[a840470].Qty,"pint",a255234[a840470].FoodPortionRno,8);a299920(a255234,a255234[a840470].Qty,"cup",a255234[a840470].FoodPortionRno,16);a299920(a255234,a255234[a840470].Qty,"fl oz",a255234[a840470].FoodPortionRno,128);a299920(a255234,a255234[a840470].Qty,"tbsp",a255234[a840470].FoodPortionRno,256);a299920(a255234,a255234[a840470].Qty,"tsp",a255234[a840470].FoodPortionRno,768);break;case "quart":a299920(a255234,a255234[a840470].Qty,"gallon",a255234[a840470].FoodPortionRno,1/4);a299920(a255234,a255234[a840470].Qty,"pint",a255234[a840470].FoodPortionRno,2);a299920(a255234,a255234[a840470].Qty,"cup",a255234[a840470].FoodPortionRno,4);a299920(a255234,a255234[a840470].Qty,"fl oz",a255234[a840470].FoodPortionRno,32);a299920(a255234,a255234[a840470].Qty,"tbsp",a255234[a840470].FoodPortionRno,64);a299920(a255234,a255234[a840470].Qty,"tsp",a255234[a840470].FoodPortionRno,192);break;case "pint":a299920(a255234,a255234[a840470].Qty,"gallon",a255234[a840470].FoodPortionRno,1/8);a299920(a255234,a255234[a840470].Qty,"quart",a255234[a840470].FoodPortionRno,1/2);a299920(a255234,a255234[a840470].Qty,"cup",a255234[a840470].FoodPortionRno,2);a299920(a255234,a255234[a840470].Qty,"fl oz",a255234[a840470].FoodPortionRno,16);a299920(a255234,a255234[a840470].Qty,"tbsp",a255234[a840470].FoodPortionRno,32);a299920(a255234,a255234[a840470].Qty,"tsp",a255234[a840470].FoodPortionRno,96);break;case "cup":case "cup (8 fl oz)":case "cup, NFS":a299920(a255234,a255234[a840470].Qty,"gallon",a255234[a840470].FoodPortionRno,1/16);a299920(a255234,a255234[a840470].Qty,"quart",a255234[a840470].FoodPortionRno,1/4);a299920(a255234,a255234[a840470].Qty,"pint",a255234[a840470].FoodPortionRno,1/2);a299920(a255234,a255234[a840470].Qty,"cup",a255234[a840470].FoodPortionRno,1);a299920(a255234,a255234[a840470].Qty,"fl oz",a255234[a840470].FoodPortionRno,8);a299920(a255234,a255234[a840470].Qty,"tbsp",a255234[a840470].FoodPortionRno,16);a299920(a255234,a255234[a840470].Qty,"tsp",a255234[a840470].FoodPortionRno,48);break;case "fl oz":case "fluid ounce":a299920(a255234,a255234[a840470].Qty,"gallon",a255234[a840470].FoodPortionRno,1/128);a299920(a255234,a255234[a840470].Qty,"quart",a255234[a840470].FoodPortionRno,1/32);a299920(a255234,a255234[a840470].Qty,"pint",a255234[a840470].FoodPortionRno,1/16);a299920(a255234,a255234[a840470].Qty,"cup",a255234[a840470].FoodPortionRno,1/8);a299920(a255234,a255234[a840470].Qty,"fl oz",a255234[a840470].FoodPortionRno,1);a299920(a255234,a255234[a840470].Qty,"tbsp",a255234[a840470].FoodPortionRno,2);a299920(a255234,a255234[a840470].Qty,"tsp",a255234[a840470].FoodPortionRno,6);break;case "tbsp":case "tablespoon":a299920(a255234,a255234[a840470].Qty,"gallon",a255234[a840470].FoodPortionRno,1/256);a299920(a255234,a255234[a840470].Qty,"quart",a255234[a840470].FoodPortionRno,1/64);a299920(a255234,a255234[a840470].Qty,"pint",a255234[a840470].FoodPortionRno,1/32);a299920(a255234,a255234[a840470].Qty,"cup",a255234[a840470].FoodPortionRno,1/16);a299920(a255234,a255234[a840470].Qty,"fl oz",a255234[a840470].FoodPortionRno,1/2);a299920(a255234,a255234[a840470].Qty,"tbsp",a255234[a840470].FoodPortionRno,1);a299920(a255234,a255234[a840470].Qty,"tsp",a255234[a840470].FoodPortionRno,3);break;case "tsp":case "teaspoon":a299920(a255234,a255234[a840470].Qty,"gallon",a255234[a840470].FoodPortionRno,1/768);a299920(a255234,a255234[a840470].Qty,"quart",a255234[a840470].FoodPortionRno,1/192);a299920(a255234,a255234[a840470].Qty,"pint",a255234[a840470].FoodPortionRno,1/96);a299920(a255234,a255234[a840470].Qty,"cup",a255234[a840470].FoodPortionRno,1/48);a299920(a255234,a255234[a840470].Qty,"fl oz",a255234[a840470].FoodPortionRno,1/6);a299920(a255234,a255234[a840470].Qty,"tbsp",a255234[a840470].FoodPortionRno,1/3);a299920(a255234,a255234[a840470].Qty,"tsp",a255234[a840470].FoodPortionRno,1);break;}}a438249(a292854);for(a840470=0;a840470<a255234.length;a840470++){a453156(a292854,a255234[a840470].Unit,a255234[a840470].FoodPortionRno+"|"+(a255234[a840470].Qty*a255234[a840470].PortionRatio),a552265);}if(a552265==""){iSetSelIdx("Portion",0);iSetStr("Serving",FmtFract(a255234[0].Qty,4,""));}a552265="";}if(a244663){GenerateNutritionLabel();}}}else{a488633(a800452)}}function a336955(a217563,a658131,a342040,a207393,a633926){this.Qty=a217563;this.Unit=a658131;this.FoodPortionRno=a342040;this.PortionRatio=a207393;this.fDBPortion=a633926;}function a299920(a255234,a217563,a658131,a342040,a207393){var a637764=true;var a840470;for(a840470=0;a840470<a255234.length;a840470++){if(a658131==a255234[a840470].Unit){a637764=false;if(!a255234[a840470].fDBPortion){var a301718=Math.max(a207393,1/a207393);var a658854=Math.max(a255234[a840470].PortionRatio,1/a255234[a840470].PortionRatio);if(a301718<a658854){a255234[a840470].Qty=a217563;a255234[a840470].FoodPortionRno=a342040;a255234[a840470].PortionRatio=a207393;}}break;}}if(a637764){a255234[a255234.length]=new a336955(a217563,a658131,a342040,a207393,false);}}function TotSet(){GenerateNutritionLabel();}function ShowFood(a109239){if(iGetNum("Serving")==0){iSetStr("Serving",1);}a244663=true;a503855(a109239);SetFocus("Serving");}function ShowInitFood(a073125){a096265=true;a244663=true;a552265=a073125;SearchChange(1);SetFocus("Food");}function GenerateNutritionLabel(){var a109239=iGetNum("FoodRno");var a072569=iGetSelVal("Portion");var a500252=a072569.split("|");var a342040=Num(a500252[0]);var a436997=Num(a500252[1]);var a909556=FractNum(iGetStr("Serving"))/a436997;var a302300=Num(iGetStr("DailyCalories"));if(a109239!=0&&a342040!=0){a028137();SetDisplay("trError",false);var a444084="../FoodLabel.aspx?Command=Label&FoodRno="+a109239+"&FoodPortionRno="+a342040+"&Serving="+a909556+"&DailyCalories="+a302300;new a664029(a444084,a271316,a481144);}}function a271316(a070041,a800452){a488633(a800452);if(a244663){a244663=false;}}function a488633(a800452){oSetStr("FoodLabel",a800452);a325123(a606327);a609033();}function a444243(){}function a481144(a880180,a262716,a847900){oSetStr("Error","Error Communicting with Host Data Server<br>Status "+a880180+" - "+a262716);SetDisplay("trError",true);}function a717404(){var a559337="";a559337+='	<tr>\n';a559337+='		<td align="right">Food</td>\n';a559337+='		<td></td>\n';a559337+='		<td>'+iGetStr("Food")+'</td>\n';a559337+='	</tr>\n';a559337+='	<tr>\n';a559337+='		<td align="right">Serving</td>\n';a559337+='		<td></td>\n';a559337+='		<td align="left">'+FmtFract(FractNum(iGetStr("Serving")),4,"")+' '+iGetSel("Portion")+'</td>\n';a559337+='	</tr>\n';a559337+='	<tr>\n';a559337+='		<td align="right">Daily Calories</td>\n';a559337+='		<td></td>\n';a559337+='		<td>'+iGetStr("DailyCalories")+'</td>\n';a559337+='	</tr>\n';return a559337;}var a836028=80;var a616604=10;function PrintCalc(){var a559337="";a559337=a472517(CalcName,"",WebFiles+"FoodLabel.css");a559337+='	<tr><td><table border="0" cellpadding="0" cellspacing="0">\n';a559337+='		<tr>\n';a559337+='			<td width="'+a836028+'"></td>\n';a559337+='			<td width="'+a616604+'"></td>\n';a559337+='			<td></td>\n';a559337+='		</tr>\n';a559337+=a717404();a559337+='	</table></td></tr>\n';a559337+='	<tr><td height="20"></td>\n';a559337+='	<tr>\n';a559337+='		<td align="center">\n';a559337+=oGetStr("FoodLabel");a559337+='		</td>\n';a559337+='	</tr>\n';a003419(a559337,"_blank",700,630,Disclaimer);}function RelatedCalcs(a713158){var a896402="";switch(a713158){case "Advanced-RMR":a896402="Title="+escape(iGetStr("Title"))+"&Units="+(iGetChk("US")?"US":"Metric")+"&Gender="+(iGetChk("Female")?"Female":"Male")+"&Weight="+(iGetChk("US")?iGetNum("Weight"):iGetNum("WeightMetric"))+"&HeightFt="+iGetNum("HeightFt")+"&HeightIn="+iGetNum("HeightIn")+"&HeightMetric="+iGetNum("HeightMetric")+"&Age="+iGetNum("Age");break;case "Calorie-Breakdown":a896402="Title="+escape(iGetStr("Title"))+"&Gender="+(iGetChk("Female")?"Female":"Male")+"&Age="+iGetNum("Age")+"&Calories="+oGetNum("AvgCalDay");break;}PopupCalc(a713158,a896402);}
