// ---------------------------------------------------------------------------------------------------------------
// (c) ANBe Designs 2003 (MACB)
// anbedesigns@hotmail.com
// ---------------------------------------------------------------------------------------------------------------

function SelectNextControl()
{
	if (IsIE())
	{
		if (event.keyCode == 13)
		{
			event.keyCode = 9;
		}
	}
}

// ---------------------------------------------------------------------------------------------------------------

function GetFirstItem(aElement)
{
	if (aElement && aElement.length)
		return aElement[0];
	else
		return aElement;
}

// ---------------------------------------------------------------------------------------------------------------

function CheckUncheckAll(aComponent, Checked)
{
	if (aComponent)
	{
		Checked = Checked ? true : false;
		if (aComponent.length)		
		{
			for (var i = 0; i < aComponent.length; i++)
				aComponent[i].checked = Checked;
		}
		else
			aComponent.checked = Checked;
	}
}

// ---------------------------------------------------------------------------------------------------------------

function CheckIsAnyChecked(aComponent)
{
	var Result = false;
	
	if (aComponent)
	{
		if (aComponent.length)
		{
			for (var i=0; i < aComponent.length; i++)
				if (aComponent[i].checked)
				{
					Result = true;
					break;
				}
		}
		else
			Result = aComponent.checked;
	}
	
	return Result;
}

// ---------------------------------------------------------------------------------------------------------------

function SelectSelectedText(aSelect)
{
 return (aSelect && aSelect.options)? aSelect.options[aSelect.selectedIndex].text: null;			
}

// ---------------------------------------------------------------------------------------------------------------

function SelectSelectAll(aSelect, aBoolean)
{
	if (aSelect.options)
	{
		aBoolean = aBoolean == false ? false : true;
		for (var i=0; i < aSelect.options.length; i++)
			aSelect.options[i].selected = aBoolean;
	}
}

// ---------------------------------------------------------------------------------------------------------------

function SelectClearFrom(aSelect, aIndex)
{
	aIndex = aIndex ? aIndex : 0;
	aSelect = Ref(aSelect);
	while (aSelect.options.length && aSelect.options.length > aIndex)
		aSelect.options[aIndex] = null;
}

// ---------------------------------------------------------------------------------------------------------------

function SelectIndexOfValue(aSelect, aValue)
{
	with (aSelect)
	{
		for(var i=0; i < options.length; i++)
		{
			if (options[i].value == aValue)
				return i;
		}
	}
	return -1;
}

// ---------------------------------------------------------------------------------------------------------------

function SelectIndexOfText(aSelect, aText, IgnoreCase)
{
	var SearchText;
	
	IgnoreCase = IgnoreCase == true ? true : false;
	SearchText = IgnoreCase ? aText.toUpperCase() : aText;
	with (aSelect)
	{
		for(var i=0; i < options.length; i++)
		{
			if (IgnoreCase)
			{
				if (options[i].text.toUpperCase == SearchText)
					return i;
			}
			else
			{
				if (options[i].text == SearchText)
					return i;			
			}
		}
	}
	return -1;
}

// ---------------------------------------------------------------------------------------------------------------

function SelectAppendOption(aSelect, Caption, Value, DefaultSelected, Selected)
{
	with (aSelect)
	{
		options[options.length] = new Option(Caption, Value, DefaultSelected, Selected);
	}
}

// ---------------------------------------------------------------------------------------------------------------

function CheckValuesAddItem(Checked, CheckOption)
{
	if ((CheckOption == 0) || ((CheckOption == 1) && Checked) || ((CheckOption == -1) && !Checked))
		return true;
	else
		return false;
}

function CheckValues(aElement, Values, CheckOption)
{
	var Count;
	
	if (aElement)
	{		
		if (aElement.length)
		{
			Count = 0;
			for (var i = 0; i < aElement.length; i++)
			{
				if (CheckValuesAddItem(aElement[i].checked, CheckOption))
					Values[Count++] = aElement[i].value;
			}
		}
		else
		{
			if (CheckValuesAddItem(aElement.checked, CheckOption))
				Values[0] = aElement.value;
		}
		return true;		
	}
	else
		return false;
}

// ---------------------------------------------------------------------------------------------------------------

function CheckValuesStr(aElement, Separator)
{
	var Values = new Array();
	
	if (!Separator)
		Separator = "|";
	if (CheckValues(aElement, Values, 1))
		return Values.join(Separator);	
	else
		return "";
}

// ---------------------------------------------------------------------------------------------------------------

function RadioGetSelectedItem(aRadioButton)
{
	var i;
	for (i = 0; i < aRadioButton.length; i++)
	{
		if (aRadioButton[i].checked)
			return aRadioButton[i];
	}
	return aRadioButton;
}
// ---------------------------------------------------------------------------------------------------------------

