/********************************************************

-- 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 += "<table style='border:solid 1px " + this.TabBordeColor + "' cellspacing=0 cellpadding=0><tr><td>"
		C += "<table cellspacing=0 cellpadding=0>"
		for( j = 0; j < 7; j++, C += "</tr>" )
			for( i = 0, C += "<tr>"; i < 7; i++ )
				C += "<td id='" + this.Clase + "TD" + i + "x" + j + "'>&nbsp;</td>"
		C += "</table></td></tr></table>"
		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 ? "&nbsp;" : 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(d<this.NumDiasMes(a,m))d++;else{d=1;if(m<12)m++;else{m=1;a++}}
		this.Anio = a; this.Mes = m; this.Dia = d
	}
	function cCalendario_RetrocederDias( n ) {
		var a = this.Anio, m = this.Mes, d = this.Dia
		while(n--)if(d>1)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 += "<table style='border:solid 1px " + this.BordeColor + "; color:" + calendario_COLOR_pes_color + "; font-size: 12px' bgcolor=" + this.Fondo + " cellspacing=0 cellpadding=0>"
		C += "<tr>"
		C += "<td align=center style='cursor:pointer' onclick='" + this.Clase + ".OnIzquierda()'>&lt;&lt;</td>"
		C += "<td align=center id='" + this.Clase + ".Titulo'>2004</td>"
		C += "<td align=center style='cursor:pointer' onclick='" + this.Clase + ".OnDerecha()'>&gt;&gt;</td>"
		C += "<td align=center style='cursor:pointer' onclick='" + this.Clase + ".OnCerrar()'><img src='" + calendario_RUTA_WWW + "/admin/img/cerrar.gif' align='absmiddle' style='border-top: 1px solid white; border-left: 1px solid white; border-bottom: 1px solid black; border-right: 1px solid black'></td></tr>"
		C += "<tr><td colspan=4 align=center id='" + this.Clase + ".Calendario'>&nbsp;</td></tr>"
		C += "</table>"
		this.Capa.innerHTML = C
		this.Calendario = new cCalendario( this.Clase + ".Calendario", document.getElementById( this.Clase + ".Calendario" ), this.Lunes )
		this.FormatearTitulo()
	}
	function cCalendarioSelector_FormatearTitulo() {
		if( this.Mes ==  0 ) { this.Mes = 12; this.Anio-- }
		if( this.Mes == 13 ) { this.Mes =  1; this.Anio++ }
		if( this.Calendario.Lista.Fecha1 > new Date( this.Anio, this.Mes, this.Calendario.NumDiasMes( this.Anio, this.Mes ) ) )
			this.OnDerecha()
		if( this.Calendario.Lista.Fecha2 < new Date( this.Anio, this.Mes, 1 ) )
			this.OnIzquierda()
		document.getElementById(this.Clase + ".Titulo").innerHTML = aMesAnio[ this.Mes-1 ] + " " + this.Anio
		this.Calendario.Anio = this.Anio
		this.Calendario.Mes = this.Mes
		this.Calendario.Construir()
	}
	function cCalendarioSelector_OnCerrar() {
		if( window.Event )
			eval( this.Clase.substr( 0, this.Clase.length - 11) ).Ocultar()
		else
			eval( "parent." + this.ClasePadre.substr( 0, this.ClasePadre.length - 11) ).Ocultar()
	}
	function cCalendarioSelector_OnIzquierda() {
		this.Mes--; this.FormatearTitulo()
	}
	function cCalendarioSelector_OnDerecha() {
		this.Mes++; this.FormatearTitulo()
	}
	function cCalendarioSelector_IrA( mes, anio ) {
		this.Anio = anio
		this.Mes = mes
		this.FormatearTitulo()
	}
function cCalendarioSelector( Nombre, Soporte, EnLunes ) {
	this.Clase = Nombre
	this.Capa = Soporte
	this.Calendario	= null
	this.BordeColor = calendario_COLOR_cal_borde
	this.Fondo = calendario_COLOR_pes_fondo
	this.Anio = 2004
	this.Mes = 11
	this.Lunes = EnLunes
	this.Construir = cCalendarioSelector_Construir
	this.OnCerrar = cCalendarioSelector_OnCerrar
	this.OnIzquierda = cCalendarioSelector_OnIzquierda
	this.OnDerecha = cCalendarioSelector_OnDerecha
	this.FormatearTitulo = cCalendarioSelector_FormatearTitulo
	this.IrA = cCalendarioSelector_IrA
}
/*******************************************************/



/********************************************************
	cCalendarioAnual
********************************************************/
	function cCalendarioAnual_Construir( Filas, Columnas ) {
		var C = "", i, j, k
		if( Filas * Columnas != 12 ) alert("¡Filas*Columnas deberían ser 12!")
		C += "<table style='border:solid 1px " + this.BordeColor + "; color:white; font-size: 12px' bgcolor=" + this.Fondo + " cellspacing=0 cellpadding=0>"
		for( k = 0, i = 0; i < Filas; i++ ) {
			C += "<tr>"
			for( j = 0; j < Columnas; j++ ) C += "<td style='color: " + this.Color + "; font-weight: bold' align=center>" + aMesAnioLargo[k+j] + "</td>"
			C += "</tr>"
			C += "<tr>"
			for( j = 0; j < Columnas; j++ ) C += "<td id='" + this.Clase + ".Calendario." + k++ +"'>&nbsp;</td>"
			C += "</tr>"
		}
		this.Capa.innerHTML = C
		for( k = 0; k < 12; k++ ) {
			this.Calendario[k] = new cCalendario( this.Clase + ".Calendario." + k, document.getElementById( this.Clase + ".Calendario." + k ), this.Lunes )
			this.Calendario[k].Anio = this.Anio
			this.Calendario[k].Mes = k+1
			this.Calendario[k].MultiSeleccion = this.MultiSeleccion
		}
	}
function cCalendarioAnual( Nombre, Soporte, EnLunes ) {
	this.Clase = Nombre
	this.Capa = Soporte
	this.BordeColor = "black"
	this.Fondo = calendario_COLOR_anu_fondo
	this.Color = calendario_COLOR_anu_color
	this.Anio = 2004
	this.Lunes = EnLunes
	this.MultiSeleccion = false
	this.Calendario = new Array()
	this.Construir = cCalendarioAnual_Construir

	// Utiliza los miembros de cListaFechas para propagarlas a todos los calendarios:
	this.ListaAcotar = function( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Lista.Acotar( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) }
	this.ListaVaciar = function() { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Lista.Vaciar() }
	this.ListaInsertarIntervalo = function( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Lista.InsertarIntervalo( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) }
	this.ListaInsertarFecha = function ( Anio, Mes, Dia ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Lista.InsertarFecha( Anio, Mes, Dia ) }
	this.ListaDentro = function ( Anio, Mes, Dia ) { var i; for( i = 0; i < 12; i++ ) if( this.Calendario[i].Lista.Dentro( Anio, Mes, Dia ) ) return true; return false }
	this.ListaSacar = function ( Anio, Mes, Dia ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Lista.Sacar( Anio, Mes, Dia ) }
	this.SeleccionAcotar = function( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Seleccion.Acotar( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) }
	this.SeleccionVaciar = function() { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Seleccion.Vaciar() }
	this.SeleccionInsertarIntervalo = function( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Seleccion.InsertarIntervalo( Anio1, Mes1, Dia1, Anio2, Mes2, Dia2 ) }
	this.SeleccionInsertarFecha = function ( Anio, Mes, Dia ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Seleccion.InsertarFecha( Anio, Mes, Dia ) }
	this.SeleccionDentro = function ( Anio, Mes, Dia ) { var i; for( i = 0; i < 12; i++ ) if( this.Calendario[i].Seleccion.Dentro( Anio, Mes, Dia ) ) return true; return false }
	this.SeleccionSacar = function ( Anio, Mes, Dia ) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Seleccion.Sacar( Anio, Mes, Dia ) }
	this.InvertirSeleccion = function() { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].InvertirSeleccion() }
	this.PoblarSeleccion = function(Texto) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].PoblarSeleccion(Texto) }
	this.Reformatear = function() { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Reformatear() }
	this.SeleccionarContenido = function(Texto) { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].SeleccionarContenido(Texto) }
	// Métodos para realizar llamadas a todos los calendarios a la vez:
	this.AniosConstruir = function() { var i; for( i = 0; i < 12; i++ ) this.Calendario[i].Construir() }
}
/********************************************************
********************************************************/

/********************************************************
	cCalendarioCombos
********************************************************/
	function cCalendarioCombos_Construir(nombre_combo, mes_largo) {
		var C = "",i,ob
		if(mes_largo)
			ob = aMesAnioLargo
		else
			ob = aMesAnio

		//Ponemos el combo de días
		C += "<select id='" + this.Clase + "_dia' onchange='" + this.Clase + ".CambiaDia()'>"
		for(i=0 ; i<31; i++)
			C += "<option value='"+(i+1)+"' "+(this.Dia==i+1?'selected':'')+">"+(i+1)+"</option>"
		C += "</select>"

		//Ponemos el combo de meses
		C += "<select id='" + this.Clase + "_mes' onchange='" + this.Clase + ".CambiaMes()'>"
		for(i=0 ; i<ob.length ; i++)
			C += "<option value='"+(i+1)+"' "+(this.Mes==i+1?'selected':'')+">"+ob[i]+"</option>"
		C += "</select>"

		//Ponemos el combo de años
		var j
		i = this.AnioIni
		j = this.AnioFin
		C += "<select id='" + this.Clase + "_anio' onchange='" + this.Clase + ".CambiaAnio()'>"
		for(i ; i<j ; i++)
			C += "<option value='"+i+"' "+(this.Anio==i?'selected':'')+">"+i+"</option>"
		C += "</select>"

		this.Capa.innerHTML = C

		this.CDia	= document.getElementById(this.Clase + "_dia")
		this.CMes	= document.getElementById(this.Clase + "_mes")
		this.CAnio	= document.getElementById(this.Clase + "_anio")
	}
	function cCalendarioCombos_Ajustar(d) {
		var i = cCalendario_NumDiasMes( this.Anio, this.Mes )

		// Comprobamos si hay más días de los necesarios, quitamos
		if( this.CDia.length > i )
			while( this.CDia.length > i )
				this.CDia.options[this.CDia.length-1] = null

		//Comprobamos si hay menos días de los necesarios, metemos
		if( this.CDia.length < i )
			while( this.CDia.length < i )
				this.CDia.options[ this.CDia.length ] = new Option(this.CDia.length+1,this.CDia.length+1)

		// Establecemos el día, mes y año que corresponde:
		if( this.Dia > i ) {
			this.Dia = i
		}
		this.CDia.selectedIndex = this.Dia - 1

		this.CMes.selectedIndex = this.Mes - 1
		for( i = 0; i < this.CAnio.length; i++ )
			if( this.CAnio[ i ].value == this.Anio )
				this.CAnio.selectedIndex = i

		this.OnCambio()
	}

	function cCalendarioCombos_CambiaDia() {
		this.Dia = this.CDia.selectedIndex + 1
		this.Ajustar()
	}
	function cCalendarioCombos_CambiaMes() {
		this.Mes = this.CMes.selectedIndex + 1
		this.Ajustar()
	}
	function cCalendarioCombos_CambiaAnio() {
		this.Anio = this.CAnio[ this.CAnio.selectedIndex ].value
		this.Ajustar()
	}
	function cCalendarioCombos_NumDiasMes( a, m ) {
		return m==2?(28+(!(a%400)||(a%100&&!(a%4)))):(30+(m&1)^(m>7))
	}
	function cCalendarioCombos_AvanzarDias( n ) {
		var a = this.Anio, m = this.Mes, d = this.Dia
		while(n--)if(d<this.NumDiasMes(a,m))d++;else{d=1;if(m<12)m++;else{m=1;a++}}
		this.Anio = a; this.Mes = m; this.Dia = d
		this.Ajustar()
	}
	function cCalendarioCombos_RetrocederDias( n ) {
		var a = this.Anio, m = this.Mes, d = this.Dia
		while(n--)if(d>1)d--;else{if(m>1)m--;else{m=12;a--}d=this.NumDiasMes(a,m)}
		this.Anio = a; this.Mes = m; this.Dia = d
		this.Ajustar()
	}
	function cCalendarioCombos_IrA( dia, mes, anio ) {
		if (dia > cCalendario_NumDiasMes( anio, mes ) ) dia = cCalendario_NumDiasMes( anio, mes )
		if(	this.Anio != anio || this.Mes != mes ||	this.Dia != dia ) {
			this.Anio	= anio
			this.Mes	= mes
			this.Dia	= dia
			this.Ajustar()
		}
	}
	function cCalendarioCombos( Nombre, Soporte /* anio_inicial, anio_final */ ) {
		this.Clase = Nombre
		this.Capa = Soporte
		this.Anio = 2004
		this.Mes = 1
		this.Dia = 1

		this.AnioIni	= cCalendarioCombos.arguments.length >= 3 ? cCalendarioCombos.arguments[2]*1 : (new Date).getFullYear()
		this.AnioFin	= cCalendarioCombos.arguments.length >= 4 ? cCalendarioCombos.arguments[3]*1 : ( this.AnioIni + 3 )

		this.Construir = cCalendarioCombos_Construir
		this.CambiaDia = cCalendarioCombos_CambiaDia
		this.CambiaMes = cCalendarioCombos_CambiaMes
		this.CambiaAnio = cCalendarioCombos_CambiaAnio
		this.Ajustar = cCalendarioCombos_Ajustar
		this.NumDiasMes = cCalendarioCombos_NumDiasMes
		this.AvanzarDias = cCalendarioCombos_AvanzarDias
		this.RetrocederDias = cCalendarioCombos_RetrocederDias
		this.IrA = cCalendarioCombos_IrA
		this.OnCambio = function(){}
	}
/********************************************************
********************************************************/

/********************************************************
	cCalendarioIcono
********************************************************/
	function cCalendarioIcono_Construir(nombre_combo, mes_largo) {
		var C = ""
		this.NFrame = this.Clase.replace( /\./g, '_' ) + "_Capa_ifr"
		C += "<a style='cursor:pointer' id='" + this.NFrame + "c' OnClick='"+this.Clase+".Muestra_Calendario()'><img src='"+this.Imagen+"' border=0 id='"+this.Clase+"'></a>"
		C += "<div id='"+this.Clase+"_Capa' style='position: absolute; visibility: hidden; z-index: 1000; left: 0; top: 0'>"
		if( !window.Event )
			C += "<iframe id='" + this.NFrame + "' src='" + calendario_RUTA_WWW + "/LibComun/Calendario/calendario_" + aKCal_IDI + ".htm' BORDER=0 FRAMEBORDER=NO FRAMESPACING=0 MARGINHEIGHT=0 MARGINWIDTH=0 NORESIZE=NORESIZE SCROLLING=NO HEIGHT=130 WIDTH=145></iframe>"
		C += "</div>"
		this.Capa.innerHTML = C
		this.Destino = document.getElementById( this.Clase+"_Capa" )
		if( window.Event ) {
			eval("document.getElementById('" + this.NFrame + "c').onclick = function (e) {"+this.Clase+".Muestra_Calendario(e)}")
			this.Calendario = new cCalendarioSelector( this.Clase + ".Calendario", this.Destino, this.Lunes )
		}
	}

	function cCalendarioIcono_IrA( dia, mes, anio ) {
		if(	this.Anio != anio || this.Mes != mes ||	this.Dia != dia ) {
			this.Anio	= anio
			this.Mes	= mes
			this.Dia	= dia
		}
	}
	function cCalendarioIcono_Acotar(ai,mi,di,af,mf,df) {
		this.Dia_i = di; this.Mes_i = mi; this.Anio_i = ai
		this.Dia_f = df; this.Mes_f = mf; this.Anio_f = af
	}
	function cCalendarioIcono_Ocultar() {
		this.Destino.style.visibility = 'hidden'
	}
	function cCalendarioIcono_Muestra_calendario(e) {
		if( this.Destino.style.visibility == 'visible' ) {
			this.Ocultar()
			if( this.AlOcultar != null )
				this.AlOcultar()
		} else {
			if( !window.Event ) {
				this.Calendario = eval( this.NFrame + ".Calendario" )
				this.Calendario.ClasePadre = this.Clase + ".Calendario" // reajustamos el nombre
			}

			this.Calendario.Anio = this.Anio
			this.Calendario.Mes = this.Mes
			this.Calendario.Construir()
			this.Calendario.Calendario.CalendarioIcono = this
			this.Calendario.Calendario.Lista.Acotar (this.Anio_i,this.Mes_i,this.Dia_i,this.Anio_f,this.Mes_f,this.Dia_f)
			this.Calendario.Calendario.Lista.InsertarIntervalo(this.Anio_i,this.Mes_i,this.Dia_i,this.Anio_f,this.Mes_f,this.Dia_f)
			this.Calendario.Calendario.OnClick = function (td) {
				if( td.Calendario.Lista.Dentro( td.Calendario.Anio, td.Calendario.Mes, td.d ) ) {
					td.Calendario.CalendarioIcono.Dia = td.d
					td.Calendario.CalendarioIcono.Mes = td.Calendario.Mes
					td.Calendario.CalendarioIcono.Anio = td.Calendario.Anio
					td.Calendario.CalendarioIcono.Destino.style.visibility = 'hidden'
					td.Calendario.CalendarioIcono.OnCambio()
				}
			}
			this.Calendario.Calendario.Construir()

			//Posición y visibilidad de la capa con el calendario
			this.Destino.style.visibility = 'visible'
			var x, y
			if( window.Event ) {
				x = e.clientX
				y = e.clientY
			} else {
				x = event.clientX
				y = event.clientY
			}
			this.Posicionar( ( x + document.body.scrollLeft ) - 155 + "px", ( y + document.body.scrollTop ) + 15 + "px" )
			if( this.AlMostrar != null )
				this.AlMostrar()
		}
	}

	function cCalendarioIcono_Posicionar( x, y ) {
		this.Destino.style.top = y
		this.Destino.style.left = x
	}

	function cCalendarioIcono( Nombre, Soporte, EnLunes ) {
		this.Clase		= Nombre
		this.Capa		= Soporte
		//this.Destino	= aún no asignada
		//this.NFrame	= nombre del frame, aún no asignado
		this.Anio		= 2004
		this.Mes		= 1
		this.Dia		= 1
		this.Lunes		= EnLunes
		this.Imagen		= calendario_RUTA_WWW + "/web/es/fpw/19_calendario.gif"

		this.Construir = cCalendarioIcono_Construir
		this.Muestra_Calendario = cCalendarioIcono_Muestra_calendario
		//this.Calendario = aún no asignado
		this.Acotar = cCalendarioIcono_Acotar
		this.IrA = cCalendarioIcono_IrA
		this.OnCambio = function(){}
		this.Posicionar = cCalendarioIcono_Posicionar
		this.AlMostrar = null
		this.AlOcultar = null
		this.Ocultar = cCalendarioIcono_Ocultar

		this.Acotar( 2004, 1, 15, 2005, 1, 1 )
	}
/********************************************************
********************************************************/
		function cCalendarioComboIcono_IrA( dia, mes, anio ) {
			this.Anio	= anio
			this.Mes	= mes
			this.Dia	= dia
			this.Combo.IrA( dia, mes, anio )
			this.Icono.IrA( dia, mes, anio )
			this.OnCambio()
		}
		function cCalendarioComboIcono_IrADate( dateObj ) {
			this.IrA( dateObj.getDate(), dateObj.getMonth() + 1, dateObj.getFullYear() )
		}
		function cCalendarioComboIcono_Construir() {
			this.Icono.Construir()
			this.Combo.Construir()
			this.IrA( 1, 1, 2004 )
		}
		function cCalendarioComboIcono_toDate() {
			return new Date( this.Anio, this.Mes - 1, this.Dia, 12 ) // ¡las 12 del mediodía por cambios de horario!
		}
		function cCalendarioComboIcono_toUTCDate() {
			return new Date( Date.UTC( this.Anio, this.Mes - 1, this.Dia, 12 ) );
		}
		function cCalendarioComboIcono_DistanciaDiasUTCDates( dateMenor, dateMayor ) {
			return Math.floor( ( dateMayor.getTime() - dateMenor.getTime() ) / 86400000.0 )
		}
		function cCalendarioComboIcono_DateMasDias( objDate, nDias ) {
			var d = new Date()
			d.setTime( objDate.getTime() + nDias * 86400000 )
			return d
		}
		function cCalendarioComboIcono_DistanciaDias( calCoIcObj ) {
			return this.DistanciaDiasUTCDates( this.toUTCDate(), calCoIcObj.toUTCDate() )
		}
	function cCalendarioComboIcono( Nombre, SoporteIcono, SoporteCombo, EnLunes ) {
		this.Clase		= Nombre
		this.Icono		= new cCalendarioIcono	( this.Clase + ".Icono", SoporteIcono, EnLunes )
		this.Combo		= new cCalendarioCombos	( this.Clase + ".Combo", SoporteCombo )
		this.Icono.Padre	=
		this.Combo.Padre	= this
		this.Icono.OnCambio	=
		this.Combo.OnCambio	= function() { this.Padre.IrA( this.Dia, this.Mes, this.Anio ) }
		this.Construir		= cCalendarioComboIcono_Construir
		this.IrA		= cCalendarioComboIcono_IrA
		this.IrADate		= cCalendarioComboIcono_IrADate
		this.toDate		= cCalendarioComboIcono_toDate
		this.toUTCDate		= cCalendarioComboIcono_toUTCDate
		this.DateMasDias	= cCalendarioComboIcono_DateMasDias
		this.DistanciaDiasUTCDates	= cCalendarioComboIcono_DistanciaDiasUTCDates
		this.DistanciaDias	= cCalendarioComboIcono_DistanciaDias
		this.OnCambio		= function() {}
	}
/********************************************************
********************************************************/
