var highlightColor = "#D4FF7F";
var prevCell = null;

function PriceCell_Untarget( cell )
{
    cell.className = "";
    
    var parentRow = cell.parentNode;
    
    while( ( parentRow.tagName.toLowerCase() != "tr" ) && ( parentRow.parentNode != null ) )
        parentRow = parentRow.parentNode;
        
    if ( parentRow != null )
    {
        var table = document.getElementById( "PriceList" );
        var rowIndex = parentRow.rowIndex;
        var cellIndex = cell.cellIndex;
        var numCells = parentRow.cells.length;
        
        parentRow.style.backgroundColor = "";
        parentRow.cells[0].className = "rowHeader";
        parentRow.cells[ numCells - 1].className = "profitCell";
        parentRow.cells[ numCells - 2].className = "sspCell";        
        
        var rows = table.rows;
        var numRows = rows.length;
      
        rows[1].cells[cellIndex].className = "colHeader2";
        for ( var index = 2; index < numRows; index++ )
        {
            var row = rows[ index ];
            var colCell = row.cells[cellIndex];
            colCell.style.backgroundColor = "";
        }        
    }
}

function PriceCell_Target( cell )
{
    if ( cell.tagName.toLowerCase() == "td" )
    {
        var parentRow = cell.parentNode;
        
        while( ( parentRow.tagName.toLowerCase() != "tr" ) && ( parentRow.parentNode != null ) )
            parentRow = parentRow.parentNode;
            
        if ( parentRow != null )
        {
            var cellIndex = cell.cellIndex;
            if ( ( cellIndex > 0 ) && ( cellIndex < parentRow.cells.length - 2 ) && ( cell.innerHTML != "N/A" ) )
            {
                var table = document.getElementById( "PriceList" );
                var rowIndex = parentRow.rowIndex;
                var numCells = parentRow.cells.length;
                
                cell.className = " targetCell";       
                parentRow.style.backgroundColor = highlightColor;
                parentRow.cells[0].className = "targetRowHeader";
                parentRow.cells[ numCells - 1].className = "targetProfit";
                parentRow.cells[ numCells - 2].className = "targetSSP";                        
                
                var rows = table.rows;
                var numRows = rows.length;
                
                rows[1].cells[cellIndex].className = "targetColumnHeader";                
                for ( var index = 2; index < numRows; index++ )
                {
                    var row = rows[ index ];
                    var colCell = row.cells[cellIndex];
                    if ( row.rowIndex != rowIndex )
                        colCell.style.backgroundColor = highlightColor;
                }
                return true;
            }
        }
    }
    return false;
}

function Prices_OnMouseOver( evt )
{
     evt = (evt) ? evt : ((window.event) ? window.event : "")

     if (evt)
     {
        var srcElement = (evt.target) ? evt.target : evt.srcElement

        if ( ( srcElement) && ( document.getElementById ) )
        {
            if ( PriceCell_Target( srcElement ) )
            {
                if ( prevCell != null )
                {
                    PriceCell_Untarget( prevCell );
                }
                prevCell = srcElement;            
            }
        }
    }
}


function Prices_OnMouseOut( evt )
{
     evt = (evt) ? evt : ((window.event) ? window.event : "")

     if (evt)
     {
        var srcElement = (evt.target) ? evt.target : evt.srcElement

        if ( ( srcElement) && ( document.getElementById ) )
        {
                if ( prevCell != null )
                    PriceCell_Untarget( prevCell );
                prevCell = null;            
        }
    }
}