		// ********************************************************************
		// Iniciar_Ajax => Função para iniciarmos o Ajax no browser do cliente.
		// ********************************************************************
		function Iniciar_Ajax() 
		{
			var http_request = false;
			if (window.XMLHttpRequest) // Mozilla, Safari,...
			{
				http_request = new XMLHttpRequest();
				if (http_request.overrideMimeType) 
				{
					// Define que o retorno será conteudo XML
					//http_request.overrideMimeType('text/xml');
					
					// Define que o retorno será conteudo HTML 
					http_request.overrideMimeType('text/html');
				}
			}
			else if (window.ActiveXObject) // IE
			{ 
				try 
				{
					http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} 
				catch (e) 
				{
					try 
					{
						http_request = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (e) 
					{
						// Sintax do comando faz com que essa área fique vazia.
					}
				}
			}
			return http_request;
		}
		// ********************************************************************


		// ***********************************************************************
		// Ajax_POST => Envia uma informação AJAX.
		// ***********************************************************************
		function AjaxPOST(arquivo,formulario,div) 
		{
			var http_request = Iniciar_Ajax();
			if (!http_request) 
			{	
				alert('ERRO: AJAX => Não foi possível criar a instancia XMLHTTP.');
				return false;
			}
			
			var AjaxVariaveis;
		    var cont;
			var i;
			var x;
			var elementos;
			
			AjaxVariaveis = "ajax=true";
		  for ($x=0; $x < document.forms.length; $x++)
		  {
		  	if (document.forms[$x].name == formulario)
		  	{
		  		cont = document.forms[$x].elements.length;
		  		for (i = 0; i < cont; i++)
					{
						elementos = document.forms[$x].elements[i];
						if ( (elementos.type=="radio") || (elementos.type=="checkbox") )
						{ //verificar se o objeto é um checkbox ou radio pelo nome correspondente
							if (elementos.checked==true)
							{ // se for checkbox estiver checado contar mais um !!!
								AjaxVariaveis = AjaxVariaveis + '&'+elementos.name+'='+URLEncode(elementos.value);
							}
						}
						else
						{
							AjaxVariaveis = AjaxVariaveis + '&'+elementos.name+'='+URLEncode(elementos.value);
						}
					}
		  	}	
		  }
		  http_request.onreadystatechange = 	function ()
																					{
																							if((http_request.readyState == 1) || (http_request.readyState == 2))  // Quando estiver carregando, exibe: carregando...
																							{ 
																								document.getElementById(div).innerHTML = "<table align='center' height='147'><tr><td><img src='../design/padrao/imagens/ajax4.gif'></td></tr></table>";
																							}
																							else if (http_request.readyState == 4) 
																							{
																								 if (http_request.status == 200) 
																								 {
																									 extraiScript(http_request.responseText);
																									 document.getElementById(div).innerHTML = http_request.responseText;
																								 } 
																								 else 
																								 {
																									 alert('ERRO: AJAX => Não foi possível obter o resultado.');
																								 }
																							}
																					}
			http_request.open('POST', arquivo , true);	
			// -----------------------------------------------------------------------------------
			http_request.setRequestHeader('Content-Type',"application/x-www-form-urlencoded; charset=iso-8859-1");
			http_request.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");
			http_request.setRequestHeader("Cache-Control","post-check=0, pre-check=0");
			http_request.setRequestHeader("Pragma", "no-cache");
			http_request.setRequestHeader("Connection", "close");
			// -----------------------------------------------------------------------------------
			var variaveis_post = "";
			variaveis_post     = AjaxVariaveis;
			// Define o tamanho do POST.
			http_request.setRequestHeader("Content-length", variaveis_post.length);
			// Envia os dados
			http_request.send(variaveis_post);
		}				


// ********************************************************************
function extraiScript(texto){
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
            /**********************
            * Alterei pois com o eval não executava funções.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}
// ********************************************************************


function URLEncode(valor)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = valor;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for


	return encoded;
};

function URLDecode(valor)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = valor;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   
   return plaintext;
};