function jphp(metodo, url, post, funcao, carregando) {
	try {
		ajax = new XMLHttpRequest();
	} catch(ee) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				ajax = false;
			}
		}
	}

	mostrarCarregando(carregando)
	
	if(metodo == "GET") {
		ajax.open("GET", url+'?'+post, true);
		ajax.send(null);
	} else {
		ajax.open("POST", url, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");			
		ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		ajax.setRequestHeader("Pragma", "no-cache");
		ajax.send(post);
	}
	
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4 && ajax.status == 200) {
			removerCarregando(carregando)
			eval(funcao+"(url_decode(ajax.responseText));")
		}
	}
}

function removerCarregando(id) {
	document.getElementById(id).style.display = "none"
}

function mostrarCarregando(id) {
	document.getElementById(id).style.display = "block"
}

function url_encode(str) { 
	var hex_chars = "0123456789ABCDEF"; 
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
	var n, strCode, hex1, hex2, strEncode = ""; 

	for(n = 0; n < str.length; n++) { 
		if (noEncode.test(str.charAt(n))) { 
			strEncode += str.charAt(n); 
		} else { 
			strCode = str.charCodeAt(n); 
			hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
			hex2 = hex_chars.charAt(strCode % 16); 
			strEncode += "%" + (hex1 + hex2); 
		} 
	}
	
	return strEncode;
} 

function url_decode(str) { 
	var n, strCode, strDecode = ""; 

	for (n = 0; n < str.length; n++) { 
		if (str.charAt(n) == "%") { 
			strCode = str.charAt(n + 1) + str.charAt(n + 2); 
			strDecode += String.fromCharCode(parseInt(strCode, 16)); 
			n += 2; 
		} else { 
			strDecode += str.charAt(n); 
		} 
	}
	
	return strDecode; 
}
