function x_LoadXML(strURL,strLoadingText){
	var objXML=null;
	
	// CRIA O OBJETO XMLHttpRequest
	try{ objXML=new XMLHttpRequest(); }
	catch(e){
		try{ objXML=new ActiveXObject("Msxml3.XMLHTTP"); }
		catch(e){
			try{ objXML=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e){
				try{ objXML=new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) { alert("Your browser does not suport AJAX! Please use a newer browser!"); return false; }
			}
		}
	}
	
	// MOSTRA LOADING
	x_fncShowLoading(strLoadingText);
	
	// HANDLER PARA STATECHANGE
	objXML.onreadystatechange = function(){
		
		if(objXML.readyState == 4){ // readyState 4 = request complete
			if(objXML.status == 200){ // status 200 = no errors found
				
				// PROCESSA A RESPOSTA
				response = objXML.responseXML.documentElement; // process the result
				if(response){
					if(response.getElementsByTagName("function")[0].firstChild){
						strFunction = response.getElementsByTagName("function")[0].firstChild.data;
					}else{ strFunction=""; }
					if(response.getElementsByTagName("results")[0].firstChild){
						strResults = response.getElementsByTagName("results")[0].firstChild.data.replace(/\{\[\(/g,"<").replace(/\)\]\}/g,">");
					}else{ strResults=""; }
					if(strFunction!=""){ eval(strFunction + "(strResults)"); }
					
				}else{ alert("AJAX ERROR: not a valid XML object"); }
			}else{ alert("AJAX ERROR loading data:\n" + objXML.status + ": " + objXML.statusText); }
			
			// ESCONDE LOADING
			x_fncHideLoading();
		}
		
	}
	
	// ABRE, CONFIGURA E ENVIA A SOLICITACAO
	objXML.open("GET",encodeURI(strURL),true); //open("method","URL",async,"uname","pswd")
	objXML.setRequestHeader("Content-Type", "text/xml; charset=UTF-8");
	objXML.setRequestHeader("charset","UTF-8");
	objXML.setRequestHeader("Encoding","UTF-8");
//	objXML.open("POST",strURL,true); //open("method","URL",async,"uname","pswd")
//	objXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	objXML.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	objXML.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	objXML.setRequestHeader("Pragma", "no-cache");
	if(objXML.overrideMimeType){ objXML.overrideMimeType("text/xml"); }
	objXML.send(null);
}



var x_objBody,x_DivBg,x_DivLoading,x_loadingTimeout

// MOSTRA O LOADING
function x_fncShowLoading(strLoadingText){ clearTimeout(x_loadingTimeout); x_loadingTimeout=setTimeout("x_fncShowLoading2('"+strLoadingText+"')",200); }
function x_fncShowLoading2(strLoadingText){
	x_objBody = document.body;
	x_fncSHSelects("hidden");
	
	// cria o div de fundo
	if(x_getObj("x_ajaxLoadingBg")){
		x_DivBg = x_getObj("x_ajaxLoadingBg");
		x_DivBg.innerHTML = "";
	}else{
		x_DivBg = document.createElement("div");
		x_DivBg.setAttribute("id","x_ajaxLoadingBg");
		x_objBody.appendChild(x_DivBg);
	}
	
	
	
	// cria o div loading
	if(x_getObj("x_ajaxLoading")){
		x_DivLoading = x_getObj("x_ajaxLoading");
		x_DivLoading.innerHTML = "";
	}else{
		x_DivLoading = document.createElement("div");
		x_DivLoading.setAttribute("id","x_ajaxLoading");
		x_objBody.appendChild(x_DivLoading);
	}
	
	
	
	// cria o conteudo do loading
	x_DivContent = document.createElement("div");
		x_ImgPoints = document.createElement("img");
		x_ImgPoints.setAttribute("src","imagens/tres_pontos.gif");
		x_DivContent.appendChild(document.createTextNode(strLoadingText));
		x_DivContent.appendChild(x_ImgPoints);
	
	x_DivLoading.appendChild(x_DivContent);
	
	
	
	// redimensiona e posiciona os div
	var arrayPageSize = x_getPageSize();
	var arrayPageScroll = x_getPageScroll();
	//x_DivBg.style.width = arrayPageSize[0]+"px";
	x_DivBg.style.height = arrayPageSize[1]+"px";
	x_DivBg.style.zIndex="10000";
	
	x_DivLoading.style.left = ((arrayPageSize[0]/2)-(x_DivLoading.offsetWidth/2))+"px";
	x_DivLoading.style.top = (arrayPageScroll[1]+(arrayPageSize[3]/2)-(x_DivLoading.offsetHeight/2)-30)+"px";
	x_DivLoading.style.zIndex="10001";
}


// ESCONDE O LOADING
function x_fncHideLoading(){
	clearTimeout(x_loadingTimeout);
	if(x_DivBg){
		x_DivBg.innerHTML = "";
		x_DivBg.style.display = "none";
		x_DivBg = null;
	}
	if(x_DivLoading){
		x_DivLoading.innerHTML = "";
		x_DivLoading.style.display = "none";
		x_DivLoading = null;
	}
	x_fncSHSelects("visible");
	setTimeout("clearTimeout(x_loadingTimeout)",250);
}












// ##################################################
// ##################################################
// OUTRAS FUNCOES UTEIS
// ##################################################
// ##################################################

function x_getObj(xP_objID){
	if(document.getElementById){ return document.getElementById(xP_objID); }
	else if(document.all){ return document.all[xP_objID]; }
	else if(document.layers){ return document.layers[xP_objID]; }
	return false;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function x_getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function x_getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // repete
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function x_fncSHSelects(strShowHide){
	if(navigator.appVersion.indexOf("MSIE")!=-1){
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) { selects[i].style.visibility = strShowHide; }
	}
}
















