/**
 * Funciones para mostrar el calendario de eventos
 */


/**
 * Function que muestra u oculta los eventos de un dia
 */
function showEventosDayToolTip (dayDiv, show)
	{
	try
		{	
		if(show==dayDiv.mouseInDay&&show!=dayDiv.showedToolTip)
			{
			if(dayDiv.eventoToolTip===undefined||dayDiv.eventoToolTip==null)
				dayDiv.eventoToolTip = $(dayDiv).getElement('.toolTip');
			
			if(show)
				dayDiv.eventoToolTip.setStyle('display','block');
			else
				dayDiv.eventoToolTip.setStyle('display','none');
			
			dayDiv.showedToolTip = show;
			}
		}
	catch (err)
		{
		}

	}


/**
 * Funcion que se llama cuando el mouse entra al evento de un dia
 */
function inEventosDay (dayDiv)
	{
	try
		{
		dayDiv.mouseInDay = true;

		if(dayDiv.showedToolTip===undefined)
			dayDiv.showedToolTip = false;

		if((dayDiv.showToolTipCalled===undefined||(!dayDiv.showToolTipCalled)))
			{
			dayDiv.showToolTipCalled = true;
			setTimeout(function(){ showEventosDayToolTip(dayDiv,true); dayDiv.showToolTipCalled=false;},1000);
			}
		}
	catch (err)
		{
		}
	}


/**
 * Funcion que se llama cuando el mouse sale del evento de un dia
 */
function outEventosDay (dayDiv)
	{
	try
		{
		dayDiv.mouseInDay = false;
	
		if(dayDiv.showedToolTip===undefined)
			return;
	
		if(dayDiv.hiddeToolTipCalled===undefined||(!dayDiv.hiddeToolTipCalled))
			{
			dayDiv.hiddeToolTipCalled = true;
			setTimeout(function(){showEventosDayToolTip(dayDiv,false); dayDiv.hiddeToolTipCalled=false;},750);
			}
		}
	catch (err)
		{
		}
	}


/**
 * Funcion que se manda a llamar cuando el calendario de eventos cambia
 */
function changeCalendarioEventosMonth (next)
	{
	
	try
		{
		var calendario = $('calendarioEventos');
		if(calendario===undefined||calendario==null)
			return;

		if(calendario.inChangeFlag===undefined)
			calendario.inChangeFlag = false;

		if(calendario.inChangeFlag)
			return;
	
		calendario.inChangeFlag = true;
		
		calendario.task.value = (next) ? 'next' : 'last';
		sendCodecAjaxRequest(calendario);
		}
	catch (err){}

	}

/**
 * Inicia el calendario de eventos
 */
function initCalendarioEventos (year, month, monthYearName, calendarioDaysCode, id_actividad, nombreActividad, iconoActividadSrc)
	{
	
	try
		{
		closeCurrentVirtualBox();
		var oldCalendario = $('calendarioEventos');
		if((!(oldCalendario===undefined))&&oldCalendario!=null)
			oldCalendario.dispose();

		loadImagesInChache('templates/plantilla/images/calendario-eventos/calendario-buttons.png','templates/plantilla/images/calendario-eventos/tip-bg.png');

		if(Browser&&Browser.ie6)
			loadImagesInChache('templates/plantilla/images/calendario-eventos/calendario-bg-ie6.png','templates/plantilla/images/calendario-eventos/marcas-dias-ie6.png');
		else
			loadImagesInChache('templates/plantilla/images/calendario-eventos/calendario-bg.png','templates/plantilla/images/calendario-eventos/marcas-dias.png');

		if(iconoActividadSrc!=null)
			loadImagesInChache(iconoActividadSrc);
		else
			loadImagesInChache('templates/plantilla/images/calendario-eventos/icono-acuasol.png');
		

		var htmlCode = '<center><form id="calendarioEventos" action="calendario-eventos/" method="post" onsubmit="return false;">';

			htmlCode += '<center>';
			
				//Head
				htmlCode += '<table class="calendarioHeader" cellspacing="0" cellpadding="0"><tr>';
					htmlCode += '<th><div>'+monthYearName+'</div>'+nombreActividad+'</th>';
					htmlCode += '<td><button type="button" title="Mes Anterior..." onclick="changeCalendarioEventosMonth(false);"></button><button type="button" title="Mes Siguiente..." onclick="changeCalendarioEventosMonth(true);"></button><button type="button" class="close" title="Cerrar" onclick="closeCurrentVirtualBox();"></button></td>';
				htmlCode += '</tr></table>';

				
				htmlCode += '<center class="calendarioIconBg"'+((iconoActividadSrc!=null)?(' style="background-image:url('+iconoActividadSrc+');"'):'')+'>';
								
					//Dias semana
					htmlCode += '<table class="calendarioWeekDays" cellspacing="0" cellpadding="0"><tr>';
						htmlCode += '<th>Domingo</th><th>Lunes</th><th>Martes</th><th>Mi&eacute;rcoles</th><th>Jueves</th><th>Viernes</th><th>S&aacute;bado</th>';
					htmlCode +=	 '</tr></table>';

					//Dias/Eventos
					htmlCode += '<div class="calendarioDaysZone">'+calendarioDaysCode+'</div>';
				
				htmlCode += '</center>';
				

			htmlCode += '</center>';

			htmlCode += '<input type="hidden" name="year" value="'+year+'" />';
			htmlCode += '<input type="hidden" name="month" value="'+month+'" />';
			htmlCode += '<input type="hidden" name="id_actividad" value="'+id_actividad+'" />';
			htmlCode += '<input type="hidden" name="task" value="" />';
	
		htmlCode += '</form></center>';
	
		showVirtualBox(650,520,htmlCode);
		}
	catch (err){}
	}



/**
 * Funcion que se manda a llamar cuando el calendario de eventos ha cambiado
 */
function onChangeCalendarioEventos (year, month, monthYearName, calendarioDaysCode)
	{
	try
		{
		var calendario = $('calendarioEventos');
		if(calendario===undefined||calendario==null)
			return;		
		
		if(!(year===undefined))
			{
			calendario.year.value = year;
			calendario.month.value = month;
			calendario.getElement('.calendarioHeader th div').set('html',monthYearName);
			calendario.getElement('.calendarioDaysZone').set('html',calendarioDaysCode);
			}

		calendario.inChangeFlag = false;
		}
	catch (err){}
	}

/**
 * Muestra el calendario de eventos
 */
function showCalendarioEventos (year, month, id_actividad)
	{
	if(year===undefined)
		year = 0;
	
	if(month===undefined)
		month = 0;

	if(id_actividad===undefined)
		id_actividad = 0;
	
	sendNoFormCodecAjaxRequest('calendario-eventos/',{names:['year','month','id_actividad'], values:[year, month, id_actividad]});
	
	return false;
	}
