<!-- (C) Copyright IBM Corp 2004  -->
//------------------------------------------------------------------------
//
// File name: ecollat.js
//
// Purpose: Check for valid number of inputs and if invaid, prompt user
//
// Author date: June 23rd, 2004
//
//------------------------------------------------------------------------

function submitEcollat() {
	// Load the 'theForm' variable with the eCollateral form
	var theForm = document.ecollatForm;
	
	// Set maximum selection limit and error messages
	var maxSelection = 8;
	var maxSelectionMsg = theForm.maxSelectionMsg_form.value;
	var noSelectionMsg = theForm.noSelectionMsg_form.value;
	
	// Find out how many check boxes are checked in the form
	var checkedCount = 0;
	// Check to see if the list only has one item in it and if that one item is checked
	var listOfOne = 0; // 0 = false; 1 = true
	if ( theForm.ecollatRequestParm_form.checked ) {
		listOfOne = 1;
	}
	
	for (var j = 0; j < theForm.ecollatRequestParm_form.length; j++) {
		listOfOne = 0;
		if (theForm.ecollatRequestParm_form[j].checked) {
			checkedCount++;
		}
	}
	
	// Check the user's input to make sure the maximum is not exceeded
	if ( checkedCount > maxSelection ) {
		alert(maxSelectionMsg);
		// If number of selections exceeds the maximum, return the user to the form for changes
		return false;
	}
	if ( (checkedCount == 0) ) {
		if ( (listOfOne == 1 ) ) {
			// If the list only has one item in it and it is checked, return 'true' to process the form
			return true;
		}
		alert(noSelectionMsg);
		// If number of selections is 0, return the user to the form for changes
		return false;
	}
	// If no errors are found, return 'true' to invoke the action of the form
	return true;
}
