﻿// Table Hover Highlights v3...

//--------------------------------------------------------------------------------

function hoverCellOn(hoveredCell, hOn, vOn, hOffset, vOffset)
{
    hoverCellOnCol(hoveredCell, hOn, vOn, hOffset, vOffset, 0, 0, "#FFCC99", "#FF8000");
}

//--------------------------------------------------------------------------------

function hoverCellOnCol(hoveredCell, hOn, vOn, hTopOffset, vTopOffset,
                        hBottomOffset, vBottomOffset, colGeneral, colHighlight)
{
    // Controls table cell / row / coloumn highlighting...
    // If perameters are blank then all highlighting turned on...

    // Get the table (Parent of the row, Parent of the cell)...

    var currentTable = hoveredCell.parentNode.parentNode;

    // Get the row number in the table (Parent of the cell)...

    var currentRow = hoveredCell.parentNode.rowIndex;

    // Get the cell number in the row...

    var currentCell = hoveredCell.cellIndex;

    // Check offsets and define zero if null...

    if (hTopOffset == null)
    {
        hTopOffset = 0;
    }

    if (vTopOffset == null)
    {
        vTopOffset = 0;
    }

    // Check enablers and define one (ON) if null...

    if (hOn == null)
    {
        hOn = 1;
    }

    if (vOn == null)
    {
        vOn = 1;
    }

    // Highlight entire row...
    // If h_on equals one then turn on horizontal highlighting...

    for (var looper = hTopOffset; looper < (currentTable.rows[currentRow].cells.length - hBottomOffset); looper++)
    {
        if ((hOn == 1) && (looper != currentCell))
        {
            // If the cell is NOT the one with the mouse over...

            currentTable.rows[currentRow].cells[looper].style.backgroundColor = colGeneral;
        }
    }

    // Highlight entire coloumn...
    // If v_on equals one then turn on vertical highlighting...

    for (var looper = vTopOffset; looper < (currentTable.rows.length - vBottomOffset); looper++)
    {
        if ((vOn == 1) && (looper != currentRow))
        {
            // If the cell is NOT the one with the mouse over...

            currentTable.rows[looper].cells[currentCell].style.backgroundColor = colGeneral;
        }
    }

    // Make the cell with the mouse over a brighter colour...

    currentTable.rows[currentRow].cells[currentCell].style.backgroundColor = colHighlight;
}

//--------------------------------------------------------------------------------

function hoverCellOff(cell_to_revert)
{
    // Get the table (Parent of the row, Parent of the cell)...

    var current_table = cell_to_revert.parentNode.parentNode;

    // Get the row number in the table (Parent of the cell)...

    var current_row = cell_to_revert.parentNode.rowIndex;

    // Get the cell number in the row...

    var current_cell = cell_to_revert.cellIndex;

    // Revert entire row...

    for (var looper = 0; looper < (current_table.rows[current_row].cells.length); looper++)
    {
        current_table.rows[current_row].cells[looper].style.backgroundColor = "";
    }

    // Revert entire coloumn

    for (var looper = 0; looper < (current_table.rows.length); looper++)
    {
        current_table.rows[looper].cells[current_cell].style.backgroundColor = "";
    }
}

//--------------------------------------------------------------------------------