var request = false;
try
{
	// try to create an XMLHttpRequest object the standard way
	// this will work in Gecko browsers
	request = new XMLHttpRequest();
}
catch (e)
{
	// if an error occurs, it means that the request couldn't be created for some reason
	// so we try to create it on the newer versions of IE, which use Msxml2.XMLHTTP
	try
	{
		request = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		// if it still fails, we try to create the request on older versions of IE
		// which use Microsoft.XMLHTTP
		try
		{
			request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			// if after all of the above STILL fails, the browser must not support it at all
			// in other words, the browser is ancient
			request = false;
		}
	}
}

function eventPopUp(month, day)
{
	url = "includes/events.php?month=" + month + "&day=" + day;
	var newwindow = window.open(url);
	if (window.focus) {newwindow.focus()}
}

function changeMonth(month)
{
	// first, we build a URL to connect to
	var url = 'includes/calendar.php?change=1&month=' + escape(month);
	// next, we open a GET connection to the server
	request.open('GET', url, true);
	// now we need to specify the function to be called on server return
	request.onreadystatechange = updateCalendar;
	// lastly, send the request
	request.send(null);
}

function updateCalendar()
{
    // first, we need to make sure the request's readystate is 4
    if (request.readyState == 4)
    {
	// now make sure the HTTP status code is 200
	if (request.status == 200)
	{
		// we now know that everything went fine, and we can update our application
		var response = request.responseText;
		document.getElementById('calendar').innerHTML = response;
	}
    }
}