function abrir_img(imagen,title,copy,width,height,data1,data2,data3,extrahor,extraver) {
abrir_img_modelo(imagen,title,copy,width,height,data1,data2,data3,extrahor,extraver,"../../../../../../foto.htm");
}

function abrir_img_modelo(imagen,title,copy,width,height,data1,data2,data3,extrahor,extraver,modelo) {

// variables

var dimensiones;
var propiedades;
var win=null;

// Asignamos los parámetros a variables
	source=imagen;
	cabecera=title;
	copyright=copy;
	hor=width;
	ver=height;
        superior=data1;
        desc=data2;
        inferior=data3;
        totalwidth=width+45+extrahor;
	totalheight=height+182+extraver;

        dimensiones="width="+totalwidth+",height="+totalheight;
	propiedades="resizable,scrollbars,menubar=no,location=no,"+dimensiones;

var pos=imagen.lastIndexOf("/");
var nombre=imagen.substring(pos+1);
pos=nombre.indexOf(".");
nombre=nombre.substring(0,pos);

// Localiza la ventana
        win=window.open("",nombre,dimensiones); 

        if (win) {
          win.close ();
       }
window.open(modelo,nombre,propiedades);  
}

function nocheckforframe () {
	var passed    = self.location.search ? unescape(location.search.substring(1)) : '';

while (passed) {
  var posnextoption = passed.indexOf('&');
  if (posnextoption != -1) {
    var opcion = passed.substring(0, posnextoption);
    passed = passed.substring(posnextoption+1);
  } else {
    var opcion = passed;
    passed = null;
  }
  if (opcion == 'nocheckforframe') return true;
}
return false;
}

function viewlink() {
var document_name = self.location.pathname;
if (self.location.pathname.lastIndexOf('/') != -1) document_name = self.location.pathname.substring(self.location.pathname.lastIndexOf('/') + 1, self.location.pathname.length);
  if (nocheckforframe()) {
     document.write("<td><a href='" + document_name + "'>Contexto</a></td>");
  } else {
    document.write("<td><a href='" + document_name + "?nocheckforframe' target='_top'>Pantalla</a></td>");
  };
}


function linkpage(url, texto) {
  if (nocheckforframe()) {
     document.write("<a href='" + url + "?nocheckforframe'>"+texto+"</a>");
  } else {
    document.write("<a href='" + url + "'>"+texto+"</a>");
  };
}

function linkpagetarget(url, texto,target) {
  if (nocheckforframe()) {
  // La URL vendrá en forma 
  // {../}Taxon1/taxon1.htm?{Taxon&}Taxon2[&taxon] y la debemos convertir a 
  // {../}Taxon1/{Taxon/}(Taxon2/Inic.Taxon2_taxon.htm | Taxon2/taxon2.htm)?nocheckforframe
     var pos_interrogacion=url.indexOf("?",1);
	 
 	 if (pos_interrogacion != -1) {
	   // si no hay interrogación, lo dejamos todo sin tocar
	   // pero si la hay, buscamos la / anterior para eliminar luego esa parte
	   var pos_barra=url.lastIndexOf('/',pos_interrogacion);
	   if (pos_barra == -1) {
	     url = url.substring(pos_interrogacion + 1);
	   } else {
	     url = url.substring(0,pos_barra+1)+url.substring(pos_interrogacion+1);
	   }
	   // Ahora sustituimos todos los & por / guardando en niveles_abajo el número de sustituciones (+1)
	   var url2=url;
	   var niveles_abajo=1;
	   while (url2.indexOf("&") != -1) {
	    niveles_abajo++;
	    url2 = url2.replace("&","/");
		}
	    // Ahora miramos si llega a especie, viendo si el carácter después de la última / es minúsculas
	   pos_barra = url2.lastIndexOf("/",url2.Length);
	   // Si no quedan barras o acaba en /, dejamos la URL tal cual
	   if (pos_barra < 1 || pos_barra==url2.Length) {
	     url=url2;
	   } else {
	     // obtenemos el siguiente carácter y vemos si está en minúsculas
	     inic_ultima = url2.charAt(pos_barra+1);
		 if (inic_ultima == inic_ultima.toLowerCase()) {
		   // Llega a especie. Por tanto el formato de salida es ...G_especie.htm
    		 // Obtenemos el penúltimo taxon
	    	 var penultimo;
	         var pos_barra2 = url2.lastIndexOf("/",pos_barra - 1);
    		 if (pos_barra2 == -1) {
			   penultimo=url2.substring(0,pos_barra);
		     } else {
			   penultimo=url2.substring(pos_barra2+1,pos_barra);
		     }
             url = url2.substring(0,pos_barra+1)+penultimo.substring(0,1).toUpperCase()+"_"+url2.substring(pos_barra+1)+".htm";
		 } else {
		   // No llega a especie. Por tanto, el formato de salida es ...Taxon/ + htm de descripción
		   // si es un género debería servir especies_desc.htm, si es una familia, generos_desc.htm, y así sucesivamente.
		   
		   switch (target) {
		   case 'fr_genero': nivel=1; break;
		   case 'fr_familia': nivel=2; break;
		   case 'fr_orden': nivel=3; break;
		   case 'fr_clase': nivel=4; break;
		   case 'fr_tipo': nivel=5; break;
		   case 'fr_reino': nivel = 6; break;
		   default: nivel=0; 
		  }
		  nivel-=niveles_abajo;
          switch (nivel) {
		  case 1: final='especies'; break;
		  case 2: final='generos'; break;
		  case 3: final='familias'; break;
		  case 4: final='ordenes'; break;
		  case 5: final='clases'; break;
		  case 6: final='tipos'; break;
			  }
		   url = url2+"/"+final+"_desc.htm";
		 }
	   }
	 }
     document.write("<a href='" + url + "?nocheckforframe'>"+texto+"</a>");
  } else {
    document.write("<a href='" + url + "' target='"+target+"'>"+texto+"</a>");
  };
}

function check_especie(binomial) {
var pos_espacio=binomial.indexOf(' ');
var genero=binomial.substring(0,pos_espacio);
genero=genero.toLowerCase();
var especie=binomial.substring(pos_espacio+1);

    if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0) || nocheckforframe()) return;
    if ((top == self) || ((document.images) ? (parent.especie ? false : true) : (parent.frames[0].name != 'especie'))) {
    var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/'+genero+'.htm?'+especie+ ((self.location.search) ? self.location.search : '');
    if (document.images) document.location.replace(newURL);
    else document.location.href = newURL;
    }
}

function check_genero(genero) {
genero=genero.toLowerCase();

    if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0) || nocheckforframe()) return;
    if ((top == self) || ((document.images) ? (parent.especie ? false : true) : (parent.frames[0].name != 'especie'))) {
    var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/'+genero+'.htm' + ((self.location.search) ? self.location.search : '');
    if (document.images) document.location.replace(newURL);
    else document.location.href = newURL;
    }
}

function check_genero_familia(genero, familia) {
familia=familia.toLowerCase();
    
if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;    
  if ((top == self) || (top == parent) || ((document.images) ? (parent.parent.genero ? false : true) : (parent.parent.frames[0] != 'genero'))) {
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/../'+familia+'.htm?'+genero+ ((self.location.search) ? '&'+self.location.search.substring(1)  : '');
       if ((top == self) || (top == parent)) {
           if (document.images) top.location.replace(newURL);        
	   else top.location.href = newURL;    
	} else {
	   if (document.images) parent.location.replace(newURL);        
	   else parent.location.href = newURL;    
	}
  }
}

function frames_genero(genero) {
inicial=genero.charAt(0);

var passed     = location.search ? unescape(location.search.substring(1)) + '&' : '';
if (passed) {
    first  = passed.substring(0,passed.indexOf('&'));
    passed = passed.substring(passed.indexOf('&')+1);
    second = passed.substring(0,passed.indexOf('&'));
    passed = passed.substring(0,passed.length-1);
    pagina = inicial+'_' + first.toLowerCase() + '.htm';
    pagina = pagina + (second ? '#' + second : '') + (passed ? '?' + escape(passed) : '');
} else 
    pagina = 'especies_desc.htm';
 
    document.write('<frameset cols="100,*" border="1">');
    document.write('	<frame name="especie" src="especies.htm' + (location.search ? location.search : '') +'" frameborder="0" scrolling="auto">');
    document.write('	<frame name="fr_especie" src="' + pagina + '" frameborder="0">');
    document.write('</frameset>');
}

function check_familia(familia) {
familia=familia.toLowerCase();

    if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0) || nocheckforframe()) return;
    if ((top == self) || (top == parent) || ((document.images) ? (parent.genero ? false : true) : (parent.frames[0].name != 'genero'))) {
    var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/'+familia+'.htm' + ((self.location.search) ? self.location.search : '');
    if (document.images) document.location.replace(newURL);
    else document.location.href = newURL;
    }
}

function check_familia_orden(familia, orden) {
orden=orden.toLowerCase();
    
if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;    
  if ((top == self) || (top == parent) || ((document.images) ? (parent.parent.familia ? false : true) : (parent.parent.frames[0] != 'familia'))) {
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/../'+orden+'.htm?'+familia+ ((self.location.search) ? '&'+self.location.search.substring(1)  : '');
       if ((top == self) || (top == parent)) {
           if (document.images) top.location.replace(newURL);        
	   else top.location.href = newURL;    
	} else {
	   if (document.images) parent.location.replace(newURL);        
	   else parent.location.href = newURL;    
	}
  }
}

function frames_familia() {
var passed     = location.search ? unescape(location.search.substring(1)) + '&' : '';
if (passed) {
    first  = passed.substring(0,passed.indexOf('&'));
    passed = passed.substring(passed.indexOf('&')+1);
    passed = passed.substring(0,passed.length-1);
    pagina = first + '/' + first.toLowerCase() + '.htm';
    pagina = pagina + (passed ? '?' + escape(passed) : '');
} else 
    pagina = 'generos_desc.htm';
 
    document.write('<frameset cols="100,*" border="1">');
    document.write('	<frame name="genero" src="generos.htm' + (location.search ? location.search : '') +'" frameborder="0" scrolling="auto">');
    document.write('	<frame name="fr_genero" src="' + pagina + '" frameborder="0">');
    document.write('</frameset>');
}

function check_orden(orden) {
orden=orden.toLowerCase();

    if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0) || nocheckforframe()) return;
    if ((top == self) || (top == parent) || ((document.images) ? (parent.familia ? false : true) : (parent.frames[0].name != 'familia'))) {
    var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/'+orden+'.htm' + ((self.location.search) ? self.location.search : '');
    if (document.images) document.location.replace(newURL);
    else document.location.href = newURL;
    }
}

function check_orden_clase(orden, clase) {
clase=clase.toLowerCase();
    
if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;    
  if ((top == self) || (top == parent) || ((document.images) ? (parent.parent.orden ? false : true) : (parent.parent.frames[0] != 'orden'))) {
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/../'+clase+'.htm?'+orden+ ((self.location.search) ? '&'+self.location.search.substring(1)  : '');
       if ((top == self) || (top == parent)) {
           if (document.images) top.location.replace(newURL);        
	   else top.location.href = newURL;    
	} else {
	   if (document.images) parent.location.replace(newURL);        
	   else parent.location.href = newURL;    
	}
  }
}

function frames_orden() {
var passed     = location.search ? unescape(location.search.substring(1)) + '&' : '';
if (passed) {
    first  = passed.substring(0,passed.indexOf('&'));
    passed = passed.substring(passed.indexOf('&')+1);
    passed = passed.substring(0,passed.length-1);
    pagina = first + '/' + first.toLowerCase() + '.htm';
    pagina = pagina + (passed ? '?' + escape(passed) : '');
} else 
    pagina = 'familias_desc.htm';
 
    document.write('<frameset cols="100,*" border="1">');
    document.write('	<frame name="familia" src="familias.htm' + (location.search ? location.search : '') +'" frameborder="0" scrolling="auto">');
    document.write('	<frame name="fr_familia" src="' + pagina + '" frameborder="0">');
    document.write('</frameset>');
}

function check_clase(clase) {
clase=clase.toLowerCase();

    if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0) || nocheckforframe()) return;
    if ((top == self) || (top == parent) || ((document.images) ? (parent.orden ? false : true) : (parent.frames[0].name != 'orden'))) {
    var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/'+clase+'.htm' + ((self.location.search) ? self.location.search : '');
    if (document.images) document.location.replace(newURL);
    else document.location.href = newURL;
    }
}

function frames_clase()  {
var passed     = location.search ? unescape(location.search.substring(1)) + '&' : '';
if (passed) {
    first  = passed.substring(0,passed.indexOf('&'));
    passed = passed.substring(passed.indexOf('&')+1);
    passed = passed.substring(0,passed.length-1);
    pagina = first + '/' + first.toLowerCase() + '.htm';
    pagina = pagina + (passed ? '?' + escape(passed) : '');
} else 
    pagina = 'ordenes_desc.htm';
 

    document.write('<frameset cols="100,*" border="1">');
    document.write('	<frame name="orden" src="ordenes.htm' + (location.search ? location.search : '') +'" frameborder="0" scrolling="auto">');
    document.write('	<frame name="fr_orden" src="' + pagina + '" frameborder="0">');
    document.write('</frameset>');
}

function check_clase_tipo(clase, tipo) {
tipo=tipo.toLowerCase();
    
if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;    
  if ((top == self) || (top == parent) || ((document.images) ? (parent.parent.clase ? false : true) : (parent.parent.frames[0] != 'clase'))) {
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/../'+tipo+'.htm?'+clase+ ((self.location.search) ? '&'+self.location.search.substring(1)  : '');
       if ((top == self) || (top == parent)) {
           if (document.images) top.location.replace(newURL);        
	   else top.location.href = newURL;    
	} else {
	   if (document.images) parent.location.replace(newURL);        
	   else parent.location.href = newURL;    
	}
  }
}

function check_tipo(tipo) {
tipo=tipo.toLowerCase();

    if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0) || nocheckforframe()) return;
    if ((top == self) || (top == parent) || ((document.images) ? (parent.clase ? false : true) : (parent.frames[0].name != 'clase'))) {
    var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/'+tipo+'.htm' + ((self.location.search) ? self.location.search : '');
    if (document.images) document.location.replace(newURL);
    else document.location.href = newURL;
    }
}

function check_tipo_reino(tipo, reino) {
reino=reino.toLowerCase();
    
if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;    
  if ((top == self) || (top == parent) || ((document.images) ? (parent.parent.tipo ? false : true) : (parent.parent.frames[0] != 'tipo'))) {
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/../'+reino+'.htm?'+tipo+ ((self.location.search) ? '&'+self.location.search.substring(1)  : '');
       if ((top == self) || (top == parent)) {
           if (document.images) top.location.replace(newURL);        
	   else top.location.href = newURL;    
	} else {
	   if (document.images) parent.location.replace(newURL);        
	   else parent.location.href = newURL;    
	}
  }
}

function frames_tipo() {
var passed     = location.search ? unescape(location.search.substring(1)) + '&' : '';
if (passed) {
    first  = passed.substring(0,passed.indexOf('&'));
    passed = passed.substring(passed.indexOf('&')+1);
    passed = passed.substring(0,passed.length-1);
    pagina = first + '/' + first.toLowerCase() + '.htm';
    pagina = pagina + (passed ? '?' + escape(passed) : '');
} else 
    pagina = 'clases_desc.htm';
 

    document.write('<frameset cols="100,*" border="1">');
    document.write('	<frame name="clase" src="clases.htm' + (location.search ? location.search : '') +'" frameborder="0" scrolling="auto">');
    document.write('	<frame name="fr_clase" src="' + pagina + '" frameborder="0">');
    document.write('</frameset>');
}

function check_reino(reino) {
reino=reino.toLowerCase();

    if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;
    if ((top == self) || (top == parent) || ((document.images) ? (parent.tipo ? false : true) : (parent.frames[0].name != 'tipo'))) {
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/'+reino+'.htm' + ((self.location.search) ? self.location.search : '');
        if (document.images) parent.location.replace(newURL);
        else parent.location.href = newURL;
    }
}

function check_reino_raiz(reino, superior) {
superior=superior.toLowerCase();
    
if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;    
  if ((top == self) || (top == parent) || ((document.images) ? (parent.parent.reinos ? false : true) : (parent.parent.frames[0] != 'reinos'))) {
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) + '/../'+superior+'.htm?'+reino+ ((self.location.search) ? '&' + self.location.search.substring(1) : '');
        if ((top == self) || (top == parent)) {
	   if (document.images) top.location.replace(newURL);        
	   else top.location.href = newURL;    
	} else {
	  if (document.images) parent.location.replace(newURL);        
	  else parent.location.href = newURL;    
	}
  }
}

function frames_reino() {
var passed_orig     = location.search;
passed = (passed_orig)  ? unescape(passed_orig.substring(1)) + '&' : '';
if (passed) {
    first  = passed.substring(0,passed.indexOf('&'));
    passed = passed.substring(passed.indexOf('&')+1);
    passed = passed.substring(0,passed.length-1);
    pagina2 = first + '/' + first.toLowerCase() + '.htm';
    pagina2 = pagina2 + (passed ? '?' + escape(passed) : '');
    pagina = 'tipos.htm' + (passed_orig ? '?'+ passed_orig.substring(1) : '');
} else {
    pagina = 'tipos.htm';
    pagina2 = 'tipos_desc.htm';
}
 
    document.write('<frameset cols="115,*" border="1">');
    document.write('	<frame name="tipo" src="' + pagina + '" frameborder="0" scrolling="auto">');
    document.write('	<frame name="fr_tipo" src="' + pagina2 + '" frameborder="0">');
    document.write('</frameset>');
}

function musica(fichero,volumen) {
document.write('<embed id="SONIDO" type="music" src="'+fichero+'" volume="'+volumen+'" width="0" height="0">');
}
