 var no_number = "Desculpe, isto não é um número";
 function pegaSigla(sigla_hotel){
    alert(sigla_hotel);
 }
 
 function paisBrasil(){
    
    formObj = document.forms["form_hotel"];
    if (formObj.q1adt.value > 2) { 
        formObj.q1adt.value = 2;
        //alert('Para hotéis nacionais só podem ir dois hóspedes. Qualquer dúvida\nfavor entrar em contato com Obrigado');
    }
    
    //formObj.q1adt.disabled=true;
    try{
    formObj.q1chd.value = 0;
    formObj.q1chd.disabled = true;
    
    document.getElementById('chdage1').style.display = 'none';
    document.getElementById('chdage2').style.display = 'none';
    document.getElementById('chdage3').style.display = 'none';
    document.getElementById('chdage4').style.display = 'none';
    document.getElementById('chdage5').style.display = 'none';
    document.getElementById('chdage6').style.display = 'none';
    }catch(e){}
    trocaQuartos(formObj.quartos.value, false);
    
     /*       
    //formObj.q2adt.value = 0;
    formObj.q2adt.disabled = true;
    //formObj.q2chd.value = 0;
    formObj.q2chd.disabled = true;
    
    //formObj.q3adt.value = 0;
    formObj.q3adt.disabled = true;
    //formObj.q3chd.value = 0;
    formObj.q3chd.disabled = true;
    
    formObj.chdage1.style.display='none';
    formObj.chdage2.style.display='none';
    
    formObj.chdage3.style.display='none';
    formObj.chdage4.style.display='none';
    
    formObj.chdage5.style.display='none';
    formObj.chdage5.style.display='none';
    
    formObj.textoage.style.display='none';
    */
 }
 
 function verificaSabre(qtpessoas){
    if ((qtpessoas > 2) && (document.getElementById('paises').value == 14)){
       alert('O número máximo de pessoas para hotéis nacionais são 2 pessoas por quarto.');
       document.getElementById('q1adt').value=2;
       document.getElementById('q2adt').value=2;
       return;
    }
    return;
 }
 
 function habilitaQuartos(){
    var formObj = document.forms["form_hotel"];
    formObj.quartos.disabled = false;
    formObj.q1chd.disabled = false;
 }


 function zeraValores(){
    try{
    //document.getElementById('quartos').value = 1;
    document.getElementById('q1adt').value = 1;
    document.getElementById('q1chd').value = 0;
    document.getElementById('q2adt').value = 0;
    document.getElementById('q2chd').value = 0;
    document.getElementById('q3adt').value = 0;
    document.getElementById('q3chd').value = 0;
    }catch(e){}
 }
 
 function mostraIdade(idade){
    switch (idade.name) {
       case 'q1chd':
          if (idade.value == 0) {
             document.getElementById('chdage1').style.display='none';
             document.getElementById('chdage2').style.display='none';
             if ((document.getElementById('chdage3').style.display=='none') && (document.getElementById('chdage5').style.display=='none')) {
                document.getElementById('textoage').style.display='none';
             }
          }
          else if (idade.value == 1) {
             document.getElementById('chdage1').style.display='block';
             document.getElementById('chdage2').style.display='none';
             document.getElementById('textoage').style.display='block';
          }
          else if (idade.value == 2){
             document.getElementById('chdage1').style.display='block';
             document.getElementById('chdage2').style.display='block';
             document.getElementById('textoage').style.display='block';
          }
          break;
       case 'q2chd':
          if (idade.value == 0) {
             document.getElementById('chdage3').style.display='none';
             document.getElementById('chdage4').style.display='none';
             if ((document.getElementById('chdage1').style.display=='none') && (document.getElementById('chdage5').style.display=='none')) {
                document.getElementById('textoage').style.display='none';
             }
          }
          else if (idade.value == 1) {
             document.getElementById('chdage3').style.display='block';
             document.getElementById('chdage4').style.display='none';
             document.getElementById('textoage').style.display='block';
          }
          else if (idade.value == 2){
             document.getElementById('chdage3').style.display='block';
             document.getElementById('chdage4').style.display='block';
             document.getElementById('textoage').style.display='block';
          }
          break;   
       case 'q3chd':
          if (idade.value == 0) {
             document.getElementById('chdage5').style.display='none';
             document.getElementById('chdage6').style.display='none';
             if ((document.getElementById('chdage1').style.display=='none') && (document.getElementById('chdage3').style.display=='none')) {
                document.getElementById('textoage').style.display='none';
             }
          }
          else if (idade.value == 1) {
             document.getElementById('chdage5').style.display='block';
             document.getElementById('chdage6').style.display='none';
             document.getElementById('textoage').style.display='block';
          }
          else if (idade.value == 2){
             document.getElementById('chdage5').style.display='block';
             document.getElementById('chdage6').style.display='block';
             document.getElementById('textoage').style.display='block';
          }
          break;
    }
 }
 
 function trocaQuartos(qntquartos, zeraQdes){
    qrt2 = document.getElementsByTagName('div');
    //alert(qntquartos);
    if (qntquartos == 1){
       for (var i = 0; i < qrt2.length ; i++){
          if ( (qrt2[i].getAttribute('id') == 'quartoextra2') || (qrt2[i].getAttribute('id') == 'quartoextra3') )
          {
             qrt2[i].style.display = 'none';
          }
       try{
       document.getElementById('chdage3').style.display = 'none';
       document.getElementById('chdage4').style.display = 'none';
       document.getElementById('chdage5').style.display = 'none';
       document.getElementById('chdage6').style.display = 'none';
       }catch(e){}
       if(zeraQdes) {
         zeraValores();
       }
       try{//MARRETA: até resolver se vai ter o campo de criança
           if (document.getElementById('paises').value == 14) {
                
                document.getElementById('q1chd').value == 0;
                document.getElementById('q1chd').disabled = true;
                   
           }
           if (document.getElementById('q1chd').value == 0){
              document.getElementById('textoage').style.display='none';   
           }
       }catch(e){
       }
       }//for
    }
    else if (qntquartos == 2){
       for (var i = 0; i < qrt2.length ; i++){
          if (qrt2[i].getAttribute('id') == 'quartoextra2')
          {
             qrt2[i].style.display = 'block';
             
          }
          if (qrt2[i].getAttribute('id') == 'quartoextra3')
          {
             qrt2[i].style.display = 'none';
          }
       }
       document.getElementById('chdage5').style.display = 'none';
       document.getElementById('chdage6').style.display = 'none';
       if (document.getElementById('paises').value == 14) {
           document.getElementById('q2chd').value == 0;
           document.getElementById('q2chd').disabled = true;
       }
       document.getElementById('q3adt').value = 1;
       document.getElementById('q3chd').value = 0;
       if(zeraQdes) {
         zeraValores();
       }
    }
    else if (qntquartos == 3){
       if (document.getElementById('paises').value == 14) {
           alert('Apenas 2 quartos são permitidos para hotéis nacionais.');
           document.getElementById('quartos').value = 2;
           document.getElementById('quartos').focus();
           trocaQuartos(2, true);
           return;
       }
       for (var i = 0; i < qrt2.length ; i++){
          if ((qrt2[i].getAttribute('id') == 'quartoextra3') || (qrt2[i].getAttribute('id') == 'quartoextra2')) 
          {
             qrt2[i].style.display = 'block';
          }
       }
       if(zeraQdes) {
         zeraValores();
       }
    }
 }

var tipoQuarto_hotel = new Array();
var z_hotel = 1;
var chd_hotel = 1;
var textoQuarto_hotel = "Você selecionou o(s) seguinte(s) quarto(s):";

function getQtdePessoas(){ 
var formObj = document.forms["form_hotel"];
var numRooms = parseInt(formObj.quartos.value);
var res = 0;
switch (numRooms) {
  case 1:
    res = res + parseInt(formObj.q1adt.value);
  break;
  case 2:
    res = res + parseInt(formObj.q1adt.value) + parseInt(formObj.q2adt.value);
  break;
  case 3:
    res = res + parseInt(formObj.q1adt.value) + parseInt(formObj.q2adt.value) + parseInt(formObj.q3adt.value);
  break;
}
return res;
}


function enviaSabre()
{
 var formObj = document.forms["form_hotel"];
 //formObj.action = 'lista_hotel';
 formObj.pessoas.value = getQtdePessoas();
 //document.getElementById('cidade').value = formObj.destino.options[formObj.destino.selectedIndex].text;
 try{
    document.getElementById('divx_progresso_ffh').style.display = 'block';
    document.getElementById('form_hotel').style.display = 'none';
    
 }
 catch(e){}
 formObj.submit();
}

function enviaForm()
{    
 var formObj = document.forms["form_hotel"];
 var numRooms = parseInt(formObj.quartos.value);
 var temp = formObj.quartos.value;

 var quarto1 = parseInt(formObj.q1adt.value) //+ parseInt(formObj.q1chd.value);
 var quarto2 = parseInt(formObj.q2adt.value) //+ parseInt(formObj.q2chd.value);
 var quarto3 = parseInt(formObj.q3adt.value) //+ parseInt(formObj.q3chd.value);
 // Populamos o array que leva a resposta pra gente no python
 try{
 switch (numRooms) {
    
    case 1:
       if (formObj.q1chd.value == 0) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';0;0');
       }
       if (formObj.q1chd.value == 1) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';1;'+formObj.idade1.value);
       }
       if (formObj.q1chd.value == 2) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';2;'+formObj.idade1.value+'-'+formObj.idade2.value);
       }
       break;
    case 2:
       if (formObj.q1chd.value == 0) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';0;0');
       }
       if (formObj.q1chd.value == 1) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';1;'+formObj.idade1.value);
       }
       if (formObj.q1chd.value == 2) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';2;'+formObj.idade1.value+'-'+formObj.idade2.value);
       }
       if (formObj.q2chd.value == 0) {
          tipoQuarto_hotel.push(''+quarto2+';'+formObj.q2adt.value+';0;0');
       }
       if (formObj.q2chd.value == 1) {
          tipoQuarto_hotel.push(''+quarto2+';'+formObj.q2adt.value+';1;'+formObj.idade3.value);
       }
       if (formObj.q2chd.value == 2) {
          tipoQuarto_hotel.push(''+quarto2+';'+formObj.q2adt.value+';2;'+formObj.idade3.value+'-'+formObj.idade4.value);
       }
       break;
    case 3:
       if (formObj.q1chd.value == 0) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';0;0');
       }
       if (formObj.q1chd.value == 1) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';1;'+formObj.idade1.value);
       }
       if (formObj.q1chd.value == 2) {
          tipoQuarto_hotel.push(''+quarto1+';'+formObj.q1adt.value+';2;'+formObj.idade1.value+'-'+formObj.idade2.value);
       }
       if (formObj.q2chd.value == 0) {
          tipoQuarto_hotel.push(''+quarto2+';'+formObj.q2adt.value+';0;0');
       }
       if (formObj.q2chd.value == 1) {
          tipoQuarto_hotel.push(''+quarto2+';'+formObj.q2adt.value+';1;'+formObj.idade3.value);
       }
       if (formObj.q2chd.value == 2) {
          tipoQuarto_hotel.push(''+quarto2+';'+formObj.q2adt.value+';2;'+formObj.idade3.value+'-'+formObj.idade4.value);
       }
       if (formObj.q3chd.value == 0) {
          tipoQuarto_hotel.push(''+quarto3+';'+formObj.q3adt.value+';0;0');
       }
       if (formObj.q3chd.value == 1) {
          tipoQuarto_hotel.push(''+quarto3+';'+formObj.q3adt.value+';1;'+formObj.idade5.value);
       }
       if (formObj.q3chd.value == 2) {
          tipoQuarto_hotel.push(''+quarto3+';'+formObj.q3adt.value+';2;'+formObj.idade5.value+'-'+formObj.idade6.value);
       }
       break;
    
 }
 }catch(e){}
 alert(tipoQuarto_hotel);
 document.getElementById('resposta').value = tipoQuarto_hotel;
 document.getElementById('cidade').value = formObj.destino.options[formObj.destino.selectedIndex].text;
 try{
    document.getElementById('divx_progresso_ffh').style.display = 'block';
    document.getElementById('form_hotel').style.display = 'none';
    
 }
 catch(e){}
 //alert('firefox');  
 //var div = document.getElementById('hideme');
 //document.getElementById('hideme').style.display = 'none';    

 formObj.submit();
 //return true;
 while (tipoQuarto_hotel.length != 0)
 {
   tipoQuarto_hotel.pop();
 }
}    
 
function validarPesquisaHoteis()
{

/*
verifica se o nome esta preenchido no input Origem
*/
    var error = 0;
    if(document.getElementById("cidadeDestino").value != '') {
      if(document.getElementById("dsDestino").value == '') {
        //verifica se o aeroporto e valido
        orig=document.getElementById("cidadeDestino").value
        if (existelocal(orig, siglacidadehotel)) {
         document.getElementById("dsDestino").value = document.getElementById("cidadeDestino").value.toUpperCase()
        }else {
        window.alert("Por favor informe um nome de cidade válido.");
        document.getElementById("cidadeDestino").focus();
        error++;
        return;
        }
      }
    }
    else {
      window.alert("Por favor informe o destino.");
      document.getElementById("cidadeDestino").focus();
      error++;
      return;
    }

    var frm = document.forms["form_hotel"];
    var error = 0;
    with (frm)
    {
    
        //validando as datas
        dataida = formataData(dataida_hidden.value);//Formatacao p novo componente calendario
        datavolta = formataData(datavolta_hidden.value);//Formatacao p novo componente calendario
        if (!isDate(dataida,"dd/MM/yyyy")) {
            
           window.alert('Data informado no campo "chegada" inválida.')
           dataida_hidden.focus();
           return;
        }
        else
        {
            var dataIda = criaObjetoData(dataida);
        }
        
        if (datavolta!='') {
            if (!isDate(datavolta,"dd/MM/yyyy")) {
               window.alert('Data informado no campo "saída" inválida.')
               datavolta_hidden.focus();
               return
            }
            else
            {
                var dataVolta = criaObjetoData(datavolta);
            }
        }
        else
        {
            window.alert('Favor informar uma data no campo "saída".')
            datavolta_hidden.focus();
            return
        }


        //verifica se data de ida é anterior a data atual
	    var now = new Date();
        if (dataIda < now)
        {
            window.alert("A data de chegada deve ser igual ou maior a data atual");
            error++;
            dataida_hidden.focus();
            return;
        }
        //verifica se data de ida é anterior a data volta
        if (datavolta!='') {
            if (dataIda > dataVolta)
            {
                window.alert("A data de chegada deve ser anterior a data de volta");
                error++;
                datavolta_hidden.focus();
                return;
            }
        }
     
        try{//MARRETA: até descidir se o campo criança vai continuar
        //testa se o campo de crianca tem alguem, se tiver checa a idade pra ver se a pessoa escreveu
        if (q1chd.value > 0) {
           if ( (isEmpty(idade1.value)) || (isNaN(idade1.value)) ) {
              window.alert("Digite a idade da criança corretamente.");
              error++;
              idade1.focus();
              return
           }
           else if (( (q1chd.value == 2) && (isEmpty(idade2.value)) ) || (isNaN(idade2.value)) ) {
              window.alert("Digite a idade da criança corretamente.");
              error++;
              idade2.focus();
              return
           }
        }
        if (q2chd.value > 0) {
           if ( (isEmpty(idade3.value)) || (isNaN(idade3.value)) ) {
              window.alert("Digite a idade da criança corretamente.");
              error++;
              idade3.focus();
              return
           }
           else if (( (q2chd.value == 2) && (isEmpty(idade4.value)) ) || (isNaN(idade4.value)) ) {
              window.alert("Digite a idade da criança corretamente.");
              error++;
              idade4.focus();
              return
           }
        }
        if (q3chd.value > 0) {
           if ( (isEmpty(idade5.value)) || (isNaN(idade5.value)) ) {
              window.alert("Digite a idade da criança corretamente.");
              error++;
              idade5.focus();
              return
           }
           else if (( (q3chd.value == 2) && (isEmpty(idade6.value)) ) || (isNaN(idade6.value)) ) {
              window.alert("Digite a idade da criança corretamente.");
              error++;
              idade6.focus();
              return
           }
        }
        }catch(e){}
        // final da validacao dos campos caso nao haja nenhum erro
        // monta as datas nos campos hidden e o form e enviado
        if (error < 1)
        {
            var vdata = false;
            if (datavolta!='') {
              vdata = true;
            }
            setaDatas(vdata, dataida, datavolta);
            dataida_hidden.value = dataida;
            datavolta_hidden.value = datavolta;
            var cidadetratada = document.getElementById("cidadeDestino").value;
            var cidadetratada = cidadetratada.substr(0, cidadetratada.indexOf("("));
            document.getElementById("cidade").value = cidadetratada;
            if ((paises.value) == parseInt(14))
            {
                enviaSabre();
                return
            }
            else
            {
                enviaForm();
            }
            
        }
    }
}