// this is an ajax script that retrieves events from a database and places the preformatted data into the displayCalendarEvent div on the calendar.html page without reloading the page. It retrieves the data using the GetCalendarEvent.php script by submitting the date embedded in the link for each event listed on the calendar.html page.
function getCalendarEvent(eventDate, eventDay)
{
	 var responseDisplayCalendarEvent = document.getElementById("displayCalendarEvent");	
//alert(eventDate + "      " + eventDay + "     " +  responseDisplayCalendarEvent);
		 try
		 {
			 var requester = new XMLHttpRequest();
		 }

		catch (error)
		{
			try
			 {
			 var requester = new ActiveXObject("Microsoft.XMLHTTP");
			 }

			 catch (error)
			 {
			 var requester = null;
			 }
		  }

    if (requester != null)
			{
			  var ajaxLink = this;
			  ajaxLink._timer = setTimeout(function()
				  {
					requester.abort();       
					 writeError("The server timed out while making your request.");
				  }, 
				10000);       

					 ///************* the location of the php script goes here////////////////
			  requester.open("GET", "GetCalendarEvent.php?eventDate=" + encodeURIComponent(eventDate) +  "& eventDay=" + encodeURIComponent(eventDay) , true);

			  requester.onreadystatechange = function()
					 {
							if (requester.readyState == 4)
							{
								clearTimeout(ajaxLink._timer);        

							  if (requester.status == 200 || requester.status == 304)
								  {         
										responseDisplayCalendarEvent.innerHTML= requester.responseText;   //this line fills the contents of the div element.

										changeDisplay('displayCalendarEvent'); //changeDisplay function replaces current div with the displayArticle div
								   }
							  else
									 {
										writeError("The server was unable to be contacted.");
									 }
								}
						 };

				  requester.send(null); //this initiates the send sequence and now we wait for the reply which is monitored by the				onreadystatechange function above.

    } //requester !=null

  } //getCalendarEvent()

//  writeError: function(errorMsg)
function writeError(errorMsg)
  {
    alert(errorMsg);
  }

