// CRIA OBJETO AJAX
function getXmlHttpRequest(){ 
   if (window.XMLHttpRequest){ 
      return new XMLHttpRequest(); 
   } 
   else if (window.ActiveXObject){ 
      try{ 
         return new ActiveXObject("Msxml2.XMLHTTP"); 
      }catch (e){ 
         try{ 
            return new ActiveXObject("Microsoft.XMLHTTP"); 
         }catch (e){} 
      } 
   } 
} 

var xmlhttp = getXmlHttpRequest();

// CHAMA CONTEÚDO VIA AJAX
function conteudoAjax(arquivo, div){
	document.getElementById(div).innerHTML = '<img src="'+raiz+'/img/diversos/loader.gif"> Aguarde...';
	xmlhttp.open("POST", arquivo, true); 
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1"); 
	xmlhttp.setRequestHeader("Cache-Control", "no-cache, must-revalidate"); 
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); 
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState==4){   
			document.getElementById(div).innerHTML = xmlhttp.responseText;
			//alert(xmlhttp.responseText);
			execJS(div);
			
			// SE É UMA LISTA GERA OS LINKS DE ORDENAÇÃO E ARRUMA AS CORES DAS LINHAS
			//if (div == 'divList'){ uniloader(); corLinhas('tableList'); }
		} 
	}    
	xmlhttp.send(null);
}

function execJS(div){
	var conteudo = $(div);
	
	var newElement = document.createElement("script");
	var scripts = conteudo.getElementsByTagName("script");

	for(i = 0; i < scripts.length; i++){
		newElement.text = scripts[i].innerHTML;
	}
	
	conteudo.appendChild(newElement);
}


function conteudoAjax2(arquivo, div){
	document.getElementById(div).innerHTML = '<img src="'+raiz+'/img/diversos/loader.gif"> Aguarde...';
	xmlhttp.open("POST", arquivo, true); 
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1"); 
	xmlhttp.setRequestHeader("Cache-Control", "no-cache, must-revalidate"); 
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); 
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState==4){   
			document.getElementById(div).innerHTML = xmlhttp.responseText; 		
		} 
	}    
	xmlhttp.send(null);
}

function submitForm(div, formulario, funcao, animacao){	
	var metodo = document.getElementById(formulario).method.toUpperCase();
    var action = document.getElementById(formulario).action+"?";
    var variaveis = "";
    var tipoInput;
	var obrigatorio;
	var nomeGrupo;
	var erro = 0;
	
	for (var i=0;i<document.getElementById(formulario).length;i++){
        tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
		obrigatorio = document.forms[formulario].elements[i].getAttribute('obrigatorio');
	
		if (tipoInput != 'SELECT-ONE' && tipoInput != "CHECKBOX" && tipoInput != 'RADIO' && tipoInput != ''){
			document.forms[formulario].elements[i].className = 'input_normal';
		}
		
		if(tipoInput == "FILE"){
			if (obrigatorio && document.forms[formulario].elements[i].value == ''){
				erro = 1;
			} else {
				variaveis += document.forms[formulario].elements[i].id+"="+escape(document.forms[formulario].elements[i].value)+"&";
			}
		}
		
		if(tipoInput == "HIDDEN"){
			variaveis += document.forms[formulario].elements[i].name+"="+escape(document.forms[formulario].elements[i].value)+"&";
		}
		
		
		if(tipoInput == 'RADIO' && nomeGrupo != document.forms[formulario].elements[i].name){
			var nomeGrupo = document.forms[formulario].elements[i].name;
			var tamanhoGrupo = document.forms[formulario].elements[nomeGrupo].length;
			var checado = 0;
			for(j=0; j<tamanhoGrupo; j++){
				if (obrigatorio && document.forms[formulario].elements[nomeGrupo][j].checked){
					checado = 1;
				}
			}
			
			if (obrigatorio && checado == 0){ 
				erro = 1; 
			} else {
				for(j=0; j<tamanhoGrupo; j++){
					if(document.forms[formulario].elements[nomeGrupo][j].checked){
						variaveis += document.forms[formulario].elements[nomeGrupo][j].id+"="+escape(document.forms[formulario].elements[nomeGrupo][j].value)+"&";
					}
				}
			}
		}
		
		if(tipoInput == "CHECKBOX"){
			if (obrigatorio && !document.forms[formulario].elements[i].checked){
				erro = 1;	
			} else {
				if(document.forms[formulario].elements[i].checked){
					variaveis += document.forms[formulario].elements[i].id+"="+escape(document.forms[formulario].elements[i].value)+"&";
				}
			}
		} else if (tipoInput == "TEXT" || tipoInput == "TEXTAREA" || tipoInput == "PASSWORD"){
			if (obrigatorio && document.forms[formulario].elements[i].value == ''){
				erro = 1;
			} else {
				variaveis += document.forms[formulario].elements[i].name+"="+escape(document.forms[formulario].elements[i].value)+"&";
			}
		} else if (tipoInput == "SELECT-ONE"){
			document.forms[formulario].elements[i].className = 'preto_11';
			if (obrigatorio && document.forms[formulario].elements[i].value == 0){
				erro = 1;
			} else {
				variaveis += document.forms[formulario].elements[i].name+"="+escape(document.forms[formulario].elements[i].value)+"&";
			}
		}
    }
	
	if (erro == 0){
		if (funcao){
			document.getElementById(div).innerHTML = '<img src="'+raiz+'/img/diversos/loader.gif"> Aguarde...';
			xmlhttp.open(metodo, action, true); 
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			eval('xmlhttp.onreadystatechange = '+funcao+';');
			xmlhttp.send(variaveis);
		} else {
			document.getElementById(formulario).submit();	
		}
	} else {
		janelaAviso('SOL Linhas Aéreas','Preencha os campos obrigatórios!', animacao);
		for (var i=0;i<document.getElementById(formulario).length;i++){
			obrigatorio = document.forms[formulario].elements[i].getAttribute('obrigatorio');
			tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
			if (obrigatorio && document.forms[formulario].elements[i].value == '' && tipoInput != 'SELECT-ONE'){
				document.forms[formulario].elements[i].className = 'input_obrigatorio';
			}
			if (obrigatorio && document.forms[formulario].elements[i].value == 0 && tipoInput == 'SELECT-ONE'){
				document.forms[formulario].elements[i].className = 'select_obrigatorio';				
			}
		}
	}
	return false;
}


function submitFormAdm(div, formulario, funcao, animacao, fundo){	
	var metodo = document.getElementById(formulario).method.toUpperCase();
    var action = document.getElementById(formulario).action+"?";
    var variaveis = "";
    var tipoInput;
	var obrigatorio;
	var nomeGrupo;
	var erro = 0;
	
	for (var i=0;i<document.getElementById(formulario).length;i++){
        tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
		obrigatorio = document.forms[formulario].elements[i].getAttribute('obrigatorio');
	
		if (tipoInput != 'SELECT-ONE' && tipoInput != "CHECKBOX" && tipoInput != 'RADIO' && tipoInput != ''){
			document.forms[formulario].elements[i].className = 'input_adm';
		}
		
		if(tipoInput == "FILE"){
			if (obrigatorio && document.forms[formulario].elements[i].value == ''){
				erro = 1;
			} else {
				variaveis += document.forms[formulario].elements[i].id+"="+escape(document.forms[formulario].elements[i].value)+"&";
			}
		}
	
		if(tipoInput == "HIDDEN"){
			variaveis += document.forms[formulario].elements[i].name+"="+escape(document.forms[formulario].elements[i].value)+"&";
		}
		
		
		if(tipoInput == 'RADIO' && nomeGrupo != document.forms[formulario].elements[i].name){
			var nomeGrupo = document.forms[formulario].elements[i].name;
			var tamanhoGrupo = document.forms[formulario].elements[nomeGrupo].length;
			var checado = 0;
			for(j=0; j<tamanhoGrupo; j++){
				if (obrigatorio && document.forms[formulario].elements[nomeGrupo][j].checked){
					checado = 1;
				}
			}
			
			if (obrigatorio && checado == 0){ 
				erro = 1; 
			} else {
				for(j=0; j<tamanhoGrupo; j++){
					if(document.forms[formulario].elements[nomeGrupo][j].checked){
						variaveis += document.forms[formulario].elements[nomeGrupo][j].id+"="+escape(document.forms[formulario].elements[nomeGrupo][j].value)+"&";
					}
				}
			}			
		}
		
		if(tipoInput == "CHECKBOX"){
			if (obrigatorio && !document.forms[formulario].elements[i].checked){
				erro = 1;	
			} else {
				if(document.forms[formulario].elements[i].checked){
					variaveis += document.forms[formulario].elements[i].id+"="+escape(document.forms[formulario].elements[i].value)+"&";
				}
			}
		} else if (tipoInput == "TEXT" || tipoInput == "TEXTAREA" || tipoInput == "PASSWORD"){
			if (obrigatorio && document.forms[formulario].elements[i].value == ''){
				erro = 1;
			} else {
				variaveis += document.forms[formulario].elements[i].name+"="+escape(document.forms[formulario].elements[i].value)+"&";
			}
		} else if (tipoInput == "SELECT-ONE"){
			document.forms[formulario].elements[i].className = 'preto_11';
			if (obrigatorio && document.forms[formulario].elements[i].value == 0){
				erro = 1;
			} else {
				variaveis += document.forms[formulario].elements[i].name+"="+escape(document.forms[formulario].elements[i].value)+"&";
			}
		}
    }

	if (erro == 0){
		if (funcao){
			if (fundo == 'escuro'){
				document.getElementById(div).innerHTML = '<img src="'+raiz+'/img/diversos/loader2.gif"> Aguarde...';
			} else if (fundo == 'claro'){
				document.getElementById(div).innerHTML = '<img src="'+raiz+'/img/diversos/loader.gif"> Aguarde...';
			}
			xmlhttp.open(metodo, action, true); 
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			eval('xmlhttp.onreadystatechange = '+funcao+';');
			xmlhttp.send(variaveis);
		} else {
			document.getElementById(formulario).submit();	
		}
	} else {
		janelaAviso('SOL Linhas Aéreas','Preencha os campos obrigatórios!', animacao);
		for (var i=0;i<document.getElementById(formulario).length;i++){
			obrigatorio = document.forms[formulario].elements[i].getAttribute('obrigatorio');
			tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
			if (obrigatorio && document.forms[formulario].elements[i].value == '' && tipoInput != 'SELECT-ONE'){
				document.forms[formulario].elements[i].className = 'input_adm_obrigatorio';
			}
			if (obrigatorio && document.forms[formulario].elements[i].value == 0 && tipoInput == 'SELECT-ONE'){
				document.forms[formulario].elements[i].className = 'select_obrigatorio';				
			}
		}
	}
	return false;
}


function enviarNews(action, funcao, comeco){
	if (comeco == 1){
		document.getElementById('div1').innerHTML = '<img src="'+raiz+'/img/diversos/loader.gif"> Enviando...';
	}
	xmlhttp.open('post', action, true);
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");  
	xmlhttp.setRequestHeader("Cache-Control", "no-cache, must-revalidate"); 
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); 
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	eval('xmlhttp.onreadystatechange = '+funcao+';');
	xmlhttp.send(null);	
}

function retornoEnvioNews(){
	if (xmlhttp.readyState == 4) {
		resultado = unescape(xmlhttp.responseText);
		resultado = resultado.split('&&&');
		
		document.getElementById("div1").innerHTML = "<img src='"+raiz+"/img/diversos/loader.gif'> Enviando... ("+resultado[4]+"% - "+resultado[6]+"/"+resultado[7]+")";
		document.getElementById("resultadoNews").style.display = '';

		var oTable = document.getElementById("tabelaResultado");
 		var oNovaLinha = oTable.insertRow(1);
		if (resultado[5] == 1){
			oNovaLinha.bgColor = '#ffffff';
		} else {
			oNovaLinha.bgColor = '#e5e5e5';
		}
	
		var oNovaCelula  = oNovaLinha.insertCell(0);
		oNovaCelula.height = 21;
		oNovaCelula.align = "center";
		var novoTexto  = document.createTextNode(resultado[1]);
		oNovaCelula.appendChild(novoTexto);
		
		var oNovaCelula  = oNovaLinha.insertCell(1);
		oNovaCelula.align = "center";
		var novoTexto  = document.createTextNode(resultado[2]);
		oNovaCelula.appendChild(novoTexto);
		
		var oNovaCelula  = oNovaLinha.insertCell(2);
		oNovaCelula.align = "center";
		var novoTexto  = document.createTextNode(resultado[3]);
		oNovaCelula.appendChild(novoTexto);
	
		if (resultado[6] != resultado[7]){
			if (resultado[8] == 'teste'){
				enviarNews(raiz+'/action/admin/news_teste.php', 'retornoEnvioNews', 0);
			} else {
				enviarNews(raiz+'/action/admin/news_prospect.php', 'retornoEnvioNews', 0);
			}
		} else {
			document.getElementById("div1").innerHTML = '<b>Envio concluído:</b> ('+resultado[4]+'% - '+resultado[6]+'/'+resultado[7]+')';	
		}
	}	
}

function validarRelatorios(formulario, bt){
	var camposPreenchidos = 0;
	var tipoInput = '';
	
	for (var i=0;i<document.getElementById(formulario).length;i++){
		
		 tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
		 
 		 if (tipoInput == "TEXT"){
			if (document.forms[formulario].elements[i].value != ''){
				camposPreenchidos++;
			}			 
		 } else if (tipoInput == "SELECT-ONE"){
			 if (document.forms[formulario].elements[i].value != 0){
				camposPreenchidos++;	 
			 }
		 }
	}
	
	if (camposPreenchidos > 0){
		document.getElementById(formulario).submit();	
	} else {
		janelaAviso('SOL Linhas Aéreas','Preencha no mínimo um campo!', bt);
	}	
}


/***** ENVIAR ENQUETE *****/
function votarEnquete(formulario, div, funcao, bt){
	var metodo = document.getElementById(formulario).method.toUpperCase();
    var action = document.getElementById(formulario).action+"?";
	var camposPreenchidos = 0;
	var tipoInput = '';
	var variaveis = "id="+document.forms[formulario].elements[0].value+"&";
	
	for (var i=0;i<document.getElementById(formulario).length;i++){
		
		 tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
 		 if (tipoInput == "RADIO"){
			if (document.forms[formulario].elements[i].checked == true){
				camposPreenchidos++;
				variaveis += "opcao="+escape(document.forms[formulario].elements[i].value)+"&";
			}			 
		 }
	}
	
	if (camposPreenchidos > 0){
		document.getElementById(div).innerHTML = '<img src="'+raiz+'/img/diversos/loader.gif"> Aguarde...';
		xmlhttp.open(metodo, action, true); 
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		eval('xmlhttp.onreadystatechange = '+funcao+';');
		xmlhttp.send(variaveis);
	} else {
		janelaAviso('SOL Linhas Aéreas','Escolha uma opção!', bt);
	}
}

/***** TRATAMENTO RETORNO VOTO *****/
function resultadoVotar(){
	var div = 'divEnquete';
	var titulo_caixa = 'SOL Linhas Aéreas';
	
	if (xmlhttp.readyState == 4) {
		document.getElementById(div).innerHTML = 'ENQUETE';
		resultado = unescape(xmlhttp.responseText);
		if (resultado == 1){ // envio com sucesso formulário fale conosco
			document.getElementById('formEnquete').reset();
			janelaAviso(titulo_caixa, 'Voto registrado com sucesso.', '');
		} else if (resultado == 2){ // erro ao enviar mensagem
			janelaAviso(titulo_caixa, 'Erro ao votar', '');
		} else if (resultado == 3){
			janelaAviso(titulo_caixa, 'Você já votou hoje.', '');
		}
	}
}


/***** TRATA RETORNO DE FORMULÁRIOS QUE ENVIAM E-MAILS *****/
function enviarEmail(){
	var div = 'msgStatus';
	var titulo_caixa = 'SOL Linhas Aéreas';
	var envio_sucesso = 'Mensagem enviada com sucesso.';
	var envio_erro = 'Erro ao enviar mensagem.';
	
	if (xmlhttp.readyState == 4) {
		document.getElementById(div).innerHTML = '';
		resultado = unescape(xmlhttp.responseText);
		
		if (resultado == 1){ // envio com sucesso formulário fale conosco
			document.getElementById('formContato').reset();
			janelaAviso(titulo_caixa, envio_sucesso, '');
		} else if (resultado == 2){ // erro ao enviar mensagem
			janelaAviso(titulo_caixa, envio_erro, '');
		} else if (resultado == 3){ // envio com sucesso formulário anuncie, fale conosco e assine
			if (document.getElementById('formAnuncie')){ document.getElementById('formAnuncie').reset(); }
			else if (document.getElementById('formAssine')){ document.getElementById('formAssine').reset(); }
			else if (document.getElementById('formContato')){ document.getElementById('formContato').reset(); }
			janelaAviso(titulo_caixa, envio_sucesso, '');
		}
	}
}

function verificaDescadastro(){
	var div = 'msgStatus2';
	var titulo_caixa = 'SOL Linhas Aéreas';
	
	if(xmlhttp.readyState == 4){

		document.getElementById(div).innerHTML = '';
		resultado = unescape(xmlhttp.responseText);
		
		if (resultado == 1){ // não existe
			document.getElementById(div).innerHTML = 'Email e Data de Nascimento não cadastrados!';
		} else if (resultado == 2){ // excluido
			document.getElementById(div).innerHTML = 'Seu e-mail foi descadastrado com sucesso!';
		} else { // não excluido
			document.getElementById(div).innerHTML = 'Não foi possível descadastrar seu e-mail!';
		}
	}
}

/***** TRATA RETORNO DE CADASTRO *****/
function verificaCadastro(){
	var div = 'msgStatus';
	var titulo_caixa = 'SOL Linhas Aéreas';
	var cad_sucesso = 'Registro cadastrado com sucesso.';
	var edit_sucesso = 'Registro alterado com sucesso.';
	var cad_erro = 'Erro ao cadastrar registro.';
	var edit_erro = 'Erro ao alterar registro.';
	if (document.getElementById('arquivo_lista')){ var arquivo = document.getElementById('arquivo_lista').value; }
	
	if(xmlhttp.readyState == 4){
		document.getElementById(div).innerHTML = '';
		resultado = unescape(xmlhttp.responseText);
		//alert(resultado);
		if (resultado == 1){ // cadastro efetuado com sucesso
			limparFormulario('formCad');
			janelaAviso(titulo_caixa, cad_sucesso, '');
			if (arquivo){ conteudoAjax(arquivo, 'divList'); }
		} else if (resultado == 2){ // cpf inválido
			janelaAviso(titulo_caixa, 'CPF inválido. Tente novamente!', '');
			if (document.getElementById('cadastro[cpf]')){ document.getElementById('cadastro[cpf]').className = 'input_obrigatorio'; }
		} else if (resultado == 3){ // cpf já existente
			janelaAviso(titulo_caixa, 'CPF já cadastrado. Tente novamente!', '');
			if (document.getElementById('cadastro[cpf]')){ document.getElementById('cadastro[cpf]').className = 'input_obrigatorio'; }
		} else if (resultado == 4){ // email já existente
			janelaAviso(titulo_caixa, 'E-mail já cadastrado. Tente novamente!', '');
			if (document.getElementById('cadastro[email]')){ document.getElementById('cadastro[email]').className = 'input_obrigatorio'; }
			if (document.getElementById('usuario[email]')){ document.getElementById('usuario[email]').className = 'input_adm_obrigatorio'; }
		} else if (resultado == 5){ // erro ao cadastrar
			janelaAviso(titulo_caixa, cad_erro, '');
		} else if (resultado == 6){ // usuário já existente
			janelaAviso(titulo_caixa, 'Usuário já cadastrado. Tente novamente!', '');
			if (document.getElementById('cadastro[usuario]')){ document.getElementById('cadastro[usuario]').className = 'input_obrigatorio'; }
			if (document.getElementById('usuario[usuario]')){ document.getElementById('usuario[usuario]').className = 'input_adm_obrigatorio'; }
		} else if (resultado == 7){ // erro na confirmação da senha
			janelaAviso(titulo_caixa, 'Erro na confirmaç&atilde;o da senha.', '');
			if (document.getElementById('cadastro[senha]')){ 
				document.getElementById('cadastro[senha]').className = 'input_obrigatorio';
				document.getElementById('cadastro[senha2]').className = 'input_obrigatorio';
			}
			if (document.getElementById('usuario[senha]')){ 
				document.getElementById('usuario[senha]').className = 'input_adm_obrigatorio';
				document.getElementById('usuario[senha2]').className = 'input_adm_obrigatorio';
			}
		} else if (resultado == 8){ // sucesso ao editar
			// altera os textos para o padrão de quando está cadastrando
			if (document.getElementById('divSenha')){
				document.getElementById('divSenha').innerHTML = '* Senha:'
				document.getElementById('divSenha2').innerHTML = '* Repetir Senha';
				document.getElementById('usuario[senha]').setAttribute('obrigatorio', true);
				document.getElementById('usuario[senha2]').setAttribute('obrigatorio', true);
			}
			limparFormulario('formCad');
			janelaAviso(titulo_caixa, edit_sucesso, '');
			if (arquivo){ conteudoAjax(arquivo, 'divList'); }
		} else if (resultado == 9){ // erro ao editar
			janelaAviso(titulo_caixa, edit_erro, '');
		} else if (resultado == 10){ // senha atual inválida
			janelaAviso(titulo_caixa, 'Senha atual inválida. Tente novamente!', '');
		} else if (resultado == 11){
        	limparFormulario('formCad');
			janelaAviso(titulo_caixa, 'Obrigado por se cadastrar no site do Jornal Gazeta Mundial. <br />Sua solicita&ccedil;&atilde;o ser&aacute; analisada por nossa equipe e em breve voc&ecirc; receber&aacute; a <br />confirma&ccedil;&atilde;o do seu cadastro e poder&aacute; acessar a vers&atilde;o online.', '');
        }
	}
}

/***** TRATA RETORNO DE LOGINS *****/
function verificaLogin(){
	var div = 'msgStatus';
	var titulo_caixa = 'SOL Linhas Aéreas';
	
	if(xmlhttp.readyState == 4) {
		document.getElementById(div).innerHTML = '';
		resultado = unescape(xmlhttp.responseText);
	
		if (resultado == 2){ // usuário inexistente
			if (document.getElementById('login[usuario]')){ document.getElementById('login[usuario]').className = 'input_adm_obrigatorio'; }
			janelaAviso(titulo_caixa, 'Usuário ou senha inválidos! Tente novamente.', '');
		} else if (resultado == 3){ // senha inválida
			if (document.getElementById('login[senha]')){ document.getElementById('login[senha]').className = 'input_adm_obrigatorio'; }
			janelaAviso(titulo_caixa, 'Você esgotou as suas 5 tentativas. Seu IP está bloqueado por 5 minutos.', '');
		} else { // login ok
			window.location = resultado;
		}
	}
}

function verificaLogin2(){
	var div = 'msgStatusAux';
	var div2 = 'msgStatusAux2';
	var titulo_caixa = 'SOL Linhas Aéreas';
	
	if(xmlhttp.readyState == 4){
		if (document.getElementById(div2)){
			document.getElementById(div2).innerHTML = 'USU&Aacute;RIOS CADASTRADOS';						
		} else if (document.getElementById(div)){
			document.getElementById(div).innerHTML = 'ACESSO &Agrave; VERS&Atilde;O ONLINE';
		}
		resultado = unescape(xmlhttp.responseText);
		
		if (resultado == 1){ // usuário ok
			document.getElementById('logado').value = 1;
			document.getElementById('formLoginAux').submit();
		} else if (resultado == 2){ // usuário inexistente
			janelaAviso(titulo_caixa, 'Usuário inexistente. Tente novamente!', '');
		} else if (resultado == 3) { // senha inválida
			janelaAviso(titulo_caixa, 'Senha inválida. Tente novamente!', '');
		}
	}
}

function login_area_restrita(){
	var div = 'msgStatus';
	var titulo_caixa = 'SOL Linhas Aéreas';
	
	if(xmlhttp.readyState == 4){

		document.getElementById(div).innerHTML = '';
		resultado = unescape(xmlhttp.responseText);
		
		if (resultado == 1){ // usuário ok
			location.href = raiz+'/area_restrita/arquivos/';
		} else if (resultado == 2){ // usuário inexistente
			janelaAviso(titulo_caixa, 'Usuário inexistente. Tente novamente!', '');
		}
	}
}

/***** TRATA RETORNOS DE TELAS QUE NÃO TEM LISTA *****/
function tratamentoGenerico(){
	var div = 'msgStatus';
	var titulo_caixa = 'SOL Linhas Aéreas';
	if(xmlhttp.readyState == 4){
		document.getElementById(div).innerHTML = '';
		resultado = unescape(xmlhttp.responseText);
	
		if (resultado == 1){ // sucesso
			limparFormulario('formCad');
			janelaAviso(titulo_caixa, 'Senha alterada com sucesso.', '');
		} else if (resultado == 2){ // erro
			janelaAviso(titulo_caixa, 'Erro ao alterar a senha.', '');
		} else if (resultado == 3){ // senha inválida
			if (document.getElementById('senha[nova]')){ document.getElementById('senha[nova]').className = 'input_adm_obrigatorio'; }
			if (document.getElementById('senha[nova2]')){ document.getElementById('senha[nova2]').className = 'input_adm_obrigatorio'; }
			janelaAviso(titulo_caixa, 'Erro na confirma&ccedil;&atilde;o da senha.', '');
		} else if (resultado == 4){ // senha atual inválida
			if (document.getElementById('senha[atual]')){ document.getElementById('senha[atual]').className = 'input_adm_obrigatorio'; }
			janelaAviso(titulo_caixa, 'Senha atual inválida.', '');
		} else if (resultado == 5){
			janelaAviso(titulo_caixa, 'Meta tags alterado com sucesso.', '');
		} else if (resultado == 6){
			janelaAviso(titulo_caixa, 'Erro ao alterar meta tags.', '');
		} else if (resultado == 7){
			janelaAviso(titulo_caixa, 'Registro alterado com sucesso.', '');
		} else if (resultado == 8){
			janelaAviso(titulo_caixa, 'Erro ao alterar o registro.', '');
		} else if (resultado == 9){
			janelaAviso(titulo_caixa, 'Usu&aacute;rio inexistente. Tente novamente!', '');
			if (document.getElementById('usuario')){ document.getElementById('usuario').className = 'input_obrigatorio'; }
		} else if (resultado == 10){
			janelaAviso(titulo_caixa, 'Erro ao enviar senha.', '');
		} else if (resultado == 11){
			janelaAviso(titulo_caixa, 'Sua senha foi enviada para seu e-mail de cadastro.', '');
			if (document.getElementById('usuario')){ document.getElementById('usuario').value = ''; }
		} else if (resultado == 12){
			janelaAviso(titulo_caixa, 'Erro ao enviar nova senha.', '');
		}
	}
}

/***** GERA RELATÓRIO DE ACESSOS PELOS PARAMETROS PASSADOS *****/
function gerarRelatorioAcessos(){
	var div = 'msgStatus';
	var titulo_caixa = 'SOL Linhas Aéreas';
	if(xmlhttp.readyState == 4){
		document.getElementById(div).innerHTML = '';
		resultado = unescape(xmlhttp.responseText);
		document.getElementById('tdRelatorio').style.display = '';
		document.getElementById('divList').innerHTML = resultado;
	}
}


function mostraDetalhe(idDetalhe){
	var aux = $('detalhe'+idDetalhe).style.display;
	if(aux == 'none'){
		$('detalhe'+idDetalhe).style.display = '';
	} else {
		$('detalhe'+idDetalhe).style.display = 'none';
	}
}