/* Send a new Ajax Request
@param url = file to post to
@param vars = variables to post ['id=1&name=john']
@param destination = Javascript function when the data gets returned 
*/
function AjaxRequest(url, vars, destination) {
	document.body.style.cursor = "progress";
	vars = vars + '&destinationurl='+url;
	if (!destination) { destination = 'doNothing'; }
	var xmlhttp = new xmlhttpObject();
	xmlhttp.onreadystatechange = function () { stateChange(); };
	xmlhttp.open('POST', 'request/', true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  	xmlhttp.send(vars);
	 
	function stateChange() {
		if (xmlhttp.readyState == 4) {
 			if (xmlhttp.status == 200) {
 				document.body.style.cursor = "default";
 				destination(xmlhttp.responseText);
 			}
 		}
	}
}

function AjaxResponse(response) { document.getElementById("ajax_div").innerHTML=response; }

function xmlhttpObject() {
	if (window.XMLHttpRequest) {
 		return new XMLHttpRequest();
	}
	return new ActiveXObject("Microsoft.XMLHTTP");
}

function doNothing() {
//nothing happens in here
}


function blogajax(url, vars, destination) {
	vars = vars + '&destinationurl='+url;
	if (!destination) { destination = 'doNothing'; }
	var xmlhttp = new xmlhttpObject();
	xmlhttp.onreadystatechange = function () { stateChange(); };
	xmlhttp.open('POST', '../request/', true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  	xmlhttp.send(vars);
	 
	function stateChange() {
		if (xmlhttp.readyState == 4) {
 			if (xmlhttp.status == 200) {
 				destination(xmlhttp.responseText);
 			} else {
 				alert('There was a problem in the returned data');
 			}
 		}
	}
}
