
/*/
	File:  global.js
	© 2001 Locke Enterprises - All rights reserved.
	Purpose:  Export some of Nathan's stock javascript routines.
	Created:  5/8/2001 - Nathan
	Modification History:
		· 5/29/2001 - Nathan - added getSelectedButtonValue() and checkLength()
		· 1/3/2004 - Nathan - added getSelectedButtonValue() and checkLength()
	Exports: getSelectedButtonIndex(), getSelectedButtonValue(), getSelectedOptionIndex(), getSelectedOptionValue(), checkLength()
/*/

	//alert('global.js');

//-------------------------------------------------------------------------
// getSelectedButtonIndex:  Returns the index of the selected option button.
// NOTE:  Can only be used on a group of more than one objects.
//-------------------------------------------------------------------------
function getSelectedButtonIndex( buttonGroup ) {

	if( typeof(buttonGroup.length)!="undefined" ) {
		for( var i=0; i<buttonGroup.length; i++) {
			if( buttonGroup[i].checked ) {
				return i;
			}
		}
	} else {
		return -2;
	}
	return -1;

} // getSelectedButtonIndex()


//-------------------------------------------------------------------------
// getSelectedElementValue:  Returns the value of the selected option button.
//-------------------------------------------------------------------------
function getSelectedElementValue( theElement ) {

	if( typeof(theElement.length)!="undefined" ) {
		var theIndex = getSelectedButtonIndex(theElement);
		if( theIndex == -1 ) return null;
		return theElement[theIndex].value;
	} else {
		if( theElement.checked==true ) {
			return theElement.value;
		} else {
			return null;
		}
	}

} // getSelectedElementValue()


//-------------------------------------------------------------------------
// getSelectedOptionIndex:  Returns the index the first selected option item in a <select> combobox.
//-------------------------------------------------------------------------
function getSelectedOptionIndex( optionList ) {

	if( typeof(optionList.length)=="undefined" ) return -2;
	for( var i=0; i<optionList.length; i++) {
		if( optionList[i].selected ) {
			return i;
		}
	}
	return -1;

} // getSelectedOptionIndex()


//-------------------------------------------------------------------------
// getSelectedOptionValue:  Returns the value of the first selected option item in a <select> combobox.
//-------------------------------------------------------------------------
function getSelectedOptionValue( theElement ) {

	if( typeof(theElement.length)=="undefined" ) return -2;
	var theIndex = getSelectedOptionIndex(theElement);
	if( theIndex<0 ) return null;
	return theElement[theIndex].value;

} // getSelectedOptionValue()


//-------------------------------------------------------------------------
// checkLength:  Regulates a maximum length for the specified form element.
//-------------------------------------------------------------------------
function checkLength( theElement, Length, Name ) {

	var theValue = String(theElement.value);
	if( theValue.length > Length ) {
		theElement.value = theValue.substr(0,Length);
		alert( Name + " cannot exceed " + Length + " characters.   " );
	}

} // checkLength()


