function pulsar(e) { 
    tecla = (document.all) ? e.keyCode :e.which; 
    return (tecla!=13); 
}

function tabular(e,obj,elto) { 
    tecla=(document.all) ? e.keyCode : e.which; 
    if(tecla!=13) return; 
    frm=obj.form; 
    for(i=0;i<frm.elements.length;i++) 
        if(frm.elements[i].id==elto) { 
            if (i==frm.elements.length-1) i=-1; 
            break } 
        frm.elements[i].focus(); 
        return false; 
    }
    
    
    
    function carga_dato(dato1,dato2)
    {
        
        document.getElementById(dato2).value=document.getElementById(dato1).value;
        document.getElementById(dato2).style.backgroundColor='WHITE';  
        
    }
    
    function testporciento(id) {
        
        var valor;
        
        valor=document.getElementById(id).value;
        valor = parseInt(valor) ;
        
        if (valor>100) {
            alert("Se requiere un valor de porcentaje,entre [0-100]")
            document.getElementById(id).style.backgroundColor='RED';
            
            
        }
        else
            
        document.getElementById(id).style.backgroundColor='WHITE';  
        
        
    }   
    
    function compruebaPorciento(id) {
        
        
        var num,p;
        
        
        
        for (var i=0;i<id.length;i++ ) {
            
            
            num=document.getElementById(id[i]).value;
            
            for (p=0;p<6;p++)
                num = num.toString().replace('.','');
            
            num= num.toString().replace(',','.');
            
            
            
            if (num>100) {
                //alert("Se requiere un valor de porcentaje,entre [0-100]");
                document.getElementById(id[i]).style.backgroundColor='RED';
                document.getElementById(id[i]).focus();
                return 0;
            }
            
            document.getElementById(id[i]).style.backgroundColor='WHITE';
            
        }
        
        
        return 1;
        
        
        
        
    }
    
    
    
    
    
    
    
    function cambiar(obj) {
        
        var vista;
        
        
        //document.getElementById("tapa").setAttribute("visibility","visible");
        
        vista=document.getElementById(obj).style.display;
        
        if (vista=='none')
            vista='block';
        else
            vista='none';
        
        document.getElementById(obj).style.display = vista;        
    }
    /*
    ORIGINAL
    function getParameter(parameter) {
    
    // Obtiene la cadena completa de URL
    var url = window.document.location.href;
    
    
    //alert(parameter);
    
    /* Obtiene la posicion donde se encuentra el signo ?, 
    ahi es donde empiezan los parametros */
    //    var index = url.indexOf("?");
    /* Obtiene la posicion donde termina el nombre del parametro
    e inicia el signo = */
    //    index = url.indexOf(parameter,index) + parameter.length;
    /* Verifica que efectivamente el valor en la posicion actual 
    es el signo = */ 
    //    if (url.charAt(index) == "="){
    // Obtiene el valor del parametro
    //        var result = url.indexOf("&",index);
    //        if (result == -1){result=url.length;};
    // Despliega el valor del parametro
    //alert(url.substring(index + 1,result));
    //        return url.substring(index + 1,result);
    //    }
    //} 
    
    // getParameter Modificado 20/10/2007
    function getParameter(parameter) {
        
        // Obtiene la cadena completa de URL
        var url = window.document.location.href;
        
        
        
        /* Obtiene la posicion donde se encuentra el signo ?, 
        ahi es donde empiezan los parametros */
        var index = url.indexOf("?");
        
        
        /* Obtiene la posicion donde termina el nombre del parametro
        e inicia el signo = */
        index = url.indexOf(parameter,index) + parameter.length;
        /* Verifica que efectivamente el valor en la posicion actual 
        es el signo = */ 
        if (url.charAt(index) == "="){
            // Obtiene el valor del parametro
            
            var result = url.indexOf("#",index);
            
            if (result == -1) {
                result = url.indexOf("&",index);
                if (result == -1)
                    result=url.length;
                
            }   
            
            return url.substring(index + 1,result);
            
            // Despliega el valor del parametro
            //alert(url.substring(index + 1,result));
            
            
        }
        
        return null;
        
        
        
    } 
    
    function ocultarEltos(id) {
        
        var elto;
        
        
        
        for (var i=0;i<id.length;i++ ) {
            
            elto=document.getElementById(id[i]);
            elto.style.display='none';
            
        }
        
        
        
        
        
    }
    function ProcesaSubmit(id) {
        
        
        cambiar(id);
        //window.document.forms[0].action="./procesa.jsp";
        setTimeout("window.document.forms[0].submit()",3000);
        
    }
    
    
    
    function pasarVariables(pagina,variable,valor) {
        
        //href="javascript:pasarVariables('costes1.jsp', 'activo',2)"
        /*
        pagina +="?";
        nomVec = nombres.split(",");
        for (i=0; i<nomVec.length; i++)
            pagina += nomVec[i] + "=" + escape(eval(nomVec[i]))+"&";
        pagina = pagina.substring(0,pagina.length-1);
        location.href=pagina;
        */
        pagina +="?";
        pagina +=variable + "=" + valor;
        location.href=pagina;
        //alert(pagina);        
    }
    
    function activo(pagina,paramActivo) {        
        location.href=pagina+"?"+"activo"+"="+getParameter(paramActivo);        
    }
    
    function HabilitaMenu(paramActivo) {
        
        var activo = parseInt(getParameter(paramActivo));
        
        
        
        
        if (activo==2) {
            document.getElementById('tab1').href="RViajeros.jsp?activo=2";
            document.getElementById('tab2').href="costes1.jsp";
            
        }
        if (activo==3) {
            document.getElementById('tab1').href="RViajeros.jsp?activo=3"; 
            document.getElementById('tab2').href="RCostes1.jsp?activo=3"; 
            document.getElementById('tab3').href="costes2.jsp";
            
            
        }   
        if (activo==4) {
            document.getElementById('tab1').href="RViajeros.jsp?activo=4";
            document.getElementById('tab2').href="RCostes1.jsp?activo=4";
            document.getElementById('tab3').href="RCostes2.jsp?activo=4";
            document.getElementById('tab4').href="costesvariables.jsp";
            
        }
        
        if (activo==5) {
            document.getElementById('tab1').href="RViajeros.jsp?activo=5";
            document.getElementById('tab2').href="RCostes1.jsp?activo=5";
            document.getElementById('tab3').href="RCostes2.jsp?activo=5";
            document.getElementById('tab4').href="RCostesVariables.jsp?activo=5";
            document.getElementById('tab5').href="servicio.jsp?activo=5";
            
        }
        if (activo==6){
            document.getElementById('tab1').href="RViajeros.jsp?activo=6";
            document.getElementById('tab2').href="RCostes1.jsp?activo=6";
            document.getElementById('tab3').href="RCostes2.jsp?activo=6";
            document.getElementById('tab4').href="RCostesVariables.jsp?activo=6";
            document.getElementById('tab5').href="servicio.jsp?activo=6";
            document.getElementById('tab6').href="resultados.jsp";
            
            
        }
        //alert(elto.href);    
    }
    
    
    
    
    function Validar(form) {
        
        var esvalido;
        var pos;
        var elto;
        var j;
        
        esvalido=1;
        
        j=-1;
        
        
        
        for (var i = 0; i < form.length; i++) {
            
            if ((form.elements[i].name=="activo")&&(form.elements[i].value=="")){
                form.elements[i].value=getParameter('activo');                        
            }
            
            
            if ((form.elements[i].nodeName!="undefined")&&(form.elements[i].nodeName=="INPUT")&&
                (form.elements[i].name!="guardar")&&(form.elements[i].name!="activo")&&(form.elements[i].name!="nuevo")&& (form.elements[i].name!="dato-obs"))
            
            if ((form.elements[i].value == "")||(isNaN(parseFloat(form.elements[i].value)))||(!EsReal(form.elements[i].value))) { 
                if (j==-1) j=i;
                form.elements[j].focus();
                form.elements[i].style.backgroundColor='RED'
                esvalido=0;
            }
            else
                form.elements[i].style.backgroundColor='WHITE'
            
            //alert(obj.nodeName + " es de tipo " + obj.nodeType);
            //alert (form.elements[i].name);
            
        }
        
        
        if (esvalido==0)
            alert("Por favor insertar los datos correctamente"); 
        
        
        return esvalido;
        // cambiar(obj);
        
        //form.submit();
        
    }   
    
    /*
    function Validar(form) {
    
    //var puntero=document.getElementById('idpotencia');
    //var txt=document.getElementById('idpotencia').firstChild.data;
    //var obj=document.getElementById('potencia');
    //alert(obj.nodeName + " es de tipo " + obj.nodeType);    
    
    for (var i = 0; i < form.length; i++) {
    
    if ((form.elements[i].name=="activo")&&(form.elements[i].value=="")){
    form.elements[i].value=getParameter('activo');                        
    }
    
    
    
    if ((form.elements[i].nodeName!="undefined")&&(form.elements[i].nodeName=="INPUT")&&
        (form.elements[i].name!="guardar")&&(form.elements[i].name!="activo")&&(form.elements[i].name!="nuevo"))
    
    if ((form.elements[i].value == "")||(isNaN(parseFloat(form.elements[i].value)))) { 
    alert("Por favor insertar los datos correctamente"); 
    form.elements[i].focus();
    form.elements[i].style.backgroundColor='RED'
    return 0;
    }
    else
        form.elements[i].style.backgroundColor='WHITE'
    
    //alert(obj.nodeName + " es de tipo " + obj.nodeType);
    //alert (form.elements[i].name);
    
    }
    
    return 1;
    // cambiar(obj);
    
    //form.submit();
    
    }   
    */
    
    
    function progress(form,obj) {
        var progresa;
        
        progresa = Validar(form);
        
        if (progresa==1) {
            cambiar(obj);
            setTimeout(form.submit(),500);
            form.submit();
            //cambiar(obj);
        }    
    }
    
    function formateaParteEntera(num)
    {
        
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            num = num.substring(0,num.length-(4*i+3))+'.'+
        num.substring(num.length-(4*i+3));
        
        return num;
        
    }
    
    function formatCurrency(num,decimales,id) {
        //num = num.toString().replace(',','.');
        //num = num.toString().replace(/\?|\,/g,'');
        
        var i;
        var entera;
        var decimal;
        
        
        
        
        
        num = num.toString().replace(',','.');
        i=num.indexOf('.');
        
        if(isNaN(num)||(num==""))
            return num;
        
        
        
        if (i>0) {
            entera=num.substring(0,i);
            decimal=num.substring(i+1,num.length);
            
        }
        else {
            entera=num;
            decimal="00";
            
        }
        
        if (decimal.length>decimales)
            decimal=decimal.substring(0,decimales);
        
        
        
        document.getElementById(id).style.backgroundColor='WHITE';
        return (formateaParteEntera(entera)+ ',' + decimal );
    }
    
    
    
    function EsReal(num)
    {
        var numerica = "0123456789.,";
        var actual,j,i;
        
        
        if(num.charAt(0)=='.') return false; 
        
        
        for(i=0;i<num.length;i++)
            {
                actual=num.charAt(i);
                j=0;
                while ((j<numerica.length)&&(actual!=numerica.charAt(j)))
                    {
                        j++;
                    }
                    
                    if (j>=numerica.length) return false;
                }
                
                return true;
                
            }
            
            
            
            
            
            function formatCurrency1(num,id) {
                
                var sign,cents;
                
                var numerica = "123456789.";
                var actual,j,i;
                
                num = num.toString().replace(',','.');
                num = num.toString().replace(/\?|\,/g,'');
                
                //if(isNaN(num))
                //     num = "0";
                
                
                
                if(isNaN(num)||(num==""))
                    return num;
                
                
                /*
                if(!EstaenRango(id))
                    {
                if (confirm("¿Está Ud. seguro del dato?" ))
                    {
                
                
                sign = (num == (num = Math.abs(num)));
                num = Math.floor(num*100+0.50000000001);
                cents = eval(num%100);
                num = Math.floor(num/100).toString();
                if(cents<10)
                    cents = "0" + cents;
                for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
                    num = num.substring(0,num.length-(4*i+3))+'.'+
                num.substring(num.length-(4*i+3));
                document.getElementById(id).style.backgroundColor='WHITE';
                document.getElementById(id).focus();
                return (((sign)?'':'-') + num + ',' + cents );
                }
                else
                    {
                
                return "";
                }
                } 
                
                */
                // else
                //   {
                
                sign = (num == (num = Math.abs(num)));
                num = Math.floor(num*100+0.50000000001);
                cents = eval(num%100);
                num = Math.floor(num/100).toString();
                if(cents<10)
                    cents = "0" + cents;
                for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
                    num = num.substring(0,num.length-(4*i+3))+'.'+
                num.substring(num.length-(4*i+3));
                document.getElementById(id).style.backgroundColor='WHITE';
                return (((sign)?'':'-') + num + ',' + cents );
                
                // }  
                
                
            }   
            
            
            function formatCurrency2(num) {
                
                var sign,cents;
                
                num = num.toString().replace(',','.');
                num = num.toString().replace(/\?|\,/g,'');
                if(isNaN(num))
                    num = "0";
                sign = (num == (num = Math.abs(num)));
                num = Math.floor(num*100+0.50000000001);
                cents = eval(num%100);
                num = Math.floor(num/100).toString();
                if(cents<10)
                    cents = "0" + cents;
                for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
                    num = num.substring(0,num.length-(4*i+3))+'.'+
                num.substring(num.length-(4*i+3));
                return (((sign)?'':'-') + num + ',' + cents );
            }  
            
            
            function ValidarVehiculo(obj)
            {
                
                if (document.getElementById(obj).selectedIndex==0){
                    
                    return 0;
                    
                }
                
                return 1;
                
            }
            
            
            function montarURL(pagina,obj){
                
                var variable = document.getElementById(obj).selectedIndex;
                
                var tipo;
                
                
                if (variable==0) {
                    
                    alert("Seleccione el tipo de vehiculo correctamente"); 
                    
                    tipo=getParameter("tipologia");
                    if (tipo!=null) 
                        document.getElementById(obj).selectedIndex=tipo;
                    
                    return;    
                    
                    
                    
                }
                
                
                
                if (confirm("¿Estás seguro/a de seleccionar " + document.getElementById(obj).options[variable].text+"?"))
                    {
                        pagina=pagina+"?tipologia="+variable;
                        window.location = pagina;
                        
                    }     
                    
                    else
                        
                    
                    {
                        
                        tipo=getParameter("tipologia");
                        
                        
                        if (tipo==null) 
                            document.getElementById(obj).selectedIndex=0;
                        else
                            document.getElementById(obj).selectedIndex=tipo;
                        
                    }
                    
                }
                
                function montarURLActualiza(pagina,obj){
                    
                    var variable = document.getElementById(obj).selectedIndex;
                    var tipo;
                    
                    
                    pagina=pagina+"&tipologia="+variable;
                    window.location = pagina;
                    
                    
                }
                
                function cargarTipologia(obj) {
                    var tipo;
                    
                    
                    tipo=getParameter("tipologia");
                    
                    if (tipo==null) 
                        document.getElementById(obj).selectedIndex=0;
                    else
                        document.getElementById(obj).selectedIndex=tipo;
                    
                    
                    
                }   
                
                function onEnter(e,element) 
                { 
                    var code; 
                    
                    if(document.all) code = event.keyCode; 
                    else code = e.keyCode; 
                    //if (code==13 || code==9) 
                    if (code==13)
                        { 
                            
                            eval('document.formulario.'+element+'.focus();');
                            
                            
                        } 
                        
                        
                        
                    } 
                    
                    // ##############################################################################/
                    
                    
                    function cambiarImg(id,path)
                    {
                        
                        document.getElementById(id).src=path;
                        
                        
                        
                    }
                    
                    window.onload=function()
                    {
                        var op1=document.getElementById("img1");
                        var op2=document.getElementById("img2");
                        var op3=document.getElementById("img3");
                        var op4=document.getElementById("img4");
                        
                        
                        if (document.getElementById("Vehiculos")!=null)
                            cargarTipologia('Vehiculos');
                        
                        
                        HabilitaMenu('activo');
                        
                        
                        op1.onclick = function() {location.href='loginActualiza.jsp';}
                        op1.onmousemove = function (){cambiarImg('img1','./Imagenes/actualiza-obs1.jpg');}
                        op1.onmouseout = function(){cambiarImg('img1','./Imagenes/actualiza-obs.jpg');}
                        
                        op2.onclick = function() {location.href='panelControl.jsp';}
                        op2.onmousemove = function (){cambiarImg('img2','./Imagenes/control1.jpg');}
                        op2.onmouseout = function(){cambiarImg('img2','./Imagenes/control.jpg');}
                        
                        op3.onclick = function() {window.open('ayuda.pdf','Manual_Usuario','resizable');return false;}
                        op3.onmousemove = function (){cambiarImg('img3','./Imagenes/help1.jpg');}
                        op3.onmouseout = function(){cambiarImg('img3','./Imagenes/help.jpg');}
                        
                        op4.onclick = function() {location.href='acerca.html';}
                        op4.onmousemove = function (){cambiarImg('img4','./Imagenes/mf1.jpg');}
                        op4.onmouseout = function(){cambiarImg('img4','./Imagenes/mf.jpg');}
                        
                        
                        
                        
                    }
                    
