/*
 * Toda a rotina abaixo até "IFRAME WORKAROUND" serve exclusivamente para uma div ficar por cima de um select
 * no layout quando for ie6. 
 */
var g_PopupIFrame = null;
//http://xlib.wordpress.com/2006/04/12/bug-fix-select-box-displayed-through-dynamic-div-in-internet-explorer/
//This is a modified version. Please check for the url for the original.
function IsIE(version){
    var iedic = {'ie6': false /*@cc_on || @_jscript_version < 5.7 @*/, 'ie7': false /*@cc_on || @_jscript_version == 5.7 @*/};
    return iedic[version];
}

function HidePopupDiv(divID){
    var divPopup = document.getElementById(divID);
    
    if (IsIE('ie6')){
        divPopup.style.visibility = "hidden";
        if(g_PopupIFrame != null){
            document.body.removeChild(g_PopupIFrame);
            g_PopupIFrame=null;        
        }
    }
    else{
        divPopup.style.display ="none";
    }
}

function ShowPopupDiv(divID){
    var divPopup=document.getElementById(divID);
    if (!IsIE('ie6')){
        //Just display the div
        divPopup.style.display = "";
        return;
    }
    
    if(g_PopupIFrame != null){
        document.body.removeChild(g_PopupIFrame);
        g_PopupIFrame=null;
    }
    //Increase default zIndex of div by 1, so that DIV appears before IFrame
    divPopup.style.zIndex=divPopup.style.zIndex+1;

    var iFrame = document.createElement("IFRAME");
    //Use correction for ssl; it neeeds an empty *.htm file.
    var url = document.getElementById("framefixselect");
    if(url != undefined && url != "undefined" && url != null){
        iFrame.setAttribute("src", url.value);
    }
    else{
        iFrame.setAttribute("src", "");    
    }

    //Match IFrame position with divPopup
    iFrame.style.position="absolute";
    iFrame.style.left =divPopup.offsetLeft + 'px';
    iFrame.style.top =divPopup.offsetTop + 'px';
    iFrame.style.width =divPopup.offsetWidth + 'px';
    iFrame.style.height =divPopup.offsetHeight + 'px';

    document.body.appendChild(iFrame);

    //Store iFrame in global variable, so it can get removed when divPopup is hidden 
    g_PopupIFrame=iFrame;
    divPopup.style.visibility ="visible";
}
///////////////////////////////////////////////////////FIM IFRAME WORKAROUND
document.onkeypress=detectspecialkeys;
function detectspecialkeys(e)
{ 
    if (eventos(e) == 27)
    {
        try {
            //document.getElementById('veraeroportos').style.display = 'none';
            HidePopupDiv('veraeroportos');
        }
        catch(e){
            //document.getElementById('vercidades').style.display = 'none';
            HidePopupDiv('vercidades');
        }
    }
}

function hidelistHolder()
{
    try{document.getElementById('listHolder').style.display = 'none';}catch(e){}
}

function mostraTodosLocais(opcao, objLista, obj, objValor, div_local) {
    //link ver todos os aeroportos
    if(opcao == 1) {
        if(!(document.getElementById('listHolder') == null || document.getElementById('listHolder') == 'undefined' ||
             document.getElementById('listHolder').style.display=='none')) {
             	document.getElementById('listHolder').style.display='none'
        }
        //document.getElementById(div_local).style.display = 'block';
        ShowPopupDiv(div_local);
        listaSolicitada = obj;
        document.getElementById(objLista).selectedIndex = 0;
        listaSolicitadaValue = objValor;
        document.getElementById(objLista).selectedIndex = -1;
        return;
    }

    //botao voltar
    if(opcao == 2) {
        //document.getElementById(div_local).style.display = 'none';
        HidePopupDiv(div_local);
        
    }

    //selecionar aeroporto
    if(opcao == 3) {
        if(!document.getElementById(objLista).value == '') {
            
            document.getElementById(listaSolicitada).className = 'font_cinza_cBorda';
            document.getElementById(listaSolicitada).maxLength = 100;
            document.getElementById(listaSolicitadaValue).value = document.getElementById(objLista).value;
            document.getElementById(listaSolicitada).value = document.getElementById(objLista).options[document.getElementById(objLista).selectedIndex].text;
            HidePopupDiv(div_local);
            //document.getElementById(div_local).style.display = 'none';
           return;
        }
    }
}

function insereOptions(nome_form){
    //ids do select que sera populado com os dados de aeroportos ou cidades
    var nome_select = {};
    nome_select['busca_form'] = 'aeroportos';
    nome_select['form_hoteis'] = 'cidadeshotel';
    nome_select['dados_autos'] = 'cidadescarro';
    var texto = '';
    if (nome_select[nome_form] == 'aeroportos'){
        texto = criaOptions(aerointerNM, aerointerIATA, aerointerNM, document.getElementById(nome_select[nome_form]));
    }
    else{
        if(nome_select[nome_form] == 'cidadeshotel'){
            texto = criaOptions(cidadeinterNMhotel, cidadeinterIATAhotel, cidadeinterNMhotel, document.getElementById(nome_select[nome_form]));
        }
        else{
            if(nome_select[nome_form] == 'cidadescarro'){
                texto = criaOptions(cidadeinterNMcarro, cidadeinterIATAcarro, cidadeinterNMcarro, document.getElementById(nome_select[nome_form]));    
            }
        }
    }
}

function criaOptions(interNM, interIATA, interNM, elemento_pai){
    for(i = 0; i < interNM.length; i++) {
        var opt = document.createElement("option");
        opt.setAttribute("value", interIATA[i]);
        opt.innerHTML = interNM[i];
        elemento_pai.appendChild(opt);
    }
}