/*
 * Error checking scripts
 */ 


/*
 * Prompts the user if they want to reset the form, then rests the form regardless of form name
 */
function startover() {
	if (window.confirm('Are you sure You want to clear the form?') ) {
		document.forms[0].reset();
	}
}

/*
 * This is a generic universal form checker. You have a form followed and have fields you want required, this
 * will test the form for those required fields. Just put the names of the elements in the parameters in 
 * whatever calls it and this will do the rest.
 *
 * This uses one helper function to help check radio objects.
 */
function validate() {
	var parameters = validate.arguments;
	var i = 0;
	var x = parameters[i];
	var elements = document.forms[0].elements;
	var error = 'Please enter: ';
	var noflag = true;

	for(i; i < parameters.length; i++) {
		x = parameters[i];

		/*
		 * Shouldn't ever be null really.
		 */
		if(x != null) {

			/*
			 * Testing Radio Objects
			 */
			if(elements[x].value == undefined) {
				if(! testRadio(elements[x]) ) {
					error += '\n '+x;
					noflag = false;
				}
			}

			/*
			 * Testing Check Boxes
 			 */
			if(elements[x].value == 'on') {
				if(elements[x].checked == false) {
					error += '\n '+x;
					noflag = false;
				}
			}

			/*
			 * Testing Text Objects (one line text boxes, selection boxes, text areas)
			 */
			if(elements[x].value == '') {
				error += '\n '+x;
				noflag = false;
			}
		}
	}

	/*
	 * If there are errors, print them, if there aren't, submit the form.
	 */
	if(noflag) {
		document.forms[0].submit();
	}
	else {
		alert(error);
	}
}


/*
 * Radio values are stored in an array. This iterates the array and tests for checkedness
 */
function testRadio(elements) {
	var error = '';
	var s = false;

	for(var i = 0; i<elements.length; i++) {
		if(elements[i].checked == true) {				
			return true;
		}
	}
	return false;
}
