// manda uma requisição assincrona para o servidor
/**
_url = página que será executada;
_parametros = parametros que serão enviados a página;
_ret = objeto
_retorno = como a funcao vai retornar os dados;
			* 0 = retorno via alert
			* 1 = retorno via propriedade innerHTML do objeto passado (Está opção não funciona p/ Objetos Table, Select, Span no IE)
			* 2 = não retorna valor
			* 3 = retorna um texto 
*/

	function sendRequest(_url, _parametros, _retorno, _ret){
		if(typeof _retorno == 'undefined')
			_retorno = 0;

		if(typeof _ret == 'undefined')
			_ret = null;

		var ajax = false;
		if (window.XMLHttpRequest){
			ajax = new XMLHttpRequest();
		}else if (window.ActiveXObject){
			ajax = new ActiveXObject("Microsoft.XMLHttp");
			if (!ajax){
				ajax = new ActiveXObject("MSXML2.XMLHttp")
			}
		}

		if (ajax){
			ajax.open("POST", _url, true);

			ajax.onreadystatechange = function(){
				if (ajax.readyState == 4){
					if (ajax.status == 200){
						switch(_retorno){
							case 0:
								var tmp = ajax.responseText.replace(/^\s+|\s+$/,""); 
								tmp = tmp.replace(/\s+/," ");
								alert(tmp);
								break;
							case 1:
								_ret.innerHTML = ajax.responseText;
								break;
							case 2:
								break;
							case 3:
								_ret = ajax.responseText;
								break;	
							
							
						}
					}
					else{
						alert(ajax.status + " - " + ajax.statusText);
					}
				}
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send(_parametros);
	}
	
	/**	
	_url = página que será executada;
	_parametros = parametros que serão enviados a página;
	_ret = objeto
	_retorno = como a funcao vai retornar os dados;
				* 0 = retorno via alert
				* 1 = retorno via propriedade innerHTML do objeto passado
				* 2 = não retorna valor
	*/

	function sendSyncRequest(_url, _parametros, _retorno, _ret){
		if(typeof _retorno == 'undefined')
			_retorno = 0;

		if(typeof _ret == 'undefined')
			_ret = null;

		var ajax = false;
		if (window.XMLHttpRequest){
			ajax = new XMLHttpRequest();
		}else if (window.ActiveXObject){
			ajax = new ActiveXObject("Microsoft.XMLHttp");
			if (!ajax){
				ajax = new ActiveXObject("MSXML2.XMLHttp")
			}
		}

		if (ajax){
			ajax.open("POST", _url, false);
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send(_parametros);
		
		switch(_retorno){
			case 0:
				var tmp = ajax.responseText.replace(/^\s+|\s+$/,""); 
				tmp = tmp.replace(/\s+/," ");
				alert(tmp);
				break;
			case 1:
				_ret.innerHTML = ajax.responseText;
				break;
			case 2:
				break;
			case 3:
				_ret = ajax.responseText;
				break;	
		}
	}
