/*
inputControl v 1.00
copyright 2006 Thomas Frank

This program is free software under the terms of the 
GNU General Public License version 2 as published by the Free 
Software Foundation. It is distributed without any warranty.
*/

inputControl={
	rules:{},
	addRules:function(formName,controlObj){
		this.rules[formName]=controlObj;
		this.init(formName);
	},
	init:function(formName){
		if(!document || !document.forms || !document.forms[formName]){
			setTimeout('inputControl.init("'+formName+'")',200);
			return;
		};
		var f=document.forms[formName];
		var r=this.rules[formName];
		for(var i in r){
			var e=f.elements[i];
			if(!e){continue};
			if(e.type!="text" && e.type!="textarea"){continue};
			e.onkeypress=function(e){
				var key=window.event?event.keyCode:e.which;
				if(key<13){return true};
				var keychar=String.fromCharCode(key);
				var reg=new RegExp(r[this.name]);
				return reg.test(keychar)
			}
		}
	}
}