function mostrar(id){
  document.getElementById(id).style.display="inline-block";
}
function ocultar(id){
  document.getElementById(id).style.display="none";
}
function info(id) {
  var display = document.getElementById(id).style.display;
  if (display == '' || display == 'none') {
    mostrar(id);
  } else {
    ocultar(id);
  }
}

function intercambia(id){
  if(document.getElementById(id).style.display=="block"){
    document.getElementById(id).style.display="none";
  }else{
    document.getElementById(id).style.display="block";
  }
}

function codifica(id,id2){
  var input = document.getElementById(id);
  var texto=escape(input.value);
  document.getElementById(id2).value = texto;
}

function enviar(id){
  document.getElementById(id).submit();
}


function cargarPaginaPrincipal(divOrigen,divDestino) {
  var origen = document.getElementById(divOrigen);
  var destino = document.getElementById(divDestino);
  destino.innerHTML = origen.innerHTML;
  origen.innerHTML = "";
}

/**
 * Oculta el reloj de espera y hace visible la precarga
 */
function precarga(divReloj, divParrilla) {
  var par = document.getElementById(divParrilla);
  var reloj = document.getElementById(divReloj);
  reloj.style.position = "absolute";
  reloj.style.visibility = "hidden";
  par.style.visibility = "visible";
}

/**
 * Oculta el reloj de espera y hace visible la precarga
 */
function precarga2(divReloj, divParrilla) {
  if(document.getElementById(divParrilla)!=null){
    document.getElementById(divParrilla).style.display = "block";
    document.getElementById(divReloj).style.display = "none";
  }
}

/**
 * Oculta la parrilla y hace visible el reloj
 */
function inv_precarga(divReloj, divParrilla) {
  var par = document.getElementById(divParrilla);
  var reloj = document.getElementById(divReloj);
  par.style.position = "absolute";
  par.style.visibility = "hidden";
  reloj.style.position = "relative";
  reloj.style.visibility = "visible";
}

/**
 * Oculta la parrilla y hace visible el reloj
 */
function inv_precarga2(divReloj, divParrilla) {
  if(document.getElementById(divParrilla)!=null){
    document.getElementById(divParrilla).style.display = "none";
    document.getElementById(divReloj).style.display = "block";
  }
}

/**
 * Cambia la imagen de "No hay imagen disponible" por la imagen que se ha buscado del programa, si existe esta última
 */
function cambiarImagenes(img1, img2) {
  var i = document.getElementById("noticia1");
  i.setAttribute("src", img1);
  var j = document.getElementById("noticia2");
  j.setAttribute("src", img2);
}

/**
 * Pone el reloj en el div recibido
 */
function ponerReloj(div) {
  if(document.getElementById(div)!=null){
    document.getElementById(div).innerHTML = '<div class="relojIdentificado centrado"><img align="middle" alt="cargando" src="resources/loader2.gif"/></div>'
  }else{
    alert("No existe la capa");
  }
}

/**
 * Cambia la imagen del div recibido , utilizando la ruta recibida
 */
function cambiarImagen(div, ruta) {
    if(document.getElementById(div)!=null){
        document.getElementById(div).setAttribute("src", ruta);
    }
}

function seleccionar(id){
  var lista=document.getElementById(id).value;
  var listaID=lista.split(";");
  for(i=0; i<listaID.length-1; i++){
    document.getElementById(listaID[i]).checked=true;
  }
    
}

function desseleccionar(id){
  var lista=document.getElementById(id).value;
  var listaID=lista.split(";");
  for(i=0; i<listaID.length-1; i++){
    document.getElementById(listaID[i]).checked=false;
  }
}



function opacidad (elemento_id, opacidadInicio, opacidadFin, milisegundos) {
  var velocidad = Math.round (milisegundos / 100);
  var tiempo = 0;
  if (opacidadInicio > opacidadFin) {
    for (i = opacidadInicio; i >= opacidadFin; i--) {
      setTimeout ("cambiarOpacidad (" + i + ", '" + elemento_id + "')", (tiempo * velocidad));
      tiempo++;
    }
  }else if (opacidadInicio < opacidadFin) {
    for (i = opacidadInicio; i <= opacidadFin; i++) {
      setTimeout ("cambiarOpacidad (" + i + ", '" + elemento_id + "')", (tiempo * velocidad));
      tiempo++;
    }
  }
}

function cambiarOpacidad (opacidad, elemento_id) {
  var elemento = document.getElementById(elemento_id).style;
  elemento.filter = "alpha (opacity=" + opacidad + ")"; // Internet Explorer
  elemento.opacity = (opacidad / 100); // Mozilla y Safari
  elemento.MozOpacity = (opacidad / 100);
  elemento.KhtmlOpacity = (opacidad / 100); // Konqueror
}

function crearCapa(myurl){
  detenerVideo();
  document.getElementById("iframeDatos").src=myurl;
  document.getElementById("overlay").style.display="block";
  document.getElementById("mensaje").style.display="block";
  opacidad('overlay',0,70,300);
  setTimeout("opacidad('mensaje',0,100,300)",400);
     
}

function eliminarCapa(){ 
  opacidad('mensaje',100,0,200);
  setTimeout("opacidad('overlay',70,0,200)",300);
  setTimeout('document.getElementById("mensaje").style.display="none"',600);
  setTimeout('document.getElementById("overlay").style.display="none"',600);
  activarVideo();
}

function detenerVideo() {
  if(document.getElementById("pastilla_video")!=null){
    document.getElementById("pastilla_video").style.visibility="hidden";
  }
}

function activarVideo() {
  if(document.getElementById("pastilla_video")!=null){
    document.getElementById("pastilla_video").style.visibility="visible";
  }
}
