Source Code for:
"Prototyping an Advanced Calendar Class: Using JavaScript, part two," Vol. 2, Issue 10, p. 56

Listing 1.
function f_sequence_value()
{
    if ( (x=GetCookie("sequenceValue")) != null ){
        this.meeting_number = parseInt(x)+ 1;
    }
    else {
        this.meeting_number=0;
    }
    SetCookie('sequenceValue', "" +
                this.meeting_number, g_expiry_date)
    return this.meeting_number;
}

Listing 2: How the meeting object reads data.
//  Meeting.parse_meeting
function parse_meeting( s )
{
    //
    // Parameter s is a substring of the Month
    // cookie representing a formatted meeting
    //
    var startpos = 0;
    var endpos = 0;

    if ( s == null ) {
        return 1;
    }
    for ( i=0; i <= 9; i++ ) {
        endpos = s.indexOf('~',startpos);
        if ( endpos == -1 ) {
            alert("Invalid String - " + s +
                     "\nat Position " + i );
            return -1;
        }
        if ( startpos != endpos ) {
            // field has data
            this[i] = s.substring(
                              startpos, endpos );
        }
        startpos = endpos + 1;
        }
    return 0;
}

Listing 3
    // split the month into an array of formatted meetings
    a = GetCookie(month).split("|");
    for (var i = 0; i <= ( a.length-1 ); i++ )
    {
        // split the meeting into fields
        var m = a[i].split("~");
        // check the relevant field
        if ( m[7] = day_required ) {
            this.current_meeting = new meeting(m)
        }
    }

Listing 4: The Day object reads the Calendar Data and asks the Meeting in that Day to construct itself.
// Day.parse_meeting
// p_day is the day of month
function parse_meeting( p_day )
{
    // string to store month cookie
    var current_month=null;

    // start of meeting for day
    var startpos = 0;

    // end of meeting for day
    var endpos = 0;

    // extracted day number of meeting
    var thisday;

    // true if day number is requested day
    var do_his_day = false;

    //
    // fetch the cookie which contains the meetings
    // for the month
    //
    var s = 0;
    current_month = GetCookie(
                "M"+ this.month + this.year );
    if ( current_month == null ) {
        return -1
    }

    //
    // extract meetings which belong to this day
    //
    while ( s <= (current_month.length - 1) )
    {
        startpos = s;

        //
        // examine each meeting to see if it
        // belongs in this day
        // ( each meeting has 10 properties
        //  stored in the cookie )
        //
        for ( i=0; i <= 9; i++ )
        {
            // map to the day number portion of
            // the meeting
            endpos = current_month.indexOf('~',s);
            if ( endpos == -1 )
            {
                alert("\n\nEXTRACT MEETING\n\n” +
                         “Invalid String");
                return -1;
            }
            if ( i==7 )
            {
                //
                // only create meeting objects
                // for this day
                //
                thisday = current_month.substring(
                                     s,endpos
                                     );
                if ( thisday == p_day )
                {
                    do_this_day = true;
                }
            }
            s = endpos + 1;
        } // end for
        //
        // only create meeting object for this day
        //
        if ( do_this_day == true )
        {
            l_meeting = current_month.substring(
                        startpos, endpos+1
                         );
            this.current_meeting = new meeting(
                        l_meeting, true
                        );
           do_this_day = false;
        }
    } // end while
    return 0;
}

Listing 5.
function f_format_meeting_data()
{
    var return_value = "";
    for ( var i=0; i<=9; i++) {
        return_value += this[i] + '~'
    }
    return return_value;
}

Listing 6.
function new_meeting( p_meeting )
{
   // p_meeting refers to a Meeting object
   var position_in_day = this.number_of_meetings;
   this[ this.number_of_meetings++ ]= p_meeting;
 
   // return the position of the meeting in the list
   return position_in_day;
}

Listing 7.
<TD>
    <INPUT TYPE="button" NAME="button1"
                   VALUE="SELECT"
      onClick=
         "Calendar.select_calendar( this.form )">
    < INPUT TYPE="reset" NAME="button2"
                    VALUE="RESET">
</TD>

Listing 8.
// the 'this' keyword refers to this
// instance of the calendar object
this.calendar_date =  new Date(
form.year.options[form.year.selectedIndex].value,
form.month.selectedIndex-1,
01
)

Listing 9.
this.load_month();
var doc = parent.frames.cal_res.document;
doc.close ();
doc.open ("text/html");

// return a HTML formatted page
doc.write ( this.renderCalendar () );
doc.close();

Listing 10.
var result =
 ‘<HTML><HEAD><TITLE>Calendar</TITLE></HEAD>’   +
‘<BODY LINK=“#000000” VLINK=“#000000”’ +
               ‘BGCOLOR=“#96CBCB”>  '                 +
'<FORM METHOD=POST ACTION="">'          +
'<CENTER><TABLE BORDER=6 CELLSPACING=2’       +
                                                          ‘CELLPADDING=2>'    +
'<TR><TD BGCOLOR="#800040" ALIGN=CENTER>’      +
          ‘<FONT SIZE=3 COLOR="#000000">’  +
         ‘<B>Sunday</TD>' +
etc.
 

Listing 11:  Draw the Calendar Grid.
for ( var CountRow = 1; CountRow <=6; CountRow++)
{
   result += '<TR ALIGN="right" VALIGN="top">'
   for (var CountColumn = 1;
                CountColumn <=7; CountColumn++)
   {
       if ( start of month and empty cell ) {
           // create blank cell
           result+='<TD align=left’ +
                      ‘BGCOLOR="#FFFFAE"></TD>'
       }
       else {
           // render the meetings in the day,
           //Digit is the day number
           var subject_day = this.month[Digit];

           if ( subject_day != null ){
              // This is the supposedly
              //overriden method in the meeting
             result +=subject_day.render_subject(
                               userPreference1,
                               userPreference2,
                               Digit  );
           }
          else {

            // render an empty day cell
            result+=
            '<TD BGCOLOR="#FFFFFF">'          +
            '<TABLE border =0 WIDTH=100% '  +
            'cellspacing=0cellpadding=6>'    +
            '<TR><TD rowspan = 2 width=50' +
            ' align=center ' +
            // etc ..
            ''</TD></TR></TABLE></TD>'

         } // end if (subject_day is null )
         Digit++

    } // end if (start of month )
} // end for

Listing 12: The Day renders the formatting context of the Meetings within it.
function render_subject(
    userPreference1,  userPreference2, Digit )
{
    l_result=
    '<TD BGCOLOR="#FFFFAE">' +
    '<FORM METHOD=POST ACTION="">' +
    '<TABLE border =0 WIDTH=100% '
        'cellspacing=0 cellpadding=0 valign=top>'
    '<TR><TD rowspan = 2 valign=top ' +
              'BGCOLOR="#FFFFAE">'

    // render subject of meeting within user's preference
    l_result + userPreference1
    endstr = userPreference2 + '</TD>'

    for ( var cnt=0; cnt <= this.number_of_meetings; cnt++ )
    {
        if ( cnt == 4 &&
             userPreference1 == "<FONT SIZE=1>"){
            // display a continuation message
            l_result += 'More ...<BR>';
            break;
        }
        // this[cnt] is a reference to a
        // meeting object
        // this[cnt].render_subject() is a call
        //  to a method of the meeting
        l_result += this[cnt].render_subject(
            userPreference1
             )
    } // end for
    l_result += endstr
    // ...
}

Listing 13: render_subject() method of the meeting object.
// this method is assigned as:
// meeting.render_subject = m_render_subject
function m_render_subject( p_style )
{
    // use the configuration to determine the
    // rendering  requirement
    if ( p_style == calendar.LIST  ||
          p_style == calendar.SLIST ) {
       return '<OPTION VALUE=' +
       this.position_in_meetings_in_day_list+'>'+
       this.subject.substring(0,15);
    }
    else {
        return this.subject.substring(0,11)
        + '<BR>'
    }
}