﻿// JScript File
var RowColor,SelectRowColor="#FFF4D5",RowColorSelect,Selectrow,ARNOSelect;

ARNOSelect=new Array();

function getrow()
{
			var oElem;
			oElem=window.event.srcElement;
			while (oElem!=null)
			{
				if (oElem.tagName.toLowerCase() == "tr"
					&& oElem.parentElement.tagName.toLowerCase() == "tbody") 
				{
						
					return oElem;
				}
				if (oElem.tagName.toLowerCase() == "table") return false;
				oElem = oElem.parentElement;
			}
}

//---------------------------------------------------
function ColorCells(oRow, sClr)
{
    oRow.style.backgroundColor=sClr;
	return ;
}

//---------------------------------------------------
function ClickGrid(gridname)
{
		    var tbl,oRow;
		    
		    tbl=document.getElementById(gridname); 
		   // alert(Selectrow.rowIndex);
			if(Selectrow==null)
			{
				Selectrow=getrow();
				
				//if(tbl.rows[0]!=Selectrow)
				if(NoSelect(tbl))
				{
					oRow=Selectrow;
					RowColorSelect=Selectrow.style.backgroundColor;
					ColorCells(Selectrow, SelectRowColor);
				}	
				else
					Selectrow=null;
			}
			else
			{
				oRow=Selectrow;
				Selectrow=getrow();
				//alert(Selectrow.rowIndex);
				//if(tbl.rows[0]!=Selectrow )
				if(NoSelect(tbl))
				{
					ColorCells(oRow, RowColorSelect);
					RowColorSelect=Selectrow.style.backgroundColor;
					
					ColorCells(Selectrow, SelectRowColor);
			
				}	

				else
					Selectrow=oRow;
					
			}
		
}

//--------------------------------------
function NoSelect(tbl)
{
    var i;
    
    if(ARNOSelect==null)
        return true;
        
    else
    {
        for(i=0;i< ARNOSelect.length;i++)    
            if(tbl.rows[ARNOSelect[i]]==Selectrow)
                return false;
    }    

    return true;
}

function RowIndexGrid()
{
    return Selectrow.rowIndex;
}
		
//--------------------------------------
function RowIndexGridComp()
{
    var index;
    
    if(Selectrow.rowIndex+1<10)
        index="0"+(Selectrow.rowIndex+1);
    else
        index=Selectrow.rowIndex+1;

    return index;        
            
}
function GetRowGrid(oElem)
{
    
    while (oElem!=null)
	{
		if (oElem.tagName.toLowerCase() == "tr"
			&& oElem.parentElement.tagName.toLowerCase() == "tbody") 
		{
				
			return oElem;
		}
		if (oElem.tagName.toLowerCase() == "table") return false;
		oElem = oElem.parentElement;
		 
	}
			
}				
