function validator() {
	this.elementtype = "strong"; //this is the type of html element that will be created
	this.alertclass = "generatedError"; // this is the class name applied to error messages
	this.imgclass = "thinking"; // this is the class name applied to error messages
	this.loadingsrc = "/i/loading.gif";
	this.fadeyellow = true;

	function whatkind(el) {
		//  whatkind() returns an array of four elements: 
		//  the type of validation, the regex for the validation, 
		//  the invalid error string, and the required error string.
		
		var n = el.name;
		if(n.indexOf("email") != -1) { 
			var x = new Array(
				"email",
				/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/,
				"This e-mail address doesn't appear to be valid",
				"E-mail address is a required field"
				); 
			}
		if(n.indexOf("name") != -1) { 
			var x = new Array(
				"name",
				/[^\s]+/,
				"Your name is required, and it can't be just spaces",
				"Name is a required field"
				); 
			}
		
		return (x) ? x : false;
		} //end whatkind


//nothing much to configure from here on out.


	//prep this.els as an array of all input type texts in the document.
	this.els = new Array();
	var is = document.getElementsByTagName("input");
	for(i=0; i<is.length; i++) {
		if(is[i].type == "text" && whatkind(is[i]) != false) { // make sure it's a text field, and that we can validate it.
			//add properties
			is[i].info = whatkind(is[i]);
			is[i].loadingimage = this.loadingsrc;
			is[i].el = this.elementtype;
			if(this.fadeyellow) { is[i].fade = fade; } else { is[i].fade = false; }
			is[i].alertclass = this.alertclass;
			is[i].imgclass = this.imgclass;
			is[i].bgi = 0;

			//add methods
			is[i].onkeyup = think;
			is[i].onfocus = think;
			is[i].onblur = test;
			is[i].stopthinking = stopthinking;
			is[i].removeError = removeError;
			is[i].errorExists = errorExists;
			is[i].showError = showError;
			this.els.push(is[i]);
			}
		}

	function isthinking(el) {
		var x = (el.parentNode.getElementsByTagName("img").length > 0) ? true : false;
		return x;
		}
	function think() {
		this.removeError();
		if(isthinking(this)) return; //only one loading per image per element, please.
		var im = document.createElement("img");
		im.className = this.imgclass;
		im.src = this.loadingimage;
		this.parentNode.appendChild(im);
		} //end thinking
		
	function stopthinking() {
		if(imgs = this.parentNode.getElementsByTagName("img")) {
			for(i=0; i<imgs.length; i++) {
				if(imgs[i].className == this.imgclass)
					this.parentNode.removeChild(imgs[i])
				}
			}
		} //end stopthinking
	
	function test() {
		this.stopthinking();
		if(!this.info[1].test(this.value)) {
			this.showError();
			} else {
			this.removeError();
			}
		} //end test
	
	function errorExists() {
		if(errs = this.parentNode.getElementsByTagName(this.el)) {
			for(i=0; i<errs.length; i++) {
				if(errs[i].className == this.alertclass)
					return true;
				}
			}
		} //end errorExists
	function removeError() {
		this.className = "";
		if(errs = this.parentNode.getElementsByTagName(this.el)) {
			for(i=0; i<errs.length; i++) {
				if(errs[i].className == this.alertclass)
					this.parentNode.removeChild(errs[i]);
				}
			}
		} //end removeError
		
	function showError() {
		if (this.value == ""){
			var theError = this.info[3];
			} else {
			var theError = this.info[2];
			}
			
		if(this.errorExists()) { //first check for error messages
			this.removeError(); //create a blank canvas
			}
		//create new error
		var emessage = document.createTextNode(theError);
		var eel = document.createElement(this.el);
		eel.className = this.alertclass;
		eel.appendChild(emessage);
		this.parentNode.appendChild(eel);
		if(this.fade !== false) { 
			fade(this.id);
			//flashError(eel.id);
			}
		this.className = this.alertclass;
		} //end showError
		

	function fade(id) {
		return; // do nothing until this can recurse properly.  is recurse a word?
		var obj = document.getElementById(id);
		if (obj.fade == false) return;
		
		if(obj.bgi < 255) {
			obj.style.backgroundColor = "rgb(255,255," + obj.bgi + ")";
			obj.bgi+=10;

			setTimeout("this.fade()", 100);
			} else {
			obj.style.backgroundColor = "rgb(255,255,255)";
			obj.bgi = 0;
			}
		} //end fade
		
		
		
	} //end validator class

if(document.all) {
	} else {
	window.onload = function() { var val = new validator(); };
	}



