// Event Calendar Display

var HeadingBGcolor = '#cccccc';
var TodayBGcolor = '#FFDEAD';
var TextColor = '#616161';
var LinkColor = '#8C0209';
var NoMsg =  'No events today';

var index = 0;
var pageLoaded = 0;
var DayText = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var MonthText = ['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());
var SpecialDay = new Array();
// first 8 characters in ccyymmdd format for single date events
// first 8 characters in 0000mmdd format for every year events
// -- FIXED DATE EVENTS -- 
SpecialDay[index++] = "00000101 New Year's Day <br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "00000115 Martin Luther King, Jr. Birthday";
SpecialDay[index++] = "00000202 Groundhog Day <br>2011: Phil saw NO shadow! <br>Early Spring!";
SpecialDay[index++] = "00000212 Lincoln's Birthday";
SpecialDay[index++] = "00000214 Valentine's Day";
SpecialDay[index++] = "00000222 Washington's Birthday";
SpecialDay[index++] = "00000317 St. Patrick's Day";
SpecialDay[index++] = "00000401 April Fools Day";
SpecialDay[index++] = "00000422 Earth Day";
SpecialDay[index++] = "00000501 May Day <br>AKA: International Workers' Day";
SpecialDay[index++] = "00000505 Cinco de Mayo";
SpecialDay[index++] = "00000614 Flag Day";
SpecialDay[index++] = "00000619 Juneteenth";
SpecialDay[index++] = "00000704 Independence Day (USA) <br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "00000714 Bastille Day";
SpecialDay[index++] = "00001012 Columbus Day";
SpecialDay[index++] = "00001031 Halloween";
SpecialDay[index++] = "00001101 All Saint's Day";
SpecialDay[index++] = "00001102 All Soul's Day";
SpecialDay[index++] = "00001111 Veteran's Day <br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "00001201 World AIDS Day<br>A Day Without Art";
SpecialDay[index++] = "00001225 Christmas Day <br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "00001226 Boxing Day <br>First Day of Kwanza";
SpecialDay[index++] = "00001231 New Years Eve <br>IT4SOHO Offices close at NOON";
// -- FEDERAL HOLIDAYS OBSERVED -- 
SpecialDay[index++] = "20120102 New Years Day Observance<br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20120116 MLK, Jr Birthday Observance<br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20120220 President's Day Observance<br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20120528 Memorial Day <br>IT4SOHO Offices are Closed";
//SpecialDay[index++] = "20120704 Independence Day Observance<br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20120903 Labor Day <br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20121008 Columbus Day Observance<br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20121112 Veterans Day Observance<br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20121122 Thanksgiving <br>IT4SOHO Offices are Closed";
SpecialDay[index++] = "20121123 Native American Heritage Day <br>IT4SOHO Offices are Closed";
//SpecialDay[index++] = "20121226 Christmas Day Observed <br>IT4SOHO Offices are Closed";
// -- Christian Days --
SpecialDay[index++] = "00000106 Three Kings Day <br>aka: Epiphany";
SpecialDay[index++] = "20120221 Mardi Gras <br>aka: Fat Tuesday";
SpecialDay[index++] = "20120222 Ash Wednesday";
SpecialDay[index++] = "20120401 Palm Sunday";
SpecialDay[index++] = "20120406 Good Friday";
SpecialDay[index++] = "20120408 Easter";
SpecialDay[index++] = "20120517 Ascention Day";
SpecialDay[index++] = "20120527 Pentecost";
SpecialDay[index++] = "00001101 All Saints' Day";
SpecialDay[index++] = "00001102 All Souls' Day";
// -- Jewish Days -- 
SpecialDay[index++] = "20120208 Tu B'Shevat";
SpecialDay[index++] = "20120307 Fast of Esther";
SpecialDay[index++] = "20120308 Purim begins @ sunset";
SpecialDay[index++] = "00000501 Yom HaShoah <br>AKA: Holocaust Rememberance Day";
SpecialDay[index++] = "20120407 Passover <br> - began @ sunset";
SpecialDay[index++] = "20120426 Yom Ha'atzma'ut <br>Israeli Independence Day";
SpecialDay[index++] = "20120526 Shavuot begins @ sunset";
SpecialDay[index++] = "20120728 Tisha B'Av";
SpecialDay[index++] = "20120916 Rosh Hashanah begins @ sunset";
SpecialDay[index++] = "20120925 Yom Kippur begins @ sunset";
SpecialDay[index++] = "20120930 Sukkot begins @ sunset";
SpecialDay[index++] = "20121208 Chanukah begins @ sunset";
// -- Muslim Days --
SpecialDay[index++] = "20120204 Milad un Nabi <br>Birthday of Muhammad";
SpecialDay[index++] = "20120720 Ramadan begins";
SpecialDay[index++] = "20120819 Eid Ul-Fitr (Ramadan ends)";
SpecialDay[index++] = "20121026 Eid Ul-Adha begins";
SpecialDay[index++] = "20121115 Al-Hijira<br>Islamic New Year";
SpecialDay[index++] = "20121124 Ashura";
// -- Other Days -- 
SpecialDay[index++] = "20120123 Chinese New Year <br>4709 - Dragon";
SpecialDay[index++] = "00000201 National Freedom Day";
SpecialDay[index++] = "00000208 Boy Scout Day <br>- Anniversary of founding in 1910";
SpecialDay[index++] = "00000302 Read Across America Day <br>Dr. Seuss' Birthday";
SpecialDay[index++] = "20120311 Daylight Savings Time Begins";
SpecialDay[index++] = "00000320 First Day of Spring";
SpecialDay[index++] = "20120417 US Federal Tax Day <br> - Filing Deadline";
SpecialDay[index++] = "00000501 May is National Foster Care Month";
SpecialDay[index++] = "20120513 Mother's Day";
SpecialDay[index++] = "00000601 First day of Atlantic Hurricane Season";
SpecialDay[index++] = "20120617 Father's Day";
SpecialDay[index++] = "00000620 First Day of Summer";
SpecialDay[index++] = "20120722 Parent's Day";
SpecialDay[index++] = "20120909 Grandparent's Day";
SpecialDay[index++] = "20120916 Step Family Day";
SpecialDay[index++] = "00000921 First Day of Autum (Fall)";
SpecialDay[index++] = "20121104 Daylight Savings Time Ends";
SpecialDay[index++] = "20121106 Election Day (US)";
SpecialDay[index++] = "20121117 National Adoption Day";
SpecialDay[index++] = "00001221 First Day of Winter";

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();
}
function printDate(tDay,tMonth,tYear) {
  return '<u><b>' + MonthText[tMonth] + ' ' + tDay + ', ' + tYear + '</b></u>:<br>';
}
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 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 width="30" style="background:' + TodayBGcolor + '" align="center"><b>';
  var td_start = 
    '<td width="30" align="center">';
  var cal =  '<div id="cal">'
      cal += '<div style="border:1pt solid #8C0209;height:150px;width:210px">'
      cal += '<table border="0" cellspacing="0" cellpadding="2" align="center">'
      cal += '<tr>'
      cal += '<td colspan="7" style="background:' + HeadingBGcolor + '" align="center"><b>' + MonthText[month]  + ' ' + year + '<\/b>'
      cal += '<\/td><\/tr>'
      cal += '<tr>';
  for (index=0; index < 7; index++)
    cal += td_start + DayText[index] + '</td>';
  cal += '<\/tr><tr>';
  var day2 = today;
  for (index = today; index > 6; index -=7)
    day2 = index;
  weekday -= day2 - 1;
  while (weekday < 0)
    weekday += 7;
  for (index=0; index < weekday; index++)
     cal += td_start + ' <\/td>';
  for (index=1; index <= daysInMonth; index++) {
    if (weekday == 7) {
      cal += '</tr><tr>';
      weekday = 0;
    }
    if (selDate==year+getmmdd(month+1,index))
      // NOTE: hilite_start has a <b> in it that must be terminated!
      cal += hilite_start +'<span '+clickDate(index,month,year) + '>'+ index + '<\/span><\/b><\/td>';
    else
      cal += td_start + '<span '+clickDate(index,month,year) + '>' + index + '<\/span><\/td>';
    weekday += 1;
  }
  for (index=weekday; index < 7; index++)
    cal += td_start + ' <\/td>';
    cal += '<\/tr><\/table><\/div>';
    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;
      cal += '<table border="0" cellspacing="0" cellpadding="2" width="210">';
      cal += '<tr><td><a href="#" onclick="if (cala = dispCal(' + yb + ',' + mm + ')) {document.getElementById(\'cal\').innerHTML = cala; return false;}"><<</a></td><td><a href="#" onclick="if (cala = dispCal('+yyb+','+mmb+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}"><</a></td><td align="right"><a href="#" onclick="if (cala = dispCal('+yya+','+mma+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}">></a></td><td align="right"><a href="#" onclick="if (cala = dispCal('+ya+','+mm+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}">>></a></td></tr></table>';
   }
   else {
     cal += '<div> </div>';
   }
   cal += '</div>';
   return cal;
}
function start() {
  var x = '<div id="calDate" style="border:0pt solid #8C0209;width:210px"><\/div>'; var y = '';
y = x + dispCal(0,0);
document.getElementById('calendar').innerHTML = y; ev();}
loaded('calendar',start);
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:'+TextColor+'"';
  else
    return 'style="cursor:pointer;color:' + LinkColor + '" onclick="selDate = ' + year + getmmdd(month+1,day) + '; isDate(' + 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 = NoMsg;
  document.getElementById('calDate').innerHTML = printDate(dayVal,monthVal,yearVal) + ct;
  return false;
}
function nextDate(yymmdd) {
  var x = SpecialDay.length;
  for (var i = 0; i < x; i++) {
    if (SpecialDay[i].substr(0,8) == yymmdd)
      return SpecialDay[i].substr(8);
  }
  return '';
}
function getmmdd(mm,dd) {
  return (mm > 9 ? '' + mm : '0' + mm) + (dd > 9 ? dd : '0' + dd);
}
function ev() {
  var ct = nextDate(selDate);
  if (ct == '') 
    ct = nextDate ('0000' + selDate.substr(4));
  if (ct == '')
    ct = NoMsg;
  tDay = today.getDate();
  tMonth = today.getMonth();
  tYear = today.getFullYear();
  document.getElementById('calDate').innerHTML = 'Today is ' + printDate(tDay,tMonth,tYear) + ct;
}

