//<!--Hide from JS-Impaired Browsers
function numDaysIn(mth,yr) {
 if (mth==3 || mth==5 || mth==8 || mth==10) return 30;
 else if ((mth==1) && leapYear(yr)) return 29;
 else if (mth==1) return 28;
 else return 31;
}
function leapYear(yr) {
 if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0)
  return true;
 else
  return false;
}
// fixes a Netscape 2 and 3 bug
function getFullYear(d) { // d is a date object
 yr = d.getYear();
 if (yr < 1000)
  yr+=1900;
 return yr;
}
function arr() {
 for (n=0;n<arr.arguments.length;n++) {
  this[n] = arr.arguments[n];
 }
}

//weekdays = new arr("Sun.","Mon.","Tues.","Wed.",
// "Thurs.","Fri.","Sat.");
// *** comment out the one you don't want to use ***
weekdays = new arr("Sunday","Monday","Tuesday","Wednesday",
 "Thursday","Friday","Saturday");
 
//months = new arr("Jan.","Feb.","Mar.","Apr.","May",
// "June","July","Aug.","Sep.","Oct.","Nov.","Dec.");
// *** comment out the one you don't want to use ***
months = new arr("January","February","March","April","May",
 "June","July","August","September","October","November",
 "December");

// Change filename to be the name of this file
var filename="calendar1.htm";
var flg=0;
var today = new Date();

/* You control the size of this calendar
   by specifying the font size (from 1
   through 7) in the var fs below. */
var fs=3;

/* The events array - E - below uses an
     array element for each month from
     Jan thru Dec. The string for each
     month is indexed with a tilde (~), the
     date and a space, followed by the
     event description.  Substitute the
     events you wish here. Use two lines
     (with <BR>) for each. */
/* 
* Note:
* This has now been expanded to a two dimensional array.
* The first index is the year and the second is the month.
*/
E=new arr( 1999, 2000 );
E[1999]=new arr("","","","","","","","","","","","");
E[2000]=new arr("","","","","","","","","","","","");
E[1999][0]="~15 M.L.King Jr.<BR>Birthday~";
E[1999][1]="~12 Lincoln's<BR>Birthday~15 John's<BR>"+"60th~21 Erika's<BR>Birthday~22 George's<BR>"+"Birthday~";
E[1999][2]="~2 J-M's<BR>Birthday~17 St Pat's<BR>Day"+"~19 Heidi's<BR>Birthday~28 Good<BR>Friday~3"+"0 Easter<BR>Sunday~";
E[1999][3]="~6 Daylight<BR>Savings~22 Passover<BR>C"+"elebration~";
E[1999][4]="~11 Mother's<BR>Day~17 Armed<BR>Forces~"+"30 Memorial<BR>Day~";
E[1999][5]="~5 <a href='http://justanexamplelink.com'>"+"Example<BR>Link</a>~14 Flag<BR>Day~15 Father's<BR>Day~";
E[1999][6]="~4 Independence<BR>Day~17 Conference<BR>"+"Day~";
E[1999][7]="~15 Summer<BR>Doldrums~";
E[1999][8]="~1 Labor<BR>Day~22 Autumn<BR>First~";
E[1999][9]="~12 Columbus<BR>Day~31 Halloween<BR>Night~";
E[1999][10]="~10 Veteran's<BR>Day~25 Thanksgiving<B"+"R>Day~";
E[1999][11]="~13 <a href='show_121399'>Open House~25 Christmas<BR>Day~";
E[2000][0]="~15 M.L.King Jr.<BR>Birthday~";
E[2000][1]="~2 Groundhog<BR>Day~14 Valentine's<br>Day~21 President's Day~";
E[2000][2]="~17 St. Patrick's<BR>Day~20 Spring<br>Begins~";
E[2000][3]="~16 Palm<BR>Sunday~20 Passover<br>Begins~21 Good<br>"+"Friday~23 Easter<br>Sunday~27 Passover<br>Ends~";
E[2000][4]="~14 Mother's<BR>Day~29 Memorial<br>Day~";
E[2000][5]="~18 Father's<BR>Day~21 Summer<br>Begins~";
E[2000][6]="~4 Independence<BR>Day~";
E[2000][7]="~15 Summer<BR>Doldrums~";
E[2000][8]="~4 Labor<BR>Day~22 Autumn<br>Begins~";
E[2000][9]="~9 Columbus<BR>Day~31 Halloween~";
E[2000][10]="~7 Election<BR>Day~23 Thanksgiving<br>Day~";
E[2000][11]="~21 Winter<BR>Begins~25 Christmas<br>Day~";


/* You can hard code the year by setting
   hard_code_year to true and then setting the
   hard_yr variable to the year you want */
hard_code_year = false; // change to true if desired
hard_yr = 1999; // specify your hard coded year if desired

/* You can hard code the month by setting
   hard_code_date to true and then setting the
   hard_mo variable to the month you want */
hard_code_date = false; // change to true if desired
hard_mo = 11; // 0=Jan, 1=Feb, etc.

/*
* Determine the month that is required.
*/
function getMonth()
{
   if( hard_code_date )
      return( hard_mo );
   
   month=today.getMonth();
   endIndex=location.search.length;

   if( location.search.length > 1 )
   {
      index = location.search.indexOf(",");
      if( index != -1 )
      {
         endIndex=index;
      }

      mon = parseInt(location.search.substring(1,endIndex) );
      if ( ((""+mon).length<=2) && (mon >= 0) && (mon <= 11)) {
         month=mon;
      }
   }
   return( month );
}

/*
* Determine the year that is required.
*/
function getYear() 
{
   if (hard_code_year) {
      return( hard_yr );
   }

   year=getFullYear(today);

   if( location.search.length > 1 )
   {
      index = location.search.indexOf(",");
      if( index != -1 )
      {
         yr = parseInt(location.search.substring(index+1) );
      }
      if ( ((""+yr).length<=4) && (yr >= 1900) && (yr <= 2010)) {
         year=yr;
      }
   }
   return( year );
}

/*
* Output HTML to provide a month selection choice.
*/
function addMonthSelect()
{
   document.write( "<SELECT NAME='monthSelect' SIZE=1>" );
   for( i=0; i<mo; i++ )
   {
      document.write( "<OPTION>"+months[i] );
   }
   document.write( "<OPTION SELECTED>"+months[mo] );
   for( i=mo+1; i<12; i++ )
   {
      document.write( "<OPTION>"+months[i] );
   }
   document.write( "</SELECT>" );
}

/*
* Output HTML to provide a year selection choice.
*/
function addYearSelect()
{
   document.write( "<SELECT NAME='yearSelect' SIZE=1>" );
   for( i=2; i>0; i-- )
   {
      document.write( "<OPTION>"+(yr-i) );
   }
   document.write( "<OPTION SELECTED>"+yr );
   for( i=1; i<3; i++ )
   {
      document.write( "<OPTION>"+(yr+i) );
   }
   document.write( "</SELECT>" );
}

/*
* Handle changing the date from month and year selects.
*/
function changeDate(monthObj, yearObj)
{
   newMonth=monthObj.selectedIndex;
   newYear=yearObj.options[yearObj.selectedIndex].text;
   location.href=filename+"?"+newMonth+","+newYear;
}

/*
* Main calendar generator.
*/
function Calendar()
{
 todayYr=getFullYear(today);
 mo=getMonth();
 yr=getYear();

 bgn=new Date(months[mo]+" 1,"+yr);
 dy=bgn.getDay();
 ld=numDaysIn(mo,yr);

 // Start table
 document.write("<TABLE BORDER=2 BGCOLOR='lightblue'>");
 document.write("<TR><TD ALIGN=CENTER COLSPAN=7>");
 document.write("<FONT SIZE="+(fs+2)+"><B>"+months[mo]+" "+yr+"</B></FONT>");
 document.write("</TD></TR><TR>");

 for (var i=0;i<7;i++){
  document.write("<TD ALIGN=CENTER WIDTH=14%>"
  +"<FONT SIZE=1>"+weekdays[i]+"</FONT></TD>");
 }
 document.write("</TR><TR>");
 ctr=0;
 for (var i=0;i<7;i++) {
  /* If the ctr is less than the day of the
     week determined to be the first day
     of the month, print a space in
     this cell of the table. */
  if (i<dy){
   document.write("<TD ALIGN=CENTER>"
   +"<FONT SIZE="+fs+">&nbsp;</FONT>"
   +"</TD>");
  }
  /* Otherwise, write date and the event,
     if any, in this cell of the table. */
  else {
   ctr++;
   di=i; // carry var i outside this routine
   dupWrt();
  }
 }

 document.write("</TR><TR>");
 while (ctr<ld){
  for (var i=0;i<7;i++){
   ctr++;
   /* If the ctr is greater than the last
      day of the month, print a space in
      this cell of the table. */
   if (ctr>ld){
    document.write("<TD ALIGN=CENTER>"
    +"&nbsp;</TD>");
   }
   /* Otherwise, write date and the event,
      if any, in this cell of the table. */
   else{
    di=i; // carry var i outside this routine
    dupWrt();
   }
  }
  document.write("</TR><TR>");
 }

 // Create prev/next jump links
 jump = "";
 if( ! hard_code_date )
 {
   document.write("<TD colspan=3 align=center>");

   // Prev link
   prevMonth=(mo - 1);
   prevYr=yr;
   if( mo == 0 )
   {
      prevMonth=11;
      prevYr=yr - 1;
   }
   document.write('<a href="'+filename+'?'+prevMonth+','+prevYr+'">&lt;- '+months[prevMonth]+' </a>');

   // Middle
   document.write(" &nbsp; | &nbsp; ");

   // Next link
   nextMonth=(mo + 1);
   nextYr=yr;
   if( mo == 11 )
   {
      nextMonth=0;
      nextYr=yr + 1;
   }
   document.write('<a href="'+filename+'?'+nextMonth+','+nextYr+'"> '+months[nextMonth]+' -&gt;</a>');

   document.write("</TD>");

   // Create quick jump
   document.write( "<TD ALIGN=CENTER COLSPAN=4>" );
   document.write( "<FORM Name='selectForm'>" );
   addMonthSelect();
   addYearSelect();
   document.write( "<INPUT TYPE=BUTTON VALUE='Go' onClick='changeDate"
      +"(document.selectForm.monthSelect,document.selectForm.yearSelect)'>" );
   document.write( "</FORM>" );
   document.write("</TD></TR>");
 }

 document.write("</TABLE>");

}

function dupWrt() {
 document.write("<TD ALIGN=CENTER><FONT SIZE="+fs);
 colorSet=0;
 if ( (mo==today.getMonth()) && (yr==todayYr) && (ctr==today.getDate()) )
 {
  /* Change color to whatever color you wish
     for the current date to be differentiated on
     screen.  I used green here.  */
  document.write(" COLOR='yellow'");
  colorSet=1;
 }
 else if ( (di==0) )
 {
  /* Change color to whatever color you wish
     for Sundays to be differentiated on
     screen.  I used red here.  */
  document.write(" COLOR='gray'");
  colorSet=1;
 }
 /* For dates without an event, an HTML padder
    that will align dates properly with dates
    having an event. Here, space break space. */
 tmp="&nbsp;<BR>&nbsp;";
 /* Then check for event in this month's events
    array for this date. If present, rewrite the
    tmp variable to contain the event. */
 if( E[yr] )
 {
  pos=E[yr][mo].indexOf("~"+ctr+" ");
  if (pos>-1){
   tmp=E[yr][mo].substring(pos+3,E[yr][mo].length);
   pos=tmp.indexOf("~");
   tmp=tmp.substring(0,pos);
   if (colorSet!=1){
    /* Change color to whatever color you wish
       for the events to be differentiated on
       screen.  I used blue here.  */
    document.write(" COLOR='white'");
   }
  }
 }
 document.write("><B>"+ctr+"</B></FONT><BR><FONT SIZE=1>"+tmp+"</TD>");
 }
// End Hiding -->

