// requires string lib

function trimText(textField) {
	textField.value = trimString(textField.value);
}

function isTextEmpty(textField) {
	trimText(textField);
	return (textField.value == "");
}

function isARadioChecked(radioObj) {
	for (var i = 0; i < radioObj.length; i++) {
		if(radioObj[i].checked) {
			return true;
		}
	}

	return false;
}		
	
function getRadioValue(theRadioObj) {
	for (var i = 0; i < theRadioObj.length; i++) {
		if(theRadioObj[i].checked) {
			return theRadioObj[i].value;
		}
	}

	return false;
}		
	
function checkRadioFromIndex(theRadioObj, theIndex) {
	theRadioObj[theIndex].checked = true;
}

function checkRadioFromValue(theRadioObj, theValue) {
	for (var i = 0; i < theRadioObj.length; i++) {
		if (theRadioObj[i].value == theValue) {
			theRadioObj[i].checked = true;
			return;
		}
	}
}
	
function getSelectValue(theSelectObject) {
	return theSelectObject[theSelectObject.selectedIndex].value;
}

function getSelectValueAt(theSelectObject, index) {
	return theSelectObject[index].value;
}

function getSelectText(theSelectObject) {
	return theSelectObject[theSelectObject.selectedIndex].text;
}

function getSelectTextAt(theSelectObject, index) {
	return theSelectObject[index].text;
}

function setSelectFromValue(theSelectObj, theValue) {
	for (var i = 0; i < theSelectObj.length; i++) {
		if (theSelectObj[i].value == theValue) {
			theSelectObj.selectedIndex = i;
			return; 
		}
	}
}

function clearSelect(theSelectObj) {
	for (var i = 0; i < theSelectObj.length; i++) {
		theSelectObj[i].checked = false;
	}
}

function isSelectSingle(theFormObj) {
	if (theFormObj.type == "select-one") {
		return true;
	}
	else {
		return false;
	}	
}

function focusOnField(theFormObj) {
	if (theFormObj && theFormObj.focus) {
		theFormObj.focus();
	}
}

function clearRadio(theRadioObj) {
	for (var i = 0; i < theRadioObj.length; i++) {
		theRadioObj[i].checked = false;
	}
}	

