/**
 * @author: Alejandro Escario Méndez
 * @site: http://www.bitnbyte.org
 * @version: 1.0
 */

function colapso(c1, text){
    var str = document.getElementById(c1);
    str.style.display = text;
}

function colapsoFilas(c1, val, btn, text){
    if(document.getElementById(val).value == "")
        colapso(c1, text);
    else
        colapso(btn, text);
}

    function cambio(c1, c2, length, e){
        var tecla = (document.all) ? e.keyCode : e.which;
        var str = document.getElementById(c1);
        var impr = false;
        var oSel;
        if(navigator.appName == 'Opera') return;
        if(document.selection){ // IE
            if (str.createTextRange){//Creamos el rango
                var seleccion = document.selection.createRange();
                str.caretPos = seleccion.duplicate();
                if (str.caretPos) {
                    var caretPos = str.caretPos;
                    caretPos.text = String.fromCharCode(tecla);
                    seleccion.text = seleccion.text;
                    str.caretPos.select();
                }
            }
            else
                str.value  = str.value;
        }else if (typeof str.selectionStart != 'undefined'){ //Firefox
            var before, after, selection, selectionStart;
            selectionStart = str.selectionStart;
            before= str.value.substring(0, str.selectionStart);
            selection = str.value.substring(str.selectionStart, str.selectionEnd);
            after = str.value.substring(str.selectionEnd, str.value.length);
            
            if(tecla == 8){
                return;
            }else if(tecla == 0){
                return;
            }else{
                if(before.length+after.length < length)
                    str.value = String.concat(before, String.fromCharCode(tecla), after);
            }
            //Posicionamos el cursor en una posicion más
            str.setSelectionRange(before.length + 1, before.length + 1);
        }
        if(str.value.length >= length){
            document.getElementById(c2).focus();
        }
        return false;
    }