﻿// Fix standard popup menu for IE

var ENABLE_MENU_FLAG = false;

function Menu_SetEnabled(p_bEnabled)
{
    ENABLE_MENU_FLAG = p_bEnabled;
}

function Menu_GetEnabled()
{
    return ENABLE_MENU_FLAG;
}

function WrapFunction(p_sFnName)
{
    var sOldFnID = "Old_" + p_sFnName;
    window[sOldFnID] = window[p_sFnName];
    var sParamDefinition = '';
    var sParamCall = '';
    var iLen = window[p_sFnName].length;
    if (!isNaN(iLen) &&
        iLen > 0)
    {
        var aParams = new Array();
        for(var i = 0; i < iLen; ++i)
            aParams.push(String.format('p{0}', i));
        sParamDefinition = '"' + String.join(aParams, '","') + '",';
        sParamCall = ',' + String.join(aParams);
    }    
    var sWrapperTpl = 'new Function({0}"if (Menu_GetEnabled()) return {1}.call(null{2});")';
    window[p_sFnName] = eval(String.format(sWrapperTpl, sParamDefinition, sOldFnID, sParamCall));    
}

var menuFunctions = ['Menu_ClearInterval', 'Menu_Collapse', 'Menu_Expand', 'Menu_FindMenu', 
'Menu_FindNext', 'Menu_FindParentContainer', 'Menu_FindParentItem', 'Menu_FindPrevious',
'Menu_FindSubMenu', 'Menu_Focus', 'Menu_GetData', 'Menu_HideItems',
'Menu_HoverDisabled', 'Menu_HoverDynamic', 'Menu_HoverRoot', 'Menu_HoverStatic',
'Menu_IsHorizontal', 'Menu_IsSelectable', 'Menu_Key', 'Menu_ResetSiblings',
'Menu_ResetTopMenus', 'Menu_RestoreInterval', 'Menu_SetRoot', 'Menu_Unhover',
'PopOut_Clip', 'PopOut_Down', 'PopOut_Hide', 'PopOut_HideScrollers',
'PopOut_Position', 'PopOut_Scroll', 'PopOut_SetPanelHeight', 'PopOut_Show',
'PopOut_ShowScrollers', 'PopOut_Stop', 'PopOut_Up'];

function WrapMenu()
{
    for (var i = 0; i < menuFunctions.length; ++i)
        WrapFunction(menuFunctions[i]); 
}

function FixMenu_Init()
{
    if (Sys.Browser.agent == Sys.Browser.InternetExplorer)        
        WrapMenu();        
	$addHandler(window, 'load', function() {Menu_SetEnabled(true);});		
}

FixMenu_Init();

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();