// Initialize arrays.
 var months = new Array("Enero", "Febrero", "Marzo",
	"Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre",
	"Octubre", "Noviembre", "Diciembre");
 var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,
	30, 31, 30, 31);
 var days = new Array("Dom", "Lun", "Mar",
	"Mie", "Jue", "Vie", "Sab");

 function getDays(month, year) {
	// Test for leap year when February is selected.
	if (1 == month)
	   return ((0 == year % 4) && (0 != (year % 100))) ||
		  (0 == year % 400) ? 29 : 28;
	else
	   return daysInMonth[month];
 }

 function getToday() {
	// Generate today's date.
	this.now = new Date();
	this.year = this.now.getYear() + 1900; // Returned relative
										   // to 1900
	this.month = this.now.getMonth();
	this.day = this.now.getDate();
 }

 // Start with a calendar for today.
 today = new getToday();

 function newCalendar() {
	today = new getToday();
	var parseYear = parseInt(document.all.year
	   [document.all.year.selectedIndex].text) - 1900;
	var newCal = new Date(parseYear,
	   document.all.month.selectedIndex, 1);
	var day = -1;
	var startDay = newCal.getDay();
	var daily = 0;
	if ((today.year == newCal.getYear() + 1900) &&
		  (today.month == newCal.getMonth()))
	   day = today.day;
	// Cache the calendar table's tBody section, dayList.
	var tableCal = document.all.calendar.tBodies.dayList;
	var intDaysInMonth =
	   getDays(newCal.getMonth(), newCal.getYear() + 1900);
	for (var intWeek = 0; intWeek < tableCal.rows.length;
		  intWeek++)
	   for (var intDay = 0;
			 intDay < tableCal.rows[intWeek].cells.length;
			 intDay++) {
		  var cell = tableCal.rows[intWeek].cells[intDay];

		  // Start counting days.
		  if ((intDay == startDay) && (0 == daily))
			 daily = 1;

		  // Highlight the current day.
		  cell.className = (day == daily) ? "today" : "";

		  // Output the day number into the cell.
		  if ((daily > 0) && (daily <= intDaysInMonth))
			 cell.innerText = daily++;
		  else
			 cell.innerText = "";
	   }
 }

 function getDate() {
	// This code executes when the user clicks on a day
	// in the calendar.
	if ("TD" == event.srcElement.tagName)
	   // Test whether day is valid.
	   if ("" != event.srcElement.innerText)
		  alert(event.srcElement.innerText);
 }

