function getRadio(radio){

			// Parameters:
				// "radio" is a radio button object, <formname>.<radiogroup>

			// Behavior:
				// The value of the active radio button is returned to the caller
	
	for(i=0; i<radio.length; i++){
		if(radio[i].checked){
			return(radio[i].value);
			break;
		}
	}
}

function setRadio(radio, value){

			// Parameters:
				// "radio" is a radio button object, <formname>.<radiogroup>
				// "value" is the radio button to activate

			// Behavior:
				// Sets the active radio button
	
	for(i=0; i<radio.length; i++){
		if(radio[i].value == value){
			radio[i].checked = true;
		} else {
			radio[i].checked = false;
		}
	}

}

function setSelectedIndex(list, value){

			// Parameters:
				// "list" is a listbox (<select ...>) object, list = <formname>.<listname>
				// "value" is the value to use to set the selectedIndex property

			// Behavior:
				// The selectedIndex is set to the item with value="value"
	
	for(i=0; i<list.length; i++){
		if(list[ i].value == value){
			list.selectedIndex = i;
			break;
		}
	
	}
}

function getSelectedValue(list){
	for(i=0; i<list.length; i++){
		if(list[ i].selected){
			return list[ i].value;
		}
	}
}

function fillList(array, list){
			// Parameters:
				// "array" is a 1D array of items to load into the list
				// "list" is a listbox (<SELECT... >) object, list = <formname>.<listname>

			// Behavior:
				// All items are inserted into the list and the "selectedIndex" set = 0

	for(i=0; i<array.length; i++){
		list.options.length = i + 1;
		list.options[i].value = array[i];
		list.options[i].text = array[i];
	}
	list.selectedIndex = 0;
}

function emptyList(list){

			// Parameters:

			// "list" is a listbox (<SELECT... >) object, list = <formname>.<listname>

			// Behavior:

			// All items are removed from the listbox
			
	l = list.length;
	for(i=0; i<l; i++){
		//alert("i: "+i);
		list.options[0] = null;	// index 0 is correct!
	}
}

function filterArray(array, rsarray, where, index){
/*
			Parameters:
			"array" is a 2D array INPUT
			"rsarray" in a 1D array OUTPUT
			"index" is the column of array to return to the caller as rsarray INPUT 
			"where" is a 1D array INPUT

			Behavior:

			array[i][0] =where[0]
			array[i][1] = where[1]
			array[i][2] = not defined (index = 2)
			array[i][3] = where[3]

			If all defined where values match, then
				rsarray[j] = array[i][2]

			Usage:

			rsarray = new Array;
			where  = new Array(4);

			where[0] = "value0"
			where[1] = "value1"
			where[3] = "value3"

			filterArray(array, rsarray, where, 2)
			emptyList(<formname>.<listname>)
			if(rsarray.length > 0){
				fillList(rsarray, <formname>.<listname>);
			}
*/

	var j = 0;
	var aMatch
	for(i=0; i<array.length; i++){
		aMatch = true;

		// perform matches for where
		for(k=0; k<where.length; k++){
			if(!where[k]){	// = 'undefined' or ''
			;
			} else {
				if(where[k]){
					//alert("i: "+i+"k: "+k+": "+array[i][k]+":"+where[k]);
					if(array[i][k] != where[k]){
						aMatch = false;
						break;
					}
				}
			}
		}

		if(aMatch){
			rsarray[j] = array[i][index];
			j++;
		}
		
	}
}

