function setDefaultFocus()
{
  $(function() {
    $(".default:first").focus();
  });
}

function parseISO8601(timestamp)
{
  var regex = new RegExp("^([\\d]{4})-([\\d]{2})-([\\d]{2})T([\\d]{2}):([\\d]{2}):([\\d]{2})([\\+\\-])([\\d]{2}):([\\d]{2})$");
  var matches = regex.exec(timestamp);
  if(matches != null)
  {
    var offset = parseInt(matches[8], 10) * 60 + parseInt(matches[9], 10);
    if(matches[7] == "-")
      offset = -offset;
    
    return new Date(
      Date.UTC(
        parseInt(matches[1], 10),
        parseInt(matches[2], 10) - 1,
        parseInt(matches[3], 10),
        parseInt(matches[4], 10),
        parseInt(matches[5], 10),
        parseInt(matches[6], 10)
      ) - offset*60*1000
    );
  }
  return null;
}

var weekDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

function toLocalTime(date)
{
  var hour = date.getHours();
  var ampm = (hour < 12 ? "am" : "pm");
  if (hour == 0)
    hour = 12;
  else if (hour > 12)
    hour -= 12;
  
  var minutes = date.getMinutes();
  if(minutes < 10)
    minutes = "0" + minutes;
  
  return weekDays[date.getDay()] + ", "
       + months[date.getMonth()] + " "
       + date.getDate()          + ", "
       + date.getFullYear()      + " at "
       + hour                    + ":"
       + minutes                 + " "
       + ampm     /*+ " (local time)"*/;
}

//convert any timestamps tagged with "timestamp" class to the local timezone
$(function() {
  
  $("abbr.datetime").each(function() {
    var timestamp = $(this).attr("title");
    
    var date = parseISO8601(timestamp);
    if(date != null)
    {
      //generates an exception in IE6..
      try { $(this).html(toLocalTime(date)); }
      catch(e) { }
    }
  });
  
});
