// container: The element in which the checkboxes should be searched within
// state: boolean value to determine if all checkboxes should be checked
// doClick: boolean value to determine if the checkboxes should be checked by using the
//          click event or the checked property.
function checkAllCheckboxes (container, state, doClick) {
	var inputArray, i;
	inputArray = container.getElementsByTagName('input');
	for (i = 0; i < inputArray.length; i++) {
		// alert('Input element type: ' + inputArray[i].type);
		if (inputArray[i].type.toLowerCase() == "checkbox") {
			if ( inputArray[i].checked != state ) {
				if (doClick) {
					inputArray[i].click();
				} else {
					inputArray[i].checked = state;
				}
			}
		}
	}
}

// container: The element in which the checkboxes should be searched within
// state: boolean value for the state of the clicked checkbox
// index: the index of the primary checkbox
// doClick: boolean value to determine if the primary checkbox should be checked 
//          by using the click event or the checked property.
function checkPrimaryCheckbox (container, state, index, doClick) {
	var inputArray, i, checkPrimary;
	inputArray = container.getElementsByTagName('input');
	if (state) {
		checkPrimary = true;
		for (i = 0; i < inputArray.length; i++) {
			if ( i != index ) {
				if (inputArray[i].type.toLowerCase() == "checkbox") {
					if ( inputArray[i].checked != state ) {
						checkPrimary = false;
					}
				}
			}
		}
	} else {
		checkPrimary = false;
	}

	if (inputArray[index].type.toLowerCase() == "checkbox") {
		if ( inputArray[index].checked != checkPrimary ) {
			if (doClick) {
				inputArray[index].click();
			} else {
				inputArray[index].checked = checkPrimary;
			}
		}
	}
}

// container: The element in which the input elements should be searched within
// state: boolean value to determine if all the elements should be disabled
// inputType: the type of input field to disable
function disableAllElementsOfType (container, state, inputType) {
	var inputArray, i;
	inputArray = container.getElementsByTagName('input');
	for (i = 0; i < inputArray.length; i++) {
		// alert('Input element type: ' + inputArray[i].type);
		if (inputArray[i].type.toLowerCase() == inputType.toLowerCase()) {
			// alert('Input element disabled: ' + inputArray[i].disabled + ' -> ' + state);
			inputArray[i].disabled = state;
			// This overrides a span tag that Microsoft wraps around disabled
			// elements, so the element can actually be enabled
			if ( inputArray[i].parentNode.tagName.toLowerCase() == 'span' )
				inputArray[i].parentNode.disabled = state;
		}
	}
	return true;
}

// container: The element in which the input elements should be searched within
// state: boolean value to determine if all the elements should be disabled
function disableAllSelects (container, state) {
	var inputArray, i;
	inputArray = container.getElementsByTagName('select');
	for (i = 0; i < inputArray.length; i++) {
		inputArray[i].disabled = state;
		// This overrides a span tag that Microsoft wraps around disabled
		// elements, so the element can actually be enabled
		//if ( inputArray[i].parentNode.tagName.toLowerCase() == 'span' )
		//	inputArray[i].parentNode.disabled = state;
	}
	return true;
}

// objSelectBox: The select box containing text values
// objTextBox: The text box who's value will be replaced
function replaceWithSelectBoxText (objSelectBox, objTextBox) {
	if (objSelectBox.options[objSelectBox.selectedIndex].value != '') { 
		objTextBox.value = objSelectBox.options[objSelectBox.selectedIndex].value;
	}
}

function radioGroupClone (container, thisCheckbox) {
	var inputArray, i;
	inputArray = container.getElementsByTagName('input');
	for (i = 0; i < inputArray.length; i++) {
		// alert('Input element type: ' + inputArray[i].type);
		if (inputArray[i].type.toLowerCase() == "checkbox") {
			if ( inputArray[i] != thisCheckbox ) {
				if ( inputArray[i].checked )
					inputArray[i].checked = false;
			}
		}
	}
}

