var httpReq;

function sendRequest(queryString, postData, callback) {
	httpReq = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    
    if(httpReq) {
        httpReq.onreadystatechange = function() {processRequest(callback);};		
		// setup to handle GET or a POST, based on the data
		httpReq.open((postData == null ? "GET" : "POST"), 'view_controller.php?'+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);
		if(console) {
			console.log(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;
	}
}
