// Called on document load
function init() {

	// Zeroize all the selectors
	for (var a = 1; a <= totalSelectors; a++) {
		zeroSelector(a, a, true);
	}

	validateAllSelectors();
}

// Insert a "(choose one)" default and selected option with a null value at the head of the list
function zeroSelector(selectorID) {

	// Get the value from the selector
	var sel = document.getElementById(selName + selectorID);
	
	// Do we already have a null default?
	if (sel.value != '') {

		// Two arrays to hold the values while we iterate
		var newSelText = new Array();
		var newSelValue = new Array();

		newSelText[0] = '(choose one)';
		newSelValue[0] = '';

		// Shift all options down one into our array
		for (var x = 0; x < sel.options.length; x++) {
			newSelText[x + 1] = sel.options[x].text;
			newSelValue[x + 1] = sel.options[x].value;
		}

		// Copy the array over the old SELECT
		for (var x = 0; x < newSelText.length; x++) {
			sel.options[x] = new Option(newSelText[x], newSelValue[x], false, false);
		}

		// Set the selection
		sel.options[0].selected = true;
	}
}

// Called when a selector changes.
function changeSelector(ID) {

	// Get the value from the selector
	var sel = document.getElementById(selName + ID);
	var selval = sel.value;

	// Remove the null value from the selector list if present
	if (sel.options[0].value == '') { sel.options[0] = null; }

	validateAllSelectors();
}

// Loop thru the selectors looking for empty values. If none empty, return true.
function validateAllSelectors() {
	var selectorsValid = true;
	var output = '';

	for (var a = 1; a <= totalSelectors; a++) {
		var selVal = document.getElementById(selName + a).value;
		if (selVal == '') { selectorsValid = false; } else { output = output + selVal; }
	}

	// Locate the output <div>
	var out = document.getElementById(outputName);

	// Validate all the selectors to see if we can display the output
	if (selectorsValid) {

		// Set output value
		out.innerHTML = output;

		// Display the output
		out.style.display = "inline";
	} else {
		// Hide the output
		out.style.display = "none";
	}
}
