﻿var SlidesLigado = false;
var TipoBuscaOriginal = "";
var TipoBuscaParcial = "";
var AbrindoComoChegar = false;

function movimentalightbox(a) {
    if ($get('FundoNegro').style.visibility == "visible" && $get('FundoNegro').style.display == "block") {
        var Key = a.keyCode || a.which;
        if (Key == "37") { //Esquerda
            MovimentaImagem(false);
        } else {
            if (Key == "39") { //Direita
                MovimentaImagem(true);
            } else {
                if (Key == "27") { //ESC (Fechar a tela)
                    EscondeDiv('FundoNegro', 'FundoBranco');
                }
            }
        }
    }
}

function teclacomochegar(a) {
     var Key = a.keyCode || a.which;
     if (Key == "13") {
         AbrindoComoChegar = true;
         PageMethods.RegistraClique("BtnImgComoChegar", "http://maps.google.com.br", 0, registroucomochegar, null);
         return false;
     }
     else
     {
        return true;  
     }
 }
 function registroucomochegar() {
     BuscaGoogleMaps();
 }

 function controlaSlide(p_Parametro) {
     SlidesLigado = (p_Parametro == "pause");
     AtivarSlides();
 }
 
function imprimirpagina() {
    window.print();
}

function RegistraCliqueMenu(btn) {

    RegistraBuscaMidia(btn, (btn == "btn_Email" ? "Contato.aspx" : (btn=="btn_Atendimento" ? btn : "")), 0, (btn == "btn_Email" ? "_self" : "_popup"));
    
//    switch (btn) {
//        case ("btn_Atendimento"):
//            var gVariavel = "http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=BF1800719FBED01357DB&origem=Portal_Agra";
//            window.open(gVariavel, 'popupflashtopo', 'height=400,width=480');
//            break;
//        case ("btn_Email"):
//            window.location = "Contato.aspx";
//            break;
//        case ("btn_Ligamos"):
//            break;
//        case ("btn_Contato"):
//            break;
//    }
//    // btn_Atendimento, btn_Email, btn_Ligamos, btn_Contato
    //alert("Item de menú pressionado: " + btn);
}

var valorbuscasugestiva = "";
function ProdutoSelecionado(source, eventArgs) {
    valorbuscasugestiva = eventArgs.get_text();
    PageMethods.RegistraClique("BuscaSugestiva", "Produtos.aspx?Apelido=" + valorbuscasugestiva, 0, registrouprodutoselecionado, null);
}
function ProdutoSelecionadoCampanha(source, eventArgs) {
    valorbuscasugestiva = eventArgs.get_text();
    PageMethods.RegistraClique("BuscaSugestiva", "../Produtos.aspx?Apelido=" + valorbuscasugestiva, 0, registrouprodutoselecionadoCampanha, null);
}
function registrouprodutoselecionado() {
    window.location = "Produtos.aspx?Apelido=" + valorbuscasugestiva;
}
function registrouprodutoselecionadoCampanha() {
    window.location = "../Produtos.aspx?Apelido=" + valorbuscasugestiva;
}

function BuscarValor(p_TipoBusca) {
    if (p_TipoBusca == "") { //Primeira busca, buscar só cidades
        p_TipoBusca = "F";
    } else { //Buscas ciclicas originadas pelos combos
        if (TipoBuscaOriginal == "") {
            TipoBuscaOriginal = p_TipoBusca;
        }
    }
    TipoBuscaParcial = p_TipoBusca;
    PageMethods.BuscaValor(TipoBuscaParcial, $get('ddl_Cidades').value, $get('ddl_Bairros').value,
                       $get('menutopo_ddl_Tipos').value, $get('menutopo_ddl_Precos').value,
                       $get('menutopo_ddl_Fases').value, RetornoValor);
}

function BuscarValorCampanha(p_TipoBusca) {
    if (p_TipoBusca == "") { //Primeira busca, buscar só cidades
        p_TipoBusca = "F";
    } else { //Buscas ciclicas originadas pelos combos
        if (TipoBuscaOriginal == "") {
            TipoBuscaOriginal = p_TipoBusca;
        }
    }
    TipoBuscaParcial = p_TipoBusca;
    PageMethods.BuscaValor(TipoBuscaParcial, $get('ddl_Cidades').value, $get('ddl_Bairros').value,
                       $get('ddl_Tipos').value, $get('ddl_Precos').value,
                       $get('ddl_Fases').value, RetornoValorCampanha);
}


function RetornoValor(result) {
    $get('ddl_Cidades').disabled = true;
    $get('ddl_Bairros').disabled = true;
    $get('menutopo_ddl_Tipos').disabled = true;
    $get('menutopo_ddl_Precos').disabled = true;
    $get('menutopo_ddl_Fases').disabled = true;

    //Coloca Nova opção nas drops
    //incluiOpcaoFases();

    switch (TipoBuscaParcial) {
        case ("C"): //Se cidade popular bairros
            PopularCombos("ddl_Bairros", result);
            //TipoBuscaParcial = "B"; //iniciar próxima busca com bairros
            break;
//        case ("B"): //Se bairro popular tipos de imóveis
//            PopularCombos("menutopo_ddl_Tipos", result);
//            TipoBuscaParcial = "T"; //iniciar próxima busca com tipos de imóveis
//            break;
//        case ("T"): //Se tipos de imóveis popular preços
//            PopularCombos("menutopo_ddl_Precos", result);
//            TipoBuscaParcial = "P"; //iniciar próxima busca com preços
//            break;
//        case ("P"): //Se preços popular fases
//            PopularCombos("menutopo_ddl_Fases", result);
//            TipoBuscaParcial = "F"; //iniciar próxima busca com fases
//            break;
        case ("F"): //Se fases popular cidades
            PopularCombos("ddl_Cidades", result);
            TipoBuscaParcial = "C"; //iniciar próxima busca com cidades
            break;
    }
    //Apenas executa uma próxima busca se ela for diferente da busca inicial que começou o ciclo
    if (TipoBuscaOriginal != TipoBuscaParcial && TipoBuscaOriginal != "") {
        PageMethods.BuscaValor(TipoBuscaParcial, $get('ddl_Cidades').value, $get('ddl_Bairros').value,
                                       $get('menutopo_ddl_Tipos').value, $get('menutopo_ddl_Precos').value,
                                       $get('menutopo_ddl_Fases').value, RetornoValor);
    } else {
      if ((window.location.pathname.toString().substring(1).split('.')[0].toString() == "Default" ||
           window.location.pathname.toString().substring(1).split('.')[0].toString() == "") && TipoBuscaOriginal == "") {
          $get($get('Oportunidade1').value).style.color = "yellow";
           OportunidadeEscolhida = $get('Oportunidade1').value;
           PageMethods.BuscaOportunidades($get('Oportunidade1').value, RetornaOportunidades);
      }
      $get('ddl_Cidades').disabled = false;
      $get('ddl_Bairros').disabled = false;
      $get('menutopo_ddl_Tipos').disabled = false;
      $get('menutopo_ddl_Precos').disabled = false;
      $get('menutopo_ddl_Fases').disabled = false;
    }
}

function RetornoValorCampanha(result) {
    $get('ddl_Cidades').disabled = true;
    $get('ddl_Bairros').disabled = true;
    $get('ddl_Tipos').disabled = true;
    $get('ddl_Precos').disabled = true;
    $get('ddl_Fases').disabled = true;

    //Coloca Nova opção nas drops
    //incluiOpcaoFases();

    switch (TipoBuscaParcial) {
        case ("C"): //Se cidade popular bairros
            PopularCombosCampanha("ddl_Bairros", result);
            //TipoBuscaParcial = "B"; //iniciar próxima busca com bairros
            break;
        //        case ("B"): //Se bairro popular tipos de imóveis 
        //            PopularCombos("menutopo_ddl_Tipos", result); 
        //            TipoBuscaParcial = "T"; //iniciar próxima busca com tipos de imóveis 
        //            break; 
        //        case ("T"): //Se tipos de imóveis popular preços 
        //            PopularCombos("menutopo_ddl_Precos", result); 
        //            TipoBuscaParcial = "P"; //iniciar próxima busca com preços 
        //            break; 
        //        case ("P"): //Se preços popular fases 
        //            PopularCombos("menutopo_ddl_Fases", result); 
        //            TipoBuscaParcial = "F"; //iniciar próxima busca com fases 
        //            break; 
        case ("F"): //Se fases popular cidades
            PopularCombos("ddl_Cidades", result);
            TipoBuscaParcial = "C"; //iniciar próxima busca com cidades
            break;
    }
    //Apenas executa uma próxima busca se ela for diferente da busca inicial que começou o ciclo
    if (TipoBuscaOriginal != TipoBuscaParcial && TipoBuscaOriginal != "") {
        PageMethods.BuscaValor(TipoBuscaParcial, $get('ddl_Cidades').value, $get('ddl_Bairros').value,
                                       $get('ddl_Tipos').value, $get('ddl_Precos').value,
                                       $get('ddl_Fases').value, RetornoValorCampanha);
    } else {
        if ((window.location.pathname.toString().substring(1).split('.')[0].toString() == "Default" ||
           window.location.pathname.toString().substring(1).split('.')[0].toString() == "") && TipoBuscaOriginal == "") {
            $get($get('Oportunidade1').value).style.color = "yellow";
            OportunidadeEscolhida = $get('Oportunidade1').value;
            PageMethods.BuscaOportunidades($get('Oportunidade1').value, RetornaOportunidades);
        }
        $get('ddl_Cidades').disabled = false;
        $get('ddl_Bairros').disabled = false;
        $get('ddl_Tipos').disabled = false;
        $get('ddl_Precos').disabled = false;
        $get('ddl_Fases').disabled = false;
    }
}

function PopularCombos(NomeCombo, Resultado) {
    var lAtual = $get(NomeCombo).value;
    if (TipoBuscaOriginal != "") {
        for (i = $get(NomeCombo).options.length - 1; i >= 0; i--) {
            $get(NomeCombo).remove(i);
        }
    }
    if (NomeCombo.toString() != "ddl_Cidades") {
        var opc = document.createElement("option");
        $get(NomeCombo).options.add(opc);
        if (NomeCombo == "ddl_Bairros") {
            opc.text = "Bairros";
            opc.value = "Bairros";
        } else {
        if (NomeCombo == "menutopo_ddl_Tipos") {
                opc.text = "Tipos de Imóvel";
                opc.value = "TiposDeImovel";
            } else {
            if (NomeCombo == "menutopo_ddl_Precos") {
                    opc.text = "Faixas de Preço";
                    opc.value = "FaixasDePreco";
                } else {
                if (NomeCombo == "menutopo_ddl_Fases") {
                        opc.text = "Fases da Obra";
                        opc.value = "FasesDaObra";
                    }
                }
            }
        }
    }
    for (i = Resultado.split('|').length - 1; i >= 0; i--) {
        var opt = document.createElement("option");
        $get(NomeCombo).options.add(opt);
        opt.text = Resultado.split('|')[i].trim();
        opt.value = Resultado.split('|')[i].trim(); 
    }
    if ("Bairros,TiposDeImovel,Precos,Fases".indexOf(lAtual) < 0) {
        $get(NomeCombo).value = lAtual;
        if ($get(NomeCombo).value == "") {
            $get(NomeCombo).value = $get(NomeCombo).options[0].value;
        }
    }
}

function PopularCombosCampanha(NomeCombo, Resultado) {
    var lAtual = $get(NomeCombo).value;
    if (TipoBuscaOriginal != "") {
        for (i = $get(NomeCombo).options.length - 1; i >= 0; i--) {
            $get(NomeCombo).remove(i);
        }
    }
    if (NomeCombo.toString() != "ddl_Cidades") {
        var opc = document.createElement("option");
        $get(NomeCombo).options.add(opc);
        if (NomeCombo == "ddl_Bairros") {
            opc.text = "Bairros";
            opc.value = "Bairros";
        } else {
            if (NomeCombo == "ddl_Tipos") {
                opc.text = "Tipos de Imóvel";
                opc.value = "TiposDeImovel";
            } else {
                if (NomeCombo == "ddl_Precos") {
                    opc.text = "Faixas de Preço";
                    opc.value = "FaixasDePreco";
                } else {
                    if (NomeCombo == "ddl_Fases") {
                        opc.text = "Fases da Obra";
                        opc.value = "FasesDaObra";
                    }
                }
            }
        }
    }
    for (i = Resultado.split('|').length - 1; i >= 0; i--) {
        var opt = document.createElement("option");
        $get(NomeCombo).options.add(opt);
        opt.text = Resultado.split('|')[i].trim();
        opt.value = Resultado.split('|')[i].trim();
    }
    if ("Bairros,TiposDeImovel,Precos,Fases".indexOf(lAtual) < 0) {
        $get(NomeCombo).value = lAtual;
        if ($get(NomeCombo).value == "") {
            $get(NomeCombo).value = $get(NomeCombo).options[0].value;
        }
    }
}
/*
function incluiOpcaoFases() {
    var opt = document.getElementById("menutopo_ddl_Fases");
    
    var optn = document.createElement("option");
    optn.text = "Testeeeee";
    optn.value = "Valor";

    opt.options.add(optn);
}*/


function LimpaCoresItensMenu() {
    for (i = 0; i < $get('Itens_De_Menu').value.toString().split(',').length; i++) {
        $get($get('Itens_De_Menu').value.toString().split(',')[i].toString()).style.color = "white";
    }   
}

var OportunidadeEscolhida = "";
function PreencheOportunidades(p_obj) {
    OportunidadeEscolhida = p_obj;
    PageMethods.BuscaOportunidades(p_obj, RetornaOportunidades);
}

function RetornaOportunidades(result) {
    $get('Oportunidades').value = result;
    window.setTimeout('OportunidadesInicial()', 50);
}

function OportunidadesInicial() {
    $get("GuiaOportunidades").style.left = "0px";
    PageMethods.FormatarOportunidades($get('Oportunidades').value, '', '', RetornaPreenchimento);
}

function OportunidadesFrente() {
    if (parseInt($get('Indice_Oports').value.toString()) > 3) {
        lLado="E";
        if ($get('GuiaOportunidades').style.left.toString() == "") $get('GuiaOportunidades').style.left = "0px";
        lOpor=parseInt($get('GuiaOportunidades').style.left.toString().replace('px',''));
        Carrossel();
    }
//    if ($get('Tem_Proximo').value == "S") {
//        PageMethods.FormatarOportunidades($get('Oportunidades').value, $get('Indice_Oports').value, '', RetornaPreenchimento);
//    } else {
//        //alert("Não há próxima página para estas oportunidades !");
//    }
}

function OportunidadesTras() {
    if (parseInt($get('Indice_Oports').value.toString()) > 3) {
        lLado="D";
        if ($get('GuiaOportunidades').style.left.toString() == "") $get('GuiaOportunidades').style.left = "0px";
        lOpor=parseInt($get('GuiaOportunidades').style.left.toString().replace('px',''));
        Carrossel();
    }
//    if ($get('Tem_Anterior').value == "S") {
//        PageMethods.FormatarOportunidades($get('Oportunidades').value, $get('Indice_Oports').value, $get('Indice_Oports').value, RetornaPreenchimento);
//    } else {
//        //alert("Não há página anterior para estas oportunidades !");
//    }
}

function RetornaPreenchimento(result) {
    $get('BtnRetroceder').disabled = (result.split('|')[0].trim() == "N");
    $get('BtnAvancar').disabled = (result.split('|')[1].trim() == "N");
    $get('Tem_Anterior').value = result.split('|')[0].trim();
    $get('Tem_Proximo').value = result.split('|')[1].trim();
    $get('Indice_Oports').value = result.split('|')[2].trim();
    //alert("Indice_Oports = " + result.split('|')[2].trim());
    //changeInnerHTML('ResultadosBuscaInferior', result.split('|')[3].trim());
    changeInnerHTML('GuiaOportunidades', result.split('|')[3].trim());
    //alert("changeInnerHTML = " + result.split('|')[3].trim());
    $get('GuiaOportunidades').style.width = (parseInt($get('Indice_Oports').value.toString()) * 307).toString() + "px"; 
    LimpaCoresItensMenu();
    $get((OportunidadeEscolhida == "" ? "View_Lancamentos" : OportunidadeEscolhida)).style.color = "yellow";
    PageMethods.RegistraClique("Oportunidades", (OportunidadeEscolhida == "" ? "View_Lancamentos" : OportunidadeEscolhida), 0, registrouoportunidade, null);
}

var lLado = ""; //Rola para "D"ireita ou "E"squerda
var lOpor = 0;  //Posição atual no ato do clique
//Função que executa o carrossel
function Carrossel() {
  //Efetuar Verificações
  if ($get("ResultadosBuscaInferior").style.width.toString() == "") $get("ResultadosBuscaInferior").style.width = "917px";
  if ($get("ResultadosBuscaInferior").style.left.toString() == "")  $get("ResultadosBuscaInferior").style.left = "0px";
  if ($get("GuiaOportunidades").style.left.toString() == "")        $get("GuiaOportunidades").style.left = "0px";
  //Se for para rolar para a "E"squerda
  if (lLado == "E") {
      //Se a posição ESQUERDA da div GuiaOportunidades + seu tamanho for Maior ou igual ao tamanho div ResultadosBuscaInferior 
      if ((parseInt($get("GuiaOportunidades").style.left.toString().replace('px','')) +
           parseInt($get("GuiaOportunidades").style.width.toString().replace('px',''))) >= 
          (parseInt($get("ResultadosBuscaInferior").style.width.toString().replace('px','')) + 15) ) {
           //Diminuir 10px da posição ESQUERDA atual
           $get("GuiaOportunidades").style.left = (parseInt($get("GuiaOportunidades").style.left.toString().replace('px','')) - 15) + "px";
           //Executar novamente apenas se nao estiver na posição de 3 figuras à esquerda
           if (parseInt($get("GuiaOportunidades").style.left.toString().replace('px','')) >=
               ((lOpor-(302*3)))) {
               //Chamar novamente o carrossel daqui a 50 milisegundos
               window.setTimeout("Carrossel();", 15);
           } else {
             //alert('1');
           }
      } else {
        //alert('2');
      }
  } else {
    //Se for para rolar para a "D"ireita 
    if (lLado == "D") {
      //Se a posição ESQUERDA da div GuiaOportunidades for Maior ou igual ao resultado de (tamanho div ResultadosBuscaInferior - tamanho div GUIA)              
      if (parseInt($get("GuiaOportunidades").style.left.toString().replace('px','')) < 0) {
           //Aumentar 10px da posição ESQUERDA atual
           $get("GuiaOportunidades").style.left = (parseInt($get("GuiaOportunidades").style.left.toString().replace('px','')) + 15) + "px";
           //Executar novamente apenas se nao estiver na posição de 3 figuras à esquerda
           if (parseInt($get("GuiaOportunidades").style.left.toString().replace('px','')) <=
               (lOpor+(302*3))) {
               //Chamar novamente o carrossel daqui a 50 milisegundos
               window.setTimeout("Carrossel();", 15);
           } else {
             //alert('3');
           }
      } else {
        //alert('4');
      }         
    }
  }
}


function registrouoportunidade() {
    return false;
}


function MoverParaEsquerda() {
    //Deixar Botão Pressionado Invisível
    $get("divbtnDiminuir").style.visibility = "hidden";
    $get("divbtnAumentar").style.visibility = "hidden";
    //Diminuir a primeira da Esquerda até zerar
    var obj = $get("div1").style.width;
    obj = obj.replace("%", "");
    if (parseInt(obj) > 0) {
        $get("div1").style.width = (parseInt(obj) - 1).toString() + "%";
        window.setTimeout("MoverParaEsquerda()", 2);
    } else {
        //Deixar todas invisíveis
        $get("div1").style.visibility = "hidden";
        $get("div2").style.visibility = "hidden";
        $get("div3").style.visibility = "hidden";
        //Trocar as imagens
        obj = $get("img1").src;
        $get("img1").src = $get("img2").src;
        $get("img2").src = $get("img3").src;
        $get("img3").src = obj;
        //Voltar a primeira da esquerda para o tamanho correto
        $get("div1").style.width = $get("div2").style.width;
        //Deixar todas visíveis
        $get("div1").style.visibility = "visible";
        $get("div2").style.visibility = "visible";
        $get("div3").style.visibility = "visible";
        $get("divbtnDiminuir").style.visibility = "visible";
        $get("divbtnAumentar").style.visibility = "visible";
    }
}

function MoverParaDireita() {
    //Deixar Botão Pressionado Invisível
    $get("divbtnDiminuir").style.visibility = "hidden";
    $get("divbtnAumentar").style.visibility = "hidden";
    //Diminuir a primeira da Esquerda até zerar
    var obj = $get("div3").style.width;
    obj = obj.replace("%", "");
    if (parseInt(obj) > 0) {
        $get("div3").style.width = (parseInt(obj) - 1).toString() + "%";
        obj = $get("divbtnDiminuir").style.width;
        if (obj.indexOf("px") >= 0) {
            $get("divbtnDiminuir").style.width = "2%";
        } else {
            obj = obj.replace("%", "");
            $get("divbtnDiminuir").style.width = (parseInt(obj) + 1).toString() + "%";
        }
        window.setTimeout("MoverParaDireita()", 2);
    } else {
        //Deixar todas invisíveis
        $get("div1").style.visibility = "hidden";
        $get("div2").style.visibility = "hidden";
        $get("div3").style.visibility = "hidden";
        //Trocar as imagens
        obj = $get("img3").src;
        $get("img3").src = $get("img2").src;
        $get("img2").src = $get("img1").src;
        $get("img1").src = obj;
        //Voltar a primeira da direita para o tamanho correto
        $get("div3").style.width = $get("div2").style.width;
        $get("divbtnDiminuir").style.width = $get("divbtnAumentar").style.width;
        //Deixar todas visíveis
        $get("div1").style.visibility = "visible";
        $get("div2").style.visibility = "visible";
        $get("div3").style.visibility = "visible";
        $get("divbtnDiminuir").style.visibility = "visible";
        $get("divbtnAumentar").style.visibility = "visible";
    }
}

function changeInnerHTML(divId, html) {
    var e = null;
    if (document.getElementById) {
        e = document.getElementById(divId);
        if (!e) return false;
        if ("innerHTML" in e) {
            e.innerHTML = html; return true
        }
        else if ("firstChild" in e && "data" in e.firstChild) {
            e.firstChild.data = html; return true;
        }
        else {
            return false;
        }
    } else if (document.layers) {
        e = document.layers[divId];
        if (typeof e == "undefined" || !e) {
            e = document[divId];
            if (typeof e == "undefined" || !e) return false;
        }
        e.document.open();
        e.document.write(html);
        e.document.close();
        return true;
    } else if (document.all) {
        e = document.all[divId];
        if (typeof e == "undefined" || !e) return false;
        e.innerHTML = html;
        return true;
    }
    return false;
}

function TrocaAba(p_Atual) {
   $get('Aba01').style.zIndex = 11;
   $get('Aba02').style.zIndex = 12;
   $get('Aba03').style.zIndex = 13;
   $get('Aba04').style.zIndex = 14;
   $get('Aba05').style.zIndex = 15;
   var strAba;
   switch (p_Atual.toString().toUpperCase().substr(0,3)) {
       case ("EST"): //Estágio de Obras
           $get('Aba01').style.zIndex = 18;
           if ($get('DivAbaSelecionada').currentStyle) {
               window.setTimeout("$get('DivAbaSelecionada').style.left = 0;", 10);
           } else {
               window.setTimeout("$get('DivAbaSelecionada').style.left = '0px';", 10);
           }
           strAba = "abaEstagiodaObra";
           break;
       case ("FIC"): //Ficha Técnica
         $get('Aba02').style.zIndex = 18;
         if ($get('DivAbaSelecionada').currentStyle){ 
             window.setTimeout("$get('DivAbaSelecionada').style.left = 198;", 10);
         } else {
             window.setTimeout("$get('DivAbaSelecionada').style.left = '198px';", 10);
         }
         strAba = "abaFichaTecnica";
         break;
      case ("PRE"): //Financiamento/Preços
         $get('Aba03').style.zIndex = 18;
         if ($get('DivAbaSelecionada').currentStyle){ 
             window.setTimeout("$get('DivAbaSelecionada').style.left = 396;", 10);
         } else {
             window.setTimeout("$get('DivAbaSelecionada').style.left = '396px';", 10);
         }
         strAba = "abaPreco";
         break;
      case ("LOC"): //Localização
         $get('Aba04').style.zIndex = 18;
         if ($get('DivAbaSelecionada').currentStyle){ 
             window.setTimeout("$get('DivAbaSelecionada').style.left = 593;", 10);
         } else {
             window.setTimeout("$get('DivAbaSelecionada').style.left = '593px';", 10);
         }
         strAba = "abaLocalizacao";
         break;
      case ("REA"): //Realização
         $get('Aba05').style.zIndex = 18;
         if ($get('DivAbaSelecionada').currentStyle){ 
             window.setTimeout("$get('DivAbaSelecionada').style.left = 790;", 10);
         } else {
             window.setTimeout("$get('DivAbaSelecionada').style.left = '790px';", 10);
         }
         strAba = "abaRealizacao";
         break;
 }
 var Id_Empreend = $get('Id_Empreend').value;
 
 RegistraBusca(strAba, '', Id_Empreend);
}

function MovimentaImagem(p_Frente) {
   if (p_Frente) {
       if ($get('btn_Posterior').style.visibility == "hidden") return;
       if ($get('IndexImage').value.toString().split('|')[1].toString().substr(0, 1) == "S") {
           ListarImagens($get('TypeImage').value, $get('IndexImage').value.toString().split('|')[1].toString().substr(1));
       } else {
           if ($get('TypeImage').value==1) {
               ListarImagens($get('TypeImage').value, $get('DivImagensZoom').value.toString().split('|')[0].toString().split('@')[4].toString());
           } else {
               ListarImagens($get('TypeImage').value, $get('DivImagensZoomObra').value.toString().split('|')[0].toString().split('@')[4].toString());
           }
       }
   } else {
       if ($get('btn_Anterior').style.visibility == "hidden") return;
       if (SlidesLigado == false) {
           if ($get('IndexImage').value.toString().split('|')[0].toString().substr(0,1) == "S") {
               ListarImagens($get('TypeImage').value, $get('IndexImage').value.toString().split('|')[0].toString().substr(1));
           } else {
               if ($get('TypeImage').value==1) {
                   ListarImagens($get('TypeImage').value, $get('DivImagensZoom').value.toString().split('|')[$get('DivImagensZoom').value.toString().split('|').length-1].toString().split('@')[4].toString());
               } else {
                   ListarImagens($get('TypeImage').value, $get('DivImagensZoomObra').value.toString().split('|')[$get('DivImagensZoomObra').value.toString().split('|').length-1].toString().split('@')[4].toString());
               }
           }
       }
   }
}

function ExecutaSlides() {
   if (SlidesLigado) {
       MovimentaImagem(true);
       window.setTimeout("ExecutaSlides();", 3000);
   }
}

function AtivarSlides() {
   if (SlidesLigado) {
       SlidesLigado = false;
   } else {
       SlidesLigado = true;
       ExecutaSlides();
   }
   TrocaImagemPlay();
}

function ImagemInicialPlay() {
   if (SlidesLigado) {
       $get('DivBtnAtivarSlides').style.backgroundImage = "url('images/pause-gray.png')";
       $get('DivBtnAtivarSlides').style.display = "block";
   } else {
       $get('DivBtnAtivarSlides').style.backgroundImage = "url('images/play-gray.png')";
       $get('DivBtnAtivarSlides').style.display = "block";
   }
}
function TrocaImagemPlay() {
   if (SlidesLigado) {
       $get('DivBtnAtivarSlides').style.backgroundImage = "url('images/pause-blue.png')";
       $get('DivBtnAtivarSlides').style.display = "block";
   } else {
       $get('DivBtnAtivarSlides').style.backgroundImage = "url('images/play-blue.png')";
       $get('DivBtnAtivarSlides').style.display = "block";
   }    
}

function ListarImagens(p_TipoLightBox, p_IdImagem) {
   var i=0;
   var v;
   $get('TypeImage').value = p_TipoLightBox;
   if (p_TipoLightBox==1) {
       v = $get('DivImagensZoom').value;
   } else {
       v = $get('DivImagensZoomObra').value;
   }
   //alert("v="+v);
   for (i = 0; i < v.split('|').length; i++) {
        if (parseInt(v.split('|')[i].toString().split('@')[4].toString()) == p_IdImagem)
        {
           $get('btn_Anterior').style.visibility = (v.split('|')[i].toString().split('@')[0].toString().substr(0,1)=="N" ? "hidden" : "visible");
           $get('btn_Posterior').style.visibility = (v.split('|')[i].toString().split('@')[1].toString().substr(0,1)=="N" ? "hidden" : "visible");
           $get('IndexImage').value = v.split('|')[i].toString().split('@')[0].toString() + "|" +
                                      v.split('|')[i].toString().split('@')[1].toString();
           //alert("src=" + v.split('|')[i].toString().split('@')[2].toString().trim());
           v = "<img id='btnImagemFundoBranco' alt='' src='" + v.split('|')[i].toString().split('@')[2].toString().trim() + "' />" +
               "<div id='DivImagemFundoBranco'>" +
               v.split('|')[i].toString().split('@')[3].toString().replace("Perspectiva","") +
               "</div>";
           changeInnerHTML('ImagemFundoBranco', v);
           break;
        }
   }
}

var lTipoLightBox = 0;
var lIdImagem = 0;
function AbreLightBox(p_TipoLightBox, p_IdImagem, p_IdProduto) {
    //alert("AbreLightBox");
    lTipoLightBox = p_TipoLightBox;
    lIdImagem = p_IdImagem;
    //alert("p_TipoLightBox=" + p_TipoLightBox + " - p_IdImagem=" + p_IdImagem + " - p_IdProduto=" + p_IdProduto);
    PageMethods.RegistraClique("AbreLightBox", (p_TipoLightBox==1 ? "Miniaturas" : (p_TipoLightBox==2 ? "YouTube" : "Obras")), p_IdProduto, registrouabrelightbox, null);
}
function registrouabrelightbox() {
    //Tipos de LightBox's: 1->Miniaturas; 2->YouTube; 3->Obras
    //alert("registrouabrelightbox");
    $get('btn_Anterior').style.visibility = (lTipoLightBox == 2 ? "hidden" : "visible");
    $get('btn_Posterior').style.visibility = (lTipoLightBox == 2 ? "hidden" : "visible");
    $get('DivBtnAtivarSlides').style.visibility = (lTipoLightBox == 2 ? "hidden" : "visible");
    //alert("lTipoLightBox=" + lTipoLightBox);
    if (lTipoLightBox == 2) {
        changeInnerHTML('ImagemFundoBranco', $get('DivYouTube').value);
        //alert("DivYouTube=" + $get('DivYouTube').value);
    } else {
        ListarImagens(lTipoLightBox, lIdImagem);
    }
    window.setTimeout("ExibeDiv('FundoNegro', 'FundoBranco', " + lTipoLightBox + ");", 10);
}
function ExibeDiv(p_NomeDivFundo, p_NomeDivFrente, p_TipoLightBox) {
    if (AbrindoComoChegar) {
        AbrindoComoChegar = false;
        return;
    }
    //Alterar estilo da Div de fundo (position: absolute; display: block; width: (temporário); height: (temporário);
    //                                top: (temporário); left: (temporário); visibility: visible; zIndex: 50; filter:alpha(opacity = 70);)
    $get(p_NomeDivFundo).style.top = 0;
    $get(p_NomeDivFundo).style.left = 0;
    $get(p_NomeDivFundo).style.width = (parseInt(window.screen.width.toString())-23) + "px";                      
    $get(p_NomeDivFundo).style.position = "absolute";
    $get(p_NomeDivFundo).style.display = "block";
    if ($get(p_NomeDivFundo).style.height == "") {
       $get(p_NomeDivFundo).style.height = "100px";
    } else {
       $get(p_NomeDivFundo).style.height = (parseInt($get(p_NomeDivFundo).style.height.replace('px', '').replace('%', '')) + 100).toString() + "px";
    }
    $get(p_NomeDivFundo).style.visibility = "visible";
    $get(p_NomeDivFundo).style.zIndex = 500;
    $get(p_NomeDivFundo).style.filter = "alpha(opacity = 70)";
    //Se o crescimento em altura chegar em 100%
    if ($get(p_NomeDivFundo).style.height.replace('px', '').replace('%', '') >= $get('CorpoTodo').clientHeight) {
        $get('DivBtnAtivarSlides').style.visibility = (p_TipoLightBox==2 ? "hidden" : "visible");        
        $get(p_NomeDivFrente).style.top = (parseInt(document.documentElement.scrollTop) + 20).toString() + "px";
        $get(p_NomeDivFrente).style.width = "870px";
        $get(p_NomeDivFrente).style.left = (window.screen.width / 2) - (parseInt($get(p_NomeDivFrente).style.width.replace('px', '').replace('%', '')) / 2) + "px";
        $get(p_NomeDivFrente).style.position = "absolute";
        $get(p_NomeDivFrente).style.display = "block";
        $get(p_NomeDivFrente).style.visibility = "visible";
        $get(p_NomeDivFrente).style.zIndex = 501;
        if (p_TipoLightBox == 2) $get('FlashYouTube').Play();
    } else {
        //Se não em 100% aguardar 50 milisegundos e aumentar mais 100px (até chegar em 100%)
        window.setTimeout("ExibeDiv('" + p_NomeDivFundo + "', '" + p_NomeDivFrente + "', " +  p_TipoLightBox + ");", 50);
    }
}
function EscondeDiv(p_NomeDivFundo, p_NomeDivFrente) {
    if (SlidesLigado) {
        alert("Desligue o Slide Show !!!");
    } else {
        $get(p_NomeDivFundo).style.display = "none";
        $get(p_NomeDivFundo).style.width = "0px";
        $get(p_NomeDivFundo).style.height = "0px";
        $get(p_NomeDivFrente).style.display = "none";
        changeInnerHTML('ImagemFundoBranco', '');
        SlidesLigado = false;
    }
}

function BuscaGoogleMaps() {
   if ($get('txtEnderecoPartida').value.length == 0) {
       alert('Informe o endereço de partida');
   } else {
       var tela = window.open('http://maps.google.com.br/?q=from: '+ $get('txtEnderecoPartida').value + ' to: ' + $get('Endereco').value ,'poprs',
                              'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,top=0,left=0,width=' + window.screen.width +
                              ',height=' + window.screen.height); 
   }
}

function ExibeGoogleMapsNaDiv(p_NomeDaDiv, p_Latitude, p_Longitude) 
{
    try {

        var map = new GMap2($get(p_NomeDaDiv));
        if (GBrowserIsCompatible()) {
            map.setCenter(new GLatLng(p_Latitude, p_Longitude), 14);
        }
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addOverlay(new GMarker(map.getCenter()));
    }
    catch (myError) {

        //alert('erro ao abrir o google maps');

        alert(myError.name + ': ' + myError.message);
    } finally {

    }  
}
