function over(img,ruta) {
  img.src=ruta;
}
function out(img,ruta) {
  img.src=ruta;
}

var ocultar="";
//alert(ocultar);
	
function cambiaEstado(iden) {
	var este = document.getElementById(iden);
				
	//if (ocultar != este && ocultar != "") {
		if (este.style.display == 'block') {
		  este.style.display = 'none';
		} else {
		  este.style.display = 'block';
		}
		if (ocultar!= "" && este!=ocultar) {
		  ocultar.style.display = 'none';
		}
		ocultar=document.getElementById(iden);				
	//}
	//parent.resizeIframe("cont",0);
}

function hoy_tipo1(){
	fecha = new Date();
	mes = fecha.getMonth();
	diaMes = fecha.getDate();
	anio = fecha.getFullYear();
	dia = fecha.getDay();
	dias = new Array('Domingo','Lunes','Martes','Miercoles','Jueves','Viernes','Sábado');
	meses = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
    document.write (diaMes + " de " + meses[mes] + " de " + anio);
}
function validar(campo) {
    formulario=eval("document.forms[0].elements[campo]");  //llamando solicitud al formulario con el parámetro name
	//alert(document.datos.elements[campo].name);
    if (formulario.value == "" || formulario.value == "nada") {
		alert ("No puede dejar el campo ''"+formulario.name+"'' vacío");
		formulario.focus(); 
		//alert(formulario.value);
		return false;
    } else {
        return true;
    }
  }

// VALIDACION DE FECHAS
// definimos las varables globales que van a contener la fecha completa, cada una de sus partes
// y los dias correspondientes al mes de febrero segun sea el año bisiesto o no
var a, mes, dia, anyo, febrero;
// funcion para comprobar si una año es bisiesto
// argumento anyo > año extraido de la fecha introducida por el usuario
function anyoBisiesto(anyo)
  {
    // si el año introducido es de dos cifras lo pasamos al periodo de 1900. Ejemplo: 25 > 1925
    if (anyo < 100)
      var fin = anyo + 1900;
    else
      var fin = anyo ;
    // primera condicion: si el resto de dividir el año entre 4 no es cero > el año no es bisiesto
    // es decir, obtenemos año modulo 4, teniendo que cumplirse anyo mod(4)=0 para bisiesto
    if (fin % 4 != 0)
      return false;
    else {
      if (fin % 100 == 0) {
      // si el año es divisible por 4 y por 100 y divisible por 400 > es bisiesto
        if (fin % 400 == 0) {
          return true;
        }
      // si es divisible por 4 y por 100 pero no lo es por 400 > no es bisiesto
        else  {
          return false;
        }
      }
      // si es divisible por 4 y no es divisible por 100 > el año es bisiesto
      else {
        return true;
      }
    }
  }


function fecha_ok()
  {
    // obtenemos la fecha introducida y la separamos en dia, mes y año
    a=document.forms[0].fecha.value;
    dia=a.split("/")[0];
    mes=a.split("/")[1];
    anyo=a.split("/")[2];
    if( (isNaN(dia)==true) || (isNaN(mes)==true) || (isNaN(anyo)==true) ) {
      alert("La fecha introducida no es válida. Por favor, introduzca una fecha correcta");
      return;
    }
    if(anyoBisiesto(anyo))
      febrero=29;
    else
      febrero=28;
    // si el mes introducido es negativo, 0 o mayor que 12 > alertamos y detenemos ejecucion
    if ((mes<1) || (mes>12)) {
      alert("El mes introducido no es valido. Por favor, introduzca un mes correcto");
      document.forms[0].fecha.focus();
      document.forms[0].fecha.select();
      return;
    }
    // si el mes introducido es febrero y el dia es mayor que el correspondiente 
    // al año introducido > alertamos y detenemos ejecucion
    if ((mes==2) && ((dia<1) || (dia>febrero))) {
      alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
      document.forms[0].fecha.focus();
      document.forms[0].fecha.select();
      return;
    }
    // si el mes introducido es de 31 dias y el dia introducido es mayor de 31 > alertamos y detenemos ejecucion
    if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31))) {
      alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
      document.forms[0].fecha.focus();
      //document.forms[0].fecha.select();
      return;
    }
    // si el mes introducido es de 30 dias y el dia introducido es mayor de 301 > alertamos y detenemos ejecucion
    if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30))) {
      alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
      document.forms[0].fecha.focus();
      document.forms[0].fecha.select();
      return;
    }
    // si el mes año introducido es menor que 1900 o mayor que 2020 > alertamos y detenemos ejecucion
    // NOTA: estos valores son a eleccion vuestra, y no constituyen por si solos fecha erronea
    if ((anyo<1900) || (anyo>2020)) {
      alert("El año introducido no es valido. Por favor, introduzca un año entre 1900 y 2020");

      document.forms[0].fecha.focus();
      document.forms[0].fecha.select();
    } 
    // en caso de que todo sea correcto > enviamos los datos del formulario
    else
	return true;
      //alert("Ok");
      //document.forms[0].submit();    
  }
 
function fecha_hoy() {
	var mydate=new Date();
	var year=mydate.getYear();
	
	if (year < 1000)
		year+=1900;
			
	var day=mydate.getDay();
	var month=mydate.getMonth()+1;
		
	if (month<10)
		month="0"+month;
			
	var daym=mydate.getDate();
	
	if (daym<10)
		daym="0"+daym;
	document.datos.fecha.value= daym+"/"+month+"/"+year;
}

function imagen_size(miimg) {
	var tmp = new Image();
	tmp.src=miimg.src
	
//	alert("aaa"+miimg.width);

	if (tmp.width > 400 || tmp.height > 300) {
		porcentaje=(400*100)/tmp.width;
		reducido=(porcentaje*tmp.height)/100;
		miimg.width=400;
		miimg.height=reducido;
		
		alert("La imagen tiene un tamaño superior a 400x300, se previsualizará reducida pero se recomienda bajar su tamaño")
	}
	else  {
		miimg.width=tmp.width;
		miimg.height=tmp.height;
	}
}

// FUNCION QUE COLOCA LAS CAPAS UNA DETRAS DE OTRA A UNA DISTANCIAS DE 20 PIXELS
// INDEPENDIENTEMENTE DE DONDE SE COLOQUEN EN DISEÑO
var mitotal = 0;

function inicio() {
	capa1= document.getElementById("noticia1");
	capa2= document.getElementById("noticia2");
	capa3= document.getElementById("noticia3");
	capa4= document.getElementById("noticia4");
	//capa5= document.getElementById("noticia5");

  capa1.style.top=30;
  capa1.style.visibility="visible";
  for (i=2;i<=mitotal;i++) {
    actual=eval("capa"+i);
    anterior=eval("capa"+(i-1));
    actual.style.top=parseInt(anterior.style.top)+anterior.offsetHeight+20+"px";
	//alert(i);
	actual.style.visibility="visible";
  }
  mover();
}

// FUNCION QUE MUEVE PIXEL A PIXEL LAS CAPAS Y COMPRUEBA AL MISMO TIEMPO SI ALGUNA
// DESAPARECE POR ARRIBA

function mover() {
  for (i=1;i<=mitotal;i++) {
    capamov=eval("capa"+i);
    capamov.style.top=parseInt(capamov.style.top)-1+"px";
    comprobar_top(capamov,"capa"+i);
  }
  mov = setTimeout("mover()", 60);
}

// FUNCION QUE COMPRUEBA SI LA CAPA DESAPARECE POR ARRIBA
function comprobar_top(capa,nombre_capa) {
  //  VARIABLE EN DONDE CALCULAMOS DONDE SE ENCUENTRA LA PARTE BAJA DE LA CAPA
  posicion_arriba=parseInt(capa.style.top)+capa.offsetHeight;
  
  if (posicion_arriba == mitotal) {
    if (nombre_capa == "capa1") {
	  // PARA LA CAPA 1 LA SITUAMOS A CONTINUACION DE LA ULTIMA + 20 PIXELS
	  capa.style.top=parseInt(eval("capa"+mitotal).style.top)+eval("capa"+mitotal).offsetHeight+20+"px";
	}
    if (nombre_capa != "capa1") {
	  // PARA EL RESTO DE CAPAS LAS SITUAMOS A CONTINUACION DE LA ANTERIOR
	  // + 20 PIXELS
	  capa.style.top=parseInt(aux.style.top)+aux.offsetHeight+20+"px";
	}
	// VARIABLE QUE ALMACENA LA REFERENCIA DE LA CAPA ANTERIOR
	aux=capa;
  }
}

function imagen_thumb(miimg,img_tmp,tamano) {
	porcentaje=(tamano*100)/img_tmp.width;
	reducido=(porcentaje*img_tmp.height)/100;
	//miimg.src=img_tmp.src;
	miimg.width=tamano;
	miimg.height=reducido;
	miimg.style.visibility="visible";
	//alert(img_tmp.src);
}

