// this script will validate the the required fields are filled.
// whitespace characters
var whitespace = " \t\n\r";

// Check whether string s is empty.
function isEmpty(s) {   
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s) {   

	var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++) {
       
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }	// end for

    // All characters are whitespace.
    return true;
}	// end isWhitespace
// validates required fields to insure that they are not blank
function validateForSubmission() {

	var i, args;
	var theForm, fieldName, fieldType;
	
	var fieldsMissing = false;
	var missingFields = "";
	
	args = validateForSubmission.arguments;
	
	theForm	= args[0];
	for (i=1; i<(args.length); i++) { 
	
		fieldName = args[i];
		fieldType = theForm[fieldName].type;
		
		//	this script should be used only to verify to following types of form input:
		//	text, textarea, password, hidden, select-one, select-multiple
		//	form input types not supported include:  checkbox and radio
		//  these types are not supported because there is no support for
		//	validate imput groups within this script.		
		
		//	if two or more form elements have the same name
		//	(such as a group of radio buttons), the type will be undefined 
		//	when the elements are referenced by name
		if (fieldType != null) {

				if ( fieldType == "text"		||
					 fieldType == "textarea"	||
					 fieldType == "password"	||
					 fieldType == "hidden"	) { 

				
					if (isWhitespace(theForm[fieldName].value)) {
				
						if (fieldsMissing) {
						
							missingFields += ", " 
						}
						missingFields += fieldName;
				
						fieldsMissing = true;
					}	// end if
				}
				else if ( fieldType == "select-one" ||
						  fieldType == "select-multiple" ) { 
				
					var selectedIndex = theForm[fieldName].selectedIndex;
				
					if (isWhitespace(theForm[fieldName].options[selectedIndex].text)) {
				
						if (fieldsMissing) {
						
							missingFields += ", " 
						}
						missingFields += fieldName;
				
						fieldsMissing = true;
					}	// end if
				} 	
		}
	}	// end for
   
	if (fieldsMissing) {
   
		alert("The following required fields are missing:  " + missingFields);
		return false;
	}
	else {
	
		return true;
	}
}
