/********************************************************
-- JJBM, 26/11/2004, Calendario.eld
-- JJBM, 16/12/2004, cCalendarioComboIcono
-- Víctor, 19/09/2005, Cambiar colores
-- Víctor, 05/06/2006, Comprobar día en cCalendarioCombos_IrA
-- JJBM, 24/11/2006, posicionar correctamente la ventana respecto el cursor.
-- JJBM, 24/11/2006, normalizar colores.
-- JJBM, 30/11/2006, agregar funciones de tratamiento de fechas.
-- JJBM, 05/12/2007, calendario_RUTA_WWW (prefijo sobre rutas absolutas en la aplicación).
-- JJBM, 04/03/2008, cuando el mes cambia el día, el valor de Dia no se actualiza.
-- JJBM, 14/05/2009, cListaFechas.DentroIntervalo.
--/
********************************************************/
var calendario_COLOR_cal_borde = "gray" // Color del borde total de un calendario.
var calendario_COLOR_mes_borde = "gray" // Color del borde de todo mes interior.
var calendario_COLOR_int_borde = "gray" // Color del borde del interior de un mes.
var calendario_COLOR_diN_fondo = "#F0F0F0" // Celdas de días sin no disponibles.
var calendario_COLOR_diN_color = "#A0A0A0"
var calendario_COLOR_diS_fondo = "white" // Celdas de días sí disponibles.
var calendario_COLOR_diS_color = "black"
var calendario_COLOR_sem_fondo = "#022FD4" // Celdas de la cabecera con los días de la semana.
var calendario_COLOR_sem_color = "white"
var calendario_COLOR_fin_fondo = "#C0C43E" // Celdas de días disponibles en fin de semana.
var calendario_COLOR_fin_color = "#CC3300"
var calendario_COLOR_sel_fondo = "#2E1C86" // Celdas de días seleccionados.
var calendario_COLOR_sel_color = "white"
var calendario_COLOR_pes_fondo = "#A0A0A0" // Pestaña del calendario.
var calendario_COLOR_pes_color = "white"
var calendario_COLOR_anu_fondo = "#EBDB85" // Tabla del calendario anual.
var calendario_COLOR_anu_color = "#7A7E03"
var calendario_RUTA_WWW = "" // después cargar el SCRIPT se puede hacer: calendario_RUTA_WWW = "http://www.miservidor.com";
/********************************************************
cIntervaloFechas
********************************************************/
function cIntervaloFechas( Fecha1, Fecha2 ) {
this.Fecha1 = Fecha1
this.Fecha2 = Fecha2
this.Siguiente = null
}
/********************************************************
cListaFechas
********************************************************/
function cListaFechas() {
this.Fechas = null
this.Fecha1 = new Date( 1900, 1, 1 )
this.Fecha2 = new Date( 2099, 1, 1 )
this.Acotar = function( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) {
this.Fecha1 = new Date( Anio1, Mes1, Dia1 )
this.Fecha2 = new Date( Anio2, Mes2, Dia2 )
}
this.Vaciar = function() {
this.Fechas = null
}
this.InsertarNodo = function( Nodo ) {
Nodo.Siguiente = this.Fechas
this.Fechas = Nodo
}
this.InsertarIntervalo = function( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) {
this.InsertarNodo( new cIntervaloFechas( new Date( Anio1, Mes1, Dia1 ),
new Date( Anio2, Mes2, Dia2 ) ) )
}
this.InsertarFecha = function ( Anio, Mes, Dia ) {
this.InsertarIntervalo( Anio, Mes, Dia, Anio, Mes, Dia )
}
this.Dentro = function ( Anio, Mes, Dia ) {
if( Dia == 0 ) return false
var d = new Date( Anio, Mes, Dia ), l = this.Fechas
if( d < this.Fecha1 || d > this.Fecha2 ) return false // Fuera de cotas.
for(; l!= null; l=l.Siguiente ) if( l.Fecha1<=d && d<=l.Fecha2 ) return true
return false
}
// TRUE si TODO el intervalo está dentro, FALSE si alguna fecha está fuera.
this.DentroIntervalo = function( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) {
var d1 = new Date( Anio1, Mes1, Dia1 );
var d2 = new Date( Anio2, Mes2, Dia2 );
while( d1 <= d2 ) {
if( ! this.Dentro( d1.getFullYear() * 1, d1.getMonth() * 1, d1.getDate() * 1 ) )
return false;
d1.setDate( d1.getDate() * 1 + 1 );
}
return true;
}
this.Sacar = function ( Anio, Mes, Dia ) {
if( this.Fechas != null ) {
var d = new Date( Anio, Mes, Dia )
if( this.Fechas.Fecha1 <= d && d <= this.Fechas.Fecha2 )
this.Fechas = this.Fechas.Siguiente
else {
var l = this.Fechas
for(; l.Siguiente != null; l = l.Siguiente )
if( l.Siguiente.Fecha1 <= d && d <= l.Siguiente.Fecha2 ) {
l.Siguiente = l.Siguiente.Siguiente
break
}
}
}
}
}
/********************************************************
cCalendario
********************************************************/
function cCalendario_xtra_Texto( Texto ) {
this.innerHTML = Texto
}
function cCalendario_Formatear(x,y) {
var o = this.TD(x,y)
with( o.style ) {
var bgc, col
if( x == 6 || ( this.Lunes && x == 5 ) || ( !this.Lunes && x == 0 ) )
{ bgc = this.FinFondo; col = this.FinColor }
else { bgc = this.DiaFondo; col = this.DiaColor }
if( !y ) { bgc = this.TitFondo; col = this.TitColor }
else
if( !this.Lista.Dentro( this.Anio, this.Mes, o.d ) )
{ bgc = this.DiaFFondo; col = this.DiaFColor }
else
if( this.Seleccion.Dentro( this.Anio, this.Mes, o.d ) )
{ bgc = this.SelFondo; col = this.SelColor }
backgroundColor = bgc
color = col
borderRight =
borderBottom = "solid 1px " + this.TabRejillaColor
textAlign = "center"
fontSize = "12px"
if( this.Lista.Dentro( this.Anio, this.Mes, o.d ) ) {
try { o.style.cursor = "pointer" }
catch(e) { o.style.cursor = "hand" } // IE5 falla con pointer
fontWeight = "bold"
} else {
o.style.cursor = "default"
fontWeight = "normal"
}
}
}
function cCalendario_Construir() {
var C = "", i, j
C += "
"
C += "
"
for( j = 0; j < 7; j++, C += "" )
for( i = 0, C += "
"; i < 7; i++ )
C += "
"
C += "
"
this.Capa.innerHTML = C
for( i = 0; i < 7; i++ )
for( j = 0; j < 7; j++ ) {
var o = this.TD(i,j)
o.d = 0; o.x = i; o.y = j; o.Calendario = this
o.onclick = this.TDOnClick
o.Texto = cCalendario_xtra_Texto
this.Formatear(i,j)
}
this.RellenarMes()
}
function cCalendario_TD(x,y) {
return eval("document.getElementById('" + this.Clase + "TD" + x + "x" + y + "')")
}
function cCalendario_TDOnClick() {
var c = this.Calendario
var s = c.Seleccion, l = c.Lista
var a = c.Anio, m = c.Mes, d = this.d
if( c.MultiSeleccion ) {
if( l.Dentro( a, m, d ) ) {
if( s.Dentro( a, m, d ) ) s.Sacar( a, m, d )
else s.InsertarFecha( a, m, d )
c.Formatear( this.x, this.y )
}
} else {
// Sólo una selección.
}
// Propagamos el evento:
this.Calendario.OnClick( this )
}
function cCalendario_RellenarDia( x, y, NDia ) {
with( this.TD(x,y) ) {
d = NDia
title = NDia ? NDia : ""
Texto( !NDia ? " " : this.Contenido[NDia] != "" ? this.Contenido[NDia] : NDia )
}
this.Formatear(x,y)
}
function cCalendario_DiaSemana( ds ) {
if( this.Lunes ) return ( ds + 1 ) % 7
return ds
}
function cCalendario_TextoDiaSemana( ds ) {
return aDiaSemana[ ds ]
}
function cCalendario_NumDiasMes( a, m ) {
return m==2?(28+(!(a%400)||(a%100&&!(a%4)))):(30+(m&1)^(m>7))
}
function cCalendario_SumarDias( n ) {
if( n > 0 ) this.AvanzarDias( n )
if( n < 0 ) this.RetrocederDias( -n )
}
function cCalendario_AvanzarDias( n ) {
var a = this.Anio, m = this.Mes, d = this.Dia
while(n--)if(d1)d--;else{if(m>1)m--;else{m=12;a--}d=this.NumDiasMes(a,m)}
this.Anio = a; this.Mes = m; this.Dia = d
}
function cCalendario_toDDMMAAAA( separador ) {
var s = ""
if( this.Dia < 10 ) s += "0"
s += this.Dia.toString() + separador
if( this.Mes < 10 ) s += "0"
return s + this.Mes.toString() + separador + this.Anio.toString()
}
function cCalendario_toDDMMAAAAsecuencia( ndias, separadorDMA, separadorFechas ) {
var s = "", c = new cCalendario( "null", "null", 1 ), q = ""
c.Dia = this.Dia; c.Mes = this.Mes; c.Anio = this.Anio
while( ndias-- ) {
s += q + c.toDDMMAAAA( separadorDMA )
q = separadorFechas
c.SumarDias( 1 )
}
return s
}
function cCalendario_RellenarMes() {
var D = new Date( this.Anio, this.Mes-1, 1 ), ic = 0, i, pds
var ND = this.NumDiasMes( this.Anio, this.Mes )
for( i = 0; i < 7; i++ ) this.TD(i,0).Texto(" "+this.TextoDiaSemana(this.DiaSemana(i))+" ")
while( this.DiaSemana( ic ) != ( pds = D.getDay() ) ) this.RellenarDia( ic++, 1, 0 )
for( i = 1; i <= ND; ic++, i++ ) this.RellenarDia( ic % 7, 1 + Math.floor( ic / 7 ), i )
for(; ic < 42; ic++ ) this.RellenarDia( ic % 7, 1 + Math.floor( ic / 7 ), 0 )
}
function cCalendario_NumDias() {
return this.NumDiasMes( this.Anio, this.Mes )
}
function cCalendario_InvertirSeleccion() {
var i, j, R = this.OnClick
this.OnClick = function(){}
for( i = 0; i < 7; i++ )
for( j = 1; j < 7; j++ )
with( this.TD(i,j) )
if( d )
onclick()
this.OnClick = R
}
function cCalendario_PoblarSeleccion( strTexto ) {
var i, j
for( i = 0; i < 7; i++ )
for( j = 1; j < 7; j++ )
with( this.TD(i,j) )
if( d )
if( this.Seleccion.Dentro( this.Anio, this.Mes, d ) ) {
this.Contenido[d] = strTexto
this.RellenarDia(x,y,d)
}
}
function cCalendario_Reformatear() {
var i, j
for( i = 0; i < 7; i++ )
for( j = 0; j < 7; j++ )
this.Formatear(i,j)
}
function cCalendario_SeleccionarContenido( strTexto ) {
var i, j
for( i = 0; i < 7; i++ )
for( j = 1; j < 7; j++ )
with( this.TD(i,j) )
if( d )
if( this.Contenido[d] == strTexto )
if( !this.Seleccion.Dentro( this.Anio, this.Mes, d ) ) {
this.Seleccion.InsertarFecha( this.Anio, this.Mes, d )
this.Formatear(x,y)
}
}
function cCalendario( Nombre, Soporte, EnLunes ) {
this.Clase = Nombre
this.Capa = Soporte
this.TabBordeColor = calendario_COLOR_mes_borde
this.TabRejillaColor = calendario_COLOR_int_borde
this.TitFondo = calendario_COLOR_sem_fondo
this.TitColor = calendario_COLOR_sem_color
this.DiaFondo = calendario_COLOR_diS_fondo
this.DiaColor = calendario_COLOR_diS_color
this.DiaFFondo = calendario_COLOR_diN_fondo
this.DiaFColor = calendario_COLOR_diN_color
this.FinFondo = calendario_COLOR_fin_fondo
this.FinColor = calendario_COLOR_fin_color
this.SelFondo = calendario_COLOR_sel_fondo
this.SelColor = calendario_COLOR_sel_color
this.Lunes = EnLunes
this.Anio = 2004
this.Mes = 1
this.Contenido = new Array()
{ var i = 1; while(i<32) this.Contenido[i++] = "" }
this.ArrastreMes = 0
this.ArrastreDia = 0
this.MultiSeleccion = false
this.Lista = new cListaFechas()
this.Seleccion = new cListaFechas()
this.Construir = cCalendario_Construir
this.TD = cCalendario_TD
this.TDOnClick = cCalendario_TDOnClick
this.RellenarMes = cCalendario_RellenarMes
this.RellenarDia = cCalendario_RellenarDia
this.DiaSemana = cCalendario_DiaSemana
this.TextoDiaSemana = cCalendario_TextoDiaSemana
this.NumDiasMes = cCalendario_NumDiasMes
this.Formatear = cCalendario_Formatear
this.NumDias = cCalendario_NumDias
this.InvertirSeleccion = cCalendario_InvertirSeleccion
this.PoblarSeleccion = cCalendario_PoblarSeleccion
this.Reformatear = cCalendario_Reformatear
this.SeleccionarContenido = cCalendario_SeleccionarContenido
this.OnClick = function( TD ) {} // Virtual.
this.SumarDias = cCalendario_SumarDias
this.AvanzarDias = cCalendario_AvanzarDias
this.RetrocederDias = cCalendario_RetrocederDias
this.toDDMMAAAA = cCalendario_toDDMMAAAA
this.toDDMMAAAAsecuencia = cCalendario_toDDMMAAAAsecuencia
}
/*******************************************************/
/********************************************************
cCalendarioSelector
********************************************************/
function cCalendarioSelector_Construir() {
var C = ""
C += "