if ( typeof(My) === 'undefined' ) {
		My = new Object();
	}
   My.Mask = {
		install:function() {
			var elements = $$('input[alt]');
			elements.each(function(item) {
				 Event.observe(item, 'keypress',My.Mask.setMask.bindAsEventListener(item), true);
			});
		},
		mask:{
				format:'',
				regex:''
			},
		setMask:function(event) {
			var mask_code 	= this.readAttribute("alt");
			var mask_sys 	= mask_code.split("|");
			var mask = My.Mask.mask;
			mask.format = mask_sys[1].replace(/#/g,' ');
			if(mask_sys[0] == "number") {
				mask.regex = /\d/;
			}else if(mask_sys[0] == "all") {
				mask.regex = /\w/;
			}else if(mask_sys[0] == "char") {
				mask.regex = /[a-zA-Z]/;
			}

			var keyCode = My.Mask.getKeyPress(event);

			if(My.Mask.notChar(keyCode)) {
				var chr 	= String.fromCharCode(keyCode);
	            var strng 	= this.value + chr;
	            var pos     = strng.length;
	            if ( mask.regex.test(chr) && pos <= mask.format.length ) {
	               if ( mask.format.charAt(pos - 1) != ' ' ) {
	                  strng = this.value + mask.format.charAt(pos - 1) + chr;
	               }
	               this.value = strng;
	            }
	           Event.stop(event);
			}

		},
		getKeyPress: function(e) {
	      return window.event ? window.event.keyCode
	           : e            ? e.which
	           :                0;
	    },
		notChar: function(key) {
			return ( key >= 32 && key < 127 );
		}
   }