// JavaScript Document
function addEvent(obj, evt, func) {
  if (obj.attachEvent) {
    return obj.attachEvent(evt, func);
  } else if (obj.addEventListener) {
    obj.addEventListener(evt, func, true);
    return true;
  }
  return false;
}

function openAjax() { 
	var Ajax; 
	try {Ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers mais populares, como: Firefox, Safari, dentre outros. 
	}catch(ee) { 
		try {Ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS 
	}catch(e) { 
		try {Ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS 
	}catch(e) {Ajax = false; 
	} 
	} 
	} 
	return Ajax; 
} 

function exemplo(){
var tecla = window.event.keyCode;
//window.status = "Você pressionou a tecla: " + String.fromCharCode(tecla);
//alert("O Código da tecla pressionada é: " + tecla);
}

function carregaAjax(div, getURL) {
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C. 
		if (document.getElementById(div).style.display == "none"){ //If do leo
			document.getElementById(div).style.display = "block";
			var exibeResultado = document.getElementById(div); // div que exibirá o resultado. 
			var Ajax = openAjax(); // Inicia o Ajax. 
			Ajax.open("GET", getURL, true); // fazendo a requisição 
			Ajax.onreadystatechange = function(){ 
				if(Ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando... 
					exibeResultado.innerHTML = "<div><img src='http://www.braziliancarbonbureau.com.br/img/ajax-loader.gif' alt='Carregando' /></div>";
				} 
				if(Ajax.readyState == 4) { // Quando estiver tudo pronto. 
					if(Ajax.status == 200) { 
						var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável 
						resultado = resultado.replace(/\+/g,""); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4)
						//resultado = resultado.replace(/ã/g,"a");
						resultado = unescape(resultado); // Resolve o problema dos acentos 
						exibeResultado.innerHTML = resultado; 
					} else { 
						exibeResultado.innerHTML = "<span class='fonteMenu'>Por favor, tente novamente!</span>"; 
					} 
				} 
			} 
			Ajax.send(null); // submete
		}else{
			document.getElementById(div).style.display = "none";
		}
	}
}