// JavaScript Document
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","calendar.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 
var now = new Date();
nowdatecode = (now.getFullYear() * 10000) + ((now.getMonth() + 1) * 100) + (now.getDate());

var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");

var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
				"Thursday","Friday","Saturday");


document.write("<table border='0'>");
var x=xmlDoc.getElementsByTagName("year");
document.write("<tr><td style=\"font-size:16px;\" align=\"left\">");
document.write("<strong>Today is ");
document.write(dayNames[now.getDay()] + ", " + monthNames[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear());
document.write("</strong></td></tr>");
document.write("<tr><td style=\"font-size:15px;\" align=\"left\"><strong>These are the next upcoming events:</strong></td></tr></table>");
document.write("<table>");
count = 0;
for (i=0;i<x.length;i++)
  { 
  y = x[i].getElementsByTagName("month");
  if (count < 5){
  for(l=0;l<y.length;l++)
	  {
	  z = y[l].getElementsByTagName("day");
	  if(count < 5){
	  for(m=0;m<z.length;m++)
		  {
		  thendatecode = (x[i].getAttribute('value') * 10000) + (y[l].getAttribute('value') * 100) + (z[m].getAttribute('value') * 1);
		  if(nowdatecode < thendatecode && count < 5)
		  {
		  xYear = x[i].getAttribute('value');
		  xMonth = y[l].getAttribute('value');
		  xDate = z[m].getAttribute('value');
		  monthName = monthNames[xMonth-1];

		  cal = new Date(xYear, xMonth-1, xDate);
		  dayOfWeek = cal.getDay();
		  
		  document.write("<tr><td align=\"justify\">");
		  document.write(dayNames[dayOfWeek] + ", " + monthNames[xMonth-1] + " " + xDate + ", " + xYear + ":"); 
		  document.write("</td><td align=\"left\">");
		  document.write(z[m].getElementsByTagName("label")[0].childNodes[0].nodeValue);
		  document.write("</td></tr>");	
		  count = count + 1;
		  }	
		  }
		  }
		  
	  }
	  }
  }
document.write("</table>");
