//--------------------------------------------------------------------------
// Global Variable
//--------------------------------------------------------------------------

// Context Request ApplicationPath
var CONTEXT_REQUEST_APPLICATIONPATH = "/kidstraining3.0";

//--------------------------------------------------------------------------
// 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(GetClientId(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    : HandleErrMesg(txtBoxId, errLabelId)
//Description : This function clears the Error Message(label) if no text is  
//              provided in the text box.
//--------------------------------------------------------------------------------

function HandleErrMesg(txtBoxId, errLabelId)
{
    txtBox      = document.getElementById(txtBoxId);
    errLabel    = document.getElementById(errLabelId);
    
    if(txtBox.value == '')
    {
        errLabel.innerHTML = '';
    }
}

// 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;
}

// 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"];

    var clientId = id.value + "_" + control;

    return clientId.replace(/_/gi, "$");
}

