var ContaCorrenteMask = new Class({

    initialize: function() {
		this.keypress = this.keypress.bind(this);
		this.keyup = this.keyup.bind(this);
		this.focus = this.focus.bind(this);
		this.bluer = this.blur.bind(this);
     },
     
    isValid: function(value) {
        return value.match(/^(\d{1,3})(\.\d{3})*-(\d)$/) != null;
    },

    mask: function(value) {
    	value = value.onlyNumeric()
        // Limita o máximo de caracter
        if (value.length > 10) {
            value = value.substr(0, 10);
        }
        
        if (value.length > 1) {
            value = value.insert(value.length - 1, '-');
        }

        if (value.length > 5) {
            value = value.insert(value.length - 5, '.');
        }
        if (value.length > 9) {
            value = value.insert(value.length - 9, '.');
        }
        
        return value;
    },
    
    keypress: function(event) {
        var key = event.key;
        if (key.isNumeric() || Event.Keys.has(key)) {
            return true;
        } else {
            event.stop();
            return false;
        }
    },

    keyup: function(event) {
        if (!this.isValid(event.target.value)) {
        	event.target.value = this.mask(event.target.value);
        }
    },

    focus: function(event) {
    	event.target.maxLength = 13;
    	event.target.select();
        
    },

    blur: function(event) {
        if (!this.isValid(event.target.value)) {
        	event.target.value = this.mask(event.target.value);
        }
    }
});