var Ajax = new Object();
Ajax.requestList = new Array();
Ajax.isUpdating = false;

Ajax.Request = function(method, url, query, callback)
{
	if (this.isUpdating == false) {
		this.isUpdating = true;
		this.performRequest(method, url, query, callback);
	}
	else {
		var call = new Object();
		call.method = method;
		call.url = url;
		call.query = query;
		call.callback = callback;
		this.requestList.push(call);
	}
}
	
Ajax.performRequest = function(method, url, query, callback) {
	this.callbackMethod = callback;
	this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP"); 
	this.request.onreadystatechange = function() { Ajax.checkReadyState(); };
	
	if(method.toLowerCase() == 'get') url = url+"?"+query;
	//alert(url);
	this.request.open(method, url, true);
	this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this.request.send(query);
}

Ajax.checkReadyState = function(_id)
{
	switch(this.request.readyState)
	{
		case 1: break;
		case 2: break;
		case 3: break;
		case 4:
			//this.callbackMethod(this.request.responseXML);
			this.callbackMethod(this.request.responseText);
			if (this.requestList.length > 0) {
				call = this.requestList.pop();
				this.performRequest(call.method, call.url, call.query, call.callback);
			}
			else {
				this.isUpdating = false;
			}
	}
}

// Searches for a tag identified by 'tagName' in the provided document element,
// and returns the text contained within that tag.
function getTagValue(element, tagName) {
	if (element.getElementsByTagName(tagName).length > 0)
		return element.getElementsByTagName(tagName)[0].firstChild.nodeValue;
	else
		return false;
}

function getTagValueById(element, tagName, tagId) {
	if (element.getElementsByTagName(tagName).namedItem(tagId) > 0)
		return element.getElementsByTagName(tagName).namedItem(tagId).innerHTML;
	else
		return false;
}

