
<!--

// FORM VALIDATOR APPLICATION ---- AUTHORED BY GERARD KONARS MAY 2001----

// YOU MUST INCLUDE onSubmit="var the_result = checkForm(); return the_result" IN THE FORM TAG.
// ALL REQUIRED FIELD NAMES MUST INCLUDE THE PREFIX "required-" AS IN "required-something_to_check"
// THE VALIDATOR CHECKS FOR CONTENT IN TEXT FIELDS, RADIO BUTTONS AND DROP DOWN LISTS.
// DO NOT ASSIGN VALUES TO NON-OPTIONS IN YOUR DROP-DOWN LISTS.
// A POP-UP WINDOW IS GENERATED AUTOMATICALLY WITH AN ERROR MESSAGE AND THE FIELD NAMES MINUS THE "required-" PREFIX.
// FOR EXAMPLE "something_to_check was left blank!"
// GIVE YOUR FORM ELEMENTS EASILY UNDERSTOOD LONG NAMES USING UNDERSCORES FOR SPACES.



var newWindow = null
function makeNewWindow() {
		newWindow = window.open("","","dependent,resizable=yes,scrollbars=yes,width=450,height=350")
		var newContent = "<HTML><HEAD><TITLE>OOPS!</TITLE></HEAD>"
			newContent+= "<BODY BGCOLOR='FFFFFF'><FONT COLOR='990000'><B>THE FORM WAS NOT SUBMITTED</B><BR>OOPS! You forgot to fill in some required fields.<BR>They are listed below.</FONT><BR><BR>"
			newContent+= "<FONT COLOR='000000'>"
			newContent+= errorString
			newContent+= "<BR><BR>"
			newContent+= "<CENTER><A HREF='#' onClick='self.close();'>Close Window</A></CENTER>"
			newContent+= "</FONT></BODY></HTML>"
			newWindow.document.write(newContent)
			newWindow.document.close()
			newWindow.focus()
}

var errorString = "";
function checkForm(){
	emptyErrorString = "";
	errorString = emptyErrorString
	var numberOfElements = document.forms[0].elements.length;
//	alert(numberOfElements);		
	var radioButtonGroups = new Array();
	var radioChecked = new Array();
	var regexp = "required-" //CHECKS FOR THIS STRING IN THE FIELD NAME
	var regexp2 = /_/g		 //CHECKS FOR UNDERSCORES IN THE FIELD NAME
    	for(var i=0; i<numberOfElements; i++)
			if((document.forms[0].elements[i].name).match(regexp)){
//				alert(document.forms[0].elements[i].name);
				var thisElement = document.forms[0].elements[i];
//CHECKS FOR DROP DOWN LIST
				if(thisElement.type == 'select-one'&& !thisElement.options[thisElement.selectedIndex].value){
					var dropDownList = thisElement.name.replace(regexp, " "); //REMOVES THE STRING IN REGEXP FROM THE FIELD NAME
					var dropDownListName = dropDownList.replace(regexp2, " ");//REMOVES THE UNDERSCORES FROM FIELD NAME
				    errorString = errorString + 'Select an option from the drop down list: <b>'+ dropDownListName +'</b>.<BR>';
//CHECKS FOR TEXT FIELD WITH NO VALUE OR DEFAULT VALUE
				} else if(thisElement.type == 'text' && (!thisElement.value || thisElement.value == thisElement.defaultValue)){
					var textField = thisElement.name.replace(regexp, " ");
					var textFieldName = textField.replace(regexp2, " ");
			      	errorString = errorString + '<b>' + textFieldName + '</b> was left blank! <BR>';
//CHECKS FOR TEXTAREA FIELD
				} else if(thisElement.type == 'textarea' && (!thisElement.value || thisElement.value == thisElement.defaultValue)){
					var textAreaField = thisElement.name.replace(regexp, " ");
					var textAreaName = textAreaField.replace(regexp2, " ");
					errorString = errorString + '<b>' + textAreaName + '</b> was not completed. <BR>';
//CHECKS FOR RADIO BUTTONS AND GETS THEIR NAMES
                } else if(thisElement.type == 'radio'){
					newRadioButton = thisElement.name;
					var groupIndex = -1;
						for(var j=0; j<radioButtonGroups.length; j++)
							if(newRadioButton == radioButtonGroups[j]){	
								groupIndex = j;
								break;
					}
					if(groupIndex == -1){
						groupIndex = radioButtonGroups.length;
						radioButtonGroups[groupIndex]= newRadioButton;
						radioChecked[groupIndex] = false;
						}
					radioChecked[groupIndex] = radioChecked[groupIndex] || thisElement.checked	
//					alert('groupIndex is =' + groupIndex + ' radioButtonGroups ' + radioButtonGroups[groupIndex] + radioChecked[groupIndex]);
				}
			}
		for(i=0; i<radioButtonGroups.length; i++)
			if(!radioChecked[i]){
				var radioButton = radioButtonGroups[i].replace(regexp, " ");	
				var radioButtonName = radioButton.replace(regexp2, " ");
				errorString = errorString + 'Please choose an option for <b>' + radioButtonName + '</b><BR>';
			}
	if(!errorString == ""){
//		alert(errorString);
		makeNewWindow();
		return false;
		}else
			return true;
	}
//-->