/*
        date_display.js - Object to write out the current date.
*/

/* constructor
*/
function DateDisplay(elem) {
  this.elem = xgetElementById(elem);
  this.m = new Array(
    "January", "February", "March", "April",
    "May", "June", "July", "August",
    "September", "October", "November", "December"
  );

  this.d = new Array(
    "Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday"
  );
}

/*
  function to write out the date
*/
DateDisplay.prototype.writeDate = function() {
  if (this.elem != null) {
    today = new Date();
    day = today.getDate();
    end = "th";

    if (day==1 || day==21 || day==31) end="st";
    if (day==2 || day==22) end="nd";
    if (day==3 || day==23) end="rd";
    day += end;

    date = this.d[today.getDay()] + " " + this.m[today.getMonth()] + " " + day;
    this.elem.innerHTML = date;
  }
}

/*
  function to add a DateDisplay object that writes to a specific DOM element.
*/
function addDateDisplay(elem) {
  (new DateDisplay(elem)).writeDate();
}

