﻿//-----------------------------------------------------------------------------
// Highlights the current row and updates the selectedRow variable
//-----------------------------------------------------------------------------
function dg_onclick(ID, GridName)
{
    // Reset styles
    resetTable(GridName);
    
    // Get selected row
    selectedRow = document.getElementById(ID);
    
    if (selectedRow)
    {
        selectedRow.className = "TableSelectedItemStyle";
        var navRoot = document.getElementById(GridName);
        navRoot.setAttribute("currentRowID", ID);
    }
}


//-----------------------------------------------------------------------------
// Resets the CSS of all the rows
//-----------------------------------------------------------------------------
function resetTable(GridName)
{
    // Get grid and rows...
    var dataGrid = document.getElementById(GridName);
    var dataRows = dataGrid.getElementsByTagName("tr");

    // Alternately apply CSS styles to grid rows
    for (var x = 0; x < dataRows.length; x++)
    {
        if (dataRows[x].getAttribute("rowType") != "header")
        {
            // Different className if alternating row...
            if ((x % 2) == 1)
                dataRows[x].className = "TableItemStyle";
            else
                dataRows[x].className = "TableAlternatingItemStyle";
        }
    }
}

//-----------------------------------------------------------------------------
// Alter colour of rows on mouseover
//-----------------------------------------------------------------------------
function dg_onmouseover(ID)
{
    var currRow = document.getElementById(ID);
    
    if (currRow)
    {
        if ("TableAlternatingItemStyle" == currRow.className)
            currRow.className = "TableHighlightAlternating";
        else if ("TableItemStyle" == currRow.className)
            currRow.className = "TableHighlight";
    }
}

//-----------------------------------------------------------------------------
// Reset row on mouse out
//-----------------------------------------------------------------------------
function dg_onmouseout(ID)
{
    var currRow = document.getElementById(ID);
    
    if (currRow)
    {
        if ("TableHighlightAlternating" == currRow.className)
            currRow.className = "TableAlternatingItemStyle";
        else if ("TableHighlight" == currRow.className)
            currRow.className = "TableItemStyle";
    }
}

//-----------------------------------------------------------------------------
// View course information if a course item is clicked on.
//-----------------------------------------------------------------------------
function ViewCourseInfo(courseGuid)
{
    document.location.href = "Course.aspx?id=" + courseGuid;
}