/* Loads the Google data JavaScript client library */
google.load("gdata", "1");

/**
 * Uses Google data JS client library to retrieve a calendar feed from the specified
 * URL.  The feed is controlled by several query parameters and a callback 
 * function is called to process the feed results.
 *
 * @param {string} calendarUrl is the URL for a public calendar feed
 */  
function loadCalendar(calendarUrl, retFunc) 
{
  var service = new 
      google.gdata.calendar.CalendarService('uwpiv-cal-tab1.0');
  var query = new google.gdata.calendar.CalendarEventQuery(calendarUrl);
  query.setOrderBy('starttime');
  query.setSortOrder('ascending');
  query.setFutureEvents(true);
  query.setSingleEvents(true);
  query.setMaxResults(5);

  service.getEventsFeed(query, retFunc, handleGDError);
}

/**
 * Callback function for the Google data JS client library to call when an error
 * occurs during the retrieval of the feed.  Details available depend partly
 * on the web browser, but this shows a few basic examples. In the case of
 * a privileged environment using ClientLogin authentication, there may also
 * be an e.type attribute in some cases.
 *
 * @param {Error} e is an instance of an Error 
 */
function handleGDError(e) 
{
  //document.getElementById('jsSourceFinal').setAttribute('style', 'display:none');
  if (e instanceof Error) 
  {
    /* alert with the error line number, file and message */
    //alert('Error at line ' + e.lineNumber + ' in ' + e.fileName + '\n' + 'Message: ' + e.message);
    /* if available, output HTTP error code and status text */
    if (e.cause) 
	{
      var status = e.cause.status;
      var statusText = e.cause.statusText;
      //alert('Root cause: HTTP error ' + status + ' with status text of: ' + statusText);
    }
  } 
  else 
  {
    //alert(e.toString());
  }
}

