function wg_ajax (container, url, post_data, func) {
	var containerObj = document.getElementById (container);
	var xmlhttp;
	
	if (! containerObj)
		return false;
	
	var navegador = navigator.userAgent.toLowerCase();
	if (navegador.indexOf ("msie") != -1) {
		var controle = (navegador.indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
		xmlhttp = new ActiveXObject(controle);
	}
	else {
		xmlhttp = new XMLHttpRequest();
		if (! xmlhttp) {
			containerObj.innerHTML = "Seu navegador n&atilde;o tem suporte a AJAX";
			return false;
		}
	}
	
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
			if (xmlhttp.status == 200) {
				wg_script (xmlhttp.responseText, true);
				containerObj.innerHTML = xmlhttp.responseText; 
				if (func != "undefined" && func)
					func(null);
			}
		}
		else
			containerObj.innerHTML = "";
	}
	if (post_data) {
		xmlhttp.open('POST', url+'?'+post_data, true);
		xmlhttp.send(post_data); 
	}
	else {
		xmlhttp.open ("GET", url, true);
		xmlhttp.send(null); 
	}

}

function wg_script (string, direct){
    var ini = 0;
	
	if (direct == true) {
		while (ini != -1) {
			ini = string.indexOf ('<script', ini);
			if (ini >= 0){
				ini = string.indexOf ('>', ini) + 1;
	
				var fim = string.indexOf ('</script>', ini);
				var codigo = string.substring (ini, fim);
				
			}
		}
	}
	else
		var codigo = string;

	var script = document.createElement ("script");
	script.setAttribute ("type", "text/javascript");
	script.text = codigo;
	var head = document.getElementsByTagName("head")[0];
	//head.appendChild (script);
	document.body.appendChild (script);
}
