﻿var isNN = (navigator.appName.indexOf("Netscape") != -1);

function containsElementControl(arr, ele) {
    var found = false, index = 0;
    while (!found && index < arr.length)
        if (arr[index] == ele)
        found = true;
    else
        index++;
    return found;
}

function getIndexControl(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
        if (input.form[i] == input) index = i;
    else i++;
    return index;
}

function autoTabControl(input, len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElementControl(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        try{
        input.form[(getIndexControl(input) + 1) % input.form.length].focus();
        }
        catch(err){}
        return true;
    }
}

function autoTabControl_conDestino(input, len, e, idObjDestino) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElementControl(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        try{
            document.getElementById(idObjDestino).focus();
        }
        catch (err) { }
        return true;
    }
}

function validarNumeroControl(e) {
    tecla_codigo = (document.all) ? e.keyCode : e.which;
    if (tecla_codigo == 8) return true;
    patron = /[0-9]/;
    tecla_valor = String.fromCharCode(tecla_codigo);
    return patron.test(tecla_valor);
}

