// JavaScript Document
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";

<!--
/* Loads the Google data JavaScript client library */
google.load("gdata", "2.x");

function init() {
  // init the Google data JS client library with an error handler
  google.gdata.client.init(handleGDError);
  // load the code.google.com developer calendar
  loadDeveloperCalendar();
}

/**
 * Loads the Google Developers Event Calendar
 */
function loadDeveloperCalendar() {
  loadCalendarByAddress('8tp4mfs2ht22ov05uobpvnaf9k@group.calendar.google.com'); //load techlogic Calendar of Events
}

/**
 * Adds a leading zero to a single-digit number.  Used for displaying dates.
 */
function padNumber(num) {
  if (num <= 9) {
    return "0" + num;
  }
  return num;
}

/**
 * Determines the full calendarUrl based upon the calendarAddress
 * argument and calls loadCalendar with the calendarUrl value.
 *
 * @param {string} calendarAddress is the email-style address for the calendar
 */ 
function loadCalendarByAddress(calendarAddress) {
  var calendarUrl = 'https://www.google.com/calendar/feeds/' +
                    calendarAddress + 
                    '/public/full';
  loadCalendar(calendarUrl);
}

/**
 * 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) {
  var service = new 
      google.gdata.calendar.CalendarService('gdata-js-client-samples-simple');
  var query = new google.gdata.calendar.CalendarEventQuery(calendarUrl);
  query.setOrderBy('starttime');
  query.setSortOrder('ascending');
  query.setFutureEvents(true);
  query.setSingleEvents(true);
  query.setMaxResults(15);
  
  service.getEventsFeed(query, listEvents, 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());
  }
}

/**
 * Callback function for the Google data JS client library to call with a feed 
 * of events retrieved.
 *
 * Creates an unordered list of events in a human-readable form.  This list of
 * events is added into a div called 'events'.  The title for the calendar is
 * placed in a div called 'calendarTitle'
 *a
 * @param {json} feedRoot is the root of the feed, containing all entries 
 */ 
function listEvents(feedRoot) {
  var entries = feedRoot.feed.getEntries();
  var eventDiv = document.getElementById('events');
  if (eventDiv.childNodes.length > 0) {
    eventDiv.removeChild(eventDiv.childNodes[0]);
  }	
  /* create a new unordered list */
  var ul = document.createElement('ul');
  /* set the calendarTitle div with the name of the calendar */
//	document.getElementById('calendarTitle').innerHTML = ("<h4>" + feedRoot.feed.title.$t+"</h4>"); //actual Google calendar name
	document.getElementById('calendarTitle').innerHTML = ("<p class=\"leftHeader\" style=\"margin:0px 0px 0px 0px;\">Upcoming Events</p>");
	
  /* loop through each event in the feed */
  var len = entries.length;
  for (var i = 0; i < len; i++) {
    var entry = entries[i]; // array of events
    var title = entry.getTitle().getText(); //title of individual events 
    var startDateTime = null;
    var startJSDate = null;
    var endDateTime = null;
    var endJSDate = null;
    var times = entry.getTimes();
	var myDescription = entry.getContent().getText(); //the event details - description
//	alert (myDescription);
	var eventLoc = "";
	eventLoc += entry.getLocations()[0].getValueString() //event location address, city, state
	var mapLink=escape(eventLoc); //HTMLencode map query
	eventLoc += " (<a href=\"http://maps.google.com/maps?q="+mapLink+"&hl=en\" target=\"_blank\" style=\"font-weight:bold;\">Map</a>)<br />"
	
    var entryLinkHref = null; //link to calendar
    if (entry.getHtmlLink() != null) {
      entryLinkHref = entry.getHtmlLink().getHref();
    }

	if (times.length > 0) { //start time mm/dd/yyyy
      startDateTime = times[0].getStartTime();
      startJSDate = startDateTime.getDate();
    }
    if (times.length > 0) { //end time mm/dd/yyyy
      endDateTime = times[0].getEndTime();
      endJSDate = endDateTime.getDate();
    }

//	var dateString = (startJSDate.getMonth() + 1) + " " + startJSDate.getDate();
	var dateString = month[(startJSDate.getMonth())] + " " + startJSDate.getDate();
    if (!startDateTime.isDateOnly()) {
      dateString += " " + startJSDate.getHours() + ":" + 
          padNumber(startJSDate.getMinutes());
    }
	
//    var endDateString = (endJSDate.getMonth() + 1) + "/" + endJSDate.getDate()+ "/" + endJSDate.getFullYear();
    var endDateString = endJSDate.getDate()+ ", " + endJSDate.getFullYear();
    if (!endDateTime.isDateOnly()) {
      endDateString += " " + endJSDate.getHours() + ":" + 
          padNumber(endJSDate.getMinutes());
    }

//used as 'date=' in the 'copy to my calendar querystring' //
					  var startDay=startJSDate.getDate();
					  startDay+="";
					  var endDay=endJSDate.getDate();
					  endDay+="";
					  var startLinkDate=startJSDate.getFullYear()+"";
					  startLinkDate+=startJSDate.getMonth()+1+"";
					   if (startDay.length!=1) {
						  startLinkDate+=""+startJSDate.getDate()+"";
						  }else if (startDay.length=1){
						  startLinkDate+="0"+startJSDate.getDate()+"";
						  }
					  var endLinkDate=endJSDate.getFullYear()+"";
					  endLinkDate+=endJSDate.getMonth()+1+"";
					  if (endDay.length!=1) {
						  endLinkDate+=""+endJSDate.getDate()+"";
						  }else if (endDay.length=1){
						  endLinkDate+="0"+endJSDate.getDate()+"";
						  }
					  var linkDate=startLinkDate+"";
					  linkDate+="/";
					  linkDate+=endLinkDate+"";

	if (title != null){ //create a 'title' div to contain the event title
			var titlediv = document.createElement('div');
			var divIdName = ('title' + i + 'div');
			titlediv.innerHTML =("<b class=\"header\">"+title+"</b>");
//			titlediv.innerHTML =("<b class=\"header\">"+title+"</b>");
		}else{
			titlediv.innerHTML='';
			}

	if (myDescription != null) { //create a 'event' div to contain the event details
			var newdiv = document.createElement('div');
			var divIdName = ('my' + i + 'div');
			var divStyle = ('display:none')
			newdiv.setAttribute('id',divIdName);
			newdiv.setAttribute('style',divStyle)

			splitDesc=myDescription.split("<a ")
			
				if (splitDesc[1] != null) {
					newdiv.innerHTML =("<b>"+title+"</b><br />"+eventLoc+" "+splitDesc[0]+"<a "+splitDesc[1]+"");
					newdiv.innerHTML +=(" by visiting the "+ title +" web site.");
					detailsLink=escape(myDescription);
				}else{
					newdiv.innerHTML =("<b>"+title+"</b><br />"+eventLoc+myDescription)
						detailsLink=(myDescription);
						var intIndexOfMatch = detailsLink.indexOf( "\"" );
						while (intIndexOfMatch != -1){
						detailsLink = detailsLink.replace("\"", "&quot;")
						intIndexOfMatch = detailsLink.indexOf( "\"" );
						}
					detailsLink=escape(detailsLink);
					}

//			newdiv.innerHTML="<b>"+title+"</b><br /><div>"+myDescription+"</div>";					
			var showdetail=document.createElement('div');
			showdetail.setAttribute('style','padding:0px 0px 0px 5px');
			var detailIdName = ('show' + i + 'div');
				var showLink="show"+i;
				var hideLink="hide"+i;
				var showEvent="";
				newdiv.innerHTML+=("<div id=\""+hideLink+"\" onclick=\"document.getElementById('showevent').style.display='none';\" style=\"display:block;\" onmouseover=\"this.className='detailhover'\" onmouseout=\"this.className='detail'\" class=\"detail\">hide detail</div>");
				newdiv.innerHTML+=("<a href=\"https://www.google.com/calendar/event?action=TEMPLATE&hl=en&text="+title+"&dates="+linkDate+"&location="+ entry.getLocations()[0].getValueString()+"&ctz=America%2FNew_York&details="+detailsLink+"\" target=\"_blank\"  class=\"hidedetail\">copy to my calendar</a>")
				
			showdetail.setAttribute('id',detailIdName);
			showdetail.innerHTML+=("<div id=\""+showLink+"\" onclick=\"document.getElementById('showevent').style.display='block';document.getElementById('showevent').innerHTML=document.getElementById('"+divIdName+"').innerHTML;\" onmouseover=\"this.className='detailhover'\" onmouseout=\"this.className='detail'\" class=\"detail\">show detail</div>");
			//showdetail.innerHTML+=(newdiv.innerHTML);
		}else{
			newdiv.innerHTML='';
			}

var newTitle = document.createElement('div');
		newTitle.innerHTML="<b class=\"smcalheader\">"+title+"</b><span style=\"padding:0px 5px;\">" + dateString + " - " + endDateString + "</span>"

var li = document.createElement('li');
li.setAttribute("class","smcall")
    /* if we have a link to the event, create an 'a' element */
    if (entryLinkHref != null) {
      entryLink = document.createElement('a');
      entryLink.setAttribute('href', entryLinkHref);
	  entryLink.setAttribute('target', '#');
		entryLink.setAttribute('onclick','getElementById(newdiv).style.display=block;')
//      entryLink.appendChild(document.createTextNode(title));
//      entryLink.appendChild(document.createTextNode('To read more open the calendar.'));
//	  li.appendChild(titlediv);
//      li.appendChild(document.createTextNode(newTitle + ' <br /> ' + dateString + ' - ' +endDateString));
	  li.appendChild(document.createTextNode(''));
	  li.appendChild(newTitle);
	  li.appendChild(newdiv);
	  li.appendChild(showdetail);
      li.appendChild(entryLink);
    } else {
	  li.appendChild(document.createTextNode(''));
	  li.appendChild(newTitle);
	  li.appendChild(newdiv);
	  li.appendChild(showdetail);
    }	    

    /* append the list item onto the unordered list */
    ul.appendChild(li);

  }
  eventDiv.appendChild(ul);
}
google.setOnLoadCallback(init);

//-->
