/** Hide an html element given its id */
function hideElementById(id)
{
    // hide the element by setting css attribute
    document.getElementById(id).style.display = 'none'
}

// Show the subversion revision number in the page title
function showRevision()
{
    var title = document.title;
    title = title + revisionNumber;
    document.title = title;
}

// Load a CSV file and convert to a string of formatted HTML
// @param filename the file containing the CSV input
// @param targetDiv the div element in which the HTML should be placed.
function loadLog(filename, targetDiv)
{
    // Asynchronous file read of unified log data
    loadJSON("dynamicdata/" + filename, function(response)
    {
        // Format the csv data into an HTML table
        var allRows = response.split(/\r?\n|\r/);
        var table = '<table>';
        // Put the last log entry at the TOP of the table
        for (var singleRow = allRows.length-1; singleRow >= 0; singleRow--)
        {
            var rowCells = allRows[singleRow].split(',');
            var msg_type = ""; // color white is default

            // trimming white space in the type field 
            // ingore the empty line 
            if (rowCells.length > 1) 
            {
                rowCells[1] = rowCells[1].trim();
            }
            var label = String(rowCells[1]);
            var info = String(rowCells[3]).trim();
            // Implement ticket #190 
            // Checking for the type of logging information 
            if (label.startsWith("CAD")) {
                msg_type = "class=\"CAD\"";
                if (info.startsWith("Detail")) {
                    msg_type = "class=\"CADdetail\"";
                }
            } else if (label.startsWith("Activity")) {
                msg_type = "class=\"Activity\"";
            //} else if (rowCells[1] == "CMS Activated.") {
            } else if (label.startsWith("CMS")) {
                msg_type = "class=\"CMS\"";
            } else if (label.startsWith("Eval")) {
                msg_type = "class=\"Evaluation\"";
            } 

            // add the message type class to that row 
            table += '<tr ' + msg_type + '>';
            for (var rowCell = 0; rowCell < rowCells.length; rowCell++)
            {
                table += '<td>';
                table += rowCells[rowCell];
                table += '</td>';
            }
            table += '</tr>';
        }
        table += '</table>';
        targetDiv.innerHTML = table;
    }
    );
}
