/* javascript.internet.com - scripts.franciscocharrua.com */
function dspcalendar(date) {
  // If no parameter is passed use the current date.
  if(date == null)
     date = new Date();

  day = date.getDate();
  month = date.getMonth();
  year = date.getFullYear();

  months = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Setiembre','Octubre','Noviembre','Diciembre');

  this_month = new Date(year, month, 1);
  next_month = new Date(year, month + 1, 1);

  // Find out when this month starts and ends.
  first_week_day = this_month.getDay();
  
  //poner el dia de la semana en cristiano
  first_week_day = first_week_day -1;
  if (first_week_day<0) first_week_day=6;
  
  //calcula cuantos dias hay en este mes
  days_in_this_month = Math.round((next_month.getTime() - this_month.getTime()) / (1000 * 60 * 60 * 24));

  //tabla general del calendario
  calendar_html = '<table class="dspcalTable">';

  //titulo del mes y aņo
  calendar_html += '<tr><td colspan="7" class="dspcalTitle"">' + months[month] + ' ' + year + '</td></tr>';
  calendar_html += '<tr>';

  // Fill the first week of the month with the appropriate number of blanks.
  for(week_day = 0; week_day < first_week_day; week_day++) {
    calendar_html += '<td class="dspcalWeek1"> </td>';
  }

  week_day = first_week_day;
  for(day_counter = 1; day_counter <= days_in_this_month; day_counter++) {
    week_day %= 7;
    if(week_day == 0)
      calendar_html += '</tr><tr>';
    //seņalar sabados y domingos
    ExtraClass="";
    if(week_day == 5) ExtraClass=" dspcalSab";
    if(week_day == 6) ExtraClass=" dspcalDom";    

    // Do something different for the current day.
    if(day == day_counter)
      calendar_html += '<td class="dspcalHoy'  + ExtraClass + '">' + day_counter + '</td>';
    else
      calendar_html += '<td class="dspcalDias' + ExtraClass + '"> ' + day_counter + ' </td>';

    week_day++;
  }

  calendar_html += '</tr>';
  calendar_html += '</table>';

  // Display the calendar.
  document.write(calendar_html);
}
