function ajax(url,params,aonde,msg,redirect) {
  http.open("POST", url, true);
  http.onreadystatechange = function() { abrir(aonde,msg,redirect); };
  
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");

  http.send(params);
}

function abrir(aonde,msg,redirect) {
    ajx = document.getElementById(aonde);
  //if (http.readyState == 1) { if (msg == undefined) {msg = '<img src="img/loadbar.gif">';} ajx.innerHTML = msg; }
  if (http.readyState == 1) { 
  		if ((msg == undefined) || (msg == '')) {
  		ajx.innerHTML = "carregando...";
  		} else {
  			ajx.innerHTML = msg;
  		}
  }
  if (http.readyState == 4 && http.status == 200) { 
  	res = http.responseText;
    ajx.value = res;
    ajx.innerHTML = res;
    ajx.innerHTML = res;
    if (redirect != undefined) {
    window.location=redirect;
    }
  }
}

function getXHTTP( ) {
  var xhttp;
   try {
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
	    try {
	      xhttp = new XMLHttpRequest();
	    } catch (e3) {
	      xhttp = false;
	    }
      }
    }
  return xhttp;
}

var http = getXHTTP();