var vetorTabulacao = new Array();
var tamanhoAnterior = 0;
var nomeAnterior = "";
var indicadorAlteracao = false;

if(	document.layers &&
    parseFloat(navigator.appVersion) < 6 &&
    ( navigator.appVersion.indexOf("Linux") != -1 ||
      navigator.appVersion.indexOf("Mac") != -1 ) ) {
		indicadorAlteracao = true;
}

function mudaFoco(e, evento){
        var campo;
        if(document.all)
                campo = window.event.srcElement;
        else
                campo = e.target;
        if(campo.name && vetorTabulacao[campo.name]){
                if(indicadorAlteracao && evento == 1) {
                        window.focus(); campo.focus();
                }
                else{
                        if(	(campo.value.length >= vetorTabulacao[campo.name][0]) &&
                                (campo.value.length > tamanhoAnterior) &&
                                (campo.name == nomeAnterior) &&
                                campo.form.elements[vetorTabulacao[campo.name][1]]){
                                campo.form.elements[vetorTabulacao[campo.name][1]].focus();
                                nomeAnterior = campo.form.elements[vetorTabulacao[campo.name][1]].name;
                        }
                }
        }
        if(document.layers)
                routeEvent(e);
}

function processaTeclaDesce(e){
        var campo;
        if(document.all)
                campo = window.event.srcElement;
        else
                campo = e.target;
        if(campo.name){
                tamanhoAnterior = campo.value.length;
                nomeAnterior = campo.name;
        }
}

function processaTeclaSobe(e){
        mudaFoco(e, 1);
}

function processaMudanca(e){
        mudaFoco(e, 2);
}

window.document.onkeyup = processaTeclaSobe;
window.document.onkeydown = processaTeclaDesce;

if(document.layers){
        window.document.captureEvents(Event.KEYUP | Event.KEYDOWN);
        if(indicadorAlteracao)	{
                window.document.onChange = processaMudanca;
                window.document.captureEvents(Event.CHANGE);
        }
}

function cont(src, target, id, evt){
        if(indicadorAlteracao && id == 1) {
                window.focus(); src.focus();
        }
        else
                target.value = src.value.length;
}
