function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
//alert(iframeWin)
//alert(iframeEl)
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}

function goSetHeight() {
  if (parent == window) {
  	return;
  // arg: id of iframe element this doc is to be loaded into
	} else{
  	//parent.setIframeHeight('ifrm');  	
  	setIframeHeight('ifrm');
  }
}

function abrir_imagen(im,ti,ex,ancho,alto)
{
	while (im.search(" ") != -1)
	{
		im = im.replace(" ", "%20")
	}

	var imagen_aux=new Image();
	imagen_aux.src=im;
	ancho=imagen_aux.width;
	alto=imagen_aux.height;
	imagen=im;
	tituloi=ti;
	extrasi=ex;
	anchoi=ancho;
	altoi=alto;
	masAlto=alto+11;

	features = "width="+ancho+",height="+masAlto;

	if(document.getElementById&&!document.all) //Gecko Browsers
	{
		window.open("../html/ver_imagen.htm",ancho+alto,features+"status=yes,location=yes,resizable=yes");
	}
	else //Internet Explorer
	{
		window.open("../html/ver_imagen.htm",ancho+alto,features);
	}
}
//******************
function mostrar_Pagina(pagina,cod_nivel,num_de_nivel2,num_de_nivel1,viene_de,descrip_nivel1,descrip_nivel2,descrip_nivel3,imagen)
{
	if(pagina!="") // Si el elemento del menu tiene enlace:
	{
		//Si la pagina de enlace es una URL externa, abrimos una ventana flotante:
		if((pagina.indexOf("http")!=-1)||(pagina.indexOf("www")!=-1)||(pagina.indexOf("https")!=-1))
		{
			window.open(pagina,"","resizable=no,scrollbars=yes,status=no,width=800,height=600");
		}
		else
		{
			var titular;
			var pagina;
			var tituloG;

			if (descrip_nivel1 != "" && descrip_nivel2 == "" && descrip_nivel3 == "")
			{
				titular="vacio";
				tituloG=descrip_nivel1;
				//alert(tituloG);
			}
			else
			{
				if (descrip_nivel1 != "" && descrip_nivel2 != "" && descrip_nivel3 == "")
				{
					titular=descrip_nivel1 + " > ";
					tituloG=descrip_nivel2;

				}
				else
				{
					if (descrip_nivel1 != "" && descrip_nivel2 != "" && descrip_nivel3 != "")
					{
						titular=descrip_nivel1 + " > " + descrip_nivel2 + " > ";
						tituloG=descrip_nivel3;

					}
				}
			}	
			//document.form1.titulo.size=titular.length+15;
			//document.form1.titulo.value=titular;
			if((pagina.indexOf("?")!=-1))
			{
				document.location = "../portadanew/inicio.asp?pagina=" + pagina + "&descrip_nivel1="+descrip_nivel1+"&descrip_nivel2="+descrip_nivel2+"&descrip_nivel3="+descrip_nivel3+"&titulo="+titular+"&id="+cod_nivel+"&TituloG="+tituloG+"&Imagen="+imagen;
			}
			else
			{	
				document.location = "../portadanew/inicio.asp?pagina=" + pagina + "&descrip_nivel1="+descrip_nivel1+"&descrip_nivel2="+descrip_nivel2+"&descrip_nivel3="+descrip_nivel3+"&titulo="+titular+"&id="+cod_nivel+"&TituloG="+tituloG+"&Imagen="+imagen;
				
			}
			
			// Desplegamos el menu seleccionado
		}
	}
}

function mostrar_Pagina1(pagina,cod_nivel,num_de_nivel2,num_de_nivel1,viene_de,descrip_nivel1,descrip_nivel2,descrip_nivel3)
{
	if(pagina!="") // Si el elemento del menu tiene enlace:
	{
		//Si la pagina de enlace es una URL externa, abrimos una ventana flotante:
		if((pagina.indexOf("http")!=-1)||(pagina.indexOf("www")!=-1)||(pagina.indexOf("https")!=-1))
		{
			window.open(pagina,"","resizable=no,scrollbars=yes,status=no,width=800,height=600");
		}
		else
		{
			var titular;
			var tituloG;

			if (descrip_nivel1 != "" && descrip_nivel2 == "" && descrip_nivel3 == "")
			{
				titular="vacio";
				tituloG=descrip_nivel1;

			}
			else
			{
				if (descrip_nivel1 != "" && descrip_nivel2 != "" && descrip_nivel3 == "")
				{
					titular=descrip_nivel1 + " > ";
					tituloG=descrip_nivel2;

				}
				else
				{
					if (descrip_nivel1 != "" && descrip_nivel2 != "" && descrip_nivel3 != "")
					{
						titular=descrip_nivel1 + " > " + descrip_nivel2 + " > ";
						tituloG=descrip_nivel3;

					}
				}
			}
			//parent.document.form1.titulo.size=titular.length;
			//parent.document.form1.titulo.value=titular;
			
			if((pagina.indexOf("?")!=-1))
			{
				document.location = "../asp/inicio.asp?pagina=" + pagina + "&descrip_nivel1="+descrip_nivel1+"&descrip_nivel2="+descrip_nivel2+"&descrip_nivel3="+descrip_nivel3+"&titulo="+titular+"&id="+cod_nivel+"&TituloG="+tituloG;
			}
			else
			{
				document.location = "../asp/inicio.asp?pagina=" + pagina + "?descrip_nivel1="+descrip_nivel1+"&descrip_nivel2="+descrip_nivel2+"&descrip_nivel3="+descrip_nivel3+"&titulo="+titular+"&id="+cod_nivel+"&TituloG="+tituloG;
			}
		}
	}
	else
	{
		document.frames[0].document.location = "../blanca.asp";
	}
}

function ver_album_fotos ( url )
{
	window.open ( url, "pdfdocument", "width=773,height=500,top=10,left=10,Xscreen=10,Yscreen=10,scrollbars=yes,resizable=yes");
}

function tam()
{	
	if(screen.width<=800)
	{
	   tam=80;
 	}
}
//nuevo para medidas de accesibilidad
function setActiveStyleSheet(title, reset) {
  var i, a, main;
  
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) 
      {
      	  alert(a.getAttribute("title"));
     	 a.disabled = false;
      }
    }
  }
  
}

function setStyle() {
var style = readCookie("wstyle");
if (style != null) {
setActiveStyleSheet(style, 0);
}
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+escape(value)+expires+"; path=/;";
}


function ActFecha()
{
	var fecha = new Date();
	var horas=fecha.getHours();
	var minutos=fecha.getMinutes();
	var dia = fecha.getDay();
	var mes=fecha.getMonth();
	var ano=fecha.getFullYear();	
	var diaSemana = new Array('domingo', 'lunes', 'martes',
	'miércoles', 'jueves', 'viernes','sábado');
	var diaT=diaSemana[dia];
	
	horas = (horas<=9)?("0"+horas):horas;
	minutos = (minutos<=9)?("0"+minutos):minutos;
	
	dia = (dia<=9)?("0"+dia):dia;
	mes = (mes<=9)?("0"+mes):mes;	
	dato="&nbsp;&nbsp;"+diaT+", "+dia+"/"+mes+"/"+ano+" "+horas+":"+minutos+" h";
	if (document.layers)
	{
		document.layers.reloj.document.write(dato)
		document.layers.reloj.document.close()
	}
	else if (document.all)
		reloj.innerHTML=dato
		else if (document.getElementById)
		document.getElementById("reloj").innerHTML=dato
		setTimeout("ActFecha()",1000)
	
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
  
}

function createCookie(name,value,days) 
{
  if (days) 
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else 
  {
	  expires = "";
  }
  document.cookie = name+"="+value+expires+"; path=/";
}
//***************************
//nuevo 101005
//****************************
function menuOcultacion( nodo ) {
	var submenu = nodo.nextSibling;

	while( submenu ) {
		if( submenu.tagName == 'DIV' ) {
			if( submenu.style.display != 'block' )
			{
				submenu.style.display = 'block';
			}
			else
			{
				submenu.style.display = 'none';
			}
			cambiaImagen( nodo );
			return( true );
		}else if ( submenu.tagName == 'A') {
			return( false );
		}
		submenu = submenu.nextSibling;
	}

	return false;
}

function cambiaImagen( nodo ) {
	var imgs = nodo.getElementsByTagName( 'img' );
	if( imgs.length ) {
		if( imgs[ 0 ].src.indexOf( 'icono_mas.gif' ) != -1  ) {
			imgs[ 0].src = '../../imagenes/icono_menos.gif';
		}
		else {
			if( imgs[ 0 ].src.indexOf( 'icono_menos.gif' ) != -1 ) {
				imgs[ 0 ].src = '../../imagenes/icono_mas.gif';
			}	
		}
	}
}
/*********************************************************************************************
	Funciones para parsear el menu y buscar las opciones de primer nivel que tienen submenus 
	y anadirles el manejador del onclick
**********************************************************************************************/
function MENUparser( id_contenedor, id_opcion_actual ) {
	var lista = document.getElementById( id_contenedor ).getElementsByTagName( 'a' );
	for( i = 0; i < lista.length; i++ ) {
		var a = lista[ i ];
		//alert("a "+a.id+" "+id_opcion_actual);
		if( a.id == id_opcion_actual ) {
			dato=a.id;
			//alert(dato);
			if (dato.indexOf("i")!=-1)
			{
				MENUmostrar( a, id_contenedor );
			}
			else
			{	
				SUBMENUmostrar( a, id_contenedor );
			}
			return( true );
		}
	}
	return( false );
}


/*function MENU*/
function MENUmostrar( nodo, id_contenedor ) {
/*alert (nodo);
	alert (id_contenedor);	
	var padre = nodo.parentNode;
	while( padre ) {		
		if( padre.tagName == 'DIV' ) {
			if( padre.id == id_contenedor ) {
				return( true );
			}
			padre.style.display = 'block';
			padre = padre.parentNode;
		}
	}
*/
	var submenu = nodo.nextSibling;
	while( submenu ) {	
		if( submenu.tagName == 'DIV' ) {			
			submenu.style.display = 'block';
			return( true );
		}
		else {
			if( submenu.tagName == 'A' ) {
				return( false );
			}
		}
		submenu = submenu.nextSibling;
	}
}
function SUBMENUmostrar( nodo, id_contenedor ) {
	var padre = nodo.parentNode;
	while( padre ) {		
		if( padre.tagName == 'DIV' ) {
			if( padre.id == id_contenedor ) {
				return( true );
			}
			padre.style.display = 'block';
			padre = padre.parentNode;
		}
	}
}

function Cambiar(nodo)
{
	var tamnodo=document.styleSheets.length;
	if (nodo==0)
	{		
		document.styleSheets[0].href="../../../../estilos/00000/global1.css";
		document.styleSheets[1].href="../../../../estilos/00000/menu.css";				
		if (tamnodo>2) {
		document.styleSheets[2].href="../../../../estilos/00000/estilo_feht.css";		
		}
		
	}
	else if (nodo==1)
	{
		document.styleSheets[0].href="../../../../estilos/00000/global2.css";
		document.styleSheets[1].href="../../../../estilos/00000/menu1.css";	
		if (tamnodo>2) {
	  		document.styleSheets[2].href="../../../../estilos/00000/estilo_feht1.css";		
	  	}
	}
	else if (nodo==2)
	{
		document.styleSheets[0].href="../../../../estilos/00000/global3.css";
		document.styleSheets[1].href="../../../../estilos/00000/menu2.css";
		if (tamnodo>2) {
			document.styleSheets[2].href="../../../../estilos/00000/estilo_feht2.css";
		}		
		
	}
	else 
	{
		document.styleSheets[0].href="../../../../estilos/00000/global1.css";
		document.styleSheets[1].href="../../../../estilos/00000/menu.css";	
		if (tamnodo>2) {
			document.styleSheets[2].href="../../../../estilo_feht.css";
		}	
		nodo=0;		
	}

	createCookie("nodo", nodo, 365);
/*	var cookie = readCookie("nodo");
	alert(cookie);*/
}

function enfocar ( id )
{
	// Almacenamos el id del menu seleccionado en una cookie
	setCookie ( "idMenuDesplegado", id );
}

//-------------------------------------------------------------------------------------
//	Uso de cookies
//-------------------------------------------------------------------------------------
function getCookieVal ( offset )
{
	var endstr = document.cookie.indexOf ( ";", offset );
	
	if ( endstr == -1 ) endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie ( name )
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while ( i < clen )
	{
		var j = i + alen;
		if ( document.cookie.substring(i, j) == arg )
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
	
		if ( i == 0 ) break;
	}

	return null;
}

function setCookie ( name, value )
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}
function ampliarImagen ( im )
			{
				var imagen_aux = new Image();
				imagen_aux.src = im;
				ancho = imagen_aux.width;
				alto = imagen_aux.height;
				imagen = im;
				anchoi = ancho;
				altoi = alto;
				if ( anchoi > 800 || altoi > 600 )
				{
					var rx = 800 / anchoi;
					var ry = 600 / altoi;
					if ( rx > ry || rx == ry )
					{
						anchoi = ry * anchoi;
						altoi = 600;
					}
					else
					{
						anchoi = 800;
						altoi = rx * alto;
					}
				}
	
				// Añadimos los márgenes
				anchow = anchoi + 50;
				altow = altoi + 55;
	
				// Centramos la pantalla
				var x = 200;
				var y = 100;				
	
				if ( screen.width != "" || screen.width != null || screen.height != "" || screen.height != null )
				{
					x = ( screen.width - anchow ) / 2;
					y = ( screen.height - altow ) / 2 - 25;
				}
	
				window.open ( "../../html/ampliarImagen.htm", "", "left=" + x + ",top=" + y + ",toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + anchow + ",height=" + altow );
}
/*
function DisplayInfo()
{
	var expdate = new Date();
	var visit;
	
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
	
	if ( ! ( visit = GetCookie ( "visit" ) ) ) visit = 0;
	
	visit++;
	
	SetCookie("visit", visit, expdate, "/", null, false);
	
	var message;
	
	if(visit == 1) message=" Bienvenido a la página de HTMLpoint";
	if(visit == 2) message=" Ejemplo de Massimiliano Valente";
	if(visit == 3) message=" Visita el sitio Web de HTMLpoint";
	if(visit == 4) message=" Visita www.htmlpoint.com"; 
	if(visit == 5) message=" Aquí puedes incluir un mensaje a tu gusto";
	if(visit == 6) message=" Aquí puedes añadir otro mensaje";

	alert("\n"+"Has visitado esta página\n"+""+visit+" "+"volte."+"\n"+"\n"+message);
}

function ResetCounts()
{
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
	visit = 0;
	SetCookie("visit", visit, expdate , "/", null, false);
	leapto();
}
*/
