var please_wait = "<center><img src='../img/carregando.gif'></center>";
var xmlhttp;

function ajaxXML(url){
	xmlhttp=null;
	if (window.XMLHttpRequest){
		// code for IE7, Firefox, Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){
		// code for IE5, IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){
		xmlhttp.onreadystatechange = function(){responseXML();}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}else{
		alert("Seu browser não suporta XMLHTTP.");
	}
	return xmlhttp;
}

function responseXML(){
	if(xmlhttp.readyState!=4) return;
	if(xmlhttp.status!=200){
		alert("Página não encontrada");
		return;
	}else{
		trataXML();
	}
}

function ajax(url, target) {	
 	if ( ! document.getElementById) {
  		return false;
 	}

 	if (please_wait != null) {
  		document.getElementById(target).innerHTML = please_wait;
 	}

 	if (window.ActiveXObject) {
  		link = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
  		link = new XMLHttpRequest();
 	}

 	if (link == undefined) {
  		return false;
 	}
 	link.onreadystatechange = function() { response(url, target); }
 	link.open("GET", url, true);
 	link.send(null);
}

function response(url, target) {
 	if (link.readyState == 4) {
		if( link.responseText == "0" ){
			document.getElementById("frmErroBusca").submit();
		}else{
			document.getElementById(target).innerHTML = (link.status == 200) ? link.responseText : "Página não encontrada! " + link.status;
		}
	}
}

function set_loading_message(msg) {
 	please_wait = msg;
}