// A utility function that returns true if a string contains only whitespace.
function isblank(s) {
	for(var i = 0; i < s.length; i++) {
	var c = s.charAt(i);
	if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}return true;
	}

//if 'use_other' textarea is not blank, set 'other' checkbox
function checkOther(g) {
   	if (!((g.value == null) || (g.value == "") || isblank(g.value))) {
		document.cpquest.use2.checked=true;}
		}

// This is the function that performs form verification. It is invoked
// from the onsubmit event handler. The handler should return whatever
// value this function returns.
function verify(f) {
	var msg;
	var empty_fields = "";
	var checkSelected= false;
// Loop through the elements of the form, looking for all
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Put together error messages for fields that are wrong.

	for(var i = 0; i < f.length; i++) {
		var e = f.elements[i];
		
		if (e.type == 'select-one') {
            for (var k=0, l=e.options.length; k<l; k++) {
                if (e.options[k].selected && e.options[k].defaultSelected) {
                   	empty_fields += e.name + "\n";
                	}
            	}
        	}

		if (e.type == 'checkbox')  {
            if (e.checked) checkSelected = true;}
   		
	}
 
 	if (!checkSelected)  empty_fields += "use \n";
  
// If there are any errors, display the messages, and
// return false to prevent the form from being submitted.
// Otherwise return true.
	if (!empty_fields) return true;
	msg = "______________________________________________________\n\n"
	msg += "Please provide the following required information and re-submit.\n";
	msg += "______________________________________________________\n\n"
	if (empty_fields) {
		msg += empty_fields + "\n";
		}
	alert(msg);
	return false;
}
