﻿function execmascara() {
    obj.setValue(fun(obj.getValue()));
}
function mascara(objeto, funcao) {
    obj = objeto;
    fun = funcao;
    setTimeout("execmascara()", 0);
}
function mascaraCpf(field) {
    obj = Ext.getCmp(field);
    if (obj.getValue().length > 14) {
        obj.setValue(obj.getValue().substr(0, 14));
        return;
    }
    mascara(obj, cpf);
}
function cpf(v) {
    v = v.replace(/\D/g, "");
    v = v.replace(/(\d{3})(\d)/, "$1.$2");
    v = v.replace(/(\d{3})(\d)/, "$1.$2");
    v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2");
    return v;
}
function mascaraRg(field) {
    obj = Ext.getCmp(field);
    if (obj.getValue().length > 11) {
        obj.setValue(obj.getValue().substr(0, 11));
        return;
    }
    mascara(obj, rg);
}
function rg(v) {
    v = v.replace(/\D/g, "");
    v = v.replace(/(\d{1})(\d)/, "$1.$2");
    v = v.replace(/(\d{3})(\d)/, "$1.$2");
    v = v.replace(/(\d{3})(\d{1})$/, "$1-$2");
    return v;
}
function mascaraTelefone(field) {
    obj = Ext.getCmp(field);
    if (obj.getValue().length > 14) {
        obj.setValue(obj.getValue().substr(0, 14));
        return;
    }
    mascara(obj, telefone);
}
function telefone(v) {
    v = v.replace(/\D/g, "");
    v = v.replace(/^(\d\d)(\d)/g, "($1) $2");
    v = v.replace(/(\d{4})(\d)/, "$1-$2");
    return v;
}
function mascaraCep(field) {
    obj = Ext.getCmp(field);
    if (obj.getValue().length > 8) {
        obj.setValue(obj.getValue().substr(0, 8));
        return;
    }
    mascara(obj, cep);
}
function cep(v) {
    v = v.replace(/\D/g, "");
    v = v.replace(/^(\d{8})(\d)/, "$1");
    return v;
}
