function createRequest () {
	var request = null;
	
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request == null;
			}
		}
	}

	if (request == null) {
		alert("There was an error trying to process this page. Please upgrade your browser to the latest version. Note: this page does not support IE 5 on Macintosh (use Safari or Firefox).");
	} else {
		return request;
	}
}

function replaceText(el, text) {
	if (el != null) {
		clearText(el);
		var newNode = document.createTextNode(text);
		el.appendChild(newNode);
	}
}

function clearText(el) {
	if (el != null) {
		if (el.childNodes) {
			for (var i = 0; i < el.childNodes.length; i++) {
				var childNode = el.childNodes[i];
				el.removeChild(childNode);
			}
		}
	}
}

function getText(el) {
	var text="";
	if (el != null) {
		if (el.childNodes) {
			for (var i = 0; i < el.childNodes.length; i++) {
				var childNode = el.childNodes[i];
				if (childNode.nodeValue != null) {
					text = text + childNode.nodeValue;
				}
			}
		}
	}
	return text;
}
	

function fetchData(url, dataToSend, objectID, this_msg) {
	request = createRequest();
	request.onreadystatechange=function() {
		var object = top.document.getElementById(objectID);
		if (object == null) object = document.getElementById(objectID);
		if (request.readyState < 4) {
			if (this_msg) {
				object.innerHTML='<span class="ajaxmessage">' + this_msg + '</span>';
			}
		} else if (request.readyState == 4) {
			if (request.status == 200) {
				object.innerHTML = request.responseText;
			} else {
				alert("Error: Request status is " + request.status);
			}
		}
	}
	
	if (dataToSend) {
		request.open('POST',url,true);
		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send(dataToSend);
	} else {
		request.open('GET',url,true);
		request.send(null);
	}
}


// Post Temp Message
// Posts a message in a div for a specified number of seconds, then clears it
function postTempMessage(div_id, message, seconds) {
	var this_div = document.getElementById(div_id);
	clearText(this_div); // clear any existing contents
	this_div.innerHTML = '<span class="ajaxmessage">' + message + '</span>';
	
	//var message_obj = document.createTextNode(message);
	//this_div.appendChild(message_obj); // set the message
	
	var seconds = seconds * 1000; //transform seconds to milliseconds
	var mytime=setTimeout(function () {if (this_div != null) clearText(this_div);},seconds); // set the timer to clear the message
}