﻿
/// <reference path="lib/jquery_vsdoc.js" />
/// <reference path="lib/jquery.blockUI.js" />
/// <reference path="lib/jslog.js" />
/// <reference path="ajax.js" />


var iCurrentSeqNum = 0;

$.fn.outerHTML = function(s) {
    return (s)
        ? this.before(s).remove()
        : jQuery("<p>").append(this.eq(0).clone()).html();
};


$(document).ready(
    function() {

        //        $.blockUI({ showOverlay: true, message: null });

        //        // *** core.js start ***
        //        if ($('#flashheader').length > 0) {
        //            $('#flashheader').flash(
        //                { src: 'flash/MEX_banner_Home.swf',
        //                    width: 912,
        //                    height: 108,
        //                    wmode: 'transparent'
        //                },
        //                { version: 8 }
        //            );
        //        }

//        BuildFadingBorder();
//        SetFadingBorderPos();

//        $(window).resize(function() { SetFadingBorderPos(); });
//        $(window).scroll(function() { SetFadingBorderPos(); });

        BindTopButtons();
        BindGlossary();
        // *** core.js end ***

        // *** menu.js start ***
        //bind menus
//        bindLeftMenu();
        bindRightMenu();
        bindContactPopout();
        // *** menu.js end ***

//        adjustBodyHeight();

        jslog.debug('dev:document_ready handler');

        // menu button
        $('#leftmenu').find('li.leftmenu_item a.leftmenu_button').click(function(event) {
            selectTopLevelMenuButton(this);
        });

        // submenu button
        $('#leftmenu').find('li.leftmenusub_item a.leftmenusub_button').click(function(event) {
            subMenuButtonClick(this);
        });

        // subsubmenu button
        $('#leftmenu').find('li.leftmenusubsub_item a.leftmenusubsub_button').click(function(e) {
            subMenuButtonClick(this);
        });

        // rightmenu
        // we do livequery as dom updates this
        $('li.rightmenu_item > a').livequery('mouseover', function(evt) {
            $('div#rightmenucallout_title').text(
                this.innerText.substr(0, this.innerText.indexOf('(') - 1));


            positionRightHandMenuCallout($(this));
            $('div#rightmenucallout_description').html('');
            var contentArea = $('div.rightmenucallout_content_area');
            contentArea.css('height', '20');

            $('#rightmenucallout_arrow').css('top', '45px');

            contentArea.html('<img id="imgProgress" style="margin-left: 20px;" src="images/core/waiting-line.gif" alt="progress" />');
            doAjaxPost(this.id, 'resource_popup', this.id, successHandler, failureHandler);
        });


    }
);

function PollerSelectPage(pageId, resourceId) {
    closePopup();
    closeTopButtonPopup();
    if (resourceId === undefined) {
        if (pageId !== undefined) {
            if ((pageId == null) || (pageId == 'null')) {
                //DoLink('nav_menu_home', pageId);
                if ($.browser.msie && $.browser.version < 7) {
                    $('div#contentwrapper').css('height', '700px');
                } else {
                    $('div#contentwrapper').css('height', 'auto');
                    if ($('div#contentwrapper').height() < 700) {
                        $('div#contentwrapper').height('700px');
                    }
                }
            }
//            else
//                DoLink('nav_menu', pageId);

            $('#rightmenucallout').hide();
            $('div.rightmenu').css('display', 'block');
            $('div.centrebox_full').css('display', 'none');

            selectMenuButton(this, pageId);

        } else {
            // resourceid and pageid are both undefined             
        }
    } else {
        if (pageId != undefined) {
            //DoLink('get_resource_complete', JSON.stringify([pageId, resourceId]));

            $('#rightmenucallout').hide();
            $('div.rightmenu').css('display', 'block');
            $('div.centrebox_full').css('display', 'none');

            selectMenuButton(this, pageId);
        }
//        else {
//            DoLink('get_resource', resourceId);
//        }
    }
}

function PollerSelectResource(resourcelinkId) {
    closePopup();
    closeTopButtonPopup();
    if (resourcelinkId !== undefined) {
        DoLink('get_resource', resourcelinkId);
    }
}
function SelectPreview(ContentTypeID, ContentID) {
    DoLink('preview', ContentTypeID + "|" + ContentID);
}

function SelectPageContent(pageID, resourcelinkId, ContentTypeID, ContentID) {
    window._PageTracker.location = "PageTracker.aspx?nav=SelectPageContentBack(" + pageID + "," + resourcelinkId + "," + ContentTypeID + "," + ContentID + ");";
}

function SelectPageContentBack(pageID, ResourceTypeID, ContentTypeID, ContentID) {
    selectMenuButton(this, pageID);
    DoLink('get_pagecontent', pageID + "|" + ResourceTypeID + "|" + ContentTypeID + "|" + ContentID);
}

function SelectBack(cmd, arg) {
    closePopup();
    closeTopButtonPopup();
    if (cmd !== undefined) {
        DoLink('cmd_' + cmd, arg);
    }
}

function SelectWayResource(resourcelinkId) {
    window._PageTracker.location = "PageTracker.aspx?nav=SelectWayResourceBack(" + resourcelinkId + ");";
}
function SelectWayResourceBack(resourcelinkId) {
    closePopup();
    closeTopButtonPopup();
    if (resourcelinkId !== undefined) {
        DoLink('get_wayresource', resourcelinkId);
    }
}
function AcceptDisclaimer() {
    DoLinkNoBlock('cmd_disclaimer', '1');
}

//-------- Profile Stuff

function setProfileImageUploadFrame(ProfileID) {
    frameref = document.getElementById('_fileupload');
    frameref.src = "ucFileuploadProfileImage.aspx?profileid=" + ProfileID;
}
function RefreshProfileImage() {
    DoLinkNoBlock('UpdateProfilePhoto', "");
}
function ManageMyProfile() {
    DoLinkNoBlock('cmd_ManageMyProfile', '');
}
function ProfileSave() {
    doAjaxForm('frmProfilePage');
}
function SearchProfilesFrm() {
    doAjaxForm('frmSearchContacts');
}
function SearchNetworkFilter() {
    doAjaxForm('frmLaunchfilterNetwork');
}
function SearchProfiles() {
    DoLinkNoBlock('cmd_SearchProfiles', '');
}
function AddToNetwork(ProfileId) {
    DoLinkNoBlock("AddToNetwork", ProfileId);
}
function RemoveFromNetwork(ProfileId) {
    DoLinkNoBlock("RemoveFromNetwork", ProfileId);
}

//--------


function setAlertOn(bOn) {
    if (bOn) {
        $(searchbaralertadd).addClass('alerton');
    }
    else {
        $(searchbaralertadd).removeClass('alerton');
    }

}

function selectMenuButton(context, pageId) {

    window.storedPageId = window && window.storedPageId || -1;

    if (pageId != window.storedPageId) {

        var iLevel = 0; // level at which we are selected 1=top level, 2=second level, etc

        /*** level 3 ***/
        var thirdLevelExcludeWrappedSet = $('#leftcolumn').find('li[commandArgument!="' + pageId + '"][class*=leftmenusubsub_item]');

        var thirdLevelIncludeWrappedSet = $('#leftcolumn').find('li[commandArgument="' + pageId + '"][class*=leftmenusubsub_item]');
        if (thirdLevelIncludeWrappedSet.length > 0) {
            iLevel = 3;
        }

        /*** level 2 ***/

        if (iLevel == 0) {
            var secondLevelExcludeWrappedSet = $('#leftcolumn').find('li[commandArgument!="' + pageId + '"][class*=leftmenusub_item]');

            var secondLevelIncludeWrappedSet = $('#leftcolumn').find('li[commandArgument="' + pageId + '"][class*=leftmenusub_item]');
            if (secondLevelIncludeWrappedSet.length > 0) {
                iLevel = 2;
            }
        }

        /*** level 1 (top level) ***/

        if (iLevel == 0) {
            var topLevelExcludeWrappedSet = $('#leftcolumn').find('li[commandArgument!="' + pageId + '"][class*=leftmenu_item]');

            var topLevelIncludeWrappedSet = $('#leftcolumn').find('li[commandArgument="' + pageId + '"][class*=leftmenu_item]');
            if (topLevelIncludeWrappedSet.length > 0) {
                iLevel = 1;
            }
        }

        /*** expansion and contraction ***/
        switch (iLevel) {
            case 1: // top level
                var topLevelSelUL = topLevelIncludeWrappedSet.children().siblings('ul');

                // slideUp all top levels menus that aren't the selected one                
                $('#leftcolumn').find('li[class*=leftmenu_item]').children().siblings('ul').not(topLevelSelUL).slideUp(200);
                // clear highlight of all top level menus that aren't the selected one
                $('#leftcolumn').find('li[class*=leftmenu_item]').not(topLevelIncludeWrappedSet).removeClass('leftmenu_item_selected');
                // add highlight for selected top-level menu
                topLevelIncludeWrappedSet.addClass('leftmenu_item_selected');

                // clear highlight of all second level menu items
                $('#leftcolumn').find('li[class*=leftmenusub_item]').removeClass('leftmenusub_item_selected');

                // clear highlight of all third level menu items
                $('#leftcolumn').find('li[class*=leftmenusubsub_item]').removeClass('leftmenusubsub_item_selected');

                // slide down our selected top-level menu
                topLevelSelUL.slideDown(200);

                break;
            case 2: // second level
                var topLevelSelected = secondLevelIncludeWrappedSet.parent().parent();

                // clear highlight of top level items that aren't selected
                $('#leftcolumn').find('li[class*=leftmenu_item]').not(topLevelSelected).removeClass('leftmenu_item_selected');
                // highlight top level item that is selected
                topLevelSelected.addClass('leftmenu_item_selected');

                // slide up all third level ul elements
                $('#leftcolumn').find('li[class*=leftmenusub_item]').parent().not(secondLevelIncludeWrappedSet.parent()).slideUp(200);
                // clear selection of all third level elements
                $('#leftcolumn').find('li[class*=leftmenusubsub_item]').removeClass('leftmenusubsub_item_selected');

                var elem = secondLevelIncludeWrappedSet.parent().parent().children().siblings('ul');
                // slide up all second level ul elements that aren't elem
                $('#leftcolumn').find('[class*=leftmenu_item]').children().siblings('ul').not(elem).slideUp(200);
                // slide down selected second level element
                elem.slideDown(200);
                // clear highlight of all unselected second level elements
                $('#leftmenu').find('> li[class*=leftmenu_item] > ul[class*=leftmenusub] > li[class*=leftmenusub_item]').not(elem).removeClass('leftmenusub_item_selected');
                // highlight selected second level element
                secondLevelIncludeWrappedSet.addClass('leftmenusub_item_selected');


                break;
            case 3: // third level
                // get li of secondlevel
                var secondLevelSelElemLI = thirdLevelIncludeWrappedSet.parent().parent();
                // get ul container of second level
                var secondLevelSelElem = secondLevelSelElemLI.parent();

                // get first level element
                var theFirstLevel = secondLevelSelElem.parent();
                // clear highlight of all first level elements that aren't selected
                $('#leftmenu').find('> li[class*=leftmenu_item]').not(theFirstLevel).removeClass('leftmenu_item_selected');
                // highlight selected first level element
                theFirstLevel.addClass('leftmenu_item_selected');

                // slide up all second level ul elements haven't got thirdLevelSelElem in it's children
                $('#leftmenu').find('> li[class*=leftmenu_item] > ul[class*=leftmenusub]').not(secondLevelSelElem).slideUp(200);
                // clear highlight of all second level elements that aren't selected
                $('#leftmenu').find('> li[class*=leftmenu_item] > ul[class*=leftmenusub] > li[class*=leftmenusub_item]').not(secondLevelSelElemLI).removeClass('leftmenusub_item_selected');
                // slide down selected second level element container (ul)
                secondLevelSelElem.slideDown(200);
                // highlight selected second level element (li)
                secondLevelSelElemLI.addClass('leftmenusub_item_selected');

                // slide up all third level ul elements that aren't thirdLevelIncludeWrappedSet item
                $('#leftmenu').find('> li > ul > ul').not(thirdLevelIncludeWrappedSet).slideUp(200);
                thirdLevelIncludeWrappedSet.slideDown(200);
                // clear highlight of all third-level elements
                $('#leftcolumn').find('[class*=leftmenusubsub_item]').removeClass('leftmenusubsub_item_selected');
                // highlight selected third-level element (li)
                thirdLevelIncludeWrappedSet.addClass('leftmenusubsub_item_selected');
                break;
        }
    }

    window.storedPageId = pageId;
}

function isTopLevelMenuButton(context) {
    return ($(context).parent('li.leftmenu_item').length > 0);
}

function DoLinkNoBlock(cmd, arg) {
    doAjaxPost(undefined, cmd, arg, successHandler, failureHandler);
}

function DoLink(cmd, arg) {
    $('#rightmenucallout').hide();
    $.blockUI({ showOverlay: true, message: null });
    stopWaitCursor();
    startWaitCursor();
    doAjaxPost(undefined, cmd, arg, successHandler, failureHandler);
}

function DoContextClick(context) {
    $('#rightmenucallout').hide();
    $.blockUI({ showOverlay: true, message: null });
    startWaitCursor();
    doAjaxPost(context.id, $(context).attr('command'),
                $(context).attr('commandArgument'), successHandler, failureHandler);
}


function SetPageLocation() {
    window.scrollTo(0, 0);
}
function adjustBodyHeight() {
    $(document.body).height('100%');
    if ($(document.body).height() < $(window).height())
        $(document.body).height($(window).height());
}
// new version, let's try and phase out the PlayFlash above
function PlayFlashVideo(jquery, sFileName, sWidth, sHeight) {
    $(convertToJQuery(jquery)).html('').flash({
        src: sFileName,
        allowfullscreen: true,
        width: sWidth,
        height: sHeight,
        wmode: 'transparent'
    }, { version: 8 });
}

function linklocation(url, lnkmethod, pw, h) {
    lnkmethod = lnkmethod.toLowerCase();
    switch (lnkmethod) {
        case "_blank":
            win = window.open(url, "_blank");
            if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
            break;
        case "_self":
            window.location.href = url;
            return false;
        case "popup":
            var winl = (screen.width - pw) / 2;
            var wint = (screen.height - h) / 2;
            win = window.open(url, "popupscreen", "top=" + wint + ",left=" + winl + ",status=no,resizable=yes,height=" + h + ",width=" + pw + ",toolbar=no,menubar=no,location=no,scrollbars=yes");
            if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
            break;
        case "popupmenu":
            var winl = (screen.width - pw) / 2;
            var wint = (screen.height - h) / 2;
            win = window.open(url, "popupscreen", "top=" + wint + ",left=" + winl + ",status=no,resizable=yes,height=" + h + ",width=" + pw + ",toolbar=no,menubar=yes,location=no,scrollbars=yes");
            if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
            break;
        default:
            win = window.open(url, "_blank");
            if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
            break;
    }
}


function showhelp(file, pw, h) {
    var wsrc = "help.aspx?help=" + file + "&w=" + pw + "&h=" + h;
    var winl = (screen.width - pw) / 2;
    var wint = (screen.height - h) / 2;
    win = window.open(wsrc, "helpscreen", "top=" + wint + ",left=" + winl + ",status=no,resizable=no,height=" + h + ",width=" + pw + ",toolbar=no,menubar=no,location=no,scrollbars=no");
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function showbooking(pw, h) {
    var wsrc = "booking/home.aspx?ref=1";
    var winl = (screen.width - pw) / 2;
    var wint = (screen.height - h) / 2;
    win = window.open(wsrc, "bookingscreen", "top=" + wint + ",left=" + winl + ",status=no,resizable=yes,height=" + h + ",width=" + pw + ",toolbar=no,menubar=yes,location=no,scrollbars=yes");
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function showKB(Url) {
    var h = 630;
    var w = 1024;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    win = window.open(Url, "knowledgebank", "top=" + wint + ",left=" + winl + ",status=no,resizable=yes,height=" + h + ",width=" + w + ",toolbar=no,menubar=yes,location=no,scrollbars=yes");
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}
function showActivePopup(popRef) {
    switch (popRef) {
        case "ProfilePopup":
            showPopup($('#profilepopup'));
            break;
        case "SearchNetwork":
            showPopup($('#popSearchNetwork'));
            break;

        case "Disclaimer":
            showPopupESC($('#disclaimerpopup'), false);
            break;
        case "EmailColleague":
            RefreshEmailColleague();
            showPopup($('#emailcolleagepopup'));
            break;
        case "Feedback":
            RefreshFeedback();
            showPopup($('#feedbackpopup'));
            break;
        case "Bookmark":
            RefreshBookmarks();
            showPopup($('#bookmarks'));
            break;
        case "AddBookmark":
            AddBookmarks();
            showPopup($('#bookmarks'));
            break;
        case "MyAlerts":
            RefreshMyAlerts();
            showPopup($('#myalerts'));
            break;
        case "ToggleMyAlerts":
            ToggleMyAlerts();
            showPopup($('#myalerts'));
            break;
        case "Search":
            txtinput = document.getElementById('searchinput');
            RefreshSearch(txtinput.value);
            showPopup($('#searchpopup'));
            break;

    }
}

function startWaitCursor() {

    $('body').append('<img src="images/core/waiting.gif" id="loadingimage"/>').mousemove(function(event) {
        $('#loadingimage').css({
            opacity: 0.9,
            top: (event.pageY - 30) + 'px',
            left: (event.pageX - 35) + 'px'
        });
    });

}
function stopWaitCursor() {
    $('body').unbind('mousemove');
    $('#loadingimage').remove();
}


function BuildFadingBorder() {

    for (var i = 0; i < 10; i++) {
        var opacity = (1 - (i / 30)) - 0.65;

        $('body').append('<div class="innerpageborder" id="innerpageborderleft' + i + '"></div>');
        $('body').append('<div class="innerpageborder" id="innerpageborderright' + i + '"></div>');
        $('#innerpageborderright' + i + ', #innerpageborderleft' + i).css('opacity', opacity.toString()).css('filter', 'alpha(opacity=' + (opacity * 100).toString() + ')');
    }
}

function SetFadingBorderPos() {
    var innerpage = $('#innerpage');
    var offset = innerpage.offset();
    var scrollleft = $(document).scrollLeft();
    for (var i = 0; i < 10; i++) {
        $('#innerpageborderleft' + i.toString()).css('left', (offset.left - i) - scrollleft);
        $('#innerpageborderright' + i.toString()).css('left', (offset.left + innerpage.width() + i) - scrollleft);
    }
}


function BindGlossary() {
    $('.glossaryterm').cluetip();

}

function BindTopButtons() {
    $('.topbannerbutton a.topbanner_buttonlink').click(function(e) {
        //dump the topbuttonpopupcontent html into the topbannerbuttonpopup and show it.
        //use the a[title] for the title of the popup.  
        //need the arrow on as well. 
        //also set teh topbannerbutton to selected. 

        var button = $(e.target);
        var offset = button.offset();
        var src = button.css('background-image').replace('url(', '').replace(')', '').replace('_over', '_overlay').replace('"', '');

        var popup = button.siblings('.popup');
        popup.css('top', offset.top + button.height()).css('left', (offset.left - 360) + (button.width() / 2));

        showPopup(popup);

        button.parent().addClass('topbannerbuttonactive');


        //alert(src); 
        $('body').append('<img src="' + src + '" id="topbannerbuttonoverlay"/>');
        $('#topbannerbuttonoverlay').css('top', offset.top).css('left', offset.left);

    });

}

function closeTopButtonPopup() {
    $('.topbannerbuttonactive').removeClass('topbannerbuttonactive');
    $('#topbannerbuttonoverlay').remove();
    closePopup();
}


function showPopup(jqoPopup) {
    showPopupESC(jqoPopup, true);
}
function showPopupESC(jqoPopup, bAllowEscape) {
    if (bAllowEscape) {
        jqoPopup.add('#modalblanket').bgiframe().show().focus().bind('keypress', function(evt) {
            if (evt.which == 27) {
                if (jqoPopup.is('#topbannerbuttonpopup'))
                    closeTopButtonPopup();
                else
                    closePopup();
            }
        });
    }
    else {

        jqoPopup.add('#modalblanket').bgiframe().show().focus();
    }
}

function closePopup() {
    $('#modalblanket, .popup').hide().unbind('keypress');

}


function inArray(array, elem) {
    var i = 0;
    for (i = 0; i < array.length; i++) {
        if (array[i] == elem)
            return true;
    }
    return false;
}

// from menu.js
function setRightMenuCalloutContent(trigger) {
    positionRightHandMenuCallout(trigger);
}

function bindLeftMenu() {
    //check menu items for wrapping?

    $('li.leftmenu_item a.leftmenu_button').hover(function() {
        //on
        var target = $(this);
        var offset = target.offset();
        var siblings = target.siblings('.leftmenu_item_hover:first');
        var ie6special = 0;

        if ($.browser.msie && $.browser.version == '6.0')
            ie6special = 1;
        siblings.bgiframe().show().css('top', (offset.top + ie6special + (target.height() / 2)) - (siblings.height() / 2)).css('left', offset.left + target.parent().width());

    }, function() {
        //off
        var target = $(this);
        target.siblings('.leftmenu_item_hover').hide();
    });
}

function bindRightMenu() {
    //bind actual menu item
    $('.rightmenu_item a').livequery('mouseover', (function(evt) {
        //de-persist state of all menu items
        $('.rightmenu_item').removeClass('rightmenu_item_selected');

        rightmenuhidestop();
        var thisthing = $(this);
        var thisparent = $(this).parent();
        var offset = thisparent.offset();

        //persist state to the menu item
        thisparent.addClass('rightmenu_item_selected');

        positionRightHandMenuCallout(thisthing);

    })).livequery('mouseout', (function() {
        var thisparent = $(this).parent();

        rightmenuhidestart();

    }));

    //bind callout box
    $('#rightmenucallout').livequery(
            function() {
                $(this).hover
                (
                    function() {
                        rightmenuhidestop();
                    },
                    function() {
                        rightmenuhidestart();
                    }
                )
            }
    );

    $('#rightmenucallout').livequery('mouseover', function() {
        rightmenuhidestop();
    }
    );
}

function positionRightHandMenuCallout(trigger) {
    var callout = $('#rightmenucallout');
    var offset = trigger.parent().offset();
    var arrow = $('#rightmenucallout_arrow');
    var refheight = 0;

    refheight = $('body').height();


    //position the callout from the bottom up. arrow is 10 up, plus half of the arrow. then drop by half of the parent height
    var verticalpos = (refheight - offset.top) - (10 + (arrow.height() / 2) + (trigger.parent().height() / 2));

    callout.css('bottom', verticalpos).css('left', offset.left - (callout.width() + 21)).bgiframe().show();

    //position arrow as well. only left do y-axis in coreEvents.js
    arrow.css('left', callout.width());
}


var rightmenucalloutcallbacks = new Array();
function rightmenuhidestart() {
    rightmenucalloutcallbacks.push(setTimeout(function() {
        $('#rightmenucallout').fadeOut(200);
        $('.rightmenu_item').removeClass('rightmenu_item_selected');
    }, 500));
}
function rightmenuhidestop() {	//clear all timeouts. 
    while (rightmenucalloutcallbacks.length > 0) {
        clearTimeout(rightmenucalloutcallbacks.shift());
    }

}




var currentactive;
function bindContactPopout() {

    $('.share_contact_name a').livequery(function() {
        $(this).bind('mouseover', (function(evt) {
            var thisthing = $(this);
            var thisparent = $(this).parent();
            var offset = thisparent.offset();
            var callout = thisthing.siblings('.share_contact_popout');

            if (callout.length > 0) {
                currentactive = callout;
                callout.css('top', offset.top + 5).css('left', offset.left - (callout.width() + 40)).bgiframe().show();

                //hide all others.
                $('.share_contact_popout').not(callout).hide();
            }
            else currentactive = null;
        })).bind('mouseout', (function() {
            var callout = $(this).siblings('.share_contact_popout');
            currentactive = null;
            contactcallouthidestart(callout);
        }));
    });

    //bind callout box
    $('.share_contact_popout').livequery(function() {

        $(this).hover(function(evt) {
            currentactive = $(this);
        }, function(evt) {
            currentactive = null;
            contactcallouthidestart($(this));
        }).mouseover(function(evt) {
            currentactive = $(this);
        });
    });
}



function contactcallouthidestart(callout) {
    setTimeout(function() {
        try {
            if (currentactive == null || !currentactive.is(callout))
                callout.fadeOut(200);
        } catch (exception) { }
    }, 500);
}

function selectTopLevelMenuButton(_context) {
    $('div#contentwrapper').height('489px');
    //$('div#centrewrapper').html(''); // needs to be blanked out for sizing of contentwrapper white area
    //$.blockUI({ showOverlay: true, message: null });

    selectMenuButton(_context, $(_context).parent().attr('commandArgument'));

    if ($(_context).parent().attr('commandArgument') != '') {
        SelectPage($(_context).parent().attr('commandArgument'));
    }
}

function SelectPage(pg, rs) {
    PollerSelectPage(pg, rs);
}

function subMenuButtonClick(context) {
    if ($(context).parent().attr('commandArgument') != '') {
        SelectPage($(context).parent().attr('commandArgument'));
    }

    $(context).parent().attr('isSelected', 'true');
    $(context).parent().siblings().attr('isSelected', 'false');

    $('#rightmenucallout').hide();
    $('div.rightmenu').css('display', 'block');
    $('div.centrebox_full').css('display', 'none');
}
