function AJAX(url,metodo,params,processa,modo,executeJS) {
	this.url = url;
	this.metodo = (metodo) ? metodo : 'GET';
	this.params  = (metodo='GET') ? null : params;
	this.processaresultado = processa;
	this.Header = new Array();
	this.modo = (modo) ? modo : 'T';
	this.executeJS = (executeJS) ? executeJS : false;
	if(this.modo!='T'&&this.modo!='X') {
		this.modo = 'T';
	}
	this.complete = null;
	this.conectar();
}

AJAX.prototype = {
	addHeader:function(h,v) {
		this.Header[h] = v;
	},
	delHeader:	function(h) {
		delete(this.Header[h]);
	},
	setHeader:function() {
                if(this.httprequest===null) {return;}
		for(h in this.Header) {
                    try {
                        this.httprequest.setRequestHeader(h,this.Header[h]);
                    } catch (e) { }
		}
	},
	conectar:function() {
            if (!this.loading) this.createLoading();
            if(this.url===undefined||this.url==='') {
                return;
            }
            this.httprequest = null;
            if (window.XMLHttpRequest) { // Mozilla, Safari,...
                this.httprequest = new XMLHttpRequest();
            } 
            else if (window.ActiveXObject) { // IE
                try {
                } 
                catch (e) {
                    try {
                        this.httprequest = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) { }
                }
            }
            if(this.httprequest!==null&&this.httprequest!==undefined) {
                var obj = this;
                this.httprequest.onreadystatechange = function() {
                    obj.processaretorno.call(obj);
                };
                if(this.metodo===undefined||this.metodo==='') {this.metodo = 'GET';}
                this.httprequest.open(this.metodo,this.url, true);
                this.setHeader();
                this.httprequest.send(this.params);
            }
	},
	processaretorno:	function() {
		if(this.httprequest.readyState==4) {
			if(this.httprequest.status==200) {

				var resp = (this.modo=='T') ? this.httprequest.responseText : this.httprequest.responseXML;

				if(this.processaresultado!==null) {
					this.processaresultado(this, resp);
					if (this.executeJS) launchJavascript(resp);
				}
				else{
					eval.write(resp);
				}
                                this.removeLoading();
				if(this.complete!==null) {
					this.complete();
				}

			}
			else{
				this.processaerro();
			}
		}
	},
	processaerro:		function() {
		alert(this.httprequest.status + '-' + this.httprequest.statusText + ' :-> ' + this.url);
	},
        
	createLoading: function() {
		this.loading = document.createElement('span');
		
		this.loading.id = "ajax-loading";
		this.loading.className = "loading";
		this.loading.innerHTML = '<div class="divLoading"><img border="0" src="images/ajax-loader.gif"><br>Carregando...<div>';
		document.body.appendChild(this.loading);
	},

        removeLoading: function() {
        this.loading.parentNode.removeChild(this.loading);
            this.loading = null;
	}        
        
        
};

function GROUP(ajaxArray){

	this.ajax = ajaxArray;
	this.completed = 0;
	this.complete = null;

}

GROUP.prototype = {
	conectar: function(){
		for(var i=0; i<this.ajax.length; i++){
			var obj = this;
			this.ajax[i].complete = function(){
				obj.completed++;
				if((obj.completed == obj.ajax.length)&&(obj.complete!==null)) obj.complete();
				if(obj.onComplete) if((obj.completed == obj.ajax.length)&&(obj.onComplete!==null))obj.onComplete();
			}
			this.ajax[i].conectar();
		}
	}
};

function GROUP_COMPONENT(groupArray){

	this.group = groupArray;
	this.completed = 0;
	this.complete = null;

}

GROUP_COMPONENT.prototype = {
	conectar: function(){
		for(var i=0; i<this.group.length; i++){
			var obj = this;
			this.group[i].onComplete = function(){
				obj.completed++;
				if((obj.completed == obj.group.length)&&(obj.complete!==null))obj.complete();
			}
			this.group[i].conectar();
		}
	}
};

function launchJavascript(responseText) {

	var ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:</script>)';

	var match    = new RegExp(ScriptFragment, 'img');
	var scripts  = responseText.match(match);

	if(scripts) {
		var js = '';
		for(var s = 0; s < scripts.length; s++) {
			var match = new RegExp(ScriptFragment, 'im');
			js += scripts[s].match(match)[1];
		}
		eval(js);
	}

}


