  var currKey;
	/////////////////////////////////////////////////////////////
    // Identify page as enabled for Media Center. This avoids a warning dialog to user.
    function IsMCEEnabled()
    {
        return true
    }



    /////////////////////////////////////////////////////////////////
    // Initialization
 
    function Initialize()
    {
    
	// SET THE CORRECT SVP BACKGROUND COLOR
	try {
		var MCE = window.external.MediaCenter();

		if (MCE)
                        MCE.BGColor = "RGB(001,000,102)";
        }
        catch(e) { 
                //empty 
	}
    

        // if current focus is on shared or custom viewport (i.e. when you hit Back after you go to full screen for
        // the media playback), don't try to do setfocus
        if (nCurFocus == "SVP" || nCurFocus == "CVP" )
        {
            return
        }
        SetFocus();
    }


    /////////////////////////////////////////////////////////////////
    // disable right click
    function Disable()
    {
    
    
        if (event.button == 2)
            try
            {
                 //window.external.MediaCenter().Dialog("right-click disabled","",1,30,true)      
            }
            catch(e)
            {
                //alert("right-click disabled")
            }
    }


    /////////////////////////////////////////////////////////////////
    // user selected item, navigate to it based on DestinationArray
    function DoNavigation()
    {
    
        // make sure focus is not on a viewport
        if ((nCurFocus == "SVP") || (nCurFocus == "CVP"))
        {
            return  
        }

        playSelectSound();
        try
        {    
            // if array element is not empty
            if (aFocusTableArray[nCurFocus-1][10] != "")
            {
                try
                {
                    // try to run as a function; if element string is a link instead of a function, create an error
                    eval(aFocusTableArray[nCurFocus-1][10]);
                    // If element is a link starting with "http" it will not cause error;
                    // so check if string starts with "http"; if so, treat as a link
                    try 
                    {
                        var sArraySubStr = (aFocusTableArray[nCurFocus-1][10]).substring(0, 4)
                        if (sArraySubStr == "http")
                        {
                            window.navigate(aFocusTableArray[nCurFocus-1][10]);
                        }
                    }
                    catch(e)
                    {
                        // ignore error
                    }
                }
                catch(e)
                {
                    // if previous throws error, treat as a link
                    window.navigate(aFocusTableArray[nCurFocus-1][10]);
                }
            }
        }
        catch(e)
        {
            try
            {
                //window.external.MediaCenter().Dialog("Number: " + e.number + "\n\nDescription: " + e.description,"DoNavigation() Error",1,30,true); 
            }
            catch(e)
            {
                //alert("DoNavigation() Error\n\nNumber: " + e.number + "\n\nDescription: " + e.description);
            }
        }
    }


    /////////////////////////////////////////////////////////////////
    // focus on item in list based on nCurFocus value and user input
    function SetFocus(nKey)
    {
    
        try
        {
            /////////////////////////////////////////////////////////////////////////////////
            // reset mouse variable to nullify mouseover event, which can fire after keypress    
            nMouseEvent = 0;

            //////////////////////////////////////////////////////////////////////////////////
            // hold onto current focus in case it gets broken along the way

            var nPrevFocus = nCurFocus;
            
            //////////////////////////////////////////////////////////////////////////////////
            // update nCurFocus values based on key selection
            // on first visit to page, nothing to do because nCurFocus is initialized

            //first, check if previous focus is on a viewport
            if (nPrevFocus == "CVP")
            {
                // check correct array for new focus item
                nCurFocus = aCustomViewportArray[nKey];
            }
            else if (nPrevFocus == "SVP")
            {
                // check correct array for new focus item
                nCurFocus = aSharedViewportArray[nKey];
            }
                        
            // if previous focus is not on a viewport, find new focus item in regular array
            else
            {
                if (nKey >= 0)
                {
                    nCurFocus = aFocusTableArray[nCurFocus-1][nKey];
                }
            }

           //////////////////////////////////////////////////////////////////////////////////
            // user tried an illegal move, reset nCurFocus to known state
            if (nCurFocus == -1)
            {
                nCurFocus = nPrevFocus;
                return;
            }
            
            DrawFocus(nPrevFocus, nCurFocus);
			if(nCurrPage=="Help"){

				if(nCurFocus==8){
					 listTable.style.top=-186;
				}
				else{
					 listTable.style.top=0;
				}
			
				if(nCurFocus<7){
					vbarTd.className='vbarTd_noActive';
					text1.className="mainContentGrey";
					text2.className="mainContentGrey";
					text3.className="mainContentGrey";
					text4.className="mainContentGrey";

				}
				else{
					vbarTd.className='vbarTd_active';
					text1.className="mainContent";
					text2.className="mainContent";
					text3.className="mainContent";
					text4.className="mainContent";
				
				}
			}
        }
        catch(e)
        {
            try
            {
                //window.external.MediaCenter().Dialog("Number: " + e.number + "\n\nDescription: " + e.description,"SetFocus() Error",1,30,true); 
            }
            catch(e)
            {
                //alert("SetFocus() Error\n\nNumber: " + e.number + "\n\nDescription: " + e.description);
            }
        }
    }


    /////////////////////////////////////////////////////////////////
    // DrawFocus
    function DrawFocus(nPrevFocus, nCurFocus)
    {
        
        try
        {
            // if previous item is a viewport
            if ((nPrevFocus == "SVP") || (nPrevFocus == "CVP"))
            {
            // remove focus from viewport
                if (nPrevFocus == "SVP")
                {
                    try
                    {
                       // add code to remove focus from viewport (not supported yet)
                    }
                    catch(e)
                    {
                        //Viewport is hidden; ignore error
                    }
                }
                if (nPrevFocus == "CVP")
                {
                    try
                    {
                       // add code to remove focus from viewport (not supported yet)
                    }
                    catch(e)
                    {
                        //Viewport is hidden; ignore error
                    }
                }
            }
            else
            {
                // remove focus from the previous item if different
                if (nPrevFocus != nCurFocus)
                {
                    var strPrevItemName = eval('item' + nPrevFocus);
                    
                    // check if previous item is "enforced" (to indicate active category)
                    try
                    {
                        if (strPrevItemName.id == strEnforcedItem)
                        {
                            eval(strPrevItemName).className = strEnforcedItemNoFocusStyle;
                        }
                        else
                        {
                            eval(strPrevItemName).className=aFocusTableArray[nPrevFocus-1][5];
                        }
                    }
                    catch(e)
                    {
                        eval(strPrevItemName).className=aFocusTableArray[nPrevFocus-1][5];
                    }
                }
            }

                        
            // Play "click" sound
            playFocusSound();

            // set buttons in current array to non-dormant, and buttons in other
            // arrays to dormant
           setDormant(nCurFocus, nPrevFocus);


            // if new item is shared viewport
            if (nCurFocus == "SVP")
              {
                  // check if shared viewport is visible
                try
                {
                    if (window.external.MediaCenter().SharedViewPort.Visible == true)
                    {
                        window.external.MediaCenter().SharedViewPort.Focus()// focus on shared viewport
                    }
                    else
                    {
                        // viewport is hidden, so reset focus to backup item in viewport array, by setting nKey to 4
                        SetFocus(4)
                    }
                }

                catch(e)
                {
                    SetFocus(4)
                }

                return
              }
            //if new item is custom viewport
            else if (nCurFocus == "CVP")
              {
                  // check if custom viewport is visible
                try
                {
                    if (window.external.MediaCenter().CustomViewPort.visible == true)
                    {
                        window.external.MediaCenter().CustomViewPort.Focus() // focus on custom viewport
                    }
                    else
                    {
                        // viewport is hidden, so reset focus to backup item in viewport array, by setting nKey to 4
                        SetFocus(4)
                    }
                }

                catch(e)
                {
                    SetFocus(4)
                }

                return
              }

            // give focus to the new item
            var strNewItemName = eval('item' + nCurFocus)


            // check if new item is "enforced" (to indicate active category)
            try
            {
                if (strNewItemName.id == strEnforcedItem)
                {
                    // reset style
                    eval(strNewItemName).className = strEnforcedItemFocusStyle
                }
                else
                {
                // reset style
                    eval(strNewItemName).className=aFocusTableArray[nCurFocus-1][4];
                }
            }
            catch(e)
            {
                   eval(strNewItemName).className=aFocusTableArray[nCurFocus-1][4];
            }

               
            // determine if the page has a scrolling menu
            try
            {

                if  (strScrollPage == "yes")
                {
                    scrollMenu(nCurFocus);
                }
            }
            catch (e)
            {
                //ignore error
            }

            // Custom (optional) function if needed; locate this function on the HTML page
            try
            {
                doOnFocus();
            }
            catch(e)
            {
                //ignore error
            }
        }
        catch(e)
        {
            try
            {
                //window.external.MediaCenter().Dialog("Number: " + e.number + "\n\nDescription: " + e.description,"DrawFocus() Error",1,30,true);    
            }
            catch(e)
            {
                //alert("DrawFocus() Error\n\nNumber: " + e.number + "\n\nDescription: " + e.description);
            }
        }        
    }


    /////////////////////////////////////////////////////////////////
    // Scaling elements for page resize 
    function onScaleEvent(vScale)
    {
    
        try
        {
            body.style.zoom=vScale;
        }
        catch(e)
        {
            // ignore error
        }
    }


    /////////////////////////////////////////////////////////////////
    // determine which remote control key the user selected 
    // and take appropriate action
    function onRemoteEvent(keyChar)
    {

	//		window.alert(keyChar);
        try
        {
            if (doOnFocus(keyChar) == true) return;
        }
        catch(e)
        {
            // if doOnFocus function is not present on page, ignore error
        }    
		try{
    	
			if(nCurrPage=='Login'){
			return onLoginEvent(keyChar);
			}
        }
		catch(exx){
			//ignore undefine nCurrPage
		}

        try
        {

            // this switch tests to see which button on the remote is pressed        
            switch (keyChar)
            {
            case 0x26:  // Up button selected
                SetFocus(0);
                return true;
                break;

            case 0x28:  // Down button selected
                SetFocus(1);
                return true;
                break;

            case 0x25:  // Left button selected
                SetFocus(2);
                return true;
                break;

            case 0x27:  // Right button selected
                SetFocus(3);
                return true;
                break;

            case 0x0D:    // Enter button selected, execute link to content/page
                DoNavigation();
                return true;
                break;

            case 0x08:  // Keyboard Backspace selected
                return false;
                break;

            case 0xA6:            // Browser Back button selected; Media Center will already perform a Back
                return false;      // navigation when this is pressed, but this case can be used to add additional
                break;             //functionality to Back button

            case 0x21:    // Page up (plus) selected; page-up scrolling menu
                        // (currently works for keyboard pg-up, but not for remote key)
                pageUp();
                return true;
                break;
                
            case 0x22:    // Page down (minus) selected; page-down scrolling menu
                        // (currently works for keyboard pg-down, but not for remote key)
                pageDown();
                return true;
                break;

            case 176:   // ignore 'skip' button
                return true;
                break;

            case 177:   //ignore 'replay' button
                return true;
                break;
                
                                
            default:
                return false;
                // no special handling for all other clicks
            }
        }
        catch(ex)
        {
            logEx("onRemoteEvent(" + keyChar + ")", ex);
        }
    }




	   function onLoginEvent(keyChar)
    {
        
		if(currInput==1){
			 innernavigate(keyChar);
			 return true;
		}
        
        try
        {
            // this switch tests to see which button on the remote is pressed        
            switch (keyChar)
            {
            case 0x26:  // Up button selected
                SetFocus(0);
                return true;
                break;

            case 0x28:  // Down button selected
                SetFocus(1);
                return true;
                break;

            case 0x25:  // Left button selected
                SetFocus(2);
                return true;
                break;

            case 0x27:  // Right button selected
                SetFocus(3);
                return true;
                break;

            case 0x0D:    // Enter button selected, execute link to content/page
				DoNavigation();
				return true;
                break;

            case 0x08:  // Keyboard Backspace selected
                return false;
                break;

            case 0xA6:            // Browser Back button selected; Media Center will already perform a Back
                return false;      // navigation when this is pressed, but this case can be used to add additional
                break;             //functionality to Back button

            case 0x21:    // Page up (plus) selected; page-up scrolling menu
                        // (currently works for keyboard pg-up, but not for remote key)
                pageUp();
                return true;
                break;
                
            case 0x22:    // Page down (minus) selected; page-down scrolling menu
                        // (currently works for keyboard pg-down, but not for remote key)
                pageDown();
                return true;
                break;

            case 176:   // ignore 'skip' button
                return true;
                break;

            case 177:   //ignore 'replay' button
                return true;
                break;
                
                                
            default:
                return false;
                // no special handling for all other clicks
            }
        }
        catch(ex)
        {
            logEx("onRemoteEvent(" + keyChar + ")", ex);
        }
    }


    /////////////////////////////////////////////////////////////////
    // SetCounter
    function setCounter()
    {
        //if page contains a scrolling button menu, set counter values
        if (strScrollPage == "yes")
        {
            // Make the menu's item counter visible
            itemCounterSpan.style.display = "block";
            // Show total number of buttons in menu
            counterTotal.innerText = eval(nTotalBtns);
        }
    }

	/////////////////////////////////////////////////////////////////
    // SetCounter

	function enableScroll()
    {
        //if page contains a scrolling button menu, set counter values
        strScrollPage = "yes"
    }



    /////////////////////////////////////////////////////////////////
    // Sounds
    function playSelectSound()
    {
        btnSound.src = strSelectSound;
    }


    /////////////////////////////////////////////////////////////////
    // Sounds
    function playFocusSound()
    {
        btnSound.src = strFocusSound;
    }


    // ----------------- Start code to scroll menu ------------------                         
    function scrollMenu(nCurFocus)
    {
        var nFocusBtnRow
        //test for number of columns
        try 
        {
            var nCols = nScrollMenuBtnCols
        }
        catch(e)
        {
            var nCols = 1
        }

            // if selected item button is not on the scrolling menu table, gray-out counter and end function
        if ((nCurFocus < nScrollMenuStartNo) || (nCurFocus > nScrollMenuEndNo))
        {
            itemCounterSpan.style.filter = "alpha(opacity=50)";
            return
        }
        // determine what position the current-focus button occupies in list table by
        // subtracting the number of buttons that occur on the page before the 
        // menu starts (nScrollMenuStartNo - 1) from the item number
        // of the current-focus button (nCurFocus)
        var nFocusBtnPosition = (nCurFocus - (nScrollMenuStartNo - 1));
            // determine what row in list table current-focus button occupies
        if (Math.floor((nFocusBtnPosition) / nCols) < ((nFocusBtnPosition) / nCols))
        {
            nFocusBtnRow = (Math.floor((nFocusBtnPosition) / nCols) + 1)
        }
        else 
        {
            nFocusBtnRow = ((nFocusBtnPosition) / nCols)
        }

        // reset counter
        resetCounter(nCurFocus);

        // set a variable for the current position (# of button spaces offset) of 
        // the top of the list table
        var nTableTopPosition = (listTable.offsetTop / -(nBtnHeight));

        // determine whether the current-focus button is out of view, above or below; scroll accordingly

        if (nFocusBtnRow > (nVisibleBtns + nTableTopPosition))
        {
            // focus btn is below view, so scroll down
            listTable.style.top = (listTable.offsetTop - nBtnHeight)    
        }
        if (nFocusBtnRow <= nTableTopPosition)
        {
            // focus btn is above view, so scroll up
            listTable.style.top = ((nFocusBtnRow - 1) * -(nBtnHeight))
        }
    }
    // ----------------- End code to scroll menu ------------------


    // ----------------- Start code to set non-selected menu to dormant ------------------
    function setDormant(nCurFocus, prevItemNo)
    // NOTE: this function does not work for every item; it is made to catch errors and ignore them
    {
    
        try
        {
            // if strDormantPage variable on HTML page is not set to "yes" then end function
            if (strDormantPage != 'yes')
            {
                return
            }
        }
        catch(e)
        {
        // ignore error
        }

        try
        {
        // find previous button
            var oPrevBtn = eval('item' + prevItemNo);
            // find outer tables for previous button
            var oPrevParentTable = oPrevBtn.parentElement.parentElement.parentElement.parentElement;
        }
        catch(e)
        {
            //ignore error
            // can't set previous item to dormant
        }

        try
        {
            // find current button
            var oCurrentBtn = eval('item' + nCurFocus);
            // find outer tables for current button
            var oCurParentTable = oCurrentBtn.parentElement.parentElement.parentElement.parentElement;
        }
        catch(e)
        {
            //ignore error
            // can't set current item to dormant
        }

        // if previous and current buttons are in the same table, do nothing
        try
        {
            if (oPrevParentTable == oCurParentTable)
            {
                return
            }
        }
        catch(e)
        {
            //ignore error
        }

        try
        {
            // set previous-table items to dormant
            for (i=0; i < oPrevParentTable.cells.length; i++)
            {
                // reset background for each span
                oPrevParentTable.cells(i).children(0).className=aFocusTableArray[(prevItemNo-1)][6];
            }
            // reset type style in each cell
            oPrevParentTable.className=aFocusTableArray[(prevItemNo-1)][7];
            //if enforced item is in previous table, make it dormant too
            try
            {
                if(eval(strEnforcedItem).parentElement.parentElement.parentElement.parentElement == oPrevParentTable)
                { 
                    eval(strEnforcedItem).className = strEnforcedItemDormantStyle
                }
            }
            catch(e)
            {
            //ignore error
            }
        }
        catch(e)
        {
        //ignore error
        }

        // set current button's menu to active (non-dormant)
        try
        {
            for (i=0; i < oCurParentTable.cells.length; i++)
            {
                // reset background for each span
                oCurParentTable.cells(i).children(0).className=aFocusTableArray[(nCurFocus-1)][5];
                
            }
            // reset type style in all of parent table
               oCurParentTable.className=aFocusTableArray[(nCurFocus-1)][8];
            //if enforced item is in current table, make it active too
            try
            {
                if(eval(strEnforcedItem).parentElement.parentElement.parentElement.parentElement == oCurParentTable)
                {
                    eval(strEnforcedItem).className = strEnforcedItemNoFocusStyle
                }
            }
            catch(e)
            {
            //ignore error
            }o
        }
        catch(e)
        {
            //ignore error
        }
    }
    // ----------------- End code to set non-selected menu to dormant ------------------


    // ----------------- Start code to reset counter number values (for scrolling menus) ------------------
    function resetCounter(nCurFocus)
    {
        var nFocusBtnPosition = (nCurFocus - (nScrollMenuStartNo - 1));
        // un-gray counter
        itemCounterSpan.style.filter = "alpha(opacity=100)";
        // display position of currently selected btn in counter
        counterNum.innerText = eval(nFocusBtnPosition);
        // gray out up arrow if focus in on top button
        if (nCurFocus == nScrollMenuStartNo)
        {
            arrowUp.disabled = true;
            arrowUp.style.filter = "alpha(opacity=20)";
        }
        else
        {
            arrowUp.disabled = false;
            arrowUp.style.filter = "alpha(opacity=60)";
        }
        // gray out down arrow if focus in on bottom button
        if (nCurFocus == nScrollMenuEndNo)
        {
            arrowDown.disabled = true;
            arrowDown.style.filter = "alpha(opacity=20)"
        }
        else
        {
            arrowDown.disabled = false;
            arrowDown.style.filter = "alpha(opacity=60)"
        }
    }
    // ----------------- End code to reset counter number values  ------------------


    // --------------- Start code for Paging up/down (for scrolling menus) ---------------------------
    try 
    {
        var nPageDistance = ((nVisibleBtns * nBtnHeight) - nBtnHeight)        // Maximum distance to scroll for one "page" increment
    }
    catch(e)
    {
        nPageDistance = 0;
    }
    
    function pageDown()
    {
        // determine if listTable has cellspacing; will need to subtract extra spacing from bottom of table
        var nTablePadding = eval(listTable.getAttribute("cellspacing"));
        // variables
        nPageDistance = ((nVisibleBtns * nBtnHeight) - nBtnHeight);                        // Maximum distance to scroll for one "page" increment

        // if there is just one big selectable row showing at a time in the scrollable menu, treat paging down the same as
        // scrolling down one item at a time (call setFocus function, passing the down-arrow key code).
        if (nPageDistance < nBtnHeight)
        {
            SetFocus(1);
            return
        }

        var nMaxPageDistance = ((listTable.offsetHeight - nTablePadding) - nPageDistance); // Maximum total paging distance
        var nCurrentScrollAmnt = -listTable.offsetTop;                                     // amount already scrolled
        //test for number of columns
        try
        {
            var nCols = nScrollMenuBtnCols
        }
        catch(e)
        {
            var nCols = 1
        }

        // if selected item button is not on the scrolling menu table, end function
        if ((nCurFocus < nScrollMenuStartNo) || (nCurFocus > nScrollMenuEndNo))
        {
            return
        }

        var nFocusBtnPosition = (nCurFocus - (nScrollMenuStartNo - 1));

        // determine what row in list table current-focus button occupies
        if (Math.floor((nFocusBtnPosition) / nCols) < ((nFocusBtnPosition) / nCols))
        {
            nFocusBtnRow = (Math.floor(nFocusBtnPosition / nCols) + 1)
        }
        else
        {
            nFocusBtnRow = ((nFocusBtnPosition) / nCols)
        }
        // determine last row in menu
        var nLastRow = Math.floor((nScrollMenuEndNo - (nScrollMenuStartNo - 1)) / nCols)

        if (Math.floor((nScrollMenuEndNo - (nScrollMenuStartNo - 1)) / nCols) < ((nScrollMenuEndNo - (nScrollMenuStartNo - 1)) / nCols))
        {
            nLastRow = ((Math.floor((nScrollMenuEndNo - (nScrollMenuStartNo - 1)) / nCols)) + 1)
        }
        else
        {
            nLastRow = ((nScrollMenuEndNo - (nScrollMenuStartNo - 1)) / nCols)
        }
        // find which column current focus btn is in (multiply number of previous row by # of columns, and subtract from nFocusBtnPosition)    
        var nFocusCol = (nFocusBtnPosition - ((nFocusBtnRow - 1) * nCols));
        // bottom visible row
        var nBottomVisRowNo = ((nCurrentScrollAmnt / nBtnHeight) + nVisibleBtns);
        if (nBottomVisRowNo >= nLastRow)
        {
            nBottomVisRowNo = nLastRow;
        }

        // determine which button is in focus col of bottom visible row
        var nNewFocusPosition = (((nBottomVisRowNo -1) * nCols) + nFocusCol);
        var nNewFocusBtnNo = (nNewFocusPosition + (nScrollMenuStartNo - 1));
        if (nNewFocusBtnNo > nScrollMenuEndNo)
        {
            nNewFocusBtnNo = nScrollMenuEndNo;
        }

        // if menu has already scrolled to bottom, set focus to last button and end function
        if (listTable.offsetHeight <= ((nVisibleBtns * nBtnHeight) + nCurrentScrollAmnt + nTablePadding))
        {

            DrawFocus(nCurFocus, nNewFocusBtnNo);
            nCurFocus = nNewFocusBtnNo;
            //reset counter
            resetCounter (nCurFocus);
            return;
        }

        // If current-focus btn is not in bottom visible row, assign focus there, do resets, and end function
        if (nCurFocus != nNewFocusBtnNo)
        {
            DrawFocus(nCurFocus, nNewFocusBtnNo);
            nCurFocus = nNewFocusBtnNo;
            //reset counter
            resetCounter (nCurFocus);
            return
        }

        // move page down
        listTable.style.top = -(nCurrentScrollAmnt + nPageDistance);

        // update variables
        nCurrentScrollAmnt = -listTable.offsetTop;
        nBottomVisRowNo = ((nCurrentScrollAmnt / nBtnHeight) + nVisibleBtns);
        if (nBottomVisRowNo >= nLastRow)
        {
            nBottomVisRowNo = nLastRow;
        }

        // update which button is in bottom visible row, focus col -- based on new position
        nNewFocusPosition = (((nBottomVisRowNo -1) * nCols) + nFocusCol);
        nNewFocusBtnNo = (nNewFocusPosition + (nScrollMenuStartNo - 1));
        if (nNewFocusBtnNo > nScrollMenuEndNo)
        {
            nNewFocusBtnNo = nScrollMenuEndNo;
        }

        //reset focus to bottom visible btn
        DrawFocus(nCurFocus, nNewFocusBtnNo);
        nCurFocus = nNewFocusBtnNo;
        //reset counter
        resetCounter (nCurFocus);
    }


    //----------------------------Page Up ---------------------------------------------
    function pageUp()
    {
        // determine if listTable has cellspacing; will need to subtract extra spacing from bottom of table
        var nTablePadding = eval(listTable.getAttribute("cellspacing"));
        // variables
        nPageDistance = ((nVisibleBtns * nBtnHeight) - nBtnHeight);                         // Maximum distance to scroll for one "page" increment

        // if there is just one big selectable row showing at a time in the scrollable menu, treat paging up the same as
        // scrolling up one row at a time (to do this, call setFocus function, passing the up-arrow key code).
        if (nPageDistance < nBtnHeight)
        {
            SetFocus(0);
            return
        }
        var nMaxPageDistance = ((listTable.offsetHeight - nTablePadding) - nPageDistance);  // Maximum total paging distance
        var nCurrentScrollAmnt = -listTable.offsetTop;                                      // amount already scrolled

        //test for number of columns
        try 
        {
            var nCols = nScrollMenuBtnCols;
        }
        catch(e)
        {
            var nCols = 1;
        }

        // if selected item button is not on the scrolling menu table, end function
        if ((nCurFocus < nScrollMenuStartNo) || (nCurFocus > nScrollMenuEndNo)){
        return;
        }

        var nFocusBtnPosition = (nCurFocus - (nScrollMenuStartNo - 1));

        // determine what row in list table current-focus button occupies
        if (Math.floor((nFocusBtnPosition) / nCols) < ((nFocusBtnPosition) / nCols))
        {
            nFocusBtnRow = (Math.floor(nFocusBtnPosition / nCols) + 1);
        }
        else
        {
            nFocusBtnRow = ((nFocusBtnPosition) / nCols);
        }

        // find which column current focus btn is in (multiply number of previous row by # of columns, and subtract from nFocusBtnPosition)    
        var nFocusCol = (nFocusBtnPosition - ((nFocusBtnRow - 1) * nCols));

        // top visible row
        var nTopVisRowNo = ((nCurrentScrollAmnt / nBtnHeight) + 1);

        // determine which button is in target col of top visible row
        var nNewFocusPosition = (((nTopVisRowNo -1) * nCols) + nFocusCol);

        var nNewFocusBtnNo = (nNewFocusPosition + (nScrollMenuStartNo - 1));

        // if menu is already at top, set focus to top btn, reset counter, and end function
        if (listTable.offsetTop >= 0)
        {
            DrawFocus(nCurFocus, nNewFocusBtnNo);
            nCurFocus = nNewFocusBtnNo;
            resetCounter (nCurFocus);
            return;
        }

        // If focus is not on top visible button in column, assign focus there and end function    
        if (nCurFocus != nNewFocusBtnNo)
        {
            DrawFocus(nCurFocus, nNewFocusBtnNo);
            nCurFocus = nNewFocusBtnNo;
            // reset counter
            resetCounter (nCurFocus);
            return;
        }

        // move page up
        if ((-nCurrentScrollAmnt + nPageDistance) < 0) 
        {
            listTable.style.top = (-nCurrentScrollAmnt + nPageDistance);
        }
        else 
        {
            listTable.style.top = 0;
        }

        // update variables
        nCurrentScrollAmnt = -listTable.offsetTop;
        nTopVisRowNo = ((nCurrentScrollAmnt / nBtnHeight) + 1);
        nNewFocusPosition = (((nTopVisRowNo -1) * nCols) + nFocusCol);
        nNewFocusBtnNo = (nNewFocusPosition + (nScrollMenuStartNo - 1));

        //reset focus to top visible btn
        DrawFocus(nCurFocus, nNewFocusBtnNo);
        nCurFocus = nNewFocusBtnNo;

        //reset counter
        resetCounter (nCurFocus);
    }
    // --------------------------------- End code for Paging up/down ----------------------------------------------------


    //----------------------------- Start code for switching to mouse ------------------------------------
    function useMouse(newItem)
    {
    
        if (nMouseEvent == 0)
        {
            nMouseEvent = 1;
            return;
        }
        var nNewItemNo = (newItem.children(0).id).substring(4);
        var nPrevFocus = nCurFocus;
        nCurFocus = nNewItemNo;
        DrawFocus(nPrevFocus, nCurFocus);
    }

//
    function useMouse2(newItem)
    {
    
        if (nMouseEvent == 0)
        {
            nMouseEvent = 1;
            return;
        }
        var nNewItemNo = (newItem.id).substring(4);
        var nPrevFocus = nCurFocus;
        nCurFocus = nNewItemNo;
        DrawFocus(nPrevFocus, nCurFocus);
    }

    //----------------------------- End of code for switching to mouse ------------------------------------

    // Temporary "highlight" effect when button is clicked  state, or clicked state
    function btnHiLite (srcBtn, style)
    {
    
        try
        {
            if ((strEnforcedItem == srcBtn.id) && (window.event.type == 'mouseup'))
            {
                style = strEnforcedItemFocusStyle;
            }
        }
        catch(e)
        {
        }
        srcBtn.className = style;
    }

    function btnHiLite2(srcBtn, style)
    {
    
        try
        {
            if ((strEnforcedItem == srcBtn.id) && (window.event.type == 'mouseup'))
            {
                style = inputItemFocusStyle;
            }
        }
        catch(e)
        {
        }
        srcBtn.className = style;
    }




    // Set button for enforced state (add code as necessary)
    function btnEnforced(btn)
    {
    
    }


    //----------------------------- Start code for Spinner control ------------------------------------
    // args are: (string to indicate whether to move up or down, number to identify which spinner to set)
    function countSpinner(sPlusMinusStr, nSpinnerNumber)
    {
    
        // check for disabled button
        if (eval("item" + nCurFocus).disabled == true)
        {
            return
        }

        // determine which array to use
        var sCurrentArray = "aSpinnerArray" + nSpinnerNumber
        // determine which element is currently shown
        var nTempElementCount = eval("aSpinnerArray" + nSpinnerNumber).count
        // if user clicked Plus, move element count forward by one
        if (sPlusMinusStr == "plus")
        {
            nTempElementCount = nTempElementCount + 1
        }
        // if user clicked Minus, move element count back by one
        if (sPlusMinusStr == "minus")
        {
            nTempElementCount = nTempElementCount - 1
        }

        // Call function to set spinner text
        setSpinner(sCurrentArray, nSpinnerNumber, nTempElementCount)

        // disable plus/minus buttons as needed
        if (nTempElementCount >= eval(sCurrentArray).length -1)
        {
            // disable second button in span (should be plus button)
            eval("item" + nCurFocus).parentElement.children[1].disabled = true
        }
        else
        {
            // enable second button in span (should be plus button)
            eval("item" + nCurFocus).parentElement.children[1].disabled = false
        }

        if (nTempElementCount <= 0)
        {
            // disable first button in span (should be minus button)
            eval("item" + nCurFocus).parentElement.children[0].disabled = true
        }
        else
        {
            // enable first button in span (should be minus button)
            eval("item" + nCurFocus).parentElement.children[0].disabled = false
        }

        //reset element count    
        eval(sCurrentArray).count = nTempElementCount;

    }


    /////////////////////////////////////////////////////////////////
    // setSpinner
    function setSpinner(sCurrentArray, nSpinnerNumber, nTempElementCount)
    {
    
        //determine which spinner box to update
        var oCurBox = eval("spinnerBox" + nSpinnerNumber)
        // update box text with contents of array element
        oCurBox.innerHTML = (eval(sCurrentArray)[nTempElementCount]);
    }
    
    
    /////////////////////////////////////////////////////////////////
    // detect whether user is in a remote session on a Media Center Extender device
    function IsMCExtender()
    {
        try
        {
            // if this is not a console session ...
            if (window.external.MediaCenter.Capabilities.IsConsole == false)
            {
                /* ...then it is either a Media Center Extender session or a traditional Remote Desktop session.
                To tell which type of session it is, check if video is allowed. If video is allowed... */
                if (window.external.MediaCenter.Capabilities.IsVideoAllowed == true)
                {
                    // ... then it is an extender session, so return true    
                    return true
                }
                // Media Center does not allow video in a traditional Remote Desktop session. So if video is not allowed ...
                else
                {
                    /* IsConsole and IsVideoAllowed are both false false, so user is accessing through a traditional Remote 
                    Desktop session, rather than from an extender device. That means that they probably have access to a keyboard 
                    and mouse, but they cannot play video. If your application features video playback, you may want to 
                    adjust your functionality for this user accordingly. 
                    Returning false simply indicates that this is not an Extender session.  */                
                    return false
                }
            }
            else
            {
                // If not, this is a Media Center session on the console PC, so return false
                return false
            }
        }
        catch(e)
        {
            /* If above cause errors, user is probably accessing from a browser outside of Media Center.
            Return false to indicate that it is not an extender session. */
            return false
        }   
    }

    
    ///////////////////////////////////////////////
    // isWMC
    function isWMC() 
    {
        try {
    		var MCE = window.external.MediaCenter();
    		if (MCE) {
	            return true;
		    }
	    }
    	catch(e) {
            return false;
	    }
    }
    
        

    
    function debug(msg)
    {

        window.external.MediaCenter().Dialog(msg,"",1,30,true)     
    
    }
    
    
    
/////////////////////////////////////////////////////////////////////////////////////////////////
/* this function gives console users three options:
1. Open an IE window and go to the assigned URL
2. Create a shortcut on their desktop to the URL
3. Cancel 

NOTE: bobsled users don't get option 1 
*/
function goToURL(title, url)
{
	// params are str shortcut title, str URL
	window.external.MediaCenter.CreateDesktopShortcut(title, url);
}


/////////////////////////////////////////////////////////////////////////////////////////////////
// This function detects what version of Media Center the user is running. 
// It will return year as string, such as "2005"

function showMCEVersion()
{
	try
	{
		var nVer = (window.external.MediaCenter.MajorVersion + (window.external.MediaCenter.MinorVersion / 10))
	}
	catch (e)
	{
		return null
	}
	
	if (nVer < 6.7) return "2004" // harmony
	if (nVer > 6.7) return "2005" //Symphony
	// in case above fails, return null
	return null
}
   

function IsSymphony()
{
    if (showMCEVersion() ==  "2005")
        return true;

    return false;
}         

function IsHarmony()
{
    if (showMCEVersion() ==  "2004")
        return true;

    return false;
}         

function pageDownHelp(){
	 SetFocus(1);
	 listTable.style.top=-186;
}
function pageUpHelp(){
	 listTable.style.top=0;
	 SetFocus(0);
}


var currentLine=-1;
var currentCol=-1;

function innernavigate(keyCode)   
{
    switch(keyCode)  
    {
	case 37: //LEFT KEY
            currentCol--;
            changeItem();
	    break;
        case 38: //UP KEY
            currentLine--;
            changeItem();
            break;
	case 39: //RIGHT KEY
            currentCol++;
            changeItem();
            break;
        case 40: //DOWN KEY
            currentLine++;
            changeItem();
            break;
		case 13:
/*			try{
				if(currKey.id=='enterID'){
					endInput(); 
				}
			}
			catch(e){
			}
			break; */
			break;
        default   :
            break;
    }
}

//direction key function

function   changeItem()
{  
if(   document.all   ){
        var   it   =   document.getElementById("ice");//.children[0];
	}
	else{
        var   it   =   document.getElementById("ice");
	}
 /*   for   (i=0;i<it.rows.length;i++)   
    {
        it.rows[i].className   =   "";
    }
*/
    if   (currentLine   <   0)
{
        currentLine   =   it.rows.length   -   1;
}
    if   (currentLine   ==   it.rows.length)
{
        currentLine   =   0;
}

var objtab = document.all.ice;
var objrow=objtab.rows[currentLine].getElementsByTagName("INPUT");

if(currentCol<0)
{
currentCol=objrow.length-1;
}else if(currentCol==objrow.length)
{
currentCol=0;
}
try{
objrow[currentCol].select();
currKey=objrow[currentCol];
}
catch(e){
	try{
		objrow[currentCol-1].select();
		currKey=objrow[currentCol-1];
	}
	catch(e){
		objrow[currentCol-2].select();
		currKey=objrow[currentCol-2];
	}

}
	it.rows[currentLine].className   =   "highlight";
}
  
//-->