function buttonRollOn(theRow, id)
{
	idRow = theRow.id;
	idButton = idRow.substring( 0, idRow.length - 4 );
	if(  document.getElementById( idButton ) != undefined && document.getElementById( idButton ).disabled == false )
	{
		c = (id == 0) ? 'White' : 'Gray';
		theRow.cells[0].className = 'buttonOn' + c + 'LeftOn';
		if( theRow.cells.length == 3 )
		{	theRow.cells[1].className = 'buttonOn' + c + 'MiddleOn';
			theRow.cells[2].className = 'buttonOn' + c + 'RightOn';
		}
		else
		{   theRow.cells[1].className = 'buttonOn' + c + 'MiddleOn';
			theRow.cells[2].className = 'buttonOn' + c + 'MiddleOn';
			theRow.cells[3].className = 'buttonOn' + c + 'RightOn';
		}
	}
}
function buttonRollOut(theRow, id)
{
	idRow = theRow.id;
	idButton = idRow.substring( 0, idRow.length - 4 );
	if( document.getElementById( idButton ) != undefined && document.getElementById( idButton ).disabled == false )
	{
		c = (id == 0) ? 'White' : 'Gray';
		theRow.cells[0].className = 'buttonOn' + c + 'LeftOut';
		if( theRow.cells.length == 3 )
		{	theRow.cells[1].className = 'buttonOn' + c + 'MiddleOut';
			theRow.cells[2].className = 'buttonOn' + c + 'RightOut';
		}
		else
		{
			theRow.cells[1].className = 'buttonOn' + c + 'MiddleOut';
			theRow.cells[2].className = 'buttonOn' + c + 'MiddleOut';
			theRow.cells[3].className = 'buttonOn' + c + 'RightOut';
		}
	}
}
function buttonRollOff(theRow, id)
{
	c = (id == 0) ? 'White' : 'Gray';
	theRow.cells[0].className = 'buttonOn' + c + 'LeftOff';
	if( theRow.cells.length == 3 )
	{	theRow.cells[1].className = 'buttonOn' + c + 'MiddleOff';
		theRow.cells[2].className = 'buttonOn' + c + 'RightOff';
	}
	else
	{
		theRow.cells[1].className = 'buttonOn' + c + 'MiddleOff';
		theRow.cells[2].className = 'buttonOn' + c + 'MiddleOff';
		theRow.cells[3].className = 'buttonOn' + c + 'RightOff';
	}
}

function deactivateButton( idButton )
{	//Dezactiveaza butonul
	if( document.getElementById( idButton ) != undefined )
	{
		document.getElementById( idButton ).disabled = true;
		buttonRollOff( document.getElementById( idButton + '_row' ), 0 );
	}

}

function activateButton( idButton )
{	//Activeaza butonul
	if( document.getElementById( idButton ) != undefined )
	{
		document.getElementById( idButton ).disabled = false;
		buttonRollOut( document.getElementById( idButton + '_row' ), 0 );
	}
}
function clickButton( idButton )
{
	if( document.getElementById( idButton ) != undefined )
	{
		if( document.getElementById( idButton ).disabled == true )
		{	//Daca butonul e dezactivat... ii dam un mesaj
			//alert( 'Butonul ' + idButton + ' e dezactivat.' );
		}
		else
		{	//Altfel facem click pe buton
			document.getElementById( idButton ).click();
		}
	}
}
function keyPressedFunction( idButton, oEvent )
{
	var tragetId = "";
	/* ie*/
	if( document.addEventListener == undefined )
	{
		oEvent = event;
		tragetId = oEvent.srcElement.id;
	}
	else/*mozilla*/
	{
		tragetId = oEvent.target.id;
	}

	if( oEvent.keyCode == 13 && tragetId == idButton + '_span' )
	{
		clickButton( idButton );
		if(  oEvent.stopPropagation != undefined )/*mozilla*/
		{		oEvent.stopPropagation();
		}
		else/*ie*/
		{
			oEvent.cancelBubble = true;
		}
	}
}

function changeButtonText( idButton, newText )
{
	var buttonLabel = document.getElementById( idButton + '_span' );
	var buttonRef = document.getElementById( idButton );
	if( buttonLabel != undefined && buttonRef != undefined )
	{
		//verificam accesskey-ul
		var i =  newText.indexOf('' + buttonRef.getAttribute( 'accessKey' )  );
		var replacementText = newText;
		if( i >= 0 ) //exista in noul text
		{
			if( i == 0 )
			{
				replacementText = '<u>' + buttonRef.getAttribute('accessKey') + '</u>' + newText.substring(i + 1);
			}
			else if( i == (newText.length -1 ) )
			{
				replacementText = newText.substring( 0, i-1 ) + '<u>' + buttonRef.getAttribute( 'accessKey' ) + '</u>';
			}
			else
			{
				replacementText = newText.substring( 0, i-1 ) + '<u>' + buttonRef.getAttribute( 'accessKey' ) + '</u>' +  newText.substring( i+1 );
			}
		}
		//alert( replacementText );
		buttonLabel.innerHTML = replacementText;
	}
}
