function countdown_clock() {

//I chose a div as the container for the timer, but
//it can be an input tag inside a form, or anything
//who's displayed content can be changed through
//client-side scripting.
  html_code = '<div id="countdown"></div>';
  document.write(html_code);
  countdown();
}

         
function countdown() {

//  document.write('in countdown');

  var monthName=new Array(12);
  monthName[0]="Jan";
  monthName[1]="Feb";
  monthName[2]="Mar";
  monthName[3]="Apr";
  monthName[4]="May";
  monthName[5]="Jun";
  monthName[6]="Jul";
  monthName[7]="Aug";
  monthName[8]="Sep";
  monthName[9]="Oct";
  monthName[10]="Nov";
  monthName[11]="Dec";

// Difference to GMT in hours -6 Dailight Savings, -7 Standard Time
  var TimezoneOffset = -6  // adjust for time zone
  var localTime = new Date()
  var ms = localTime.getTime() 
    + (localTime.getTimezoneOffset() * 60000)
    + TimezoneOffset * 3600000
  var curtime =  new Date(ms) 

  var end_year = curtime.getFullYear();
  var end_month = PadDigits(curtime.getMonth() + 1,2)             
  var mth = curtime.getMonth();
  var month_name = monthName[mth];
  var week = 0;
  var ends = "";

// Calculate the SISEL week:
  Todays_Day = curtime.getDate();
  if (Todays_Day<8) {
    week  = 1;
    ends  = end_year+"."+end_month+".07&nbsp; 11:59:59 PM"
  }
  if (Todays_Day>7 && Todays_Day<15) {
    week  = 2;
    ends  = end_year+"."+end_month+".14&nbsp; 11:59:59 PM"
  }
  if (Todays_Day>14 && Todays_Day<22) {
    week  = 3;
    ends  = end_year+"."+end_month+".21&nbsp; 11:59:59 PM"
  }
  if (Todays_Day>21) {
    week = 4;
    ends  = end_year+"."+end_month+"."+daysInMonth(curtime.getMonth()+1,end_year)+"&nbsp; 11:59:59 PM"
  }

  display = "<span style=\"color:white; font-size:8pt;\">"+month_name+" week "+week+" Ends:&nbsp; "+ends+"&nbsp;&nbsp;<br />";

  var curyear = curtime.getFullYear();
  var curmonth = PadDigits(curtime.getMonth()+1,2);
  var curdate = PadDigits(curtime.getDate(),2);
  var curhour = curtime.getHours();
  var curmin = curtime.getMinutes();
  var cursec = curtime.getSeconds();
  var time = "";

  if(curhour == 0) curhour = 12;
  time = (curhour > 12 ? curhour - 12 : curhour) + ":" +
    (curmin < 10 ? "0" : "") + curmin + ":" +
    (cursec < 10 ? "0" : "") + cursec + " " +
    (curhour > 12 ? "PM" : "AM");

  display += "Utah, USA:&nbsp; "+curyear+"."+curmonth+"."+curdate+"&nbsp; "+time;
  display += "&nbsp;&nbsp;</span>"
  
//  document.write('testing');
  document.getElementById('countdown').innerHTML = display;

//Recursive call, keeps the clock ticking.
  setTimeout('countdown();', 1000);

}
         

function PadDigits(n, totalDigits) { 
  n = n.toString(); 
  var pd = ''; 
  if (totalDigits > n.length) { 
    for (i=0; i < (totalDigits-n.length); i++) { 
      pd += '0'; 
    } 
  } 
  return pd + n.toString(); 
} 


function daysInMonth(month,year) {
  var m = [31,28,31,30,31,30,31,31,30,31,30,31];
  if (month != 2) return m[month - 1];
  if (year%4 != 0) return m[1];
  if (year%100 == 0 && year%400 != 0) return m[1];
  return m[1] + 1;
}
