function checkKey(form, e) {
	if (client.isIE4Plus) {
		e = window.event;
		key = e.keyCode
	}
	
	else if (client.isNN4Plus) {
		key = e.which;
	}
	
	if (key == 13 || key == 3) {
		for(var i = 0; i < form.length; i++) {
			if(form.elements[i].type == "button") form.elements[i].onclick();
		}
	}
	else return true;
}



function validate(form) {
	var errors = null;
	var errorMsg = 	"The form was not submitted because of the following errors.\n";
	errorMsg += 	"Please correct them and resubmit the form.\n";
	errorMsg += 	"------------------------------------------\n";
	
	var emptyMsg = 			"-These required fields were empty:\n";
	var emailMsg = 			"-You did not provide a valid email address.\n";
	var alphanumericMsg = 	"-These fields can contain only letters or numbers:\n";
	var numericMsg = 		"-These fields can contain only numbers:\n";
	var minMsg = 			"-These fields had too few characters:\n";
	var selectionMsg = 		"-These dropdowns require a valid selection:\n";
	
	var nullErrors = false;
	var emailErrors = false;
	var alphanumericErrors = false;
	var numericErrors = false;
	var minErrors = false;
	var selectionErrors = false;
	
	for (var i =0; i < form.length; i++) {
		thisEl = form.elements[i];
		
		//alert(thisEl.name);
		
		//check  required fields
		if ((thisEl.type == "text" || thisEl.type == "textarea" || thisEl.type == "password") && thisEl.required) {
			if(thisEl.value == null || thisEl.value == "") {
				emptyMsg += "    " + thisEl.name + "\n";
				errors = true;
				nullErrors = true;
			}
		}
		
		//check for valid email
		if (thisEl.validEmail) {
			dots = 0;
			at = false;
			for (var j = 0; j < thisEl.value.length; j++) {
				var c = thisEl.value.charAt(j);
				if (c == ".") dots++;
				if (c == "@") at = true;
			}
			
			if (dots < 1 || at  == false) {
				errors = true;
				emailErrors = true;
			}
		}
		
		//check alphanumeric
		if (thisEl.alphaNumeric) {
			if(alphaNumerExp = /[^a-zA-Z0-9]/) {
				if (thisEl.value.match(alphaNumerExp)) {
					errors = true;
					alphanumericErrors = true;
					alphanumericMsg += "    " + thisEl.name + "\n";
				}
			}
		}
		
		//check digits
		if (thisEl.numeric) {
			if(numExp = /[^0-9]/) {
				if (thisEl.value.match(numExp)) {
					errors = true;
					numericErrors = true;
					numericMsg += "    " + thisEl.name + "\n";
				}
			}
		}
		
		//check min
		if (thisEl.min) {
			alert(thisEl.type);
			var v;
			if(thisEl.type == "select-one") v = this.selectedIndex;
			else v = thisEl.value.length;
			if (isNaN(v) || v < thisEl.min) {
				errors = true;
				minErrors = true;
				minMsg += "    " + thisEl.name + "\n";
			}
		}
		
		//check selected
		if (thisEl.selection) {
			//alert(thisEl.type);
			if(thisEl.type == "select-one")  {
				var v = thisEl.selectedIndex;
				if (isNaN(v) || v < thisEl.selection) {
					errors = true;
					selectionErrors = true;
					selectionMsg += "    " + thisEl.name + "\n";
				}
			}
		}
		
		//remove tabs, newlines, double spaces, etc..
		if (thisEl.format) {
			badCharExp = /[\t\r\n\f\v]+/g ;
			multiSpaceExp = / {2,}/g ;
			var newValue = thisEl.value.replace(badCharExp, " ");
			newValue = newValue.replace(multiSpaceExp, " ");
			thisEl.value = newValue;
		}
	
	}
	
	if (errors == null) {
		form.submit();
	} else {
		if (nullErrors == true) errorMsg += emptyMsg;
		if (emailErrors == true) errorMsg += emailMsg;
		if (alphanumericErrors == true) errorMsg += alphanumericMsg;
		if (numericErrors == true) errorMsg += numericMsg;
		if (minErrors == true) errorMsg += minMsg;
		if (selectionErrors == true) errorMsg += selectionMsg;
		alert(errorMsg);
		/*
		var errorWin = window.open("","","toolbar=no,width=425,height=250,scrollbars");
		errorWinMsg = "<html><head><title>Form Errors<\/title><\/head><body bgcolor='white'><pre style='font-size:11px;'>"
		errorWinMsg += "";
		errorWinMsg += errorMsg;
		errorWinMsg += "<\/pre>";
		errorWinMsg += "";
		errorWinMsg += "<\/body><\/html>";
		errorWin.document.write(errorWinMsg);
		*/
	}
}
