//Create a boolean variable to check for a valid IE instance
var xmlhttp = false;

//Check if we are using IE
try {
	//If the Javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	//If not, then use the older ActiveX object.
	try {
		//If we are using IE.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		//Else we must be using a non-IE browser.
		xmlhttp = false;
	}
}

//If we are using a non-IE browser, create a JavaScript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

function showCalendar(year, month) {
	var objID = "calendar";
	var randomNumber = Math.floor(Math.random()*1001)
	var serverPage = "includes/calendar.php?year=" + year + "&month=" + month + "&number=" + randomNumber;
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function createform (e) {

	theObject = document.getElementById("createtask");
	
	theObject.style.visibility = "visible";
	theObject.style.height = "200px";
	theObject.style.width = "200px";
	
	var posx = 0;
	var posy = 0;
	
	posx = e.clientX + document.body.scrollLeft;
	posy = e.clientY + document.body.scrollTop;
	
	theObject.style.left = posx + "px";
	theObject.style.top = posy + "px";
	
	//The location we are loading the pagin into.
	var objID = "createtask";
	var serverPage = "includes/createtask.php";
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);

}

function closetask () {

	theObject = document.getElementById("createtask");
	
	theObject.style.visibility = "hidden";
	theObject.style.height = "0px";
	theObject.style.width = "0px";
	
}

function checkfortasks (thedate, e) {
	theObject = document.getElementById("taskbox");
	
	theObject.style.visibility = "visible";
	
	var posx = 0;
	var posy = 0;
	
	posx = e.clientX + document.body.scrollLeft;
	posy = e.clientY + document.body.scrollTop;
	
	theObject.style.left = posx + "px";
	theObject.style.top = posy + "px";
	
	serverPage = "includes/taskchecker.php?thedate=" + thedate;
	objID = "taskbox";
	
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function hidetask () {
	tObject = document.getElementById("taskbox");
	
	tObject.style.visibility = "hidden";
	tObject.style.height = "0px";
	tObject.style.width = "0px";
}

