﻿function ChangeConteudo(Conteudo) {

    document.getElementById("PesquisaAereo").className = "VisibleFalse";
    document.getElementById("PesquisaHotel").className = "VisibleFalse";
    //    document.getElementById("PesquisaCarro").className = "VisibleFalse";
    //    document.getElementById("PesquisaResort").className = "VisibleFalse";
    //    document.getElementById("PesquisaPacotes").className = "VisibleFalse";
    //    document.getElementById("PesquisaCruzeiros").className = "VisibleFalse";
    //    document.getElementById("PesquisaPasseios").className = "VisibleFalse";

    switch (Conteudo) {
        case "Aereo":
            document.getElementById("TdHome1").className = "bgAereo";
            document.getElementById("TdHome2").className = "bgAereo";
            document.getElementById("PesquisaAereo").className = "VisibleTrue";
            document.getElementById("ctl00_hdnRefPage").value = "Aereo";
            document.getElementById("imgHomeSeta").src = "Recursos/Imagens/Home/HomeSetaAereo.gif";
            break;
        case "Hotel":
            document.getElementById("TdHome1").className = "bgHotel";
            document.getElementById("TdHome2").className = "bgHotel";
            document.getElementById("ctl00_hdnRefPage").value = "Hotel";
            document.getElementById("PesquisaHotel").className = "VisibleTrue";
            document.getElementById("imgHomeSeta").src = "Recursos/Imagens/Home/HomeSetaHotel.gif";
            break;
        case "Carro":
            document.getElementById("TdHome1").className = "bgCarro";
            document.getElementById("TdHome2").className = "bgCarro";
            document.getElementById("imgHomeSeta").src = "Recursos/Imagens/Home/HomeSetaCarro.gif";
            break;
        case "Resort":
            document.getElementById("TdHome1").className = "bgResort";
            document.getElementById("TdHome2").className = "bgResort";
            document.getElementById("imgHomeSeta").src = "Recursos/Imagens/Home/HomeSetaResort.gif";
            break;
        case "Pacotes":
            document.getElementById("TdHome1").className = "bgPacotes";
            document.getElementById("TdHome2").className = "bgPacotes";
            document.getElementById("imgHomeSeta").src = "Recursos/Imagens/Home/HomeSetaPacotes.gif";
            break;
        case "Cruzeiros":
            document.getElementById("TdHome1").className = "bgCruzeiros";
            document.getElementById("TdHome2").className = "bgCruzeiros";
            document.getElementById("imgHomeSeta").src = "Recursos/Imagens/Home/HomeSetaCruzeiros.gif";
            break;
        case "Passeios":
            document.getElementById("TdHome1").className = "bgPasseios";
            document.getElementById("TdHome2").className = "bgPasseios";
            document.getElementById("imgHomeSeta").src = "Recursos/Imagens/Home/HomeSetaPasseios.gif";
            break;
    }

    document.getElementById("TdHomeBottom").className = document.getElementById("TdHome1").className;

}

function RecuperarHidden() {
    if (document.getElementById("ctl00_hdnRefPage") != null) {
        if (document.getElementById("ctl00_hdnRefPage") != "") {
            var hidden = document.getElementById("ctl00_hdnRefPage").value;
            ChangeConteudo(hidden);
        }
    }
}


function CheckAll(Nome, Segmento) {
    cont = 0;
    for (var i = 0; i < document.aspnetForm.elements.length; i++) {
        var x = document.aspnetForm.elements[i];
        if (x.id == Nome) {
            if (Segmento == "I") {
                x.checked = document.aspnetForm.SelecionarTodosIda.checked;
            }
            else if (Segmento == "V") {
                x.checked = document.aspnetForm.SelecionarTodosVolta.checked;
            }
            else {
                var select = "SelecionarTodos" + Segmento;
                x.checked = document.getElementById(select).checked;
            }
        }
        if (cont == 0) {
            cont = 1;
        }
        else {
            cont = 0;
        }
    }
}



function Show(Div) {
    document.getElementById(Div).className = "VisibleTrue";

}
function Hide(Div) {

    document.getElementById(Div).className = "VisibleFalse";
}
function ShowHide(Div) {
    if (document.getElementById(Div).className == "VisibleTrue" || document.getElementById(Div).className == "") {
        document.getElementById(Div).className = "VisibleFalse";
    }

}
///ordenar div: organiza elementos conforme criterios passados como parametros
///vetorDivs: vertor unidemensional com os elementos que serao organizados
///EOrdenCrescente: paramertro boleano indicando se para organizar na ordem crescente ou decrescente
///recuperaVal1: function(ELEMENTO) que retornara o valor 1 que estara contido dentro do elemento passado como parametro, a ser comparado com retorno do valor 2
///recuperaVal2: function(ELEMENTO) que retornara o valor 2 que estara contido dentro do elemento passado como parametro, a ser comparado com retorno do valor 1
function ordernarElementos(vetorDivs, EOrdenCrescente, recuperaVal1, recuperaVal2) {
    VETOR = ordenarVetor(vetorDivs, EOrdenCrescente, recuperaVal1, recuperaVal2);
    div = document.createElement('div');
    div.setAttribute('id', 'divOrganizar');
    for (count = 0; count < VETOR.length; count++) {
        loclFor = VETOR[count].cloneNode(true);
        div.appendChild(loclFor);
        delete loclFor;
    }
    divPai = document.getElementById(VETOR[0].parentNode.id);
    for (count = 0; count < VETOR.length; count++) {
        VETOR[count].parentNode.removeChild(VETOR[count]);
    }
    filhosLcls = div.childNodes;
    nmrFilhos = filhosLcls.length;
    for (count = 0; count < nmrFilhos; count++) {
        divPai.appendChild(filhosLcls[count].cloneNode(true));
    }
    delete div;

} //fim function ordenar

function ordenarVetor(vetor, EOrdenCrescente, recuperaVal1, recuperaVal2) {
    if (vetor.length <= 0) {
        return;
    }
    VETOR = vetor;
    var i;
    var j;
    var aux;
    var k = VETOR.length - 1;

    for (i = 0; i < VETOR.length; i++) {
        for (j = 0; j < k; j++) {
            val = recuperaVal1(VETOR[j]);
            val2 = recuperaVal2(VETOR[j + 1]);

            if (EOrdenCrescente == true) {
                if (val > val2) {
                    aux = VETOR[j];
                    VETOR[j] = VETOR[j + 1];
                    VETOR[j + 1] = aux;
                } //fim if
            }
            else {
                if (val < val2) {
                    aux = VETOR[j];
                    VETOR[j] = VETOR[j + 1];
                    VETOR[j + 1] = aux;
                } //fim if
            } //fim if-else
        } //fim for
    } //fim for em todas pacotes
    return VETOR;
}

function displayMonetario(valorFloat) {
    IntDec = valorFloat.toString().split('.');

    inteiro = IntDec[0];
    inteiro = inteiro.toString();
    inteiroSlices = "";
    for (contador = 0; contador < inteiro.length; contador++) {
        inteiroSlices += inteiro.slice(contador, contador + 1);
        if (contador < inteiro.length - 1) {
            inteiroSlices += ",";
        }
    }

    retorno = "";
    inteiroSlices = inteiroSlices.split(",");
    for (contador = 0; contador < inteiroSlices.length; contador++) {

        retorno = retorno.toString() + inteiroSlices[contador].toString();
        if (((contador + 1) < inteiroSlices.length) && ((inteiroSlices.length - contador - 1) % 3) == 0)
            retorno = retorno + ".";
    }
    if (IntDec[1]) {
        if (IntDec[1].length >= 2) {
            IntDec[1] = IntDec[1].slice(0, 2);
        }
        retorno += "," + IntDec[1];
    }
    else {
        retorno += ",00";
    }
    return retorno;
}
function removeDisplay(stringValorMenetario) {
    retorno = stringValorMenetario.toString().replace(".", "").replace(",", ".");
    return parseFloat(retorno);
}

function displayTempo(minutos) {
    displayTempoHoras = parseFloat(minutos / 60);
    displayTempominutos = Math.ceil((displayTempoHoras - parseInt(displayTempoHoras)) * 60);
    displayTempodias = null;
    if (displayTempoHoras >= 24) {
        displayTempodias = displayTempoHoras / 24;
        displayTempoHoras = (displayTempodias - parseInt(displayTempodias)) * 24;
    }
    displayDuracao = (displayTempodias != null ? parseInt(displayTempodias) + "ds" : "") + (parseInt(displayTempoHoras).toString().length == 1 ? "0" + parseInt(displayTempoHoras) : parseInt(displayTempoHoras)) + "h" + (parseInt(displayTempominutos).toString().length == 1 ? "0" + parseInt(displayTempominutos) : parseInt(displayTempominutos)) + "";
    return displayDuracao;
}
function calcularTotaMinutos(vvDvvHvvM) {
    duracaoFiltrardias = vvDvvHvvM.split('ds');
    if (duracaoFiltrardias.length > 1) {
        duracaoFiltrarHoras = vvDvvHvvM.split('ds')[1].split('h')[0];
        duracaoFiltrarMinutos = vvDvvHvvM.split('ds')[1].split('h')[1];

        duracaoTotalMinMinutos = (parseInt(duracaoFiltrardias[0]) * 24) * 60;
        duracaoTotalMinMinutos += (parseInt(duracaoFiltrarHoras) * 60);
        duracaoTotalMinMinutos += parseInt(duracaoFiltrarMinutos);
    }
    else {
        duracaoFiltrarHoras = vvDvvHvvM.split('h')[0];
        duracaoFiltrarMinutos = vvDvvHvvM.split('h')[1];

        duracaoTotalMinMinutos = (duracaoFiltrarHoras * 60);
        duracaoTotalMinMinutos += parseInt(duracaoFiltrarMinutos);
    }
    return duracaoTotalMinMinutos;
}




function woobaExecFuncComAguarde(funcao) {
    divAguard = document.createElement("div");
    id = "DivAguarde_messageBox";
    img = document.createElement("img");
    img.src = "../App_Themes/Padrao/Imagens/loading_icon.gif";
    txt = document.createElement("text");
    txt.innerHTML = "Aguarde..";
    center = document.createElement("center");
    center.appendChild(img);
    center.appendChild(document.createElement("br"));
    center.appendChild(txt);
    center.setAttribute("innerTEXT", "Aguarde..")
    divAguard.appendChild(center);
    divAguard.id = id;
    resultado = document.getElementsByTagName('body')[0];
    resultado.appendChild(divAguard);
    //divAguard = $("#" + id);

    css =
    {
        "position": "absolute",
        "left": "0px",
        "top": "0px",

        "text-align": "center",
        "z-index": "1000",
        "background-color": "gray"
    };
  dial=  $("#" + id).dialog({
        bgiframe: true,
        modal: true
    });
    funcao();
    dial.dialog('destroy');
    $("#" + id).hide();
   // resultado.removeChild(divAguard);
}

function minMax(vetorNumerico) {
    for (pos1 = 0; pos1 < vetorNumerico.length; pos1++) {
        for (pos2 = 0; pos2 < vetorNumerico.length - 1; pos2++) {
            val = parseFloat(vetorNumerico[pos2]);
            val2 = parseFloat(vetorNumerico[pos2 + 1]);
            if (val > val2) {
                aux = vetorNumerico[pos2];
                vetorNumerico[pos2] = vetorNumerico[pos2 + 1];
                vetorNumerico[pos2 + 1] = aux;
            } //fim if
        }
    }
    retorno = { min: vetorNumerico[0], max: vetorNumerico[vetorNumerico.length - 1] };
    return retorno;
}


function Html_CriarElemento(qElemento, qId, qClasse, qTexto, qTipo) {
    var el = document.createElement(qElemento);
    if (qId != undefined) { el.id = qId; }
    if (qClasse != undefined) { el.className = qClasse; }
    if (qTipo != undefined) { el.type = qTipo; }
    if (qTexto != undefined) { var txt = document.createTextNode(qTexto); el.appendChild(txt); }

    return el;

};

function Html_AdicionarElemento(qElementoPai, qElementoNovo, qId, qClasse, qTexto, qTipo) {
    var el = document.createElement(qElementoNovo);

    if (qId != undefined) { el.id = qId; }
    if (qClasse != undefined) { el.className = qClasse; }
    if (qTipo != undefined) { el.type = qTipo; }
    if (qTexto != undefined) {
        if (qElementoNovo != "input") {
            var txt = document.createTextNode(qTexto);
            el.appendChild(txt);
        }
        else {
            if (qTipo == "text" || qTipo == "hidden") {
                el.value = qTexto;
            }
        }
    }


    qElementoPai.appendChild(el);
    return el;

};

function Html_AdicionarTexto(qElemento, qTexto) {
    if (qTexto != undefined) {
        if (qElemento != "input") {
            var txt = document.createTextNode(qTexto);
            qElemento.appendChild(txt);
        }
        else {
            if (qTipo == "text" || qTipo == "hidden") {
                qElemento.value = qTexto;
            }
        }
    }

};

function Html_AdicionarImagem(qElemento, qSrc, qAlt) {
    var img = document.createElement("img");
    img.src = qSrc;
    if (qAlt != undefined) {
        img.alt = qAlt;
    }
    img.border = 0;
    qElemento.appendChild(img);
    return img;
};

function Html_AdicionarLink(qElemento, qHREF, qTexto) {
    var a = document.createElement("a");
    if (qHREF != undefined) {
        a.href = qHREF;
    }
    if (qTexto != undefined) {
        Html_AdicionarTexto(a, qTexto)
    }
    qElemento.appendChild(a);
    return a;
};

function XML_Load(conteudo) {
    if (window.DOMParser) {
        try {
            parser = new DOMParser();
            XML_Documento = parser.parseFromString(conteudo, "text/xml");
        }
        catch (e) {
            alert(e.message);
        }
    }
    else // Internet Explorer
    {
        XML_Documento = new ActiveXObject("Microsoft.XMLDOM");
        XML_Documento.async = "false";
        XML_Documento.loadXML(conteudo);
    }
    XML_Documento = $(XML_Documento);
    return XML_Documento;
}

//function getTextoDoNo(XmlDoc, PathNo) {
//    retorno = "";
//    result = $(PathNo, XmlDoc);
//    retorno = $(result[0]).text();
//    delete result;
//    return retorno;
//}


function getTextoDoNo(XmlDoc, PathNo) {
    retorno = "";
    result = $(PathNo, XmlDoc);
    if (result.length == 1) {
        retorno = $(result[0]).text();
    }
    else {
        ex = new Error();
        ex.message = PathNo + " não e um caminho valido em " + XmlDoc.tagName;
        throw ex;
    }
    delete result;
    return retorno;
}

function dataTparaDDMMAAAA(sData) {
    retorno = "";
    sData = sData.split('T')[0];
    sData = sData.split('-');
    return sData[2] + "/" + sData[1] + "/" + sData[0];
}



var win = null;
function windowOpen(mypage, myname, w, h, features) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    if (winl < 0) winl = 0;
    if (wint < 0) wint = 0;
    var settings = 'height=' + h + ',';
    settings += 'width=' + w + ',';
    settings += 'top=' + wint + ',';
    settings += 'left=' + winl + ',';
    settings += 'alwaysRaised=yes,';
    settings += features;
    win = window.open(mypage, myname, settings);
    win.window.focus();

}