var httpReq;

function sendRequest(page, queryString, postData, callback) {
	httpReq = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    
    if(!page) {
    	page = 'view_controller.php';
    }
    
    if(httpReq) {
        httpReq.onreadystatechange = function() {processRequest(callback);};		
		// setup to handle GET or a POST, based on the data
		httpReq.open((postData == null ? "GET" : "POST"), page+'?'+queryString, true);
		if(postData && postData.length > 0) {			
			httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");			
		}
		
		httpReq.send(postData);
    }
}

function processRequest(callback) {
	if(httpReq.readyState == 4 && httpReq.status == 200) {
		eval(callback);
    } else if (httpReq.readyState == 4 && httpReq.status != 200) {
		// oh noes, http error
		alert('HTTP error: '+httpReq.status);
		// NOTE: This console check looks perfectly valid to me - but it's throwing a Javascript error in FF. Switching to an alert for now.
		//if(console) {
		//	console.log(httpReq.responseText);
		//}
		alert(httpReq.responseText);
		return;
	}
}

function getPageDataDirect(url) {
	var req = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	
	if(req) {
		req.open("GET", url, false);
		req.send(null);
		
		return req.responseText == null ? '' : req.responseText;
	}
}