﻿var expandImageSrc = 'expand.gif';
var collapseImageSrc = 'collapse.gif';

function toggleDetailRowVisibility(expandCollapseImage, rowId)
{
        //NOTE: assumes details are in last cell of parent row
        var currentRow = document.getElementById(rowId);
        var detailColumnIndex = currentRow.childNodes.length - ((navigator.appVersion.indexOf("MSIE") != - 1) ? 1 : 2);
        var isExpanded = expandCollapseImage.src.indexOf(collapseImageSrc) > -1;
        
        if (!isExpanded)
        {
            var newRow = currentRow.parentNode.insertRow(currentRow.rowIndex + 1);
            var newCell = newRow.insertCell(0);
            newCell.colSpan = currentRow.childNodes.length;
            newCell.innerHTML = currentRow.childNodes[detailColumnIndex].innerHTML;
            expandCollapseImage.src = changeFileWithoutPath(expandCollapseImage.src, collapseImageSrc);
        }
        else
        {
            var expandedRow = currentRow.parentNode.childNodes[currentRow.rowIndex + 1];
            currentRow.parentNode.deleteRow(currentRow.rowIndex + 1);
            expandCollapseImage.src = changeFileWithoutPath(expandCollapseImage.src, expandImageSrc);
        }
}
    
function changeFileWithoutPath(pathWithFileName, newFileName)
{
    var path = pathWithFileName.substring(0, pathWithFileName.lastIndexOf('/') + 1);
    var pathWithNewFilename = path + newFileName;
    return pathWithNewFilename;
}

