var ajaxLoadDiv;
var Ajax = function() {
	//if (!theBody){ theBody = document.getElementsByTagName('BODY')[0]; }
	//ajaxLoadDiv = document.createElement('DIV');
	//ajaxLoadDiv.style.background = '#FFFFFF';
	//ajaxLoadDiv.innerHTML = '<img src="' + URLCREFISANET + '/imagens/ajax-loader.gif"> carregando...';
	//ajaxLoadDiv.innerHTML = '<img src="http://www.thesafehouse.org/~fricka/Offline/zooms/loading_zoom.jpg">';
	//ajaxLoadDiv.style.position = 'absolute';
	//ajaxLoadDiv.style.visibility = 'hidden';
	//ajaxLoadDiv.style.display = 'none';
	//mousePersuit(ajaxLoadDiv);
	//theBody.appendChild(ajaxLoadDiv);

	var self 			= this;
	var xmlhttp 		= null;

	this.file  			= null;
	this.ret    		= null;
	this.xml    		= '';
	this.xmlDoc 		= null;
	this.transf 		= 'POST';
	this.debug			= false;
	this.returnType 	= 'xml';
	
	this.load = function(){;
			//ajaxLoadDiv.style.visibility = 'visible';
			//ajaxLoadDiv.style.display = 'block';	
			//theBody.style.cursor = "progress";
		if (self.file != '' && self.ret != '') {
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e1) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e2) {
					if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
						xmlhttp = new XMLHttpRequest();
					}
				}
			}
			if (xmlhttp != null) {
				xmlhttp.onreadystatechange = _testReadyStateSend;
				
				if (self.transf == 'POST'){
					xmlhttp.open('POST', self.file, true);
					xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					xmlhttp.send(self.xml);
				} else {
					if (self.xml != ''){
						self.xml = '?' + self.xml;
					}
					xmlhttp.open('GET', self.file + self.xml, true);
					xmlhttp.send(false);
				}

			}
		} else {
			return false;
		}
	}


	function _testReadyStateSend() {
		if (xmlhttp.readyState == 4) {
			//theBody.style.cursor = "auto";
			//ajaxLoadDiv.style.visibility = 'hidden';
			//ajaxLoadDiv.style.display = 'none';

			if (xmlhttp.status == '200') {
				_evalInternalGet();
			} else {
				alert('Página nao encontrada');
				return false;
			}
		}
	}

	function _testReadyStateReturn() {
		if (self.xmlDoc.readyState == 4) {
			_evalReturn();
		}
	}

	function _evalReturn() {
		var retFunc = '';
		if (typeof(self.ret) == 'function') {
			eval('new self.ret');
		}
	}

	function _evalInternalGet() {
		self.xmlDoc = (self.returnType == 'xml' ? xmlhttp.responseXML : xmlhttp.responseText);
		if (self.debug){
			var newDiv = document.createElement("DIV");
			newDiv.setAttribute("style", "position:absolute; width:640; left:150; top:300; background: #FFFFFF; border: 2px solid #000000");
			var txt = document.createTextNode(xmlhttp.responseText);
			newDiv.appendChild(txt);
			//theBody.appendChild(newDiv);
		}
		_evalReturn();
	}
}
