/********************************************************************* 

  Javascript code for Design Concepts in Programming Languages Web Supplement 
 
  Author: Lyn Turbak 

  History:
   + 8/20/08 Created
   + 8/23/08 Added unavailable links for links to pages that currently have no content.

 ********************************************************************/

/* Write the HTML for the standard DIVs of a DCPL page. 

   selected_file is the (extensionless) name of the displayed page,
     which has a different appearance in the navbar. 

   page_title is the title of the displayed page, which appears in the banner. 

*/
function write_standard_divs(page_title) {
  write_pic();
  write_banner(page_title);
  write_navbar(page_title);
}


/* Write the HTML for the inuksuk picture */
function write_pic() {
  document.write(
     '"<DIV id="pic">'
     + '<IMAGE src="inuksuk-web.jpg" width=175px>'
     + '</DIV>'
  );
}

/* Write the HTML for the banner. 

   page_title is the title of the displayed page. */
function write_banner(page_title) {
  document.write(
    '<DIV id="banner">'
    + '<SPAN class="booktitle">Design Concepts in Programming Languages</SPAN>'
    + '<BR>'
    + '<SPAN class="authors">by Franklyn Turbak and David Gifford with Mark A. Sheldon</SPAN>'
    + '<BR>'
    + '<BR>'
    + '<SPAN class="supplementtitle">Web Supplement:</SPAN> <SPAN class="supplementlocation">'
  );
  document.write(page_title);
  document.write(
     '</SPAN>'
     + '</DIV>'
  );
}

function write_navbar(selected_page) {
/* Goal is to write a navbar that looks like: 

  <DIV id="navbar">
   <UL>
    <LI><A class="selected" href="index.html">Home</A></LI>
    <LI><A href="http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=11656">MIT Press</A></LI>
    <LI><A href="http://www.amazon.com/Design-Concepts-Programming-Languages-Franklyn/dp/0262201755/ref=sr_1_1?ie=UTF8&s=books&qid=1219097355&sr=8-1">Amazon</A></LI>
    <LI><A href="bugs.html">Bug List</A></LI>
    <LI><A href="supplements.html">Chapter Supplements</A></LI>
    <LI><A href="additional.html">Additional Materials</A></LI>
    <LI><A href="software.html">Software</A></LI>
    <LI><A href="course.html">6.821 Course</A></LI>
    <LI><A href="news.html">News</A></LI>
   </UL>
  </DIV>  

Only one of the links (the one matching selected_page) should be selected.

*/

   var write_link = function (pagetitle, url, comment) {
    /* Write a link in one of the following two forms: 

         <LI><A href="[url]" title="commment">[pagetitle]</A></LI>
         <LI><A class="selected" href="[url] title="[comment]">[pagetitle]</A></LI>

       The class="selected" attribute is only set when [pagetitle] matches [selected_page]

    */
      document.write('<LI><A');
      if (pagetitle == selected_page) {
	  document.write(' class="selected" ');
      }
      document.write(' href="');
      document.write(url);
      document.write('" title="');
      document.write(comment);
      document.write('">');
      document.write(pagetitle);
      document.write('</A></LI>\n');
  }

   var write_unavailable_link = function (pagetitle, url, comment) {
    /* Write a link with the following form: 

         <LI><A class="unavailable" href="[url]" onclick="return false;" title="This content is not available">[pagetitle]</A></LI>

       Note that comment is ignored.

    */
      document.write('<LI><A class= "unavailable" href="');
      document.write(url);
      document.write('" onclick="return false;" title="This content is not yet available">');
      document.write(pagetitle);
      document.write('</A></LI>\n');
  }


  /* Start of DIV and list */
  document.write(
    '<DIV id="navbar">'
    + '<UL>'
  );

  /* Individual links */
  write_link("Home", "index.html", "Home page for DCPL Web Supplement");
  write_link("MIT Press", 
             "http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=11656",
              "MIT Press web site for DCPL");
  write_link("Amazon", 
             "http://www.amazon.com/Design-Concepts-Programming-Languages-Franklyn/dp/0262201755/ref=sr_1_1?ie=UTF8&s=books&qid=1219097355&sr=8-1",
             "Amazon web site for DCPL");
  write_link("Bug List", "bugs.html", "Errata for DCPL");
  write_unavailable_link("Chapter Supplements", "supplements.html",
                         "Supplementary material for DCPL chapters");
  write_unavailable_link("Additional Materials", "additional.html",
                         "Concurrency, Scheme+, Definitional Interpreters, etc.");
  write_unavailable_link("Software", "software.html", 
                         "Interpreters, type checkers, etc.");
  write_link("6.821 Course", "course.html", "MIT course on which DCPL is based");
  write_link("News", "news.html", "News about this web supplement");
  /* End of DIV and list */
  document.write(
    ' </UL>\
     </DIV>'
  );


}

