Integrating webinar hosting with developer.android.com

Change-Id: I320378560bbb09efade14f583dbcf2d66f34a9d8
diff --git a/docs/html/resources/index.jd b/docs/html/resources/index.jd
index 1668721..699952a 100644
--- a/docs/html/resources/index.jd
+++ b/docs/html/resources/index.jd
@@ -29,6 +29,10 @@
 <dd>Links to the Android discussion groups and information about other ways to
 collaborate with other developers. </dd>
 
+<dt><b>Webinars</b></dt>
+<dd>Online training videos on wide range of Android topics
+coupled with live IRC chat sessions for discussions. </dd>
+
 <dt><b>More</b></dt>
 <dd>Quick development tips, troubleshooting information, and frequently asked
 questions (FAQs). </dd>
diff --git a/docs/html/resources/resources_toc.cs b/docs/html/resources/resources_toc.cs
index ed23c7c..0e17188 100644
--- a/docs/html/resources/resources_toc.cs
+++ b/docs/html/resources/resources_toc.cs
@@ -270,8 +270,18 @@
       </li>
     </ul>
   </li>
-
-
+  <!-- Webinar section -->
+  <li>
+    <h2><span class="en">Webinars</span></h2>
+    <ul>
+      <li><a href="<?cs var:toroot ?>resources/webinars/webinar-watch.html">
+            <span class="en">Watch a Webinar</span>
+          </a></li>     
+      <li><a href="<?cs var:toroot ?>resources/webinars/webinar-upcoming.html">
+            <span class="en">Upcoming Schedule</span>
+          </a></li>
+    </ul>
+  </li>
 
   <li>
     <h2><span class="en">More</span>
diff --git a/docs/html/resources/webinars/date.js b/docs/html/resources/webinars/date.js
new file mode 100644
index 0000000..97abf4b
--- /dev/null
+++ b/docs/html/resources/webinars/date.js
@@ -0,0 +1,100 @@
+// Copyright 2009 Google Inc. All Rights Reserved.
+
+/**
+ * @fileoverview Utility functions for formating date.
+ */
+
+/**
+ * Formats start date and end date in JSON format to string of format:
+   "09/09/2010 20:00 PM to 22:00 PM PST"
+ * @param {object} start date in JSON format.
+ * @param {object} end date in JSON format.
+ * @param {string} formatted date string.
+ */
+function formatDate(start,end) {
+  var s_ampm = null;
+  var e_ampm = null;
+
+  var toStr = function (num) {
+    if (num <= 12) {
+      return "" + num;
+    } else {
+      return "" + (num - 12);
+    }
+  };
+
+  var getMonthName = function (num) {
+    switch(num) {
+      case 1:
+        return 'January';
+      case 2:
+        return 'February';
+      case 3:
+        return 'March';
+      case 4:
+        return 'April';
+      case 5:
+        return 'May';
+      case 6:
+        return 'June';
+      case 7:
+        return 'July';
+      case 8:
+        return 'August';
+      case 9:
+        return 'September';
+      case 10:
+        return 'October';
+      case 11:
+        return 'November';
+      case 12:
+        return 'December';
+     }
+  }
+
+  var regex =  /(^\d{4})-(\d{2})-(\d{2})\s{1}(\d{2}):(\d{2}):(\d{2}$)/;
+  var s_match = regex.exec(start.toString());
+
+  if( s_match == null) {
+   return '';
+  }
+  var yy = s_match[1];
+
+  var mm = parseInt(s_match[2], 10 /** base 10 **/);
+  var dd = s_match[3];
+
+  var s_hh = parseInt(s_match[4], 10 /** base 10 **/);
+ 
+  if (s_hh > 12) {
+    s_ampm = "PM";
+  } else {
+    s_ampm = "AM";
+  }
+  s_hh = toStr(s_hh);
+  var s_mi = s_match[5];
+
+
+  var str =  getMonthName(mm) + " " +  dd + ", " + yy ;
+  str += " " + s_hh + ":" + s_mi;
+  str += " " + s_ampm;
+
+  regex =  /(^\d{4})-(\d{2})-(\d{2})\s{1}(\d{2}):(\d{2}):(\d{2}$)/;
+  var e_match = regex.exec(end.toString());
+  if( e_match == null) {
+   return str + ' PST';
+  }
+  var e_hh = parseInt(e_match[4], 10 /** base 10 **/);
+  if (e_hh > 12) {
+    e_ampm = "PM";
+  } else {
+    e_ampm = "AM";
+  }
+  e_hh = toStr(e_hh);
+  var e_mi = e_match[5];
+
+  str += " to " + e_hh + ":" + e_mi;
+  str += " " + e_ampm;
+  str += " PST";
+  return str;
+
+}
diff --git a/docs/html/resources/webinars/webinar-upcoming.jd b/docs/html/resources/webinars/webinar-upcoming.jd
new file mode 100644
index 0000000..b9602f4
--- /dev/null
+++ b/docs/html/resources/webinars/webinar-upcoming.jd
@@ -0,0 +1,53 @@
+page.title=Upcoming Schedule
+@jd:body
+
+<script type="text/javascript">
+
+/**
+/* Draw all webinars from feed into a 'webinars' div
+ * @param data  The feed data returned from the webinars request
+ */
+function renderWebinar(data) {
+
+  var entries = data.webinars || [];
+
+  var resultsDiv = $('#resource-browser-results');
+  var code = [];
+
+  // Loop through each entry (each webinar) and add it to the 'webinars' list
+  for (var i = 0; i < entries.length; i++) {
+    var entry = entries[i];
+
+    var title = entry.title;
+    var description = entry.description;
+    var url = entry.url;
+    var start = entry.start;
+    var end = entry.end;
+
+    code.push('<div>');
+    code.push('<h3>' + title + '</h3>');
+    code.push('<p ><i>' + formatDate(start, end) + '</i>');
+    code.push('<p>' + description);
+    code.push('</div>');
+  }
+
+  var html = code.join('\n');
+  resultsDiv.html(html);
+}
+
+/* Request the webinar feeds from webinarhosting server */
+function showWebinars() {
+  var script = "<script type='text/javascript' src='/resources/webinars/date.js'><\/script>";
+  $("body").append(script);
+  $.getJSON(
+  'http://android-webinars.appspot.com/feeds/api/upcomingwebinars?callback=?',
+  function(json){renderWebinar(json);});
+}
+// Initialization actions
+showWebinars();           // load webinars
+
+</script>
+
+
+<div id="resource-browser-results">
+  </div>
diff --git a/docs/html/resources/webinars/webinar-watch.jd b/docs/html/resources/webinars/webinar-watch.jd
new file mode 100644
index 0000000..5301b3f
--- /dev/null
+++ b/docs/html/resources/webinars/webinar-watch.jd
@@ -0,0 +1,106 @@
+page.title=Watch A Webinar
+@jd:body
+
+<script type="text/javascript">
+
+/**
+ * Draw all webinars from feed into a 'live_webinar' div
+ * @param data  The feed data returned from the live webinars request
+ */
+function renderLiveWebinar(data) {
+
+  var entries = data.webinars || [];
+
+  var resultsDiv = $('#live_webinar');
+  var code = [];
+
+  // Loop through each entry (each webinar) and add it to the 'webinars' list
+  for (var i = 0; i < entries.length; i++) {
+    var entry = entries[i];
+
+    var title = entry.title;
+    var description = entry.description;
+    var url = entry.url;
+    var start = entry.start;
+    var end = entry.end;
+    code.push('<div >');
+    code.push('<h3><b>Live!</b><a href="' + url + '"  target="_blank" onClick=_gaq.push(["_trackEvent", "Live Webinar", "' + title + '"]);>' + title + '</a></h3>');
+    code.push('<p ><i>' + formatDate(start, end) + '</i>');
+    code.push('<p>' + description);
+    code.push('</div>');
+  }
+  if (entries.length == 0) {
+    code.push('<div >');
+    code.push('<p>There is currently no live webinar. Watch one of the previous webinars from the list below and check the schedule for <a href="/resources/webinars/webinar-upcoming.html">Upcoming Webinars</a>.');
+    code.push('</div>');
+  }
+  var html = code.join('\n');
+  resultsDiv.html(html);
+}
+
+/* Request the webinar feeds from webinarhosting server */
+function showLiveWebinars() {
+  var script = "<script type='text/javascript' src='/resources/webinars/date.js'><\/script>";
+  $("body").append(script);
+  $.getJSON(
+  'http://android-webinars.appspot.com/feeds/api/livewebinar?callback=?',
+  function(json){renderLiveWebinar(json);});
+}
+// Initialization actions
+showLiveWebinars();      // load webinars
+
+/**
+ * Draw all past webinars from feed into a 'webinars' div
+ * @param data  The feed data returned from the webinars request
+ */
+function renderPastWebinar(data) {
+
+  var entries = data.webinars || [];
+
+  var resultsDiv = $('#past_webinars');
+  var code = [];
+  code.push('<h2> Past Webinars </h2>');
+    
+  // Loop through each entry (each webinar) and add it to the 'webinars' list
+  for (var i = 0; i < entries.length; i++) {
+    var entry = entries[i];
+
+    var title = entry.title;
+    var description = entry.description;
+    var url = entry.url;
+    var start = entry.start;
+    var end = entry.end;
+    code.push('<div >');
+    code.push('<h3><a href="' + url + '"  target="_blank" onClick=_gaq.push(["_trackEvent", "Past Webinars", "' + title + '"]);>' + title + '</a></h3>');
+    code.push('<p ><i>' + formatDate(start, end) + '</i>');
+    code.push('<p>' + description);
+    code.push('</div>');
+  }
+   if (entries.length == 0) {
+    code.push('<div >');
+    code.push('<p>There are no past webinars.');
+    code.push('</div>');
+  }
+  var html = code.join('\n');
+  resultsDiv.html(html);
+}
+
+/* Request the past webinar feeds from webinarhosting server */
+function showPastWebinars() {
+  var script = "<script type='text/javascript' src='/resources/webinars/date.js'><\/script>";
+  $("body").append(script);
+  $.getJSON(
+  'http://android-webinars.appspot.com/feeds/api/pastwebinars?callback=?',
+  function(json){renderPastWebinar(json);});
+}
+// Initialization actions
+showPastWebinars();      // load webinars
+
+</script>
+
+
+
+<div id="live_webinar">
+  </div>
+<div id="past_webinars">
+  </div>