/*
	caiacAJAX 1.0 - 23/11/2007
	-------------------------------------------
	Caiac Soluções Para Internet
	www.caiac.com.br
*/

var caiacAJAX = function() {
	var modo = "POST";
	var async = true;
	var xmlhttp  = false;
	var callback;
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ex) {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch(exc) {
				xmlhttp = false;
			}
		}
	}
	this.executa = function() {
		var script   = arguments[0];
		callback = arguments[1];
		var query = "";
		if (script == 'SELF') script = document.location.href;
		for (i = 2; i < arguments.length; i++) {
			if (i == 2) query += "var[]=" + encodeURIComponent(arguments[i]);
			else query += "&var[]=" +  encodeURIComponent(arguments[i]);
		}
		if (modo == "GET") script = script + "?" + query;
		xmlhttp.open(modo, script, async);
		if (modo == "POST") xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = xmlhttpcallback;
    if (modo == "GET") xmlhttp.send(null);
    else xmlhttp.send(query);
    if (async == true) xmlhttpcallback();
	}
	var xmlhttpcallback = function() {
		var resp = null;
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				resp = xmlhttp.responseText;
				resp = resp.replace(/\+/g," ");
				resp = unescape(resp);
				if (typeof callback == 'function') callback(resp);
			} else {
				alert("Ocorreu um erro:\n" + xmlhttp.statusText);
			}
		}
	}
}
