Ancho = 140;	
Fondo	= "#ddffdd";
fndFes 	= "#ccffc";
fndTit 	= "#ddffdd";
FondoweekDay = "#eeeeee";
colLin 		= "#FFFFFF";
cp = 1;				
cs = 1;			
month = new Array;
month[0]  = "Enero";
month[1]  = "Febrero";
month[2]  = "Marzo";
month[3]  = "Abril";
month[4]  = "Mayo";
month[5]  = "Junio";
month[6]  = "Julio";
month[7]  = "Agosto";
month[8]  = "Septiembre";
month[9]  = "Octubre";
month[10] = "Noviembre";
month[11] = "Diciembre";
	
weekDay = new Array ("L","M","X","J","V","S","D");
DiasMes = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
function writeCal(fecha){
	dia = fecha.getDate();
	diaSemana = fecha.getDay();
	mes = fecha.getMonth();
	anno = fecha.getYear();
	
	if (anno%4 == 0) {
		DiasMes[1] = 29
	}
	
	stTexto = "";
	stTexto += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
	stTexto += "<tr>\n";
	stTexto += "<td bgcolor=\"" + colLin + "\">\n";
	stTexto += "<table cellpadding=\"" + cp +"\" cellspacing=\"" + cs + "\" border=\"0\" width=\"" + Ancho + "\">\n";
	stTexto += "<tr>\n";
	stTexto += "<td colspan=\"7\" bgcolor=\"" + fndTit + "\" class=\"titulo\" align=\"center\"><b>&nbsp;" + month[mes].toUpperCase() + "&nbsp;" + anno +"&nbsp;</b></td>\n";
	stTexto += "</tr>\n";
	stTexto += "<tr>\n";
	document.write(stTexto);
	for(i=0;i<7;i++){
	document.write ("<td bgcolor=\"" + FondoweekDay + "\" class=\"txt\" align=\"center\"><b>&nbsp;" + weekDay[i] + "&nbsp;</b></td>");
	}
			
	stTexto  = "";			
	stTexto += "</tr>\n";
	document.write(stTexto);
	aux = (dia - diaSemana + 1)%7	
	
	if (aux > 1) {
		aux = aux - 7;				
	}

	nS = Math.ceil((DiasMes[mes] - aux + 1)/7);
	
	for (var numSemana = 0; numSemana < nS; numSemana++){
		document.write("<tr>");
		for (i=0; i<7 ; i++){

			if (i > 4) {
				fondo = fndFes;
				clase = "txtFestivo";
			} else {
				fondo = Fondo;
				clase = "txt";
			}
			iAux = aux + i + numSemana*7;
			if (iAux < 1){
				document.write("<td align=\"center\" bgcolor=\"" + fondo +"\" class=\"" + clase +"\">&nbsp;</td>");
			}else if (iAux < DiasMes[mes] + 1 ){
				if (iAux == dia){
					document.write("<td align=\"center\" bgcolor=\"" + fondo +"\" class=\"" + clase +"\"><b>" + iAux + "</b></td>");				
				}else{
					document.write("<td align=\"center\" bgcolor=\"" + fondo +"\" class=\"" + clase +"\">" + iAux + "</td>");
				}
			}else{
				document.write("<td align=\"center\" bgcolor=\"" + fondo +"\" class=\"" + clase +"\">&nbsp;</td>");
			}
		}
		document.write("</tr>");
	}
	stTexto  = "";			
	stTexto += "</tr>\n";
	stTexto += "</table>\n";
	stTexto += "</td>\n";
	stTexto += "</tr>\n";
	stTexto += "</table>\n";
	document.write(stTexto);
}
