
function xmlhttpObject() {
	var xmlHttpReq = null;
	if(window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		try {
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {}
		}
	}
	return xmlHttpReq;
}

function xmlhttpPost(strURL, success, failure) {
	var strURL = strURL.split('?');
	var xmlHttpReq = xmlhttpObject();
	xmlHttpReq.open('POST', strURL[0], true);
	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() { stateChanged(xmlHttpReq, success, failure); }
	xmlHttpReq.send(strURL[1]);
}

function xmlhttpGet(strURL, success, failure) {
	var xmlHttpReq = xmlhttpObject();
	xmlHttpReq.open('GET', strURL, true);
	xmlHttpReq.onreadystatechange = function() { stateChanged(xmlHttpReq, success, failure); }
	xmlHttpReq.send(null);
}

function stateChanged(xmlHttpReq, success, failure) {
	try {
		if (xmlHttpReq.readyState == 4) {
			if(xmlHttpReq.status == 200) {
				success(xmlHttpReq.responseText);
			}
			if(xmlHttpReq.status == 404) {
				if(failure) {
					failure(xmlHttpReq.responseText);
				}
			}
		}
	} catch(e) {
		if(failure) {
			failure(e.description);
		}
	}
}

function success(str) {
}

function failure(str) {
}

function download(url, success, failure) {
	var a = url.split('?')[1] != null ? '&' : '?';
	url +=  a + 'r=' + Math.random();	// tack on random number to prevent caching
	xmlhttpGet(url, success, failure);
}

