var numDias = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function cambiaMes(m,a)
	{
	var f = new Date(a,m,1);
  var Layer;
  var doc = "document.all";
  var sty = ".style";
  var htm="";
  Layer=eval(doc + '["calendario"]' + htm);
  Layer.innerHTML=generaCalendario(f.getMonth(),f.getFullYear());
	}
function ponFecha(fecha)
	{
	document.all["fecha"].value=fecha;
	document.all["calendario"].style.visibility='hidden';
	document.all["calendario"].innerHTML='';
	}
function misubmit(dia)
	{
	document.formEvento["dia"].value=dia;
//	alert(document.formEvento["dia"].value);
	document.formEvento.submit();
	}
function generaDiasMes(mes,agno)
	{
	var html='';
	var param = ' ';
	pos = 0;
	var fecha=new Date(agno,mes,1)
	var nDias=numDias[mes];
	if (mes==1)
		if ((agno%4) == 0)
			nDias++;
	html+='<TR><TD width="30" class="texto" align="center">L</TD><TD width="30" class="texto"  align="center">M</TD><TD  width="30" class="texto" align="center">X</TD><TD  width="30" class="texto" align="center">J</TD><TD  width="30" class="texto"  align="center">V</TD><TD  width="30" class="texto"  align="center">S</TD><TD  width="30" class="texto" align="center">D</TD></TR>\n';
	html+='<TR>';

	pos=(fecha.getDay()+6)%7;
	if (pos>0)
		html+='<TD colspan="'+pos+'" class="texto">&nbsp;</td>';
	for (i=0;i<nDias;i++)
		{

		if (hayEvento(i+1,mes))
			{
//			html+='<form name="_form" action="/db/eventos/public/listadoEventos.php" method="post"><input type="hidden" value="'+(i+1)+'/'+(mes+1)+'/'+(agno)+'" name="dia">';
			html+='<td class="textoBorde" align="center" valign="middle">';
			html+='<a href="#" onclick="misubmit(\''+(i+1)+'/'+(mes+1)+'/'+(agno)+'\')">'+(i+1)+'</a></TD>';
//			html+='</form>';
			}
		else
			{
			html+='<td class="texto" align="center" valign="middle">';
			html+=(i+1)+'</TD>';
			}
		pos++;
		if (pos==7)
			{
			html+='</TR>\n<TR>';
			pos=0;
			}
		}
	if (pos!=7)
		html+='<TD colspan="'+(7-pos)+'">&nbsp;</TD>';
	html+='</TR>\n';
	return html;	
	}
function hayEvento(dia,mes)
	{
	var fecha=new Date();
	mes=(mes-fecha.getMonth()+12)%12;
	for (j=0;j<eventos[mes].length ;j++ )
		if (eventos[mes][j]==dia)
			return true;
	return false;
	}
function getMes(mes)
	{
	switch(mes)
		{
		case 0:return 'ENERO';break;
		case 1:return 'FEBRERO';break;
		case 2:return 'MARZO';break;
		case 3:return 'ABRIL';break;
		case 4:return 'MAYO';break;
		case 5:return 'JUNIO';break;
		case 6:return 'JULIO';break;
		case 7:return 'AGOSTO';break;
		case 8:return 'SEPTIEMBRE';break;
		case 9:return 'OCTUBRE';break;
		case 10:return 'NOVIEMBRE';break;
		case 11:return 'DICIEMBRE';break;
		}
	}
function generaCalendario(mes,agno)
	{
	var html;
	var fecha=new Date();
	var f2=new Date(fecha.getFullYear(),fecha.getMonth()+5,1);

	html='<table border="0" bordercolor="#000000" width="100%">\n';
	html+='<TR>';
	html+='<TD  width="100%">';
	html+='<table border="0"  width="100%">';
	html+='<TR>';
	html+='<TD class="textoGris" width="100%">'+getMes(mes)+' '+agno+'</TD>';
	html+='<TD class="textoGris">';
	if (fecha.getFullYear()<agno)
		html+='<a href="#" onclick="cambiaMes('+(mes-1)+','+agno+')"><img src="/img/flechaIzq.gif" border="0"></a>';
	else
		if (fecha.getMonth()<mes)
			html+='<a href="#" onclick="cambiaMes('+(mes-1)+','+agno+')"><img src="/img/flechaIzq.gif" border="0"></a>';
		else
			html+='&nbsp;';
	html+='</TD>';

	html+='<TD class="textoGris">';
	if ((f2.getFullYear()==agno) && (f2.getMonth()==mes))
		html+='&nbsp;';
	else
		html+='<a href="#" onclick="cambiaMes('+(mes+1)+','+agno+')"><img src="/img/flechaDer.gif" border="0"></a>';
	html+='</TD>';
	html+='</TR>';

	html+='<TR>';

	html+='<TD  width="100%" align="left">';
	html+='<table  width="210" border="0">';
	html+=generaDiasMes(mes,agno);
	html+='</table>';

	html+='</TD>';
	html+='</TR>';

	html+='</table>';
	html+='</TD>';
	html+='</TR>';

	html+='</table>';
	return html;
	}

function generaCalendario2(mes,agno)
	{
	var html;
	var fecha=new Date();
	var f2=new Date(fecha.getFullYear(),fecha.getMonth()+5,1);

	html='<table border="1" bordercolor="#000000" >\n';
	html+='<TR><TD width="15%" align="center">';
	if (fecha.getFullYear()<agno)
		html+='<input type="button" class="botones_calendario" value="<<" onclick="cambiaMes('+(mes-1)+','+agno+')">';
	else
		if (fecha.getMonth()<mes)
			html+='<input type="button" class="botones_calendario" value="<<" onclick="cambiaMes('+(mes-1)+','+agno+')">';
		else
			html+='&nbsp;';

	html+='<TD colspan="5" class="titulo_calendario" align="center">'+getMes(mes)+' '+agno+'</td><TD width="15%" align="center">';

	if ((f2.getFullYear()==agno) && (f2.getMonth()==mes))
		html+='&nbsp;';
	else
		html+='<input type="button" value=">>" class="botones_calendario" onclick="cambiaMes('+(mes+1)+','+agno+')">';
	
	html+='</TD></TR>\n<TR><TD width="15%" class="titulo_calendario" align="center">Lu</TD><TD width="15%" class="titulo_calendario" align="center">Ma</TD><TD width="15%" class="titulo_calendario" align="center">Mi</TD><TD width="15%" class="titulo_calendario" align="center">Ju</TD><TD width="15%" class="titulo_calendario" align="center">Vi</TD><TD width="15%" class="titulo_calendario" align="center">Sa</TD><TD width="15%" class="titulo_calendario" align="center">Do</TD></TR>\n';
	html+=generaDiasMes(mes,agno);
	html+='</table>\n';
	return html;
	}
function muestraCalendario()
	{
	var fecha=new Date();
	if (document.all["calendario"].style.visibility=='hidden')
		{
		document.all["calendario"].style.visibility='visible';
		cambiaMes(fecha.getMonth(),fecha.getFullYear());
		}
	else
		{
		document.all["calendario"].style.visibility='hidden';
		document.all["calendario"].innerHTML='';
		}
	}
