// File: .../corliss.js
// Author: Dr. George Corliss, MU EECE, August, 2001

// document.write('<p>In course.js</p>\n');

courseBaseCGI = "www.eng.mu.edu/cgi-bin/cgiwrap/corlissg";
w_arr = '<img src="../12assets/zimages/arrow.gif" width="7" height="7" alt="-">';

var noWeeks = 16;
var sp = "&nbsp;";
var BR = "<br>";
var br = BR;
var NL = "\n";
var TBD = "To be determined";
var formActionMethod = '<form action="http://www.eng.mu.edu/cgi-bin/cgiwrap/corlissg/to_corliss.cgi" method="POST">';

var today = new Date();
var isNew = '<img src="../12assets/zimages/new_tiny2.gif" width="32" height="16" alt="NEW">';
var monthName = new Array();
    monthName[0] = 'January';  monthName[1] = 'February';  monthName[2] = 'March';
    monthName[3] = 'April';    monthName[4] = 'May';       monthName[5] = 'June';
    monthName[6] = 'July';     monthName[7] = 'August';    monthName[8] = 'September';
    monthName[9] = 'October';  monthName[10] = 'November'; monthName[11] = 'December';
var Sun = 0;
var Mon = Sun + 1;
var Tue = Mon + 1;
var Wed = Tue + 1;
var Thu = Wed + 1;
var Fri = Thu + 1;
var Sat = Fri + 1;


function isUpdate( d, n ) {
   var then = new Date(d);
   var gap = today.getTime() - then.getTime();
   if (gap <= n*1000*60*60*24) {
      document.write('\n    ' + isNew + '\n    Updated ' + d + '.');
   }
   document.write('<br>\n');
}

function padZero(i) {
  if (i < 10) { return ('0' + i); }
  else { return (i); }
}

function subjToChange(wk) {
   if (wk > thisWeek)
   document.write('Schedule is subject to change');
}


function getDayName(d) {
   dayName = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
   if (d < 0) { d = 0; }
   if (d > 6) { d = 6; }
   return dayName[d];
}


function getDayAbbrev(d) {
   dayName = new Array("Sun.", "Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat.");
   if (d < 0) { d = 0; }
   if (d > 6) { d = 6; }
   return dayName[d];
}


function getMonthName(m) {
   monthName = new Array("January", "February", "March", "April", "May", "June",
                          "July", "August", "September", "October", "November", "December");
   if (m <  0) { m = 0; }
   if (m > 11) { m = 11; }
   return monthName[m];
}

function getMonthAbbrev(m) {
   monthName = new Array("Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.",
                          "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec.");
   if (m <  0) { m = 0; }
   if (m > 11) { m = 11; }
   return monthName[m];
}


function getMonthAndDate(wk, da) {
   if (wk <  1) { wk = 1; }
   if (wk > 17) { wk = 17; }
   if (da <  0) { da = 1; }
   if (da >  6) { da = 5; }
   // There seems to be a bug in the handling of Daylight Savings Time
   // at the beginning of November.  Add an extra hour to the day:
   thisDate = new Date(semesterStartDate.getTime() + (7*wk - 7.9 + da) * (1000 * 60 * 60 * 24) );
   return getMonthName(thisDate.getMonth()) + ' ' + thisDate.getDate();
}

function getMonthSlashDate(wk, da) {
   if (wk <  1) { wk = 1; }
   if (wk > 17) { wk = 17; }
   if (da <  0) { da = 1; }
   if (da >  6) { da = 5; }
   thisDate = new Date(semesterStartDate.getTime() + (7*wk - 7.9 + da) * (1000 * 60 * 60 * 24));
   m = thisDate.getMonth() + 1;
   return m + '/' + thisDate.getDate();
}


function getMonDate(wk, da) {
   if (wk <  1) { wk = 1; }
   if (wk > 17) { wk = 17; }
   if (da <  0) { da = 1; }
   if (da >  6) { da = 5; }
   thisDate = new Date(semesterStartDate.getTime() + (7*wk - 7.9 + da) * (1000 * 60 * 60 * 24));
   return getMonthAbbrev(thisDate.getMonth()) + ' ' + thisDate.getDate();
}


function toLastWeekNextWeek(wk) {
   if (wk == -1) { return; }
   str = '';
   if (wk >  1) { str += '<a href="cal_' + padZero(wk-1) + '.html">&lt; PREV week</a>'; }
   if ( (wk >  1) && (wk < 17) ) { str += ' <b>|</b> '; }
   if (wk < 17) { str += '<a href="cal_' + padZero(wk+1) + '.html">SUCC week &gt;</a>'; }
   document.write(str);
}


function toLastWeekNextAssign(wk) {
   if (wk == -1) { return; }
   str = '';
   if (wk >  1) { str += '<a href="OneAssign' + padZero(wk-1) + '.html">&lt; PREV assign</a>'; }
   if ( (wk >  1) && (wk < 9) ) { str += ' <b>|</b> '; }
   if (wk < 9) { str += '<a href="oneAssign' + padZero(wk+1) + '.html">SUCC assign &gt;</a>'; }
   document.write(str);
}


function lectureScores(wk) {
   str = "";
   for (j = 1; j <= 5; j ++) { 
      if (lectureEvaluation[wk][j] >= 0) {
	     str += getDayName(j) + ": " + lectureEvaluation[wk][j] + br;
	  }
   }
   if (str.length > 1) {
      document.write("<p><b>Lecture evaluation scores:</b><blockquote>" + str + "</blockquote></p>\n");
   }
}

function chaptCrumb(ch) {
   thisChapt = ch; 
   document.write('Ch' + ch + ' ' + Chapter[ch]);
}

function chaptBodyHead(ch) {
   document.write('Discussion Notes on Chapter ' + ch + '<br>' + Chapter[ch]);
}

function subjToChange(wk) {
   if (wk > thisWeek)
   document.write('Schedule is subject to change');
}

function emitAfterUntil(afterDate, untilDate, message) {
   var nowDay   = new Date();
   afterDate = new Date(afterDate);
   untilDate = new Date(untilDate);
   if ( (afterDate <= nowDay) && (nowDay <= untilDate) ) {
      document.write(message);
   }
}


// document.write('<p>In corliss.js</p>\n');

