
//--------------------------------------------------------------------------
// Global Variable
//--------------------------------------------------------------------------
// 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;
// true: Browser is Opera / False: Browser is NOT Opera
var IS_BROWSER_OPERA = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
// true: operating System is Windows / False: operating System is NOT Windows
var IS_SYSTEM_WIN = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
// Context Request ApplicationPath
var CONTEXT_REQUEST_APPLICATIONPATH = "/khs1.0";
// Name of MasterPage Control Id of Home
var MasterPageIdHomeCtlName = "_ctl0";
// Name of MasterPage Control Id of Secondary
var MasterPageIdSecondaryCtlName = "_ctl0";
// Name of MasterPage Id of Home
var MasterPageIdHome = "cphOuter";
// Name of MasterPage Id of Secondary
var MasterPageIdSecondary = "cphSecondary";

//--------------------------------------------------------------------------
// Global Logic
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// 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    : GetClientIdSecondary(controlId)
// Paramter    : controlId (for example, "txtName", "txtEmail", "ddlCity")
// Description : This function returns Client ID of a specified control 
//             : inside the content of Home.Master.
//--------------------------------------------------------------------------
function GetClientIdSecondary(controlId)
{   
    return MasterPageIdHomeCtlName + "_" + MasterPageIdSecondaryCtlName + "_" + MasterPageIdHome + "_" + MasterPageIdSecondary + "_" + controlId;
}
//--------------------------------------------------------------------------
// Function    : GetClientIdHome(controlId)
// Paramter    : controlId (for example, "txtName", "txtEmail", "ddlCity")
// Description : This function returns Client ID of a specified control 
//             : inside the content of Home.Master.
//--------------------------------------------------------------------------
function GetClientIdHome(controlId)
{   
    return MasterPageIdHomeCtlName + "_" + MasterPageIdSecondaryCtlName + "_" + MasterPageIdHome + "_" + controlId;
}
//--------------------------------------------------------------------------
// Function    : GetClientIdSecondaryInGrid(gridId, rowIndex, controlId)
// Paramter    : gridId    (for example, "dgTrainingList")
//             : rowIndex  (row index of grid control, begin with 1. index 1 is header. body is from index 2)
//             : controlId (for example, "txtName", "txtEmail", "ddlCity")
// Description : This function returns Client ID of a specified control 
//             : inside the content of Home.Master.
//--------------------------------------------------------------------------
function GetClientIdSecondaryInGrid(gridId, rowIndex, controlId)
{   
    return "_ctl0_" + "_ctl0_" + MasterPageIdHome + "_" + MasterPageIdSecondary + "_" + gridId + "_" + "_ctl" + rowIndex + "_" + controlId;
}
//--------------------------------------------------------------------------
// Function    : PostBackPage()
// Description : This function post back this page
//--------------------------------------------------------------------------
function PostBackPage()
{   
    document.forms[0].submit();
}
//--------------------------------------------------------------------------
// 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(GetClientIdSecondary(control));
    
    if (node == null || node == undefined)
    {
        // if control is not server control, get as html control
        node = document.getElementById(control);
    }

    if (node == null || node == undefined) return;

    var scrollLeft = node.offsetLeft;
    var scrollTop = 0;

    while (node)
    {
        scrollTop = scrollTop + node.offsetTop;
        node = node.offsetParent;
    }

    window.scrollBy(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"];

    var clientId = id.value + "_" + control;

    return clientId;
}
