formValidate = function(){
	
	var fields = [
		{id:"pin_number", 		validator:"numeric"},
		{id:"phone_number", 	validator:"numeric"},
		{id:"contact_name", 	validator:"alphaNumeric"},
		{id:"customer_order_no", 	validator:"alphaNumeric"}
    ];
	
	
	var setup = function(){
		
		var forms = document.getElementsByTagName("form");
		for(var i = 0; i<forms.length; i++){
			var f = forms[i];
			EventUtils.addEventListener(f, "submit", submit);
		}
		

		for(var i = 0; i<fields.length; i++){			
			var f = document.getElementById(fields[i].id);
			var v = formValidate.validators[fields[i].validator];
			if(f){f.validator = v;}
		}
		  
	}
	
	  
	var submit = function(e){
		
		if(e.target){
			var form = e.target;
		}else if(e.srcElement){
			var form = e.srcElement;
		}
		
		var fs = form.getElementsByTagName("input");
		for(var i=0; i < fs.length; i++){
			var f = fs[i];
			if(f.validator){
				f.value = f.validator(f.value);
			}
		}
		
	  }
	  

	var numeric = function(str){
		var rx = /([^0-9 ])/ig;
		return str.replace(rx, "");
	}
	
	var alphaNumeric = function(str){
		var rx = /['"<>]/ig;
		return str.replace(rx, "");
	}
	
	return {
	/* Public API
	*/
	setup: setup,
	validators: {
		numeric:numeric,
		alphaNumeric:alphaNumeric
		}
	}

		
}();


/* @constructor */
function EventUtils() {
	throw 'RuntimeException: EventUtils is a static utility class ' +
		' and may not be instantiated';
}

/**
 *	@access static
 *	@param HTMLElement target
 *	@param string type
 *	@param Function callback
 *	@param boolean captures
 */
EventUtils.addEventListener = function (target,type,callback,captures) {
	if (target.addEventListener) {
			// EOMB
		target.addEventListener(type,callback,captures);
	} else if (target.attachEvent) {
		// IE
		target.attachEvent('on'+type,callback,captures);
	} else {
		// IE 5 Mac and some others
		target['on'+type] = callback;
	}
}

EventUtils.removeEventListener = function (target,type,callback,captures) {
	if (target.removeEventListener) {
			// EOMB
		target.removeEventListener(type,callback,captures);
	} else if (target.detachEvent) {
		// IE
		target.detachEvent('on'+type,callback);
	} else {
		// IE 5 Mac and some others
		target['on'+type] = null;
	}
}

EventUtils.addEventListener(window,'load', formValidate.setup);
