///////////////////////////////////////////////////////////////////
// Copyright (c) 2001 Nebula Internet Software, LLC
///////////////////////////////////////////////////////////////////

var days = new Array(7);

days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";

var months = new Array(12);

months[1]  = "January";
months[2]  = "February";
months[3]  = "March";
months[4]  = "April"; 
months[5]  = "May";
months[6]  = "June";
months[7]  = "July";
months[8]  = "August"; 
months[9]  = "September";
months[10] = "October";
months[11] = "November"; 
months[12] = "December";

var monthdays = new Array(12);

monthdays[1]  = 31;
monthdays[2]  = 28;
monthdays[3]  = 31;
monthdays[4]  = 30; 
monthdays[5]  = 31;
monthdays[6]  = 30;
monthdays[7]  = 31;
monthdays[8]  = 31; 
monthdays[9]  = 30;
monthdays[10] = 31;
monthdays[11] = 30; 
monthdays[12] = 31;

function initialize()
  {
   /*  Get the Starting Month/Year and Number of months from the view calendar frame. The context
    *  is: parent.[frame name].getFirstDay();
    *  or: parent.frame[index].getFirstDay();
    *
    *  var firstDay  = parent.frames[0].getFirstDay();
    *  var numMonths = parent.frames[0].getNumMonths();
    */
   var firstDay  = parent.View_Calendar.getFirstDay();
   var numMonths = parent.View_Calendar.getNumMonths();

   // The undefined property indicates that the number of months variable has not been assigned
   // a value.
   if(numMonths == undefined)
     {
      return false;
     }

   var background   = "#F0E68C"			// Background color - Khaki.
   var todayBgColor = "#00FFFF"; 		// Current day's background color - Aqua or Cyan.

   var highlightDay = "#FAFAD2"; 		// Highlight background color - Light Goldenrod Yellow.

   var cellwidth    = "35"; 			// Width of cell in pixels.

   var sunColor     = "#FF0000";  		// Sunday font color - Red.
   var satColor     = "#0000FF";  		// Saturday font color - Blue.
   var todayColor   = "#000080"; 		// Today's color - Navy.

   var fontColor    = "#000000"; 		// Font color - Black.
   var borderColor  = "#0000FF"; 		// Border color - Blue.

   var numMonths = parent.frames[0].getNumMonths();
   var firstDay  = parent.frames[0].getFirstDay();

   var text = "<font class=\"title\" size=\"3\" color=\"" + fontColor + "\"><b>";

   text += getDateStr(new Date());
   text += "</b></font><br><br>";

   var tempYear;

   for(j = 0; j < numMonths; j++)
      {
       text    += "<table border=\"2\" cellpadding=\"5\" bgcolor=\"" + background + "\" bordercolor=\"" + borderColor + "\">";
       tempYear = getFullYear(firstDay);

       if( ((tempYear % 4 == 0) && (tempYear % 100 != 0)) || (tempYear % 400 == 0) )
         {
          monthdays[2] = 29;
	 }
       else
         {
	  monthdays[2] = 28;
	 }

       month    = firstDay.getMonth();
       ndays    = monthdays[month+1];		
       startDay = firstDay.getDay();

       text += "<tr>";
       text += "<th class=\"borderMonth\" colspan=\"7\"><font color=\"" + fontColor + "\">";
       text +=  getMonthStr(firstDay);
       text += "</font></th>";
       text += "</tr>";

       text += "<tr>";
       text += "<th class=\"borderDay\" width=\"" + cellwidth + "\"><font color=\"" + fontColor + "\">Sun</font></th>";
       text += "<th class=\"borderDay\" width=\"" + cellwidth + "\"><font color=\"" + fontColor + "\">Mon</font></th>";
       text += "<th class=\"borderDay\" width=\"" + cellwidth + "\"><font color=\"" + fontColor + "\">Tue</font></th>";
       text += "<th class=\"borderDay\" width=\"" + cellwidth + "\"><font color=\"" + fontColor + "\">Wed</font></th>";
       text += "<th class=\"borderDay\" width=\"" + cellwidth + "\"><font color=\"" + fontColor + "\">Thu</font></th>";
       text += "<th class=\"borderDay\" width=\"" + cellwidth + "\"><font color=\"" + fontColor + "\">Fri</font></th>";
       text += "<th class=\"borderDay\" width=\"" + cellwidth + "\"><font color=\"" + fontColor + "\">Sat</font></th>";
       text += "</tr>";

       text += "<tr>";

       column = 0;
       
       for(i = 0; i < startDay; i++)
          {
	   text  += "<td class=\"borderDay\"><br></td>";
 	   column++;
	  }

       for(i = 1; i <= ndays; i++)
          {
           if(isCurrentDay(firstDay, i))
             {
              text += "<td class=\"borderDay\" align=\"center\" bgcolor=\"" + todayBgColor + "\"";
	      text += " onMouseOver=\"style.background=\'" + highlightDay + "\'; return true\"";
	      text += " onMouseOut =\"style.background=\'" + todayBgColor + "\'; return true\">";
	     }
           else
             {
	      text += "<td class=\"borderDay\" align=\"center\"";
	      text += " onMouseOver=\"style.background=\'" + highlightDay + "\'; return true\"";
	      text += " onMouseOut =\"style.background=\'" + background + "\'; return true\">";
	     }

	   if(isCurrentDay(firstDay, i))
             {
	      text += "<font  color=\"" + todayColor + "\"><b>";
	     }
           else if(column == 0)
             {
	      text += "<font color=\"" + sunColor + "\">";
	     }
           else if(column == 6)
             {
	      text += "<font color=\"" + satColor + "\">";
	     }
           else
             {
	      text += "<font color=\"" + fontColor + "\">";
	     }

	   text += i;

	   if(isCurrentDay(firstDay, i))
             {
	      text += "</b>";
	     }

	   text += "</font>";

	   text += "</td>";

	   if(i >= ndays)
             {
	      while(column < 6)
                {
		 text += "<td class=\"borderDay\"><br></td>";
		 column++;
		}
	     }

	   column++;

	   if(column == 7)
             {
	      text  += "<tr>";
	      column = 0;
	     }
          }

       firstDay.setMonth(firstDay.getMonth() + 1);
       text += "</table><br>";
      }

   text += "<table align=\"Center\">";

   text += "<!-- Print Page button. -->";
   text += "<tr>";
   text += "<td valign=\"Top\">";
   text += "<table border=\"2\" align=\"Center\" cellspacing=\"0\" cellpadding=\"0\">";
   text += "<tr>";
   text += "<td bgcolor=\"#C0C0C0\"><input type=\"Button\" class=\"button01\"";
   text += " onmouseover=\"this.className='button02'\"";
   text += " onmouseout =\"this.className='button01'\" value=\"Print Page\" onclick=\"window.print()\">";
   text += "</td>";
   text += "</tr>";
   text += "</table>";
   text += "</td>";
   text += "</tr>";

   text += "</table>";

   document.write(text);
  }

function getMonthStr(theDate)
  {
   return months[theDate.getMonth()+1] + " " + getFullYear(theDate);
  }

function getFullYear(theDate)
  {
   var year = theDate.getYear();

   // Older versions of Netscape and IE 5.0 deal with the millenium differently.
   // This HACK fixes those problems.
   if(year  < 1900)
     {
      year += 1900;
     }

   return year;
  }

function getDateStr(theDate)
  {
   return days[theDate.getDay()+1] + ":  " + " " + months[theDate.getMonth()+1] + " "+ theDate.getDate() + ", " + getFullYear(theDate);
  }

function isCurrentDay(date, day)
  {
   var today = new Date();

   if(today.getDate() == day && today.getMonth() == date.getMonth() && today.getYear() == date.getYear())
     {
      return(true);
     }

   return false;
  }
