var oldRowClass;

function HiLightRow(row)
{
	if( row.className == 'gridover' )
	{	
		row.className = oldRowClass;
	}
	else
	{
		oldRowClass = row.className;
		row.className = 'gridover';
	}
}


function SelectRow(type,row,DataKey)
{
	SelectedItemStyle(type,row,DataKey);
}

function xReplace(checkMe,toberep,repwith){

	var temp = checkMe;
	var i = temp.indexOf(toberep);

	while(i > -1)
	{
		temp = temp.replace(toberep, repwith);
		pos = (repwith.length == 0 ? 0 : i + (repwith.length + 1) );
		i = temp.indexOf(toberep, pos);
	}
	
	return temp;
}



function SelectedItemStyle(type,oRow,DataKey)
{
	// Obtém as linhas da TABLE
	var oRows = oRow.parentElement.parentElement.rows;

	if (oRows)
	{
		var nRows = oRows.length;
		if (nRows == 1)
		{
			GetRow(type,DataKey);
		}

		// Loop em todas as linhas do grid para o tratamento de SELEÇÃO.
		for ( var i=1; i<nRows; i++ )
		{
			if ( oRows[i] == oRow )
			{
				oRows[i].className = 'gridselected';
				GetRow(type,DataKey);
			}
			else
			{
				oRows[i].className = 'gridNOselected';
			}
		}
	}
	return;
}

function GetRow(type,DataKey)
{
	var oHidden = document.getElementById("txtHiddenField");
	if (oHidden != null)
	{
		oHidden.value = DataKey;
		
		//DIRECIONA PARA A LISTA DE VEÍCULOS DESTE LEILÃO
		if(type == "l")
		{
			window.navigate("ListaLeilaoVeiculos.aspx?LeilaoID="+oHidden.value);
		}
		
		if(type == "v")
		{
			window.navigate("DetalheVeiculos.aspx?CarID="+oHidden.value);
		}
		
		if(type == "cc") //conta corrente
		{
			window.navigate("teste.aspx?Id="+oHidden.value);
		}
	}
}

function SelectAllRow(row,DataKey)
{
	SelectedItemAllStyle(row,DataKey);
}

function SelectedItemAllStyle(oRow,DataKey)
{
	// Obtém as linhas da TABLE
	var oRows = oRow.parentElement.parentElement.rows;

	if (oRows)
	{
		var nRows = oRows.length;
		if (nRows == 1)
		{
			GetAllRow(oRow, oRows, 1,DataKey);
		}

		// Loop em todas as linhas do grid para o tratamento de SELEÇÃO.
		for ( var i=1; i<nRows; i++ )
		{
			if ( oRows[i] == oRow )
			{
				oRows[i].className = 'gridselected';
				GetAllRow(oRow, oRows, i,DataKey);
			}
			else
			{
				oRows[i].className = 'gridNOselected';
			}
		}
	}
	return;
}

function GetAllRow(oRow, oRows, i,DataKey)
{
	var oHidden = document.getElementById("txtHiddenField");
	if (oHidden != null)
	{
		oHidden.value = oRows[i].innerHTML + "#" + DataKey;
	}
}


function SelectRowDocs(row,DataKey)
{
	SelectedItemStyleDocs(row,DataKey);
}


function SelectedItemStyleDocs(oRow,DataKey)
{
	// Obtém as linhas da TABLE
	var oRows = oRow.parentElement.parentElement.rows;

	if (oRows)
	{
		var nRows = oRows.length;
		if (nRows == 1)
		{
			GetRowDocs(DataKey);
		}

		// Loop em todas as linhas do grid para o tratamento de SELEÇÃO.
		for ( var i=1; i<nRows; i++ )
		{
			if ( oRows[i] == oRow )
			{
				oRows[i].className = 'gridselected';
				GetRowDocs(DataKey);
			}
			else
			{
				oRows[i].className = 'gridNOselected';
			}
		}
	}
	return;
}

function GetRowDocs(DataKey)
{
	var oHidden = document.getElementById("txtHiddenField");
	if (oHidden != null)
	{
		window.returnValue=DataKey;
		//oHidden.value = DataKey;
	}
	window.close();
}

function ClearDropDownList(list)
{
	for(i=list.options.length-1; i>=0 ;i--)
	{
		list.remove(i);
	}
}

function addDropDownListOption(list, text, value)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	list.options.add(optn);
}

function AtivaTab(id)
{
	
	for(i=1;i<10;i++)
	{
		tab = document.getElementById('__tab_ctl' + i);
		if(tab)
			if( i == id )
				tab.className='tab';
			else
				if( tab.className == 'tab' )
					tab.className = 'backtab';
	}
}
