<!--

// Function library to return flat activity and tide information

// Author: Roger Bray specifix@bray.net.nz
// This script copywrite Specifix - ALL RIGHTS RESERVED

// Requires both activity.js and tides.js
// Host page must include activity.ccs

 


//****************************************************************************************
// FlatLine - write a one day line of activity
//****************************************************************************************


function FlatLine(month,day) {  

 // day
 document.write('<TR ALIGN=RIGHT><TD ALIGN=RIGHT><B>' + day + ' ' + actvmonths[month-1].slice(0,3) + '</B></TD><TD>&nbsp &nbsp </TD>');

 // activities
 for (j=0; j<3; j++) {
   document.write('<TD ALIGN=LEFT><SPAN cLASS=ActvCell' + actvclass[j] +'>' + actvdaya[j] + '</SPAN></TD><TD>&nbsp &nbsp </TD>');
 }

 document.write('<TD>&nbsp &nbsp &nbsp &nbsp </TD>');

 // tides
 for (j=0; j<4; j++) {
   document.write('<TD><SPAN cLASS=TideCell');
   if (tideday[j] < 600 || tideday[j] > 1800 ) document.write('N>')
   else document.write('D>');
   document.write(tideday[j]);
   document.write(' &nbsp </SPAN><SPAN cLASS=TideCell');
   if (tidehgt[j] > 2) document.write('H>')
   else document.write('L>');
   document.write(tidehgt[j] + '</SPAN>&nbsp &nbsp</TD>');
 }

 document.write('</TR>');

 // continuation

 if (actvmax >3) {

   // day
   document.write('<TR ALIGN=RIGHT><TD ALIGN=RIGHT><B> ...and</B></TD><TD>&nbsp &nbsp </TD>');

   // activities
   for (j=3; j<actvmax; j++) {
     actvclno = j;
     while (actvclno >2) actvclno = actvclno-3;
     document.write('<TD ALIGN=LEFT><SPAN cLASS=ActvCell' + actvclass[actvclno] +'>' + actvdaya[j] + '</SPAN></TD><TD>&nbsp &nbsp </TD>');
   }

 }

}

//****************************************************************************************
// FlatTerm - write dated message
//****************************************************************************************


function FlatTerm(month,day,message) {  

// day
 document.write('<TR ALIGN=RIGHT><TD ALIGN=RIGHT><B>' + day + ' ' + actvmonths[month-1].slice(0,3) + '</B></TD><TD>&nbsp &nbsp </TD>');
// description
 document.write('<TD ALIGN=LEFT COLSPAN=5>&nbsp &nbsp &nbsp --- --- ---<SPAN cLASS=TideCellH> Term ' + 
   Math.round(month/3 + 0.34)  + ' ' + message + ' </SPAN>--- --- ---</TD><TR>');
}


//****************************************************************************************
// FlatHead - write column headers
//****************************************************************************************

function FlatHead() {  

  document.write('<TABLE CLASS=Actv BORDER=0 CELLSPACING=0>' +
   '<TR CLASS=ActvDH ALIGN=RIGHT><TD>Date</TD><TD>&nbsp &nbsp </TD>' +
   '<TD ALIGN=LEFT><SPAN cLASS=ActvCell' + actvclass[0] +'>Daytime</SPAN></TD><TD>&nbsp &nbsp </TD>' +
   '<TD ALIGN=LEFT><SPAN cLASS=ActvCell' + actvclass[1] +'>Afternoon</SPAN></TD><TD>&nbsp &nbsp </TD>' +
   '<TD ALIGN=LEFT><SPAN cLASS=ActvCell' + actvclass[2] +'>Night</SPAN></TD><TD>&nbsp &nbsp </TD>' +
   '<TD>&nbsp &nbsp &nbsp &nbsp </TD>');

  for (j=0; j<4; j++) {
    document.write('<TD CLASS=TideCellF><SPAN cLASS=TideCellC><B>Time&nbsp &nbsp Hgt&nbsp &nbsp</B></SPAN></TD>');
  }

  document.write('</TR>');

  skipline =0;
}

//****************************************************************************************
// FlatMonth - build a flat table with months's activities
//****************************************************************************************

function FlatMonth(month) {  

  if (month < 1 || month > 12) {
    today = new Date();
    month = today.getMonth() +1;
  } 

  document.write('<TABLE CLASS=Actv BORDER=0 CELLSPACING=0><TR CLASS=ActvM ALIGN=CENTER>' +
   '<TD><FONT size=-2>North Shore Centre for<BR>Maritime Education </FONT></TD>' +
   '<TD>&nbsp<A HREF=' + actvhome + '><IMG SRC=' + actvhomeimg + ' BORDER=0></A>&nbsp');

  mthwrk = month;
  mthwrk--;
  if (mthwrk < 1) mthwrk=12;     
  if (month == actvstartmth) document.write('&nbsp')
    else document.write('<A HREF=' + document.location.pathname + '?m=' + mthwrk +
    '><IMG SRC=' + actvnavprev +' BORDER =0 WIDTH=20 HEIGT=20></A>');

  document.write('</TD><TD>Activities for ' + actvmonths[month-1] + '</TD><TD>');

  mthwrk = month;
  mthwrk++;
  if (mthwrk > 12) mthwrk=1;     
  if (mthwrk == actvstartmth) document.write('&nbsp')
    else document.write('<A HREF=' + document.location.pathname + '?m=' + mthwrk +
    '><IMG SRC=' + actvnavnext +' BORDER =0 WIDTH=20 HEIGT=20></A>');

  document.write('&nbsp<A HREF=' + actvclndr + '?m=' + month + '><IMG SRC=' + actvclndrimg + ' BORDER=0></A>' +
   '&nbsp<A HREF=' + actvyear + '><IMG SRC=' + actvyearimg + ' BORDER=0></A>&nbsp</TD>' +
   '<TD><FONT size=-2>Please notify any changes to<BR><A HREF="mailto:maritime@bray.net.nz?subject=Timetable">maritime@bray.net.nz</A></FONT></TD></TR>' +
   '</TABLE>');

  FlatHead();

  for (day = 1; day <= actvmaxday[month-1]; day++) {
   if (day == termstart[month-1]) FlatTerm(month,day,'Begins');

   actvcnt = 0;
   actvcnt = ActvGet(month,day);
   if (actvcnt >0) {
      TideGet(month,day);
      FlatLine(month,day);
      skipline =0;
   } else if (skipline == 0) {
       document.write('<TR ALIGN=CENTER><TD COLSPAN=11>&nbsp</TD></TR>');
       skipline =1;
   }
   if (day == termstop[month-1]) FlatTerm(month,day,'Ends &nbsp');
  }

  document.write('</TABLE>');
}


//****************************************************************************************
// FlatMenuA - build a menu of activities
//****************************************************************************************

function FlatMenuA(astart,aend) {

  if (aend < 1 || aend >= actvcode.length) aend = actvcode.length-1;
  if (astart < 1 || astart > aend) astart = 1;

  for (actwrk = astart; actwrk <= aend; actwrk++) {
    if (actwrk == 11 || actwrk == 17 || actwrk == 21) document.write('<BR>'); 
    document.write('<BR><A HREF=' + document.location.pathname + '?a=' + actwrk + ' TARGET=_top>' + 
     actvname[actwrk] + '</A>');
  }
}

//****************************************************************************************
// FlatMenuM - build a menu of months
//****************************************************************************************

function FlatMenuM() {
  FlatMenuML(actvstartmth-1,11);
  if (actvstartmth > 1)  FlatMenuML(1,actvstartmth-2);
}

function FlatMenuML(astart,aend) {
  for (actwrk = astart; actwrk <= aend; actwrk++) {
    j=actwrk+1;
    document.write('<BR><A HREF=' + actvlist + '?m=' + j + ' TARGET=_top>' + 
     actvmonths[actwrk] + '</A>');
  }
}

//****************************************************************************************
// FlatActv - build a flat table for chosen activity
//****************************************************************************************

function FlatActv(actv) {  

  if (actv < 1 || actv >= actvcode.length) {
    actv = 0;
  }

  //pagehead
  document.write('<TABLE CLASS=Actv BORDER=0 CELLSPACING=0><TR CLASS=ActvM ALIGN=CENTER>' +
   '<TD><FONT size=-2>North Shore Centre for<BR>Maritime Education </FONT></TD>' +
   '<TD>&nbsp<A HREF=' + actvhome + '><IMG SRC=' + actvhomeimg + ' BORDER=0></A>&nbsp');

  actwrk = actv;
  actwrk--;
  if (actwrk < 1) document.write('&nbsp')
    else document.write('<A HREF=' + document.location.pathname + '?a=' + actwrk +
    '><IMG SRC=' + actvnavprev +' BORDER =0 WIDTH=20 HEIGT=20></A>');

  document.write('</TD><TD>Dates for ' + actvname[actv] + '</TD><TD>');

  actwrk = actv;
  actwrk++;
  if (actwrk >= actvcode.length || actv < 1) document.write('&nbsp')
    else document.write('<A HREF=' + document.location.pathname + '?a=' + actwrk + 
    '><IMG SRC=' + actvnavnext +' BORDER =0 WIDTH=20 HEIGT=20></A>');

  document.write('&nbsp<A HREF=' + actvclndr + '><IMG SRC=' + actvclndrimg + ' BORDER=0></A>');

  if (actv < 1) document.write('&nbsp<A HREF=' + actvlist + '><IMG SRC=' + actvlistimg + ' BORDER=0></A>') 
   else document.write('&nbsp<A HREF=' + actvyear + '><IMG SRC=' + actvyearimg + ' BORDER=0></A>');

  document.write('&nbsp</TD>' +
   '<TD><FONT size=-2>Please notify any changes to<BR><A HREF="mailto:maritime@bray.net.nz?subject=Timetable">maritime@bray.net.nz</A></FONT></TD></TR>' +
   '</TABLE>');

  // no activity - do menu
  if (actv < 1 || actv >= actvcode.length) {
    document.write('<P><CENTER><TABLE><TR ALIGN=LEFT VALIGN=TOP><TD><SPAN CLASS=ActvCellT>Please choose an activity</SPAN><BR>');
    FlatMenuA(0,0);
    document.write('</TD><TD WIDTH=28% ALIGN=CENTER>or</TD><TD><SPAN CLASS=ActvCellT>Please choose a Month</SPAN><BR>');
    FlatMenuM();
    document.write('</TD></TR></TABLE><CENTER>');
    return(0);
  }

  // do activity list
  FlatHead();

  month = actvstartmth;
  skipline =1;
  for (mcnt=1; mcnt<13; mcnt++) {
    for (day = 1; day <= actvmaxday[month-1]; day++) {
      if (actv < 11 && day == termstart[month-1]) {
        if (skipline == 0) {
            document.write('<TR ALIGN=CENTER><TD COLSPAN=11>&nbsp</TD></TR>');
            skipline =1;
        }
        FlatTerm(month,day,'Begins');
      }
      for (k=0; k<4; k++) {
        try {
          actvwork = activitys[month][day][k];
          if (actvwork == actvcode[actv]) {
            ActvGet(month,day);
            TideGet(month,day);
            FlatLine(month,day);
            skipline =0;
            k=3;
          } else if (skipline == 0) {
            document.write('<TR ALIGN=CENTER><TD COLSPAN=11>&nbsp</TD></TR>');
            skipline =1;
          }
        }
        catch(e) {
          k =3;
        }
      }
      if (actv < 11 && day == termstop[month-1]) {
        FlatTerm(month,day,'Ends &nbsp');
        skipline =0;
      }
    }
    month++;
    if (month > 12) month =1;
  }

  document.write('</TABLE>');
}

//-->

