var mealOptionsList=new Array();var selMealItems=new Array();var uniqueMealTypes=new Array();var selMealOptionsList=new Array();var selCurItems=new Array();var mealType=new Array();var selMealItemsId=new Array();var mealTypeId=new Array();var tempSelItemsArr=new Array();var selDescription=new Array();var curMealItemId=new Array();var mealDeadLine=new Array();var mealItemOptions=0;var mealTypeOptions=0;var curMealType=0;var totalCurItems=0;var prevMealOption=0;var curMealOption=0;var prevMealListOption=0;var curMealListOption=0;var totalMeals=2;var mealOption=0;var mealOptionCursor=0;var mealOptionSelected=0;var mealListCursor=0;var mealListSelected=0;var currentWidgetId=0;var mealTypeClick=0;var mealItemClick=0;function resetMealList(){mealListCursor=0;mealListSelected=0;prevMealListOption=0;curMealListOption=0;selMealOptionsList=new Array();selCurItems=new Array();selDescription=new Array();mealTypeId=new Array();curMealItemId=new Array()}function launchMealPanel(A){currentWidgetId=A;resetMealTypes();getMealInfo()}function buildMealOptions(){resetMealList();var B=0;for(var A=0;A<mealOptionsList.length;A++){if(uniqueMealTypes[curMealOption]==mealType[A]){selMealOptionsList[B]=mealOptionsList[A];mealTypeId[B]=mealType[A];selCurItems[B]=selMealItems[A];selDescription[B]=mealItemDesc[A];curMealItemId[B]=selMealItemsId[A];++B}}refineMealCache();totalCurItems=(selMealOptionsList.length==0?0:selMealOptionsList.length-1);updateMealOptions()}function refineMealCache(){(selMealOptionsList[0]==""?selMealOptionsList.shift():selMealOptionsList);(selCurItems[0]==""?selCurItems.shift():selCurItems)}function updateMealTypes(){var A="";var C=0;var D=uniqueMealTypes.length;for(var B=0;(D>=5&&B<5)||(D<5&&B<D);++B){A+='<tr><td id="mealTypeId'+B+'" style="height:40px;width:170px;padding-bottom:3px;padding-left:18px;border:1px solid transparent;">'+((uniqueMealTypes[B]).length>28?uniqueMealTypes[B]:uniqueMealTypes[B])+"</td></tr>";C++}for(var B=0;B<(5-C);++B){if(C==0){break}A+='<tr><td id="mealTypeId'+(B+C)+'" style="height:40px;width:170px;padding-bottom:3px;padding-left:18px;"></td></tr>'}document.getElementById("mealContentList").innerHTML='<table width="100%" align="left" valign="top" cellspacing="0" cellpadding="0" >'+(A?A:'<tr><td height="28" width="100%" align="center" valign="middle"><span style="width:100%;text-align:center;vertical-align:middle;background-repeat:no-repeat;">No options avaliable</span></td></tr>')+"</table>"}function updateMealOptions(){var A="";var C=0;var D=selMealOptionsList.length;D=(D<0?0:D);for(var B=0;(D>=5&&B<5)||(D<5&&B<D);++B){A+="<tr><td "+(statusInfo==1?' onmouseover="onMealItems('+B+');" onclick="openSelMealItems('+B+');"':"")+' style="width:100%;height:45px;text-align:left;white-space:nowrap;vertical-align:middle;border:1px solid transparent;'+(statusInfo==1?"cursor:pointer;":"")+'"><table id="selMealItemList'+B+'"width="100%" align="center" valign="middle" cellspacing="0" cellpadding="0"><tr><td id="selMealOption'+B+'" style="width:40px;text-align:center;">&nbsp;&nbsp;'+(selCurItems[B]==1?"<img src="+sCheckSmall.src+" />":"&nbsp;")+'</td><td id="selMealNames'+B+'" style="width:250px;text-align:left;height:45px;padding-bottom:3px;padding-left:18px;">'+((selMealOptionsList[B]).length>28?selMealOptionsList[B]:selMealOptionsList[B])+"</td></tr></table></td></tr>";C++}for(var B=0;B<(5-C);++B){if(C==0){break}A+='<tr><td style="width:100%;height:45px;text-align:left;white-space:nowrap;vertical-align:middle;"><table width="100%" align="center" valign="top" cellspacing="0" cellpadding="0"><tr><td id="selMealOption'+(C+B)+'"  style="width:40px;text-align:left">&nbsp;&nbsp;</td><td id="selMealNames'+(C+B)+'" style="width:250px;text-align:left;height:45px;"></td></tr></table></td></tr>'}document.getElementById("mealsOptionsList").innerHTML='<table width="100%" align="left" valign="top" cellspacing="0" cellpadding="0" >'+(A?A:'<tr><td height="28" width="100%" align="center" valign="middle"><span style="width:100%;text-align:center;vertical-align:middle;background-repeat:no-repeat;">No options avaliable</span></td></tr>')+"</table>";showMealPanel();highLightMealType();assignMealTypeDesc()}function highLightMealType(){if(document.getElementById("mealTypeId"+prevMealOption)!=null){document.getElementById("mealTypeId"+prevMealOption).style.background="none"}if(document.getElementById("mealTypeId"+curMealOption)!=null){document.getElementById("mealTypeId"+curMealOption).style.background="url('/view/tv/images/selectorMealType.png')";document.getElementById("mealTypeId"+curMealOption).style.backgroundRepeat="no-repeat"}}function highLightMealItems(){if(document.getElementById("selMealItemList"+prevMealListOption)!=null){document.getElementById("selMealItemList"+prevMealListOption).style.background="none"}if(document.getElementById("selMealItemList"+mealListCursor)!=null){document.getElementById("selMealItemList"+mealListCursor).style.background="url('/view/tv/images/selectorMealItem.png')";document.getElementById("selMealItemList"+mealListCursor).style.backgroundRepeat="no-repeat"}}function hideMealItems(){for(var B=0;B<5;B++){try{document.getElementById("selMealItemList"+B).style.background="none"}catch(A){}}}function hideMealTypes(){for(var B=0;B<3;B++){try{document.getElementById("mealTypeId"+B).style.background="none";document.getElementById("mealTypeId"+B).style.border="0px solid HoneyDew"}catch(A){}}}function selectMealItem(){if(selCurItems[mealListSelected]==1){updateSelList(0);selCurItems[mealListSelected]=0;document.getElementById("selMealOption"+mealListCursor).innerHTML=""}else{updateSelList(1);selCurItems[mealListSelected]=1;document.getElementById("selMealOption"+mealListCursor).innerHTML="<img src="+sCheckSmall.src+" />"}}function updateSelList(A){for(var B=0;B<selMealItemsId.length;B++){if(curMealItemId[mealListSelected]==selMealItemsId[B]){selMealItems[B]=A;break}}}function mealKeyHandler(D){switch(D){case rcOK:if(mealOption==0){mealKeyHandler(rcRIGHT)}else{selectMealItem()}break;case rcRIGHT:case rcLEFT:if(mealOption==0){if(selMealOptionsList.length>0){mealOption=1;highLightMealItems();assignMealDesc()}}else{mealOption=0;hideMealItems();highLightMealType();assignMealTypeDesc()}break;case rcUP:if(mealOption==0){if(curMealOption==0){break}prevMealOption=curMealOption;curMealOption--;if(mealOptionCursor!=0){mealOptionCursor--;highLightMealType()}else{var E=curMealOption;var A=curMealOption+4;scrollMealOptions(E,A)}mealOptionSelected=curMealOption;mealTypeClick=curMealOption-mealOptionCursor;buildMealOptions();assignMealTypeDesc()}else{if(curMealListOption==0){break}prevMealListOption=mealListCursor;curMealListOption--;if(mealListCursor!=0){mealListCursor--;highLightMealItems()}else{var E=curMealListOption;var A=curMealListOption+4;scrollMealList(E,A)}mealListSelected=curMealListOption;mealItemClick=curMealListOption-mealListCursor;assignMealDesc()}break;case rcDOWN:if(mealOption==0){if(curMealOption==totalMeals){break}prevMealOption=curMealOption;curMealOption++;if(mealOptionCursor<4){mealOptionCursor++;highLightMealType()}else{var E=curMealOption-4;var A=curMealOption;scrollMealOptions(E,A)}mealOptionSelected=curMealOption;mealTypeClick=curMealOption-mealOptionCursor;buildMealOptions();assignMealTypeDesc()}else{if(curMealListOption==totalCurItems){break}prevMealListOption=mealListCursor;curMealListOption++;if(mealListCursor<4){mealListCursor++;highLightMealItems()}else{var E=curMealListOption-4;var A=curMealListOption;scrollMealList(E,A)}mealListSelected=curMealListOption;mealItemClick=curMealListOption-mealListCursor;assignMealDesc()}break;case rcMENU:var C=-1;for(var B=0;B<selMealItems.length;B++){if(selMealItems[B]!=tempSelItemsArr[B]){C=1;break}else{C=0}}if(C==1){saveMealData()}else{mealActive=false;showGoPanel();showGuidePanel()}break}}function scrollMealOptions(E,A){var C=0;for(var B=E;B<=A;++B){var D="mealTypeId"+C;document.getElementById(D).innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;"+(uniqCatNameCache[B].length>16?uniqCatNameCache[B]:uniqCatNameCache[B]);C++}}function scrollMealList(F,B){var D=0;for(var C=F;C<=B;++C){var E="selMealNames"+D;document.getElementById(E).innerHTML=(selMealOptionsList[C].length>28?selMealOptionsList[C]:selMealOptionsList[C]);var A="selMealOption"+D;document.getElementById(A).innerHTML=(selCurItems[C]==1?"<img src="+sCheckSmall.src+" />":"");D++}}function resetMealTypes(){hideMealTypes();mealOption=0;curMealOption=0;prevMealOption=0;mealOptionSelected=0;mealOptionCursor=0}function saveMealData(){var A=new Array();var C=new Array();var D=0;for(var B=0;B<selMealItems.length;B++){if(selMealItems[B]==1){A[D]=selMealItemsId[B];C[D]=mealType[B];++D}}var E="method=saveMealData&widgetId="+currentWidgetId+"&selectedItems="+A+"&serial="+serial+"&mealCategory="+C;createAjaxRequest();if(ajaxRequest==null){return }ajaxRequest.onreadystatechange=function(){if(ajaxRequest.readyState==4){if(ajaxRequest.status==200){if(ajaxRequest.responseText=="recall"){saveMealData()}else{mealActive=false;showGoPanel();showGuidePanel()}}else{if(ajaxRequest.status==500){failureInfo()}}}};ajaxRequest.open("POST","/TvHandler",true);ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");ajaxRequest.send(E);return false}function getMealInfo(){var A="method=getMealInfo&widgetId="+currentWidgetId+"&serial="+serial;createAjaxRequest();if(ajaxRequest==null){return }ajaxRequest.onreadystatechange=function(){if(ajaxRequest.readyState==4){if(ajaxRequest.status==200){if(ajaxRequest.responseText=="recall"){getMealInfo()}else{var B=ajaxRequest.responseText;if(B.length>0){var D=B.split("-?#-");mealOptionsList=D[1].split("-@#-");mealItemDesc=D[2].split("-@#-");selMealItems=D[3].split("-@#-");uniqueMealTypes=D[4].split("-@#-");mealType=D[5].split("-@#-");selMealItemsId=D[6].split("-@#-");mealDeadLine=D[7].split("-@#-");for(var C=0;C<selMealItems.length;C++){tempSelItemsArr[C]=selMealItems[C]}if(mealOptionsList.length>0){buildMealOptions()}else{}}}}else{if(ajaxRequest.status==500){failureInfo()}}}};ajaxRequest.open("POST","/TvHandler",true);ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");ajaxRequest.send(A);return false}function assignMealDesc(){try{document.getElementById("mealsOptionDescription").innerHTML=selDescription[curMealListOption]}catch(A){}}function assignMealTypeDesc(){if(!(mealDeadLine[curMealOption])){document.getElementById("mealsOptionDescription").innerHTML="";return }try{showMealImage();document.getElementById("mealsOptionDescription").innerHTML=(curMealOption==0?" Breakfast deadline ":(curMealOption==1?" Lunch deadline ":" Dinner deadline "))+mealDeadLine[curMealOption]+(curMealOption==0?" AM":" PM")}catch(A){}}function highLightMealPanel(A){document.getElementById("mealPanel"+A).style.background="#fcf3b8"}function hideMealPanel(A){document.getElementById("mealPanel"+A).style.background="none"}function moveMealPanel(A){if(A==1){mealKeyHandler(rcUP)}else{if(A==2){mealKeyHandler(rcDOWN)}else{if(A==3){mealKeyHandler(rcLEFT)}else{if(A==4){mealKeyHandler(rcRIGHT)}}}}}function mealPanelHome(B){var A="";A=(B==1?"#fcf3b8":"none");document.getElementById("mealPanelHomeBtn").style.background=A}function escapeMealPanel(){mealKeyHandler(rcMENU)}function onMealType(A){prevMealOption=mealOptionCursor;mealOption=0;mealOptionCursor=A;curMealOption=A+mealTypeClick;highLightMealType();buildMealOptions()}function openMealTypeContent(A){mealKeyHandler(rcOK)}function onMealItems(A){prevMealListOption=mealListCursor;mealOption=1;mealListCursor=A;curMealListOption=A+mealItemClick;highLightMealItems();assignMealDesc()}function openSelMealItems(A){mealKeyHandler(rcOK)}function showMealImage(){try{document.getElementById("mealImage").innerHTML='<img src="./view/tv/images/widgets/meals/meal'+curMealOption+'.png" />'}catch(A){}}