/*
     MODULE:	GeneralFunctions.js
     PURPOSE:	provides general JavaScript functions 
     CREATED:	16.07.2002
     AUTHOR:	Trummer Martin
     COPYRIGHT:	(c) 2002 Trummer Martin for FH Joanneum
	 INFO:		
     CHANGE HISTORY:
	 	15.01.2003	added getCheckedRadioGroupId()
		16.01.2003	added selectRadioButtonById()
*/

/*
	replaces '@@var1@@' in the srcString with the varString
*/
function replaceVar(srcString, varString)
{
	return srcString.replace("@@var1@@", varString);
}

/*
	this function runs through all elements of the given 
	radiogroup and returns the index of the checked element.
	if none is checked the function returns -1
	return values: 			the element of the checked element,
					-1		if none of the elements in the group is checked
*/
function getCheckedRadioGroupId(radioGroup)
{
	var result = -1;
	
	for (var i=0; i<radioGroup.length; i++)
	{
		if (radioGroup[i].checked)
		{
			result = i;
			break;
		}
	}
	
	return result;
}

/*
	this function selects the desired radiobutton of the
	given radiogroup and returns true if it succeeded.
	return values:  true	the desired element has been checked
					false	id - range error
*/
function selectRadioButtonById(radioGroup, id)
{
	if (id < 0 || id >=radioGroup.length)
	{
		return false;
	}
	
	// uncheck all
	for (var i=0; i<radioGroup.length; i++)
	{
		radioGroup[i].checked = false;
	}
	// check desired id
	radioGroup[id].checked = true;
	
	return true;
}

