// JavaScript Document
function AmpliaFoto(nombre)
{
  	window.open("Foto.php?nombre=" + nombre,"Ampliación","width=680,height=505,top=200,left=200,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no");
}

function formatoFechas (cifra)
{
	if (cifra < 10)
	  return '0' + cifra.toString();
	else
	  return cifra.toString();
}

function fechaActual()
{
	var fecha=new Date();
  var dia=fecha.getDate();
  var mes=fecha.getMonth() + 1 ;
  var ano=fecha.getFullYear();
	var horas=fecha.getHours();
	var minutos=fecha.getMinutes();
	var segundos= fecha.getSeconds()	
	var id= ano.toString() + formatoFechas(mes) + formatoFechas(dia) + formatoFechas(horas) + formatoFechas(minutos) + formatoFechas(segundos);

	return id;
}

function validarEntero(codigo){
    //intento convertir a entero.
    //si era un entero no le afecta, si no lo era lo intenta convertir
    valor = parseInt(codigo);

    //Compruebo si es un valor numérico
    if (isNaN(valor)) {
       //entonces (no es numero) devuelvo el valor cadena vacia
       return false;
    }else{
       //En caso contrario (Si era un número) devuelvo el valor
       return true;
    }
} 
//***********************************************************************************************
// validarFecha(dia,mes, año)
//
// Valida que el día y el mes introducidos sean correctos. Además valida que el año introducido
// sea o no bisiesto
//
//***********************************************************************************************
function validarFecha(fecha)
{ 
	if (fecha.length != 10)
	{ return false; }
	
	
	if ((fecha.substring(2,3) != '/') ||  (fecha.substring(5,6) != '/'))
	{ return false; }
	
	dia = fecha.substring(0,2);
	mes = fecha.substring(3,5);
	anio = fecha.substring(6,10);
	
	if ((!validarEntero(dia)) || (!validarEntero(mes)) || (!validarEntero(anio)))
	{ return false; }
	
  var elMes = parseInt(mes);

  if(elMes>12)
    return false;
		
	if(elMes== 4 || elMes==6 || elMes==9 || elMes==11)
	{
    if(parseInt(dia) > 30)
	  { return false; }
   }
	 
	if(elMes== 1 || elMes==3 || elMes==5 || elMes==7 || elMes==8 || elMes==10 || elMes==12)
	{
    if(parseInt(dia) > 31)
	  { return false; }
   } 
		
  // MES FEBRERO
  if(elMes == 2)
	{
    if(esBisiesto(anio))
		{
      if(parseInt(dia) > 29)
			{ return false; }
     else 
		   return true;
    }
    else
		{
      if(parseInt(dia) > 28)
			{  return false;  }
      else
         return true;
    }
  }
	 
  return true;
}
//*****************************************************************************************
// esBisiesto(anio)
//
// Determina si el año pasado com parámetro es o no bisiesto
//*****************************************************************************************
function esBisiesto(anio)
{
  var BISIESTO;
  if(parseInt(anio)%4==0)
	{
    if(parseInt(anio)%100==0)
		{
      if(parseInt(anio)%400==0)
			{
        BISIESTO=true;
      }
      else
			{
        BISIESTO=false;
      }
    }
    else
		{
      BISIESTO=true;
    }
   }
   else
     BISIESTO=false;

  return BISIESTO;
} 