    
    var cerrable = true;
    function cerrarSubFamilias(idFamilia) {
        if (cerrable) {
        document.getElementById('subfamilasoculto').style.display = "none";
        }
        cerrable = true;
    }
    
    function eliminarOnclick() {
        cerrable = false;        
    }
    var url = "http://www.recambiosmarinos.es/";
    
    function eliminarProducto(id) {
        
        $.ajax({
            url: url+'ajax.php?page=pedido-rapido&accion=eliminarproducto&id='+id,
            cache: false,
            success: function(html){
                document.getElementById('productos-pedido-rapido').innerHTML = html;
                /*document.getElementById('insertarproductos').value = "";
                document.getElementById('insertarproductos').focus();*/
              
            }
          });
        $.ajax({
        url: url+'ajax.php?page=pedido-rapido&accion=obtenertotalproductos',
        cache: false,
        success: function(html){
            //document.getElementById('totalproducts').innerHTML = html;
            document.getElementById('totalmenuproductos').innerHTML = html;
          
        }
      });
    }

    function insertarProducto() {
        var ref = document.getElementById('insertarproductos').value;
        var cantidad = document.getElementById('cantidad').value;
        $.ajax({
        url: url+'ajax.php?page=pedido-rapido&accion=insertarproducto&ref='+ref+'&cantidad='+cantidad,
        cache: false,
        success: function(html){
            document.getElementById('productos-pedido-rapido').innerHTML = html;
            document.getElementById('insertarproductos').value = "";
            document.getElementById('insertarproductos').focus();
            document.getElementById('cantidad').value = "";
          
        }
      });
        $.ajax({
        url: url+'ajax.php?page=pedido-rapido&accion=obtenertotalproductos',
        cache: false,
        success: function(html){
            //document.getElementById('totalproducts').innerHTML = html;
            document.getElementById('totalmenuproductos').innerHTML = html;
          
        }
      });
        
    }
    function insertarProductoDesdeSelect(ref) {
        document.getElementById('insertarproductos').value = ref;
        document.getElementById('insertarproductos').focus();
        document.getElementById('cajaresultados').innerHTML = "";
        document.getElementById('cantidad').style.display = "inline";
        document.getElementById('cantidad').focus();
        //document.getElementById('selectBuscarPedido').style.display = "none";
        
    }
    function validar2(oEvento, string) {
        
                document.getElementById('cajaresultados').style.display = "block";
            var opcionseleccionada = document.getElementById('opcionseleccionada').value;
            var iAscii;
            
            if (oEvento.keyCode)
                iAscii = oEvento.keyCode;
            else if (oEvento.which)
                iAscii = oEvento.which;
            else
                return false;
            if (iAscii == 40){
                if(document.getElementById('opcionseleccionada').value == document.getElementById('totalresultados').value) {
                    
                }
                else {
                    document.getElementById('opcionseleccionada').value++;
                    opcionseleccionada = document.getElementById('opcionseleccionada').value;
                }
                for(var i=1; i<=document.getElementById('totalresultados').value; i++ ){
                    document.getElementById('opcion'+i).className = "noselected";
                }
                document.getElementById('opcion'+opcionseleccionada).className = "selected";
            }
            else if (iAscii == 38){
                if(document.getElementById('opcionseleccionada').value <= 1) {
                    
                }
                else {
                    document.getElementById('opcionseleccionada').value--;
                }
                var opcionseleccionada = document.getElementById('opcionseleccionada').value;
                for(var i=document.getElementById('totalresultados').value; i>=1; i-- ){
                    document.getElementById('opcion'+i).className = "noselected";
                }
                document.getElementById('opcion'+opcionseleccionada).className = "selected";
            }
            else if (iAscii == 13) {
                document.getElementById('cajaresultados').style.display = "none";
                document.getElementById('insertarproductos').value = document.getElementById('opcion_'+opcionseleccionada).innerHTML;
                document.getElementById('opcionseleccionada').value = 0;
                document.getElementById('cajaresultados').innerHTML = '';
                document.getElementById('cantidad').style.display = "inline";
                document.getElementById('cantidad').focus();
            }
            else {
                buscarCadena();
            }
            return true;
    }
    function buscarCadena() {
        //document.getElementById('selectBuscarPedido').style.display = "block";
        var ref = document.getElementById('insertarproductos').value;
        $.ajax({
        url: url+'ajax.php?page=pedido-rapido&accion=buscarcadena&ref='+ref,
        cache: false,
        success: function(html){
            document.getElementById('cajaresultados').innerHTML = html;
          
        }
      });
        $.ajax({
        url: url+'ajax.php?page=pedido-rapido&accion=buscarcadenatotal&ref='+ref,
        cache: false,
        success: function(html){
            document.getElementById('totalresultados').value = html;
          
        }
      });
    }
    
    function pruebas(id) {
        alert(document.getElementById('pruebadeoption').innerHTML);
    }
    var abierto = "";
    function abrirCerrar(id) {
        if(abierto != id && abierto != "") {
            document.getElementById(abierto).style.display = "none";
        }
        if (document.getElementById(id).style.display == "none") {
            document.getElementById(id).style.display = "block"
        }
        else {
            document.getElementById(id).style.display = "none"
            
        }
        abierto = id;
    }
    
    function guardarCantidad(id, value) {
        alert(value);
        $.ajax({
        url: url+'ajax.php?page=pedido-rapido&accion=modificarcantidad&id='+id+'&cantidad'+value,
        cache: false,
        success: function(html){
            document.getElementById('totalresultados').value = html;
          
        }
      });
    }
    function IsNumeric(valor) {
        var log=valor.length;var sw="S";
        for (x=0; x<log; x++)
        {v1=valor.substr(x,1);
        v2 = parseInt(v1);
        //Compruebo si es un valor numérico
        if (isNaN(v2)) {sw= "N";}
        }
        if (sw=="S") {return true;} else {return false;}
    }
    function validarInsertar(oEvento) {
            var iAscii;
            var cantidad = document.getElementById('cantidad').value;
            
            if (oEvento.keyCode)
                iAscii = oEvento.keyCode;
            else if (oEvento.which)
                iAscii = oEvento.which;
            else
                return false;
            if (iAscii == 13){
                if(cantidad != 0 && IsNumeric(cantidad)) {
                    insertarProducto();
                    document.getElementById('cantidad').style.display = "none";
                }
                else {
                    alert('El campo cantidad está vacío o no es un número.');
                }
                //crearUrlBusqueda();
            }
            return true;
    }
    function validarInsertar2() {
            var cantidad = document.getElementById('cantidad').value;
            if(cantidad != 0 && IsNumeric(cantidad)) {
                insertarProducto()
            }
            else {
                alert('El campo cantidad está vacío o no es un número.');
            }
            return true;
    }
    
    function abrirEspecificaciones(id, idproducto, total) {
        /*if(abierto != id && abierto != "") {
            document.getElementById(abierto).style.display = "none";
        }*/
        if (document.getElementById(id).style.display == "none") {
            for(var i=1; i<=total; i++) {
                document.getElementById('especificaciones_'+i).style.display = "none";
                document.getElementById('i_de_info_'+i).style.display = "none";
            }
            $.ajax({
                url: url+'ajax.php?page=pedido-rapido&accion=obtenerespecificaciones&id='+idproducto,
                cache: false,
                success: function(html){
                    document.getElementById(id).innerHTML = html;
                  
                }
              });
            document.getElementById(id).style.display = "block"
        }
        else {
            document.getElementById(id).style.display = "none";
            for(var i=1; i<=total; i++) {
                document.getElementById('i_de_info_'+i).style.display = "block";
            }
            
        }
        /*abierto = id;*/
    }





    function abrirEspecificacionesMotores(id, idproducto, total) {
        /*if(abierto != id && abierto != "") {
            document.getElementById(abierto).style.display = "none";
        }*/
        if (document.getElementById(id).style.display == "none") {
            for(var i=1; i<=total; i++) {
                document.getElementById('especificaciones_'+i).style.display = "none";
                document.getElementById('i_de_info_'+i).style.display = "none";
            }
            $.ajax({
                url: url+'ajax.php?page=pedido-rapido&accion=obtenerespecificacionesMotores&id='+idproducto,
                cache: false,
                success: function(html){
                    document.getElementById(id).innerHTML = html;
                  
                }
              });
            document.getElementById(id).style.display = "block"
        }
        else {
            document.getElementById(id).style.display = "none";
            for(var i=1; i<=total; i++) {
                document.getElementById('i_de_info_'+i).style.display = "block";
            }
            
        }
        /*abierto = id;*/
    }
    
    function abrirPedidoRapido(id) {
        if (document.getElementById('tabla_pedido_'+id).style.display == "none") {
           
            document.getElementById('tabla_pedido_'+id).style.display = "block"
        }
        else {
            document.getElementById('tabla_pedido_'+id).style.display = "none"
            
        }
    }
    
    function abrirCerrarLogin() {
        var loginbox = document.getElementById('loginbox').style.display;
        if (loginbox == "none") {
            document.getElementById('loginbox').style.display = "block";
            document.getElementById('loginarrow').style.display = "block";
            document.getElementById('btn_acceder').className = "btnacceder2";
            document.frm_login.frm_login_name.focus();
        }
        else {
            document.getElementById('loginbox').style.display = "none";
            document.getElementById('loginarrow').style.display = "none";
            document.getElementById('btn_acceder').className = "btnacceder";
            
        }
    }
    
    function toggle(id,id2,focus) {
        if (document.getElementById(id).style.display == "none") {
            document.getElementById(id).style.display = "block";
            document.getElementById(id2).style.display = "none";
        }
        else {
            document.getElementById(id).style.display = "none";
            document.getElementById(id2).style.display = "block";
        }
        if(focus == "1") {
            document.frm_recordar_contrasena.frm_login_name.focus();
        }
        else {
            document.frm_login.frm_login_name.focus();
        }
    }





var _log = function(a){
    if(window.console){
        console.log(a)
    }
}




$(function(){

    /* cerramos los .menu_navegacion cuando hacemos clic en el document */
    $(document).click(function(e){
        if(! $(e.target).hasClass('nombrefamilia'))
            $('.menu_navegacion:visible').hide();
        
            
    });
})
