// Days of the week
d = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

// Months of the year
m = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

// No. of days in each month.
nd = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

// Get todays date
today = new Date();
day  = today.getDay();
date = today.getDate();
month = today.getMonth();
year = today.getYear();

// Adjust no. of days in Feb. based on whether this is a leap year or not.
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) nd[1] = 29;

// If not sunday, then go back to last sunday.
if (day>0){
  date -= day;
  if (date<1){
    if (month>0){
      month--;
      date += nd[month];
    }     
    else{
      month = 11;
      year -= 1;
      date += nd[11];
    }  
  }
  // Update the modified date object.
  today.setDate(date);
  today.setMonth(month);
  today.setYear(year);
}

// Fix y2k bug.
if (year < 2000)    
year = year + 1900;

// Output the results
document.write(d[today.getDay()]+" "+m[today.getMonth()]+" ");
document.write(today.getDate()+", " + today.getYear());
