// Event Calendar
// copyright Stephen Chapman, 10th June 2006, 30th October 2006
var tb = 'b';				// top or bottom (t or b)
var headbg = '#FFFFFF';		// table heading background colour
var todaybg = '#DEDFE1';	// current selected date background colour
var textclr = '#000000';	// text colour
var linkclr = '#043f59';	// link text colour
var noMessage = 'Roll over a gray square of the calendar with an icon in it. The details of that date will populate in this section.';	// message to display when no entry in array
// permission is granted to use this javascript provided that the below code is not altered
var pageLoaded = 0;
window.onload = function() {
   pageLoaded = 1;
   }
function loaded(i, f) {
   if (document.getElementById && document.getElementById(i) != null) f();
   else if (!pageLoaded) setTimeout('loaded(\'' + i + '\',' + f + ')', 100);
   }
function monthlength(month, year) {
   var dd = new Date(year, month, 0);
   return dd.getDate();
   }
var moy = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var today = new Date();
var selDate = today.getFullYear() + getmmdd(today.getMonth() + 1, today.getDate());
function dispCal(yy, mm) {
   if (mm < 0 || mm > 12) {
      alert('month must be between 1 and 12');
      return false;
      }
   if (yy != 0 && (yy < 1901 || yy > 2100)) {
      alert('year must be after 1900 and before 2101');
      return false;
      }
   var dow = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
   // Day Of Week
   var calendar = new Date();
   var today = calendar.getDate();
   calendar.setDate(1);
   if (yy > 1900) calendar.setFullYear(yy);
   if (mm > 0) calendar.setMonth(mm - 1);
   var yy = year = calendar.getFullYear();
   var month = calendar.getMonth();
   calendar.setDate(today);
   var weekday = calendar.getDay();
   var daysInMonth = monthlength(month + 1, year);
   var hilite_start = '<td valign="top" style="background:' + todaybg + '"><b>';
   var th_start = '<th valign="bottom">';
   var td_start = '<td class="cal_td_hp" valign="top">&nbsp;';
   var td_start_7 = '<td class="cal_td_hp cal_td_right_hp" valign="top">&nbsp;';
   if (document.getElementById) {
      var mmb = month;
      mm = month + 1;
      var yya = yyb = yy;
      if (mmb < 1) {
         mmb += 12;
         yyb--;
         }
      var mma = month + 2;
      if (mma > 12) {
         mma -= 12;
         yya++;
         }
      var yb = yy - 1;
      var ya = yy + 1;
      }
   var cal = '<div id="cal_hp"><div class="cal_build_hp gainlayout" id="cal_build_hp">' 
   + '<table border="0">' + '<tbody>' + '<tr>'  
   + '<td width="313" valign="top"><table width="313" cellspacing="0" cellpadding="2" align="center">'  
   + '<tbody>' + '<tr>'  
   + '<td colspan="5"><h4>' + moy[month] + ' ' + year + '</h4></td>'  
   + '</tr>' + '</tbody>' + '</table>'  
   + '<table width="313" cellspacing="0" cellpadding="2" align="center">'  
   + '<tbody>' + '<tr>';
   for(dex = 0; dex < 7; dex++) {
      cal += th_start + dow[dex] + '</th>';
      }
   cal += '<\/tbody>' + '</table>' + '<table width="313" align="center" class="cal_table_hp">' + '<tbody>' + '<tr class="cal_row_hp">';
   var day2 = today;
   for (dex = today; dex > 6; dex -= 7) day2 = dex;
   weekday -= day2 - 1;
   while (weekday < 0) weekday += 7;
   for(dex = 0; dex < weekday; dex++) cal += td_start + '<\/td>';
   for(dex = 1; dex <= daysInMonth; dex++) {
      if(weekday == 7) {
         cal += '</tr><tr class="cal_row_hp">';
         weekday = 0;
         }
      if(selDate == year + getmmdd(month + 1, dex)) cal += clickDate2(dex, month, year, weekday);
      else cal += clickDate2(dex, month, year, weekday);
      weekday += 1;
      }
   for(dex = weekday; dex < 7; dex++) {
      if(dex == '6') {
         cal += td_start_7 + ' <\/td>';
         }
      else {
         cal += td_start + '<\/td>';
         }
      }
   cal += '<\/tr>' + ' </tbody>' + ' </table>' + ' <div class="calendar-key"><img src="/images/calendar_legend_hp.gif" alt="Key" width="313" height="15" /> </div></td>' + ' </tr>' + ' </tbody>' + ' </table>' + '</div>' + ' <div class="view_all_hp"><a href="/resource-center/calendar/index.html" class="read">View All Events</a></div>' + '<div id="calData_box"><div id="calDate"></div></div>';
   if (document.getElementById) {
      cal += '';
      }
   else {
      cal += '<div> </div>';
      }
   cal += '</div>';
   return cal;
   }
function start() {
   //var x = '<div id="calData_box"><div id="calDate"></div></div>';
   var y = '';
   //if (tb == 't') y = x + dispCal(0,0);
   //else y = dispCal(0,0) + x;
   y = dispCal(0, 0);
   document.getElementById('calendar_hp').innerHTML = y;
   ev();
   }
loaded('calendar_hp', start);
function clickDate2(day, month, year, weekday) {
   var ct = nextDate(year + getmmdd(month + 1, day));
   if (ct == '') ct = nextDate('0000' + getmmdd(month + 1, day));
   var thumb = thumbNail(year + getmmdd(month + 1, day));
   var thumbImage;
   if(thumb == 'A') thumbImage = '<img src="/images/appearance_icon.gif" width="17" height="17" alt="Appearance" />';
   if(thumb == 'B') thumbImage = '<img src="/images/book_icon.gif" width="17" height="17" alt="Book Signing" />';
   if(thumb == 'D') thumbImage = '<img src="/images/dividend_icon.gif" width="17" height="17" alt="Dividend Payout" />';
   if(thumb == 'E') thumbImage = '<img src="/images/earnings_icon.gif" width="17" height="17" alt="Earnings" />';
   if(thumb == 'I') thumbImage = '<img src="/images/icon_issue.gif" width="13" height="13" alt="Issue" />';
   if(thumb == 'P') thumbImage = '<img src="/images/icon_trade.gif" width="13" height="13" alt="Buy" />';
   if(thumb == 'S') thumbImage = '<img src="/images/icon_trade.gif" width="13" height="13" alt="Sell" />';
   if(thumb == 'M') thumbImage = '<img src="/images/icon_multiple.gif" width="13" height="13" alt="Multiple Events" />';
   if(thumb == 'T') thumbImage = '<img src="/images/travel_icon.gif" width="17" height="17" alt="Travel Date" />';
   if(thumb == 'W') thumbImage = '<img src="/images/webinar_icon.gif" width="17" height="17" alt="Webinar" />';
   var tdClass;
   if(weekday == '6') {
      tdClass = 'cal_td_hp cal_td_right_hp';
      }
   else {
      tdClass = 'cal_td_hp';
      }
   if (ct == '') return '<td valign="top" class="' + tdClass + '">' + dex + '<\/td>';
   else return '<td valign="top" class="' + tdClass + '" onmouseover="selDate = ' + year + getmmdd(month + 1, day) + '; isDate(' + day + ',' + month + ',' + year + ');return false;" onmouseout="isNotDate(' + day + ',' + month + ',' + year + ');return false;" style="background:' + todaybg + ';">' + dex + '<br />' + thumbImage + '<\/td>';
   }
function clickDate(day, month, year) {
   var ct = nextDate(year + getmmdd(month + 1, day));
   if (ct == '') ct = nextDate('0000' + getmmdd(month + 1, day));
   if (ct == '') return 'style="color:' + textclr + '"';
   else return 'style="text-decoration:underline;font-weight:bold;cursor:pointer;color:' + linkclr + '" onmouseover="selDate = ' + year + getmmdd(month + 1, day) + '; isDate(' + day + ',' + month + ',' + year + ');return false;" onmouseout="isNotDate(' + day + ',' + month + ',' + year + ');return false;"';
   }
function isDate(dayVal, monthVal, yearVal) {
   var ct = nextDate(yearVal + getmmdd(monthVal + 1, dayVal));
   if (ct == '') ct = nextDate('0000' + getmmdd(monthVal + 1, dayVal));
   if (ct == '') ct = noMessage;
   var re = /^(\w)(.*)/;
   ct = ct.replace(re, "$2");
   var innerHtml = '<h6>' + selDate + '</h6> <p>' + ct + '</p>';
   re = /(.*)(\d\d\d\d)(\d\d)(\d\d)(.*)/;
   var innerHtmlFormatted = innerHtml.replace(re, "$1 $3/$4/$2 $5");
   document.getElementById('calDate2').innerHTML = innerHtmlFormatted;
   return false;
   }
function isNotDate(dayVal, monthVal, yearVal) {
   var ct = nextDate(yearVal + getmmdd(monthVal + 1, dayVal));
   if (ct == '') ct = nextDate('0000' + getmmdd(monthVal + 1, dayVal));
   if (ct == '') ct = noMessage;
   var re = /^(\w)(.*)/;
   ct = ct.replace(re, "$2");
   var innerHtml = '<h6>How to Use the Calendar&hellip;</h6><p> ' + noMessage + '</p>';
   re = /(.*)(\d\d\d\d)(\d\d)(\d\d)(.*)/;
   var innerHtmlFormatted = innerHtml.replace(re, "$1 $3/$4/$2 $5");
   document.getElementById('calDate2').innerHTML = innerHtmlFormatted;
   return false;
   }
function nextDate(yymmdd) {
   var x = dA.length;
   for (var i = 0; i < x; i++) {
      if (dA[i].substr(0, 8) == yymmdd) return dA[i].substr(8);
      }
   return '';
   }
function thumbNail(yymmdd) {
   var x = dA.length;
   for (var i = 0; i < x; i++) {
      if (dA[i].substr(0, 8) == yymmdd) return dA[i].substr(8, 1);
      }
   return '';
   }
function getmmdd(mm, dd) {
   return (mm > 9 ? '' + mm : '0' + mm) + (dd > 9 ? dd : '0' + dd);
   }
function ev() {
   var ct = nextDate(selDate);
   var ct = nextDate(selDate);
   if (ct == '') ct = nextDate('0000' + selDate.substr(4));
   if (ct == '') ct = noMessage;
   var re = /(\d\d\d\d)(\d\d)(\d\d)/;
   var formatDate = selDate.replace(re, "$2/$3/$1");
   // adding blank element so script doesn't spazz
   document.getElementById('calDate').innerHTML = '';
   //document.getElementById('calDate').innerHTML = '<p><span class="date_highlight_hp">' + formatDate + '</span> ' + ct + '</p>';
   document.getElementById('calDate2').innerHTML = '<h6>How to Use the Calendar&hellip;</h6><p> ' + noMessage + '</p>';
   }
