// true: Browser is IE / False: Browser is NOT IE
var IS_BROWSER_IE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
// true: Browser is Firefox / False: Browser is NOT Firefox
var IS_BROWSER_FF  = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false;
// Context Request ApplicationPath
var CONTEXT_REQUEST_APPLICATIONPATH = "/trainingTeam3.0";
//--------------------------------------------------------------------------
// Function    : This is not a funtion
// Paramter    : none
// Description : This logic runs all of the pages 
//             : to add the title of the smart navigation title
//--------------------------------------------------------------------------
if (document.getElementById('__hifSmartNav'))
{
    document.getElementById('__hifSmartNav').title = "Smart Navigation is on";
}
//--------------------------------------------------------------------------
// Function    : SetScrollBar()
// Description : (1)This function gets the following left and top from control postion
//             :    and set scroll position
//             : (2)This function is for Firefox. Use "window.navigate" for IE
//             : for example
//             : 
//             : node1----------------Left------------------|
//             :    |---node2                               |
//             :        |---node3                          top (pixels)
//             :             |---node4                      |
//             :                 |---node5                  |
//             :                     |---node6              |
//             :                         |---control--------|
//             :
//             : See http://developer.mozilla.org/en/docs/DOM:element.offsetLeft
//--------------------------------------------------------------------------
function SetScrollBar(control)
{
    //get as server control
    var node = document.getElementById(GetClientId(control));
    
    if (node == null || node == undefined)
    {
        // if control is not server control, get as html control
        node = document.getElementById(control);
    }

    var scrollLeft = node.offsetLeft;
    var scrollTop = 0;

    while (node)
    {
        scrollTop = scrollTop + node.offsetTop;
        node = node.offsetParent;
    }

    window.scrollTo(scrollLeft, scrollTop);
}

//--------------------------------------------------------------------------
// Function    : SetMessageForHoldKey
// Description : this function detect browser and replace hint for popup window in div named txtHint in page
//--------------------------------------------------------------------------
function SetMessageForHoldKey(browser, version)
{
    var txtHint= document.getElementById('txtHint');
        
    if(txtHint!= null && txtHint != undefined)
    {
        if (browser == "IE" && version == "7")
        { 
            txtHint.innerHTML = "Hold down Ctrl + Alt Key before clicking Launch Training.";
        }
        else if (browser == "IE" && version == "6")        
        { 
            txtHint.innerHTML = "Hold down Ctrl Key before clicking Launch Training.";
        }
        else
        {
            txtHint.innerHTML = "";
        }
    }
}
//--------------------------------------------------------------------------
// Function    : DetectAddEvent(eventName, functionName)
// Description : this function detect given DOM event and 
//             : Reset given function on the given event
//--------------------------------------------------------------------------
function DetectAddEvent(eventName, functionName)
{
    if (IS_BROWSER_IE)
    {
        if( window.attachEvent ) 
        {
            window.attachEvent("on" + eventName,functionName);
        }
    }
    else if (IS_BROWSER_FF)
    {
        if( window.addEventListener || document.addEventListener) 
        {
            window.addEventListener(eventName,functionName,false);
        }
        else if( document.addEventListener ) 
        {
            document.addEventListener(eventName,functionName,false);
        } 
    }
}
// Gets the Client ID of the control passed.
// Client ID is set in BasePage on attribute "clientId" of "bodyHome" of Home.Master
// get the value from the attribute, add "_" and control id which is passed.
function GetClientId(control) {
    var body = document.getElementsByTagName("body");

    var id = body[0].attributes["clientId"];

    // new window needs to get body Id from parent window
    if (id == null || id == undefined) id = parent.window.document.body.attributes["clientId"];

    var clientId = id.value + "_" + control;

    return clientId;
}

// Gets the Unique ID of the control passed.
// Unique ID can ben obtained by replacing "_" of clientId with "$"
function GetUniqueId(control) {
    var body = document.getElementsByTagName("body");

    var id = body[0].attributes["clientId"];

    // new window needs to get body Id from parent window
    if (id == null || id == undefined) id = parent.window.document.body[0].attributes["clientId"];
    
    var clientId = id.value + "_" + control;

    return clientId.replace(/_/gi, "$");
}


