var req;
var ajaxResponse;
var ajaxDiv = "dvAjax";
var isInitialized = false;
	
function Initialize(_divName){
	ajaxDiv = _divName;
	
	//se esta incializado
	//if(isInitialized){
		try{req = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e){
			try{req = new ActiveXObject("Microsoft.XMLHTTP");}
			catch(oc){req = null;}
		}

		if ( !req && typeof XMLHttpRequest != "undefined" ) 
			req = new XMLHttpRequest();
		
		isInitialized = true;
		
	//}
}


function getAjaxData(_url){
	if(!isInitialized){
		alert('A função Initialize(divName) não foi chamada!');
		return false;
	}
	var url = "";
	document.getElementById(ajaxDiv).innerHTML = "<span style='position:relative;top:0%;width:50px;background-color:#ff6f03;font-family:Tahoma;font-size:12px;color:White;z-index:99;'>&nbsp;&nbsp;carregando...&nbsp;&nbsp;&nbsp;</span>";
	
	//maque unique	
	if(_url.indexOf('?') > 0) 
		url = _url + "&ms=" + new Date().getTime();
	else 
		url = _url + "?ms=" + new Date().getTime();
	
	//req = null;
	
	if ( req != null ){
		req.onreadystatechange = ProcessaAjax;
		req.open("GET", url, true);
	    req.send(null);
	}
	//se req == null, entao browser nao suporta ajax:
	else{	
		ProcessEnd = null;
		HideDiv(ajaxDiv);
		url = _url.replace(".ajax", ""); 
		url = url.replace("template=none", ""); 
		//alert(url);
		window.location.href = url;
	}
	
}

function ProcessEnd(){};

function ProcessaAjax(){
	if (req.readyState == 4){
        // only if "OK"
		if (req.status == 200){
			if(req.responseText=="")
				HideDiv(ajaxDiv);
			else{
				ShowDiv(ajaxDiv);
				document.getElementById(ajaxDiv).innerHTML = "";
				ProcessEnd(trim(req.responseText));
			}
		}
		else{
			document.getElementById(ajaxDiv).innerHTML="Erro:"+req.statusText;
		}
	}
}

//trim string
function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

//mostra o div
function ShowDiv(divid){
	el = document.getElementById(divid);
	el.style.display = '';
}

//esconde o div
function HideDiv(divid){
	el = document.getElementById(divid);
	el.style.display = 'none';
}