
//--------------------------------------------------------------------------
// 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: Browser is Opera / False: Browser is NOT Opera
var IS_BROWSER_SAFARI = (navigator.userAgent.indexOf("Safari") != -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 = "/DbhsUpdates1.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);
    }

    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);
        } 
    }
}

//--------------------------------------------------------------------------
// Function     : isNumberKey(evt)
// Description  : This function checks if the input was a number or not. 
// Return values:
//                  true  - If the provided key input was a number.
//                  false - If the provided key input was not a number.
//--------------------------------------------------------------------------
function isNumberKey(evt)
{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;
   return true;
}

//--------------------------------------------------------------------------
// Function     : loadFlash(src, height)
// Description  : This function loads flah. 
// Return values: None
//--------------------------------------------------------------------------
function LoadFlash(src, height)
{   
    document.write("<object data='" + src + "' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' id ='objFlashLoader' name='objFlashLoader' type='application/x-shockwave-flash' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,60,0' align='center' width='100%' height='" + height + "'>");
        document.write("<param name='movie' value='" + src + "' />"); 
        document.write("<param name='swliveconnect' value='true' />");
        document.write("<param name='WMode' value='transparent' />");
        document.write("<param name='Play' value='1' />");
        document.write("<param name='Loop' value='-1' />");
        document.write("<param name='Quality' value='high' />");
        document.write("<param name='SAlign' value='' />");
        document.write("<param name='Menu' value='-1' />");
        document.write("<param name='Base' value='' />");
        document.write("<param name='AllowScriptAccess' value='always' />");
        document.write("<param name='Scale' value='ShowAll' />");
        document.write("<param name='DeviceFont' value='0' />");
        document.write("<param name='EmbedMovie' value='0' />");
        document.write("<param name='BGColor' value='' />");
        document.write("<param name='SWRemote' value='' />");
        document.write("<param name='MovieData' value='' />");
        document.write("<param name='SeamlessTabbing' value='1' />");
        document.write("<param name='Profile' value='0' />");
        document.write("<param name='ProfileAddress' value='' />");
        document.write("<param name='ProfilePort' value='0' />");
        document.write("<param name='height' value='100%' />");                           
        document.write("<param name='pluginspage' value='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'/>");
        document.write("<param name='type' value='application/x-shockwave-flash'/>");
        document.write("<param name='width' value='100%' />");
        document.write("<embed play='true' swliveconnect='true' wmode='transparent'  name='flashLoader' src='" + src + "' quality='high' width='100%' height='" + height + "' align='center' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' />");
    document.write("</object>");
}

