 


function getElement(eName)
{
return document.getElementById(eName);
}

 

function openajax() /* Cria a Funcao*/
{
var ajax; /* Defini a Variável */
try
{
ajax = new XMLHttpRequest(); /* Tenta Instanciar o Objeto */
}
catch(ee)
{
try
{
ajax = new ActiveXObject("Msxm12.XMLHTTP"); /* Se Nao Conseguiu o Anterior Tenta esse*/
}
catch(e)
{
try
{
ajax = new ActiveXObject("Microsoft.XMLHTTP"); /* E o memso se repete aqui*/
}
catch(E)
{
ajax = false; /* Se nao conseguiu em Nenhum retorna False pois o Navegador Usado nao Suporta Ajax*/
}
}
}
return ajax; /* Retorna um Boleano*/
}






function carrega_pagina(plink,elemento,var1,var2,var3) /*Recebe parâmetro o Link a Pagina Solicitada */
{
var divCarregando = document.getElementById('Carregando'); /* Pega o Div pelo id*/
var divResposta = document.getElementById(elemento); /* Pega o Div pelo ID */
var isLoading = getElement('Carregando');
	isLoading.innerHTML = '<img src=\"images/spinner.gif\" alt=\"..\." height=\"16\" hspace=\"5\" width=\"16\"><FONT   COLOR=\"#FF3300\">Carregando...</FONT>';


var ajax = openajax(); /* Chama a Função que Instancia o AJAX */

 
ajax.open("GET",plink+"?var1="+var1+"&var2="+var2+"&var3="+var3,true);

//alert(plink);
 
ajax.onreadystatechange = function()
/* ajax.onreadystatechange = O que ele fara de acordo com o tempo de execuação*/
{
if (ajax.readyState < 4)
/* ajax.readystate = Estado que se encontra a Requisição

1. Sendo enviado;
2. Processando;
3. Armazenando;
4. Pronto.
*/

{
divCarregando.style.display = 'block';
}
if (ajax.readyState == 4)
{
if (ajax.status == 200)
/* Estado de Carregamento*/
{

divCarregando.style.display = 'none';
 
divResposta.innerHTML = ajax.responseText;
/* ajax.responseText = Recebe o que foi enviado pelo  arquivo de tratamento*/
}
}
}
 
	 
ajax.send(null);
 

/* Muito Importante Envia o Resultado para o Navegador */
}





function carrega_pagina_type2(plink,elemento) /*Recebe parâmetro o Link a Pagina Solicitada */
{

var divCarregando = document.getElementById('Carregando'); /* Pega o Div pelo id*/
var divResposta = document.getElementById(elemento); /* Pega o Div pelo ID */
var isLoading = getElement('Carregando');
	isLoading.innerHTML = '<img src=\"images/spinner.gif\" alt=\"..\." height=\"16\" hspace=\"5\" width=\"16\"><FONT   COLOR=\"#FF3300\">Carregando:::</FONT>';
var ajax = openajax(); /* Chama a Função que Instancia o AJAX */
ajax.open("GET",plink,true);

//alert(plink);
 
ajax.onreadystatechange = function()
/* ajax.onreadystatechange = O que ele fara de acordo com o tempo de execuação*/
{
if (ajax.readyState < 4)
/* ajax.readystate = Estado que se encontra a Requisição

1. Sendo enviado;
2. Processando;
3. Armazenando;
4. Pronto.
*/

{
divCarregando.style.display = 'block';
}
if (ajax.readyState == 4)
{
if (ajax.status == 200)
/* Estado de Carregamento*/
{

divCarregando.style.display = 'none';
 
divResposta.innerHTML = ajax.responseText;
/* ajax.responseText = Recebe o que foi enviado pelo  arquivo de tratamento*/
}
}
}
 
	 
ajax.send(null);
 

/* Muito Importante Envia o Resultado para o Navegador */
}








function Dados(valor,rating) {
 
 

var ajax = openajax();
       openajax();
	  //se tiver suporte ajax
	  if(ajax) {
	     //deixa apenas o elemento 1 no option, os outros são excluídos
		 document.forms['form4'].listDestinos.options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("POST", "modulos/escala/pesq_rota.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...!";   
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "--Primeiro selecione o estado--";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "Forigem="+valor+"&rating="+rating;
		
         ajax.send(params);
      }
   }
   


function processXML(obj){
      //pega a tag cidade
      var dataArray   = obj.getElementsByTagName("icao_origen");
      
	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var icao    =  item.getElementsByTagName("icao")[0].firstChild.nodeValue;
			var nome_icao =  item.getElementsByTagName("nome_icao")[0].firstChild.nodeValue;
			
	        idOpcao.innerHTML = "Destinos Disponiveis";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = icao;
				//atribui um texto
			    novo.text  = nome_icao;
				//finalmente adiciona o novo elemento
				document.forms['form4'].listDestinos.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "Primeiro selecione a Origem";
	  }	  
   }




 function carrega_pagina_type3 (plink) 
{
var divCarregando = document.getElementById('Carregando'); 
var divResposta = document.getElementById('Resposta'); 
var divrota = document.getElementById('Rota'); 
var divrotaant = document.getElementById('RotaAnt'); 
var isLoading = getElement('Carregando');
isLoading.innerHTML = '<img src=\"reservoor/spinner.gif\" alt=\"..\." height=\"16\" hspace=\"5\" width=\"16\"><FONT   COLOR=\"blue\">Carregando...</FONT>';
var isLoading = getElement('Rota');

isLoading.innerHTML = ' ';
var ajax = openajax(); 
ajax.open("GET",plink,true);
ajax.onreadystatechange = function()
{
if (ajax.readyState < 4)
{
divCarregando.style.display = 'block';
}
if (ajax.readyState == 4)
{
if (ajax.status == 200)
{
divCarregando.style.display = 'none';
divResposta.innerHTML = ajax.responseText;
}
}
}
ajax.send(null);

document.getElementById('Rota')='';
}
