
/**
* checks a radio button identifies by its name and value
* and calls a callBack() function after the button is checked
* if the parameter is given
* 
* example : checkRadioButton('myname','myvalue', disable('myform', myfields));
*/
function checkRadioButton(inputName, inputValue, callBack) 
{
	getInputByNameAndValue(inputName, inputValue).checked=true;
	callBack;
}

/**
* get an input button, identified by its name and value
* example : <input type="..." name="inputName" value="myValue" />
*/
function getInputByNameAndValue(inputName, inputValue)
{
	var inputList = document.getElementsByName(inputName);
	for (var i = 0; i < inputList.length; i++)
	{
		var myInput = inputList[i];
		if (myInput.getAttribute('value') == inputValue) 
		{
			return myInput;
		}
	}
}

function getCheckedInputByName(inputName)
{
	var inputList = document.getElementsByName(inputName);
	for (var i = 0; i < inputList.length; i++)
	{
		var myInput = inputList[i];
		if (myInput.checked == 'checked' || myInput.checked==true) 
		{
			return myInput;
		}
	}
}

function addOptionFirst(message, value, boxId)
{
	var y =document.createElement('option');
	y.text=message;
	y.value=value;
	var x=document.getElementById(boxId);
	var sel=x.options[0];  
	try
	{
	  x.add(y,sel); // standards compliant
	}
	catch(ex)
	{
	  x.add(y,0); // IE only
	}
}

function removeFirstOption(boxId)
{
	document.getElementById(boxId).remove(0);
}

//disable an <input> identified by its id
function disableElement(id)
{
	document.getElementById(id).setAttribute('disabled','disabled');
}

//enable an <input> identified by its id
function enableElement(id)
{
	document.getElementById(id).removeAttribute('disabled');
}

//JSF Dependant functions

/**
* disable a list of input fields belonging to the <form id="formId">
* the names are given in the array of fields
*/
function disable(formId, fieldsArray)
{	
	if (fieldsArray!=null)
	{
		for (var j=0; j<fieldsArray.length; j++) 
		{
			disableElement(formId + ":" + fieldsArray[j]);
		}
	}
}

function enable(formId, fieldsArray)
{
	if (fieldsArray!=null)
	{
		for (var i=0; i<fieldsArray.length; i++) 
		{
			enableElement(formId + ":" + fieldsArray[i]);
		}
	}
}