var Ajax = new Object();

/*
url = url of the file to load 
loadedFunction = the name of the function that will receive the response xml object
errorFunction = the name of the function that will be called if there is an error.
unchangedFunction = the name of the function that will be called if the server returns a 304.
*/

Ajax.getXmlFile = function(url, loadedFunction, unchangedFunction, errorFunction) {	
	var StateChange = function() {
		if (req.readyState == 4) {
			if (req.status == 200) {
				xmlDoc = req.responseXML;
				eval(loadedFunction + '(xmlDoc, req, url)');
			}
			else if (req.status == 304) {
				eval(unchangedFunction + '(req, url)');
			}
			else {
				// there was an issue retreiving the XML file.  try again.
				eval(errorFunction + '(req, url)');
			}
		}
	}
	if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = StateChange;
    req.open("GET", url, true);
    req.send(null);
  }
  else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    req.open("GET", url, true);
    req.onreadystatechange = StateChange;
		req.send();
  }
	else {
	  // we need to message the user they do not support live scoring.
	}
}

// this function takes the place of document.getElementById
function $(element) {
	if (arguments.length > 1) {
		for(i=0,elements=[],length=arguments.length;i<length;i++) {
			elements.push($(arguments[i]));
			return elements;
		}
	}
	if (typeof element == 'string') {
		element = document.getElementById(element);
		return element;
	}
}