﻿// JavaScript File
// svIncoll4
// Pham Yen Phuc
// 24/11/2007

// 
// TODO: To mau cho table khi di chuyen chuot
// USAGE: HightLightTable(tableId, classIdentify, colorOver, colorClick)

/*

*/

function showError(error)
{
    alert(error.message);
}

function rowMouseOver(row)    
{
    try
    {        
        if( row.clicked == null || row.clicked == false )
            row.style.backgroundColor = row.colorOver;
        
    }catch(err)
    {
        showError(err );
    }
}

function rowMouseOut(row)
{
    try
    {
        if( row.clicked == null || row.clicked == false )
            row.style.backgroundColor = '';
    }catch(err)
    {
        showError(err);
    }
}

function rowMouseClick(row)
{
    try{
        if( row.clicked == null || row.clicked == false )
        {
            row.style.backgroundColor = row.colorClick;
            row.clicked = true;
        }
        else
        {
            row.style.backgroundColor = '';
            row.clicked = false;
        }
    }catch(err)
    {
        showError(err);
    }
}

function tableMouseOver(table, classIdentify, colorOver, colorClick, fromRow, toRow)
{
    if( table.currentInited == null )
    {        
        HightLightTable(classIdentify, colorOver, colorClick, fromRow, toRow);
     }
        
    table.currentInited = false;
}

/*
* TODO: to mau cho table khi co chuot di chuyen trong table
* @classIdentify: ten class de nhan biet table se thuc thi
* @colorOver: mau cua row khi co mouse over
* @colorClick: mau cua row khi co mouse click
*/
function HightLightTable(classIdentify, colorOver, colorClick, fromRow, toRow)
{
    try    
    {
        if( classIdentify == null )
            return;
            
        if( colorOver == null )
            colorOver = '#EFE2AD';
            
        if( colorClick == null )
            colorClick = '#99cccc';
        
        var tables = document.body.getElementsByTagName("TABLE");     
        var table = null;
        var indexTable = tables.length - 1;  
        
        for(; indexTable >=0; indexTable -- )
        {
            if( tables[indexTable].className.indexOf(" " + classIdentify + " ") > 0 || 
                tables[indexTable].className.indexOf(" " + classIdentify) == tables[indexTable].className.length ||
                tables[indexTable].className.indexOf(classIdentify + " ") == 0 ||
                tables[indexTable].className.indexOf(classIdentify) > 0 )
            {
                table = tables[indexTable];
                
                var rows = table.rows;               
                
                var index = (toRow == null ? rows.length-1 : toRow);
                var endrow = (fromRow == null ? 1 : fromRow - 1);
                
                for(; index >= endrow; index--)
                {
                    rows[index].clicked = false;
                    rows[index].colorOver = colorOver;
                    rows[index].colorClick = colorClick;
                    
                    rows[index].onmouseover = function()
                    {
                        rowMouseOver(this);
                    };
                    
                    onmouse = rows[index].mouseout;
                    rows[index].onmouseout = function()
                    {                    
                        rowMouseOut(this);
                    };
                    
                    if( colorClick != '' && colorClick != null)
                    rows[index].onclick = function()
                    {
                        rowMouseClick(this);
                    };
                }
           }
       }
  }catch(err)
  {
    showError(err);
  }
}



