// 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);
    }
  }
}
function crearAjax()
{
    var xmlhttp=false;
     try
    {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try
        {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (E)
        {
               xmlhttp = false;
          }
     }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined')
    {
          xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function Contenido(pag)
{
	
    var contenedor;
    contenedor = document.getElementById('popupM02');
    
    // creamos un nuevo objeto ajax
    ajax=crearAjax();

    //cargar el archivo html por el método GET
    ajax.open("GET", pag,true);
  
    ajax.onreadystatechange=function()
    {
        if (ajax.readyState==4) // Readystate 4 significa que ya acabó de cargarlo
        {
            contenedor.innerHTML = ajax.responseText;
		//	alert(ajax.responseText);
        }
    }
    ajax.send(null)
}

function carga_prueba(id, idioma)
{
	//alert("http://localhost/darwin/wp-content/themes/darwin4/lista.php?id="+id+idioma);
	Contenido("http://www.misterdarwin.eu/wp-content/themes/darwin4/lista.php?id="+id+idioma);
}

function carga_prueba2(id, idioma)
{
	Contenido("http://www.misterdarwin.eu/wp-content/themes/darwin4/lista.php?id="+id+"&lang="+idioma+"&texto="+document.comentar.texto.value+"&nombre="+document.comentar.nombre.value+"&mail="+document.comentar.mail.value);
}
function carga_prueba3(id, idioma)
{
	Contenido("http://www.misterdarwin.eu/wp-content/themes/darwin4/lista.php?id="+id+"&lang="+idioma+"&anhadir=1");
}
function carga_prueba4(id, idioma, ids, numero)
{
	//alert("http://localhost/darwin/wp-content/themes/darwin4/lista.php?id="+id+"&lang="+idioma+"&individual="+ids+"&numero="+numero);
	Contenido("http://www.misterdarwin.eu/wp-content/themes/darwin4/lista.php?id="+id+"&lang="+idioma+"&individual="+ids+"&numero="+numero);
}

var oAlert = alert;
function alert(txt, title) {
    try {
        jAlert(txt, title);
    } catch (e) {
        oAlert(txt);
    }
}
//confirm()
var oConfirm = confirm;
function confirm(txt, title, func) {
    try {
        jConfirm(txt, title, func);
    } catch (e) {
        if (oConfirm (txt, title)) func();
    }
}
//prompt()
var oPrompt = prompt;
function prompt(txt, input, title, func){
    try {
        jPrompt(txt, input, title, func);
    } catch(e) {
        func(prompt(txt, input, title));
    }
}

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;
}
function validar()
{
	var msg="Se ha producido un error al dar de alta, fallan los siguientes campos:" + "\n\n";
	var enviar=true;
	if(document.comentar.nombre.value.length==0) 
	{
		enviar=false;
		msg = msg + "   -El nombre es obligatorio"  + "\n";
	}
	if(document.comentar.texto.value.length==0) 
	{
		enviar=false;
		msg = msg + "   -El comentario es obligatorio" + "\n";
	}
	if(document.comentar.mail.value.length==0)
	{
		enviar=false;
		msg = msg + "    -La direccion de email es obligatoria" + "\n";
	}
	else
	{
		if(mail(document.comentar.mail.value)==false)
		{
			enviar=false;
			msg = msg + "Mail incorrecto" + "\n";
		}
	}
	if(enviar==false)
	{
		alert(msg);
		return(false);
	}
	else
	{
		return(true);
	}
}
