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

var on_image_url = "/6.01/images/red-line.gif";
var off_image_url = "/6.01/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_601_header() {
   generate_601_menu_bar_header();
//   write_under_construction();
 }

function write_under_construction() {
  document.write("                            \
    <p />                           \
    <center>	                              \
    <table border=3>                \
    <tr>                                      \
    <td bgcolor=yellow>                       \
    This site is still under construction. \
    The information here is subject to change between now    \
    and the beginning of the semester.                           \
    </td></tr>                                 \
    </table>                                   \
    </center>                                  \
")
  }

function generate_601_footer() {
 document.write("<p>&nbsp;</p>");
 generate_601_menu_bar_footer(); 
 document.write("<p />");
 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><a href=\"mailto:6.01-help@mit.edu\">6.01-help@mit.edu</a></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> (<a href=\"mailto:hal@mit.edu\">hal@mit.edu</a>)<br>");
// document.write("<a href= \"http://people.csail.mit.edu/people/lpk\">Leslie Kaelbling</a> (<a href=\"mailto:lpk@mit.edu\">lpk@mit.edu</a>)<br>");
// document.write("<a href= \"http://people.csail.mit.edu/people/tlp\">Tomas Lozano-Perez</a> (<a href=\"mailto:tlp@mit.edu\">tlp@mit.edu</a>)<br>");
 // document.write("<a href= \"http://people.csail.mit.edu/people/teller\">Seth Teller</a> (<a href=\"mailto:teller@csail.mit.edu\">teller@csail.mit.edu</a>)<br>");
 // document.write("<a href= \"http://www.rle.mit.edu/rleonline/People/JacobK.White.html\">Jacob White</a> (<a href=\"mailto:white@mit.edu\">white@mit.edu</a>)<br>");
// document.write(" </address> </font> </td> </tr> </table> </center> </body> </html>");
 document.close();
}


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


function generate_601_menu_bar_header(){
  open_table();
  create_banner();
//we need the extra table here so the cells in the two rows won't try to align
  open_table();
  document.write("<tr>");
  generate_601_menu_bar();
  document.write("</tr>");
  close_table();
  close_table();
}

function generate_601_menu_bar_footer(){
  open_table();
  generate_601_menu_bar();
  close_table();
}

//we don't give a table width here because the banner is fixed width so it's too
//hard to make the banner and the menu width align when the screen resizes
//fix this by redoing the banner to be more shrinkable
function open_table(){
  document.write("<center><table width=100% cellspacing=0 cellpadding=0 border=0 border-collapse=collapse>");
}

function close_table(){
  document.write("</table></center>");
}

//The cascading menu under General Information doesn't work in Internet Explorer.
//What happens with Safari?

function generate_601_menu_bar(){
  var web_root = "/6.01/spring08/";
  document.write("<tr align=center>");
  document.write("</li></td>");

  document.write("<td width=25% class='menucell'><li>");
  document.write("<a href=\"/6.01/index.html\">6.01 Home</a>");
  document.write("</li></td>");

//  document.write("<td width=20% class='menucell'><li>");
//  document.write("<a href=\"" + web_root + "6.188/6.188-home.html\">6.188 home</a>");
//  document.write("</li></td>");

  document.write("<td width=25% class='menucell'><li>");
  document.write("<a href=\"" + web_root + "general-information.html\">General Information</a>");
  document.write("<ul>");
//  document.write("<li><a href=\"" + web_root + "general-information.html\">General Information</a><li>");
  document.write("<li><a href=\"" + web_root + "software/\">Software</a></li>");
  document.write("<li><a href=\"" + web_root + "resource.html\">Resource Material</a></li>");
  document.write("<li><a href=\"" + web_root + "homework-guidelines.html\">Homework guidelines</a></li>");
  document.write("<li><a href=\"" + web_root + "staff.html\">Staff</a></li>");
  document.write("</ul>");
  document.write("</li></td>");
  document.write("<td width=25% class='menucell'><li>");
  document.write("<a href=\"" + web_root + "calendar/\">Calendar</a>");
  document.write("<ul>");
  document.write("<li><a href=\"" + web_root + "calendar/due-dates.html\">Due Dates</a></li>");
  document.write("</ul>");
  document.write("</li></td>");
  document.write("<td width=25% class='menucell'><li>");
  document.write("<a href=\"http://sicp.csail.mit.edu/6.01/\">On-line Tutor</a>");
//  document.write("<ul>");
//  document.write("<li><a href=\"http://sicp.csail.mit.edu/6.01/\">For 6.01</a><li>");
//  document.write("<li><a href=\"http://icampustutor.csail.mit.edu/6.001-for-6.188\">For 6.188</a><li>");
//  document.write("</ul>");
  document.write("</li></td>");
  document.write("</tr>");
}

// create a cell in the menu bar
function create_row_entry(label,target_url){
  //add quotes to arguments for inclusion in event function strings
  //  var qurl = "\"" + target_url + "\"";  
  //  var link_full_tag = "<a href = " + qurl + ">" +  label + "</a>";
//  document.write("<td align=center width=20%  class='menucell'>");
//      document.write("<td class='menucell'><li>foo<ul><li>foo1</li><li>foo2</li></ul></li></td>");
//  document.write(link_full_tag + "</td>");
}	       

//Banner
//Note the stretchable extra blocks to accommodate resizing the window
function create_banner() {
   document.write("<tr>             \
        <td width=15%  bgcolor=#003163>&nbsp;</td>                     \
        <td width=70%><img src=\"/6.01/images/course-banner-601.gif\"></td>       \
        <td width=15% bgcolor=#003163>&nbsp;</td> \
        </tr>")
   }


//-------------------------------------------
// 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;
}

