// Muestra oculta elementos html
function muestraoculta(id,cambioclase,etiquetaclase,clase) {
  if(document.getElementById(id).style.display=='none') {
    document.getElementById(id).style.display='block';
    if(cambioclase==1) document.getElementById(etiquetaclase).className = clase;
  } else {
    document.getElementById(id).style.display='none';
    if(cambioclase==1) document.getElementById(etiquetaclase).className = '';
  }
}

// Ocultar elemento
function ocultarElemento(id) {
  document.getElementById(id).style.display='none';
}

// Muestra/Oculta elementos de una serie
function mostrarElementoOcultarSerie(nombreserie,id,tot){
  for(i=1;i<=tot;i++){
    if(i==id) document.getElementById(nombreserie+""+id).style.display='block';
      else document.getElementById(nombreserie+""+i).style.display='none';
  }
}

// Ocultar todos los elementos de una serie
function ocultarMostrarElementosSerie(nombreserie,tot,mostrar){
  if(mostrar==1){
    for(i=1;i<=tot;i++){
      document.getElementById(nombreserie+""+i).style.display='block';
    }
  } else if(mostrar==0) {
    for(i=1;i<=tot;i++){
      document.getElementById(nombreserie+""+i).style.display='none';
    }
  }
}

// Establecer atributo a una etiqueta dada.
function cambiarAtributoEtiqueta(id,att,valor){
  document.getElementById(id).setAttribute(att,valor);
}

// Anhadir clase etiqueta html
function anhadirclaseetiqueta(id,clase) {
  document.getElementById(id).className = clase;
}

// Eliminar clase etiqueta html
function eliminarclaseetiqueta(id) {
  document.getElementById(id).className = '';
}

//Anhadir o modificar la clase de la pestanha
function anhadirclasepestanha(nombreserie,id,tot,clase,pordefecto){
  for(i=1;i<=tot;i++){
    if(i==id){
      eliminarclaseetiqueta(nombreserie+""+id);
      anhadirclaseetiqueta(nombreserie+""+id,clase);
    } else {
      eliminarclaseetiqueta(nombreserie+""+i);
      anhadirclaseetiqueta(nombreserie+""+i,pordefecto);
    }
  }
}

// Validar mail
function mail(texto){

  var mailres = true;            
  var cadena = "abcdefghijklmn?opqrstuvwxyzABCDEFGHIJKLMN?OPQRSTUVWXYZ1234567890@._-";
  
  var arroba = texto.indexOf("@",0);
  if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
  
  var punto = texto.lastIndexOf(".");
  
  for (var contador = 0 ; contador < texto.length ; contador++) {
    if (cadena.indexOf(texto.substr(contador, 1),0) == -1) {
      mailres = false;
      break;
    }
  }

  if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
   mailres = true;
  else
   mailres = false;
  
  return(mailres);
}
