//
// Program wyświetla kalendarz Manny na dowolny miesiąc w roku.
// Jako parametr należy podać numer miesiąca (1-12).
// (c) 1999 Piotr Wasilewski <Wasilewski@Jezus.pl>
//

function Manna( data )
{
  var par = "http://www.biblia.net.pl/cgi-bin/manna.cgi?"
  par += data
  var win3=window.open( par, "" , "width=250,height=450,noresizable" )
  win3.creator=self
}

function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
   this[0] = m0;
   this[1] = m1;
   this[2] = m2;
   this[3] = m3;
   this[4] = m4;
   this[5] = m5;
   this[6] = m6;
   this[7] = m7;
   this[8] = m8;
   this[9] = m9;
   this[10] = m10;
   this[11] = m11;
}

function MannaCalendar( month )
{
   var monthNames = "Styczeń    Luty       Marzec     Kwiecień   Maj        Czerwiec   Lipiec     Sierpień   Wrzesień   PaździernikListopad   Grudzień   ";
   var today = new Date();
   var thisDay;
   var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

   year = today.getYear()
   thisDay = today.getDate();

   if (month == null)
     month = today.getMonth() + 1;

   if ( (month < 1) || (month > 12) )
   {
     alert("Podano zły miesiąc (" + month + ").\nPrawidłowe wartości to 1-12.");
     exit (1);
   }
   month--;

   // do the classic leap year calculation
   if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
      monthDays[1] = 29;

   // and go back to the first day of the month...
   //firstDay = today;
   var firstDay = new Date();
   firstDay.setDate(1);
   firstDay.setMonth(month);
   // and figure out which day of the week it hits...
   startDay = firstDay.getDay();

   // figure out how many days this month will have...
   nDays = monthDays[firstDay.getMonth()];
   document.write("<TABLE BORDER=0 BGCOLOR=\"#FFFFC8\" WIDTH=\"100%\" style=\"font-size: 10.9px; font-family: arial,helvetica,sans-serif;\">");
   document.write("<TR><TH COLSPAN=7>");
   document.write(monthNames.substring(firstDay.getMonth() * 11,
      (firstDay.getMonth() + 1) * 11));
   document.write(" ");
   document.write(year);
   document.write("<TR><TH>Nie<TH>Pon<TH>Wto<TH>Śro<TH>Czw<TH>Pią<TH>Sob");

   // now write the blanks at the beginning of the calendar
   document.write("<TR>");
   column = 0;
   rows = 0;

   for (i=0; i<startDay; i++)
   {
      document.write("<TD>");
      column++;
   }

   for (i=1; i<=nDays; i++)
   {
      document.write("<TD><CENTER>");
      document.write("<SPAN STYLE='cursor: hand' onClick='Manna(\"");
      if ( i < 10 )
        document.write("0");
      document.write(i);      
      if ( (month+1) < 10 )
        document.write("0");
      document.write(month+1);      
      document.write("\");'><U><B><FONT COLOR=\"#800000\">");
      if ( (i == thisDay) && (month == today.getMonth()) )
         document.write("<B><FONT COLOR=\"#FF0000\">")
      document.write(i);
      if ( (i == thisDay) && (month == today.getMonth()) )
         document.write("</FONT></B>")
      document.write("</FONT></B></U></SPAN>");
      document.write("</CENTER></TD>")
      column++;
      if (column == 7)
      {
         document.write("</TR><TR>");
         rows++;
         column = 0;
      }
   }
   document.write("</TR></TABLE>");
   return "";
} 
