function ComboIata_Change(cboIata, txtCidade) {
    if (cboIata.value == 'out') {
        txtCidade.value = "";
        txtCidade.style.visibility = "visible";
        txtCidade.style.width = "100px";
        cboIata.style.visibility = "hidden";
        cboIata.style.width = 0;
    }
    else
        txtCidade.value = cboIata.value;
}

function pesquisaavancada() {
    buscahoteis_home.action = '/VxlHotel20/BuscaAvancada.aspx';
    buscahoteis_home.submit();
}

function InitDataAereos(campo, dias) {
    DataHoje = new Date();
    dia = DataHoje.getDate();
    mes = DataHoje.getMonth();

    if (mes >= 11 && dia > 22) { dia = 1; mes = 12; }
    ano = DataHoje.getFullYear();

    if (dia < 10) { dia = '0' + dia; } if (mes < 10) { mes = '0' + mes; } AddDias(dia + "/" + mes + "/" + ano, campo, dias);
} function FormataData_Hoteis(objCampo) {
    intKeyCode = event.keyCode; if ((intKeyCode < 47) || (intKeyCode > 57)) {
        psValidChars = objCampo.value;
        event.cancelBubble = true;
        event.returnValue = ((psValidChars.indexOf(String.fromCharCode(event.keyCode)) >= 0) || (event.keyCode == 13));

        if (event.returnValue == false) {
            return event.returnValue;
        }
    }
    else {
        var strValor = objCampo.value;
        var intLengthValor = parseInt(strValor.length);

        if ((intLengthValor == 2) && (intKeyCode != 47)) {
            objCampo.value = strValor + "/";
        }

        if ((intLengthValor == 1) && (intKeyCode == 47)) {
            objCampo.value = "0" + strValor;
        }

        if ((intLengthValor == 4) && (intKeyCode == 47)) {
            objCampo.value = strValor.substring(0, 3) + '0' + strValor.substring(2, 1);
        }

        if ((intLengthValor == 5) && (intKeyCode != 47)) {
            objCampo.value = strValor + "/";
        }
    }
    return true;
}

function InitDataIda() {
    DataHoje = new Date();
    dia = DataHoje.getDate();
    mes = DataHoje.getMonth();
    ano = DataHoje.getFullYear();
    if (dia < 10) dia = '0' + dia; if (mes < 10) mes = '0' + mes; AddDias(dia + "/" + mes + "/" + ano, document.buscaaereos_home.DataIda, 3);
} function verificaDatasHome(dtInicial, dtFinal) { var dtini = dtInicial; var dtfim = dtFinal; datInicio = new Date(dtini.substring(6, 10), dtini.substring(3, 5), dtini.substring(0, 2)); datInicio.setMonth(datInicio.getMonth() - 1); datFim = new Date(dtfim.substring(6, 10), dtfim.substring(3, 5), dtfim.substring(0, 2)); datFim.setMonth(datFim.getMonth() - 1); if (datInicio < datFim) { return true; } else { document.buscahoteis_home.checkout.focus(); return false; } } function isDate(dt) {
    var vlr = new String(dt.value); if (isNaN(parseInt(dt.value))) { alert('data inválida'); return false; } else {
        if (vlr.length == 0) { alert('Campo em branco'); dt.focus(); return false; } if (vlr.substr(3, 2) > 12 || vlr.substr(3, 2) < 1) { alert('data inválida'); dt.focus(); return false; } else {
            if (vlr.substr(3, 2) == 2) {
                if (vlr.substr(0, 2) > 29 || (vlr.substr(0, 2) == 29 && vlr.substr(6, 4) % 4 != 0)) {
                    alert('Data inválida');
                    dt.focus();
                    return false;
                }
            }
            else {
                if (vlr.substr(0, 2) > 31) {
                    alert('Data inválida');
                    dt.focus();
                    return false;
                }
            }
        }
    }
    return true;
}

function InitDataHoteis(campo, dias) {
    DataHoje = new Date();
    dia = DataHoje.getDate();
    mes = DataHoje.getMonth();
    ano = DataHoje.getFullYear();
    if (mes >= 11 && dia > 22) { dia = 1; mes = 12; }
    if (dia < 10) { dia = '0' + dia; } if (mes < 10) { mes = '0' + mes; } AddDias(dia + "/" + mes + "/" + ano, campo, dias);
} function FormataData_Hoteis(objCampo) {
    intKeyCode = event.keyCode; if ((intKeyCode < 47) || (intKeyCode > 57)) {
        psValidChars = objCampo.value;
        event.cancelBubble = true;
        event.returnValue = ((psValidChars.indexOf(String.fromCharCode(event.keyCode)) >= 0) || (event.keyCode == 13));
        if (event.returnValue == false) {
            return event.returnValue;
        }
    }
    else {
        var strValor = objCampo.value;
        var intLengthValor = parseInt(strValor.length);
        if ((intLengthValor == 2) && (intKeyCode != 47)) {
            objCampo.value = strValor + "/";
        }
        if ((intLengthValor == 1) && (intKeyCode == 47)) {
            objCampo.value = "0" + strValor;
        }
        if ((intLengthValor == 4) && (intKeyCode == 47)) {
            objCampo.value = strValor.substring(0, 3) + '0' + strValor.substring(2, 1);
        }
        if ((intLengthValor == 5) && (intKeyCode != 47)) {
            objCampo.value = strValor + "/";
        }
    }
    return true;
}
function LimpaCombos() {
    buscahoteis_home.quarto1a.value = "1";
    buscahoteis_home.quarto1b.value = "0";
    buscahoteis_home.quarto2a.value = "0";
    buscahoteis_home.quarto2b.value = "0";
    buscahoteis_home.quarto3a.value = "0";
    buscahoteis_home.quarto3b.value = "0";
    buscahoteis_home.quarto4a.value = "0";
    buscahoteis_home.quarto4b.value = "0";
}
function EscondeCombos(valor) {
    if (valor == 0) {
        LimpaCombos();
        buscahoteis_home.quarto1a.style.visibility = "hidden";
        buscahoteis_home.quarto1b.style.visibility = "hidden";
        buscahoteis_home.quarto2a.style.visibility = "hidden";
        buscahoteis_home.quarto2b.style.visibility = "hidden";
        buscahoteis_home.quarto3a.style.visibility = "hidden";
        buscahoteis_home.quarto3b.style.visibility = "hidden";
        buscahoteis_home.quarto4a.style.visibility = "hidden";
        buscahoteis_home.quarto4b.style.visibility = "hidden";
    }
    if (valor == 1) {
        LimpaCombos();
        buscahoteis_home.quarto1a.style.visibility = "visible";
        buscahoteis_home.quarto1b.style.visibility = "visible";
        buscahoteis_home.quarto2a.style.visibility = "hidden";
        buscahoteis_home.quarto2b.style.visibility = "hidden";
        buscahoteis_home.quarto3a.style.visibility = "hidden";
        buscahoteis_home.quarto3b.style.visibility = "hidden";
        buscahoteis_home.quarto4a.style.visibility = "hidden";
        buscahoteis_home.quarto4b.style.visibility = "hidden";
    }
    if (valor == 2) {
        LimpaCombos();
        buscahoteis_home.quarto1a.style.visibility = "visible";
        buscahoteis_home.quarto1b.style.visibility = "visible";
        buscahoteis_home.quarto2a.style.visibility = "visible";
        buscahoteis_home.quarto2b.style.visibility = "visible";
        buscahoteis_home.quarto3a.style.visibility = "hidden";
        buscahoteis_home.quarto3b.style.visibility = "hidden";
        buscahoteis_home.quarto4a.style.visibility = "hidden";
        buscahoteis_home.quarto4b.style.visibility = "hidden";
    }
    if (valor == 3) {
        LimpaCombos();
        buscahoteis_home.quarto1a.style.visibility = "visible";
        buscahoteis_home.quarto1b.style.visibility = "visible";
        buscahoteis_home.quarto2a.style.visibility = "visible";
        buscahoteis_home.quarto2b.style.visibility = "visible";
        buscahoteis_home.quarto3a.style.visibility = "visible";
        buscahoteis_home.quarto3b.style.visibility = "visible";
        buscahoteis_home.quarto4a.style.visibility = "hidden";
        buscahoteis_home.quarto4b.style.visibility = "hidden";
    }
    if (valor == 4) {
        LimpaCombos();
        buscahoteis_home.quarto1a.style.visibility = "visible";
        buscahoteis_home.quarto1b.style.visibility = "visible";
        buscahoteis_home.quarto2a.style.visibility = "visible";
        buscahoteis_home.quarto2b.style.visibility = "visible";
        buscahoteis_home.quarto3a.style.visibility = "visible";
        buscahoteis_home.quarto3b.style.visibility = "visible";
        buscahoteis_home.quarto4a.style.visibility = "visible";
        buscahoteis_home.quarto4b.style.visibility = "visible";
    }
}
function pesquisahomehoteis() {
    with (document.buscahoteis_home) {
        if (cidade.value == '') {
            alert('Preencha o campo localidade');
            return;
        }
        if (checkin.value == '') {
            alert('Preencha o campo checkin');
            return;
        }
        if (!(isDate(document.buscahoteis_home.checkin)))
            return;
        if (document.buscahoteis_home.checkout.value == '') {
            alert('Preencha o campo checkout');
            return;
        }
        if (!(isDate(document.buscahoteis_home.checkout)))
            return;
        if (!(verificaDatasHome(checkin.value, checkout.value))) {
            alert('A data de checkin deve ser menor que a de checkout!');
            return;
        }
        submit();
    }
}
function SetaEnableVoltaOnLine() {
    with (document.buscaaereos_home) {
        DataVolta.disabled = radNacSoIda.checked;
    }
}
function verificaporciamaritima() {
    valorDestino = document.BuscaCruzeiros.destino.value;
    valorCiaMaritima = document.BuscaCruzeiros.select.value;
    if (valorDestino == '' && valorCiaMaritima == '') {
        window.alert('Selecione um destino ou uma cia. marítima para pesquisar.');
        return;
    }
    if (valorDestino != '' && valorCiaMaritima != '') {
        window.alert('Selecione um destino ou uma cia. marítima para pesquisar.');
        return;
    }

    if (valorDestino != '') {
        document.BuscaCruzeiros.submit();
    }

    if (valorCiaMaritima != '') {
        window.location.href = (valorCiaMaritima)
    }
}

function verificapesq() {
    var valorDestino = document.BuscaPacotes.destino.value;
    var valorTipoViagem = document.BuscaPacotes.modalidadeexc.value;
    if (valorDestino == 0 && valorTipoViagem == '') {
        window.alert('Selecione um destino ou um tipo de viagem.');
        return;
    }
    if (valorDestino != 0 && valorTipoViagem != '') {
        window.alert('Selecione um destino ou um tipo de viagem.');
        return;
    }

    if (valorDestino != 0) {
        document.BuscaPacotes.submit();
    }

    if (valorTipoViagem != '') {
        document.BuscaPacotes.action = '/excursoes/pesqwrdRes.asp';
        document.BuscaPacotes.submit();
    }
}

function TrocaPesquisa(NomeDiv) {
    if (NomeDiv == 'Pacotes') {
        divgeral.style.height = "207";
        pacotes.style.visibility = "visible";
        aereos.style.visibility = "hidden";
        cruzeiros.style.visibility = "hidden";
        hoteis.style.visibility = "hidden";
        BuscaPacotes.a[3].checked = "true";
        EscondeCombos('0');
    }
    if (NomeDiv == 'Aereos') {
        divgeral.style.height = "475";
        pacotes.style.visibility = "hidden";
        aereos.style.visibility = "visible";
        cruzeiros.style.visibility = "hidden";
        hoteis.style.visibility = "hidden";
        buscaaereos_home.a[0].checked = "true";
        EscondeCombos('0');
    }
    if (NomeDiv == 'Cruzeiros') {
        divgeral.style.height = "208";
        pacotes.style.visibility = "hidden";
        aereos.style.visibility = "hidden";
        cruzeiros.style.visibility = "visible";
        hoteis.style.visibility = "hidden";
        BuscaCruzeiros.a[2].checked = "true";
        EscondeCombos('0');
    }
    if (NomeDiv == 'Hoteis') {
        divgeral.style.height = "290";
        pacotes.style.visibility = "hidden";
        aereos.style.visibility = "hidden";
        cruzeiros.style.visibility = "hidden";
        hoteis.style.visibility = "visible";
        buscahoteis_home.a[1].checked = "true";
        buscahoteis_home.nquartos[0].selected = "true";
        EscondeCombos('1');
    }
}
function pesquisahomevoos() {
    if (document.buscaaereos_home.Origem.value == '') {
        alert('Selecione a Origem.');
        return;
    }
    if (document.buscaaereos_home.radNacIdaVolta.checked) {
        if (document.buscaaereos_home.DataVolta.value == 'dd/mm/aaaa' || document.buscaaereos_home.DataVolta.value == '') {
            alert('Selecione a data de volta.');
            return;
        }
        if (!(isDate(document.buscaaereos_home.DataVolta))) {
            return;
        }
    }
    if (document.buscaaereos_home.DataIda.value == 'dd/mm/aaaa') {
        alert('Selecione a data de ida.');
        return;
    }
    if (!(isDate(document.buscaaereos_home.DataIda))) {
        return;
    }
    if (document.buscaaereos_home.Destino.value == '') {
        alert('Selecione o Destino.');
        return;
    }
    if (document.buscaaereos_home.DataVolta.value == 'dd/mm/aaaa') {
        document.buscaaereos_home.DataVolta.value = '';
    }
    document.buscaaereos_home.submit();
}

function SetaData(objCampo, Valor) {
    if ((objCampo.value == '' && Valor == 'dd/mm/aaaa') || (objCampo.value == 'dd/mm/aaaa' && Valor == ''))
        objCampo.value = Valor;
}

function FormataData_New(objCampo) {
    intKeyCode = event.keyCode;
    if ((intKeyCode.keyCode < 48) || (intKeyCode.keyCode > 57)) {
        return false;
    }
    else {
        strValor = objCampo.value;
        intLengthValor = parseInt(strValor.length);
        if ((intLengthValor == 2) && (intKeyCode != 47)) {
            objCampo.value = strValor + "/";
        }
        if ((intLengthValor == 1) && (intKeyCode == 47)) {
            objCampo.value = "0" + strValor;
        }
        if ((intLengthValor == 4) && (intKeyCode == 47)) {
            objCampo.value = strValor.substring(0, 3) + '0' + strValor.substring(2, 1);
        }
        if ((intLengthValor == 5) && (intKeyCode != 47)) {
            objCampo.value = strValor + "/";
        }
    }
    return true;
}


function MostraClassificIdades() {
    botao = document.getElementById("botaoClassificaIdades");
    obj = document.getElementById("divClassificIdades");
    obj.style.visibility = "visible";
    obj.style.top = obj.style.top + 370;
    obj.style.left = obj.style.left + 142;
}

function EscondeClassificIdades() {
    obj = document.getElementById("divClassificIdades");
    obj.style.visibility = "hidden"
}

function findPosition(obj) {
    if (obj.offsetParent) {
        for (var posX = 0, posY = 0; obj.offsetParent; obj = obj.offsetParent) {
            posX += obj.offsetLeft; posY += obj.offsetTop;
        }
        return [posX, posY];
    }
    else {
        return [obj.x, obj.y];
    }
}

var popupListAero;

function OpenListaAeroportos(id, txt, somenteNacional) {
    var DataIda = "0";
    var URL;

    if (somenteNacional == '1')
        URL = '/Produtos/Aereo/listaAeroportos.aspx?id=' + id + '&txt=' + txt + '&pais=Brazil&SomentePais=1'
    else
        URL = '/Produtos/Aereo/listaAeroportos.aspx?id=' + id + '&txt=' + txt + '&SomentePais=0'

    popupListAero = window.open(URL,
		'popupListAero',
		'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=557,height=480');
}

function SetListaAeroportos(id, txt, newIata, nomeCidade) {
    var TextControl;
    TextControl = document.getElementById(txt)
    popupListAero.close();
    TextControl.value = newIata;
}

var data = new Date();
var dia = data.getDate();
var mes = data.getMonth();
var ano = Number(data.getFullYear());

if (Number(dia) < 10)
    dia = "0" + dia;
if (Number(mes) < 10)
    mes = "0" + String(Number(mes) + 1);
if (ano < 2000)
    ano = 1900 + ano;

var CalS = mes + '/' + dia + '/' + ano;


if (dia == '29' && mes == '2')
    dia = '28';
ano = ano + 1;
var CalE = mes + '/' + dia + '/' + ano;

function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_showHideLayers() {
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}


function HabilitaIdaVolta() {
    document.getElementById('DataVolta').disabled = document.getElementById('radNacSoIda').checked;
}
function SetaDataVolta(campoIda, campoVolta) {
    return;
    if ((campoVolta.value == 'dd/mm/aaaa' || campoVolta.value.length == 0) && campoIda.value.length == 10) {
        DataIda = GetData(campoIda.value);

        if (DataIda) {
            DataIda = DataIda + 1;
            campoVolta.value = DataIda.getDate() + "/" + (DataIda.getMonth() + 1) + "/" + DataIda.getYear();
        }
    }
}
function PesquisaAereoHome() {
    var strParam = '';

    if (document.getElementById('Origem').value == '') {
        alert('Selecione a Origem.');
        return;
    }
    if (document.getElementById('Destino').value == '') {
        alert('Selecione o Destino.');
        return;
    }

    /*Novo alert*/
    if (document.getElementById('DataIda').value == '') {
        alert('Selecione a data de ida.');
        return;
    }
    /*Fim do novo alert*/


    if (document.getElementById('Origem').value.toLowerCase() == document.getElementById('Destino').value.toLowerCase()) {
        alert('Origem não pode ser igual ao Destino.');
        return;
    }
    if (document.getElementById('DataIda').value == 'dd/mm/aaaa') {
        alert('Selecione a data de ida.');
        return;
    }
    if (document.getElementById('radNacIdaVolta').checked) {
        if (document.getElementById('DataVolta').value == 'dd/mm/aaaa' || document.getElementById('DataVolta').value == '') {
            alert('Selecione a data de volta.');
            return;
        }


    }


    strParam = '?Origem=' + document.getElementById('Origem').value;
    strParam += '&Destino=' + document.getElementById('Destino').value;
    strParam += '&Data=' + document.getElementById('DataIda').value;
    strParam += '&Hora=' + document.getElementById('HorarioIda').value;
    if (document.getElementById('radNacIdaVolta').checked) {
        if (CompararDatas(document.getElementById('DataIda').value, document.getElementById('DataVolta').value) > 0) {
            alert('Data de Ida menor que a data de volta.');
            return;
        }

        strParam += '&Origem=' + document.getElementById('Destino').value;
        strParam += '&Destino=' + document.getElementById('Origem').value;
        strParam += '&Data=' + document.getElementById('DataVolta').value;
        strParam += '&Hora=' + document.getElementById('HorarioVolta').value;
    }

    strParam += '&NumADT=' + document.getElementById('NumAdt').value;
    strParam += '&NumCHD=' + document.getElementById('NumChd').value;
    strParam += '&NumINF=' + document.getElementById('NumInf').value;



    /*Modificaddo função javascript*/
    /* if ( document.getElementById('chkSomenteDireto').checked )
    strParam += '&SomenteDireto=1';
    else
    strParam += '&SomenteDireto=0';*/


    if (document.getElementById('chkSomenteDireto').checked)
        strParam += '&SomenteDireto=1';

    else

        strParam += '&SomenteDireto=0';

    strParam += (document.getElementById("radNacSoIda").checked) ? '&SomenteIda=1' : '&SomenteIda=0';

    strParam += '&Cia=' + document.getElementById('ddlNacCia').value;

    strParam += '&Cabine=' + document.getElementById('ddlNacClasse').value;


    document.forms[0].method = 'post';
    document.forms[0].action = '/Produtos/Aereo/Masterpricer.aspx' + strParam;
    document.forms[0].submit();
}

debugger
function CompararDatas(DataInicial, DataFinal) {
    if (DataInicial == DataFinal) return 0;

    if (DataFinal == "") return 1;

    try {
        var aI = DataInicial.split("/")[2].toString();
        var mI = DataInicial.split("/")[1].toString();
        var dI = DataInicial.split("/")[0].toString();

        aI = aI.lenght > 1 ? aI : "0" + aI;
        mI = mI.lenght > 1 ? mI : "0" + mI;
        dI = dI.lenght > 1 ? dI : "0" + dI;

        var aF = DataFinal.split("/")[2].toString();
        var mF = DataFinal.split("/")[1].toString();
        var dF = DataFinal.split("/")[0].toString();

        aF = aF.lenght > 1 ? aF : "0" + aF;
        mF = mF.lenght > 1 ? mF : "0" + mF;
        dF = dF.lenght > 1 ? dF : "0" + dF;

        aI = parseInt(aI, 10)
        mI = parseInt(mI, 10)
        dI = parseInt(dI, 10)
        aF = parseInt(aF, 10)
        mF = parseInt(mF, 10)
        dF = parseInt(dF, 10)

        if (aI > aF)
            return 1;
        else if (aI == aF) {
            if (mI > mF) return 1;
            if (dI > dF && mI == mF) return 1;
        }

        return 0;
    }
    catch (err) {
        return 1;
    }
}




















