
  var calendarImage = "/common/images/calendar.gif";
  var targetURI     = "/missionyearbook/";

  function getPageDate() {
    var uriDatePattern = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/\\d\\d";
// uriDatePattern is a Regular Expression pattern used to extract a URI-encoded date 
    var re = new RegExp(uriDatePattern);
    var pageDate = new Date();
// Get the URI pathname, replacing any forwardslashes with backslashes.
    var dateTxt = window.location.pathname.replace(/\\/g, "/");
    if (re.test(dateTxt)) {
      var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
      dateTxt = re.exec(dateTxt)[0];
      var monthTxt = dateTxt.substr(0,3);
      var monthIdx = 0;
      while (monthTxt != months[monthIdx]) {
        monthIdx++;
      }
      pageDate.setMonth(monthIdx);
      pageDate.setDate(dateTxt.substr(4,2));
    }
    return pageDate; 
  }

  function navToDate(dateTxt) {
// The format of dateTxt is specified by the jQuery UI Datepicker dateFormat config
    if (dateTxt && dateTxt.value != "") {
      var URIp = window.location.protocol;
      var URIh
      if (URIp == "file:") {
        URIp = "http:";
        URIh = "staging.pcusa.org";
      }
      else {
        URIh = window.location.host;
      }
      window.location.href = (URIp + "//" + URIh + targetURI + dateTxt.value + ".htm"); 
    }
  }

// Configure and initialize the jQuery UI Datepicker
  $(function() {
    var dp = $("#datepicker");
    var pageDate = getPageDate();
    dp.datepicker({
      showOn: 'button',
      buttonImage: calendarImage,
      buttonText: 'Select a reading from the Mission Yearbook',
      buttonImageOnly: true,
      changeMonth: true,
      dateFormat: 'M/dd',
      defaultDate: pageDate
    });
    dp.datepicker('setDate', pageDate);
  });
