// Standard Javascript functions for Computer Science pages.
todaysdate = new Date();
months = new Array(
   "January","February","March","April","May","June",
   "July","August","September","October","November","December"
);
function today()
{
   document.write(
     todaysdate.getDate() + " " + months[todaysdate.getMonth()] + " " +
     todaysdate.getFullYear()
   );
}

// Create a login/logout link to the https/http version of the page

function log()
{
   document.write('<a href="');
   url = location.href;
   if (location.protocol == 'http:') url = 'https:' + url.substring(5);
   else url = 'http:' + url.substring(6);
   document.write(url)
   document.write('">')
   if (location.protocol == 'http:') document.write('login');
   else document.write('logout');
   document.write('</a>');
}

// Use a menu to go to a new page.  Reset the menu to its original state, in
// case the "back" button is used on a browser that remembers menu selections.

function gotoPage(menu, originalIndex)
{
   var temp;
   with(menu)
   {
      temp = selectedIndex;
      selectedIndex = originalIndex;
      document.location = options[temp].value;
   }
}

// Set the selected item of a menu according to the value of a page parameter

function setMenu (menu, param)
{
   with(menu)
   {
      params = location.search;
      pos = params.indexOf(param+"=");
      if (pos == -1) return;
      pos = pos + param.length + 1;
      paramval = params.substring(pos, params.length);
      pos = paramval.indexOf("&");
      if (pos >= 0) paramval = paramval.substring(0, pos);
      selectedIndex = 0;
      for (i=0; i<options.length; i++)
      {
         if (options[i].text == paramval) selectedIndex = i;
      }
      if (selectedIndex != 0) document.bgColor = '#FAFAA0';
   }
}
