Evento = function(){}

Evento.prototype.addEvent = function( o , t , f ){

	o.addEventListener ? o.addEventListener( t , f , true ) : o.attachEvent( "on" + t , f )

}

Restrict = function( f ){

	this.items = []
	this._function = f

}

Restrict.prototype = new Evento()

Restrict.prototype.addItem = function( o ){

	this.items.push( o )

}

Restrict.prototype.start = function(){

	for( var i = 0 ; i < this.items.length ; i++ ){

		this.addEvent( this.items[i] , "keypress" , this.restrict )
		this.items[i]._function = this._function
	
	}
	
}

Restrict.prototype.restrict = function( e ){

	var eDefault = e,
		e = typeof( e ) == "undefined" ? event : e,
		flag = true,
		$this = e.target ? e.target : e.srcElement
	
	if( e.srcElement )
			e.returnValue = $this._function( String.fromCharCode( e.keyCode ) )
		else{

			flag = !( e.keyCode == 9 || e.keyCode == 8 )
				
			e.cancelBubble = !flag ? false : !$this._function( String.fromCharCode( e.which ) );
	
			if( e.cancelBubble ){
			
				e.preventDefault()
				e.stopPropagation()				
			
			}
		
	}				

}
