//Utilitarios
function replaceText(el, text) {
  if (el != null) {
    clearText(el);
	el.innerHTML = text;
   
  }
}

function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}

function getText(el) {
  var text = "";
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        if (childNode.nodeValue != null) {
          text = text + childNode.nodeValue;
        }
      }
    }
  }
  return text;
}
/// Fim Utilitarios
var request = null;
function createRequest() {
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxm12.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = null;
			}
		}
	}
	if (request == null) {
		alert("Erro ao criar o objeto!");
	}
}

function chajax(link, idelemento){
	createRequest();
	tmpElemento = idelemento;
	url = link;
	request.open("GET",url,true);
	request.onreadystatechange = updatePage;
	request.send(null);
}

function updatePage(){
	btnNews = document.getElementById(tmpElemento);
	if(request.readyState < 4) {
	   	btnNews.innerHTML = '<br /><br /><b><i>Carregando...</i></b><br /><br />';
	} else {
		if(request.status == 200){
				c=window.setTimeout(function (){ btnNews.innerHTML  = request.responseText; }, 3000);
		} else {
				btnNews.innerHTML = 'Erro: A solicitacao AJAX falhou!';
		}
	}
}