// Javascript functions to create 6.805 header bar and menu bar
// This version of the menu bar uses image rollover so that it works
// on Netscape 4.

// Warning: The url names here are absolute and need to be fixed if this
// directory is moved.

var on_image_url = "http://groups.csail.mit.edu/mac/classes/6.805/images/red-line.gif";
var off_image_url = "http://groups.csail.mit.edu/mac/classes/6.805/images/yellow-arrow.gif";
var image_width = 20;
var image_height = 20;

//precache the images
if (document.images) {
   var on_image = new Image(image_width, image_height);
   var off_image = new Image(image_width, image_height);
   on_image.src = on_image_url;
   off_image.src = off_image_url;
}


//----------------------------------------
// Top-level routines

//Call this to generate the menu bar by itself (eventually for page footer)

// Call this to generate the standard header

function generate_6805_header() {
   create_color_bar();
   generate_6805_menu_bar_header();
//   write_under_construction();
 }

function write_under_construction() {
  document.write("                            \
    <center>	                              \
    <table width=50% border=1>                \
    <tr>                                      \
    <td bgcolor=yellow>                       \
    This site is being updated for fall 03. \
    The information here is subject to change between now    \
    and the beginning of the semester.                           \
    </td></tr>                                 \
    </table>                                   \
    </center>                                  \
")
  }

function generate_6805_footer() {
 document.write("<p>&nbsp;</p>");
 generate_6805_menu_bar_footer(); 
 document.write(" <center> <table width=100%> <tr valign=top> <td align=left><font size=-1>");
 document.write("<font size=-1><p>Send comments about this site to ");
 document.write("<i>6.805-staff at mit dot edu</i>");
 document.write("<br>Last modified: ");
 document.write(document.lastModified);
 document.write("</font></td>");
 document.write("<td align=right><font size=-1><address>");
 document.write("<a href= \"http://www-swiss.ai.mit.edu/~hal/hal.html\">Hal Abelson</a>(hal at mit.edu</a>)<br>");
 document.write("Mike Fischer (mfischer at mit dot edu)<br>");
 document.write("<a href=\"http://www.w3.org/People/all#djweitzner\">Danny Weitzner</a> (djweitzner at csail dot mit dot edu)<br>");
document.write("<a href=\"http://www.mit.edu/~shekhar\">Shekhar Krishnan</a> (shekhar at mit dot edu)<br>");
  document.write(" </address> </font> </td> </tr> </table> </center> </body> </html>");
 document.close();
}


//----------------------------------------
// Routines for generating menu

//turn images on and off
function turn_image_off(image_name) {
  if (document.images) {
    document.images[image_name].src = off_image.src;
  }
}

function turn_image_on(image_name) {
  if (document.images) {
    document.images[image_name].src = on_image.src;
  }
}

function set_message(msg) {
  window.status = msg;
  return true;
}

function generate_6805_menu_bar_header(){
  generate_6805_menu_bar_marked("1");
}

function generate_6805_menu_bar_footer(){
  generate_6805_menu_bar_marked("2");
}

// marker is to add to image label to give images distinct names 
function generate_6805_menu_bar_marked(marker){
  document.write("<center><table border=0 callpadding=0 cellspacing=0 bordercolor=yellow width=100%><tr>");
  create_row_entry(marker, "Home", "/mac/classes/6.805/", "Go to course home page");
  create_row_entry(marker,"General Information", "/mac/classes/6.805/admin/admin-fall-2008/general-information.html", "General information about 6.805");
  create_row_entry(marker, "Calendar", "/mac/classes/6.805/admin/admin-fall-2008/calendar.html","Course calendar");
//  create_row_entry(marker, "Announcements", "/mac/classes/6.805/admin/admin-fall-2008/announcements.html", "Course announcements");
  document.write("</tr></table></center>");
}

// create a cell in the table bar

//color should match definition in stylesheet
cell_text_color = "#FFFFFF"
qcell_text_color = "\"" + cell_text_color + "\""
cell_highlight_text_color = "#FFFF00"
qcell_highlight_text_color = "\"" + cell_highlight_text_color + "\""

//some day, fix this so that it works in Netscape 4 as well, i.e., so
//that the image and text color flips when you mouse over text, as it does
//in IE and Netscape 6

function create_row_entry(marker, label,target_url,message){
  //add quotes to arguments for inclusion in event function strings
  var qlabel = "\"" + marker + label + "\"";
  var qurl = "\"" + target_url + "\"";  
  var qmessage = "\"" + message + "\"";
  var qoff_image_url = "\"" + off_image_url + "\"";
  var text_mouse_over_action = "this.style.color =" + qcell_highlight_text_color;
  var text_mouse_out_action = "this.style.color =" + qcell_text_color;
  var image_mouse_over_action = "turn_image_on(" + qlabel + "); return set_message(" + qmessage + ")";
  var image_mouse_out_action ="turn_image_off(" + qlabel + "); return set_message(\"\")";
  var link_mouse_spec = "onMouseOver=" + "\'" +
                         text_mouse_over_action + ";" + image_mouse_over_action + "\'"
                         + "onMouseOut=" + "\'" +
                            text_mouse_out_action +  ";" + image_mouse_out_action + "\'";
  var link_font_spec = "<font color=" + qcell_text_color + link_mouse_spec +">" + label + "</font>";
  var link_full_tag = "<a href = " + qurl + ">" +  link_font_spec + "</a>";
  document.write("<td align=center width=20%  class='menucell'><table border=0><tr><td align=center>");
  document.write("<a href=" + qurl + " ");
  document.write(" onMouseOver=" + "\'" + image_mouse_over_action + "\'");
  document.write(" onMouseOut=" + "\'" + image_mouse_out_action + "\' >");
  document.write("<img src=" + qoff_image_url + " name=" + qlabel +
                   " alt=" + qmessage +
                   " height=" + image_height + " width=" + image_width + " border=0></a></td>");
  document.write("<td class=\'menucell\'>" + link_full_tag + "</td></tr></table></td>");
}	       


//----------------------------------------
//Routines used in generating color bar

function create_color_bar() {
   document.write("<center>                                                     \
	<table cellspacing=0 cellpadding=0 border=0 width=100%>                    \
	<tr><td rowspan=2 bgcolor=red>&nbsp;</td><td bgcolor=blue>&nbsp;</td>   \
	<tr><td bgcolor=black>&nbsp;</td>                                       \
	</table>                                                                \
	</center>");
   }


//-------------------------------------------
// function date_lastmodified() 
// prettier format than built-in document.lastModified
function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y >= 2000)
  {
    y -= 2000;
  }
  if(y >= 100)
  {
    y -= 100;
  }

  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
    ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
    ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
    (10==m)?'Oct':(11==m)?'Nov':'Dec';

  return "" +
    (d<10?"0"+d:d) + "-" +
    mmm + "-" +
    (y<10?"0"+y:y);
}


//
// get last modified date of the 
// current document.
//
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}

