﻿var gMetodo;
var gVariavel;
var contagem = "";

function trocaimagem(p_Obj, p_Imagem) {
    $get(p_Obj).style.backgroundImage = "url('" + p_Imagem + "')";
}

function HideBusca(){
    setTimeout("dvContentBusca.style.visibility='hidden';",500);
}

function MontaGoogleImpressao() {
   ExibeGoogleMapsNaDiv('DivImagemGoogleMaps', $get('Latitude').value, $get('Longitude').value);
}

function ListagemParametros() {
    //alert($get('menutopo_ddl_Tipos').value);
    if ( ($get('ddl_Cidades').value == "Cidades" || $get('ddl_Cidades').value == "") &&
          ($get('menutopo_ddl_Tipos').value == "TiposDeImovel" || $get('menutopo_ddl_Tipos').value == "") &&
          ($get('menutopo_ddl_Precos').value == "FaixasDePreco" || $get('menutopo_ddl_Precos').value == "") && 
          ($get('menutopo_ddl_Fases').value == "FasesDaObra" || $get('menutopo_ddl_Fases').value == "") ) { 
        alert("Selecione um dos Itens !!!");
    } else {
        PageMethods.RegistraClique("BuscaCombosSuperiores", "Listagem.aspx?Parametros=" + $get('ddl_Cidades').value + "|" + $get('ddl_Bairros').value + "|" +
                               $get('menutopo_ddl_Tipos').value + "|" + $get('menutopo_ddl_Precos').value + "|" + $get('menutopo_ddl_Fases').value, 0, registroubuscaporparametros, null);
    }
}

function registroubuscaporparametros() {
    window.location = 'Listagem.aspx?Parametros=' + $get('ddl_Cidades').value + "|" + $get('ddl_Bairros').value + "|" + $get('menutopo_ddl_Tipos').value + "|" +
                          $get('menutopo_ddl_Precos').value + "|" + $get('menutopo_ddl_Fases').value;
}

function ListagemParametrosCampanha() {
    //alert($get('menutopo_ddl_Tipos').value);
    if (($get('ddl_Cidades').value == "Cidades" || $get('ddl_Cidades').value == "") &&
          ($get('ddl_Tipos').value == "TiposDeImovel" || $get('ddl_Tipos').value == "") &&
          ($get('ddl_Precos').value == "FaixasDePreco" || $get('ddl_Precos').value == "") &&
          ($get('ddl_Fases').value == "FasesDaObra" || $get('ddl_Fases').value == "")) {
        alert("Selecione um dos Itens !!!");
    } else {
        PageMethods.RegistraClique("BuscaCombosSuperiores", "../Listagem.aspx?Parametros=" + $get('ddl_Cidades').value + "|" + $get('ddl_Bairros').value + "|" +
                               $get('ddl_Tipos').value + "|" + $get('ddl_Precos').value + "|" + $get('ddl_Fases').value, 0, registroubuscaporparametrosCampanha, null);
    }
}

function registroubuscaporparametrosCampanha() {
    window.location = '../Listagem.aspx?Parametros=' + $get('ddl_Cidades').value + "|" + $get('ddl_Bairros').value + "|" + $get('ddl_Tipos').value + "|" +
                          $get('ddl_Precos').value + "|" + $get('ddl_Fases').value;
}

function LimpaCampo(Campo){
    if(Campo.value == 'Buscar por nome ou endereço')
        Campo.value = "";
}
function tecla(a) {
    var Key = a.keyCode || a.which;
    if (Key == "13") {
        PageMethods.RegistraClique("BuscaSugerida", "Listagem.aspx?Parametros=" + $get('menutopo_txt_busca').value, 0, registroubuscasugerida, null);
        return false;
     }
     else
     {
         return true;  
     }
 }
 function teclaCampanha(a) {
     var Key = a.keyCode || a.which;
     if (Key == "13") {
         PageMethods.RegistraClique("BuscaSugerida", "../Listagem.aspx?Parametros=" + $get('txt_busca').value, 0, registroubuscasugeridaCampanha, null);
         return false;
     }
     else {
         return true;
     }
 }
 function registroubuscasugerida() {
     window.location.href = 'Listagem.aspx?Parametros=' + $get('menutopo_txt_busca').value;
 }
 function registroubuscasugeridaCampanha() {
     window.location.href = '../Listagem.aspx?Parametros=' + $get('txt_busca').value;
 }

function ContaChecks(ctl) {
    var lLin = 0;
    var lCon = "";
    if (ctl.checked) {
       if (contagem != "") contagem += ",";
       contagem += ctl.id.toString().split('_')[1].toString();
   } else {
       if (contagem == ctl.id.toString().split('_')[1].toString()) {
           contagem = "";
       } else {
         lCon = "";
         for (lLin = 0; lLin < contagem.split(',').length; lLin++) {
             if (contagem.split(',')[lLin].toString().trim() != ctl.id.toString().split('_')[1].toString()) {
                 if (lCon.toString().trim().length > 0) lCon += ",";
                 lCon += contagem.split(',')[lLin].toString().trim();
             }
         }
         contagem = lCon;
       }
   }
   if (contagem.split(',').length > 3) {
       alert("Quantidade máxima excedida: " + contagem.split(',').length.toString());
       lCon = "";
       for (lLin = 0; lLin < contagem.split(',').length; lLin++) {
           if (contagem.split(',')[lLin].toString().trim() != ctl.id.toString().split('_')[1].toString()) {
               if (lCon.toString().trim().length > 0) lCon += ",";
               lCon += contagem.split(',')[lLin].toString().trim();
           }
       }
       contagem = lCon;
       ctl.checked = false;
   }
}

function CompararProdutos() {
    if (contagem.split(',').length < 2) {
        alert("Não existem produtos selecionados suficientes para iniciar comparação!");
    } else {
        PageMethods.RegistraClique("CompararProdutos", "Compare.aspx?Ids=" + contagem, 0, registroucompare, null);
    }
}
function registroucompare() {
    var tela = window.open('Compare.aspx?Ids=' + contagem, 'compare',
                              'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,top=0,left=0,width=998' +
                              ',height=' + window.screen.height);
}

function PosicionaDescricaoProdutoNoSafari() {
    if (window.navigator.appVersion.toString().indexOf("Safari") > 0 &&
        window.navigator.appVersion.toString().indexOf("Chrome") < 0) {
        $get('DescritivoDoProduto').style.position = "absolute";
        $get('DescritivoDoProduto').style.paddingTop = "15px";
    }
}

function CentralizaDivGeral() {
   var meiotela = screen.width/2;
   meiotela = meiotela - (980 / 2) - 15;
   /*alert('Meio tela = ' + meiotela);*/
   document.getElementById("CorpoTodo").style.left = meiotela + "px";
   BuscarValor('');
   if (window.location.pathname.toString().substring(1).split('.')[0].toString() == "Listagem") {
       PreencheBusca(null);
   }
   if (window.location.pathname.toString().substring(1).split('.')[0].toString() == "Produtos") {
       $get($get('Itens_De_Menu').value.toString().split(',')[0].toString()).style.color = '#095EAE';
       PageMethods.BuscaMiniaturas($get('Miniatura1').value, $get('Id_Empreend').value, RetornaMiniaturas);
       if ($get('DadosProduto_Ls').innerHTML.toString().indexOf('Dorm') > 0) {
           $get('btnApartamentos').innerHTML = "APARTAMENTOS"
       } else {
           $get('btnApartamentos').innerHTML = "ESCRITÓRIOS"
       }
       PosicionaDescricaoProdutoNoSafari();
   }
}

function setFocusAbaProdutos() {
    var iEstagio = $get('EstagioObraDescricao').value;
    if (iEstagio == "2") { //LANÇAMENTO
        TrocaAba("FIC");
    } else if (iEstagio == "3") { //EM OBRAS
        TrocaAba("EST");
    }else{
        TrocaAba("EST");
    }
}

function RetornaMiniaturas(result) {
    $get('Miniaturas').value = result;
    if (result == "") {
        changeInnerHTML('TopoFundoBranco', result);
    } else {
        changeInnerHTML('TopoFundoBranco', result.split('@')[result.split('@').length - 1].toString());
    }
    window.setTimeout('MiniaturasInicial()', 50);
}

function MiniaturasTrocaBusca(p_ctrl){
    $get('TipoMini').value = p_ctrl;
    LimpaCoresItensMenu();
    var lCampo = 0;
    var strAba;
    switch (p_ctrl.toString().substr(0, 2)) {
        case ("FA"): //Fachada
            lCampo = 0;
            strAba = "abaFachada";
            break;
        case ("PL"): //Plantas
            lCampo = 1;
            strAba = "abaPlantas";
            break;
        case ("IM"): //Implantação
            lCampo = 2;
            strAba = "abaImplantacao";
            break;
        case ("AP"): //Apartamentos/Escritórios
            lCampo = 3;
            strAba = "abaApartamentos";
            break;
        case ("AR"): //Área de Lazer
            lCampo = 4;
            strAba = "abaAreadeLazer";
            break;
    }
    $get($get('Itens_De_Menu').value.toString().split(',')[lCampo].toString()).style.color = '#97bb33';
    PageMethods.BuscaMiniaturas(p_ctrl, $get('Id_Empreend').value, RetornaMiniaturas);
    var Id_Empreend = $get('Id_Empreend').value;    RegistraBusca(strAba, '', Id_Empreend);
}

function MiniaturasInicial() {
    PageMethods.FormatarMiniaturas($get('Miniaturas').value, '', '', RetornouMiniaturas);
}

function MiniaturasFrente() {
    PageMethods.FormatarMiniaturas($get('Miniaturas').value, $get('Indice_Minits').value, '', RetornouMiniaturas);
}

function MiniaturasTras() {
    PageMethods.FormatarMiniaturas($get('Miniaturas').value, $get('Indice_Minits').value, $get('Indice_Minits').value, RetornouMiniaturas);
}

function RetornouMiniaturas(result) {
    $get('DivBtnEsqImgProdutos').style.visibility     = (result.split('|')[0].trim() == "N" ? "hidden" : "visible");
    $get('MiniaturasPaginaAnterior').style.visibility = (result.split('|')[0].trim() == "N" ? "hidden" : "visible");
    $get('DivBtnDirImgProdutos').style.visibility     = (result.split('|')[1].trim() == "N" ? "hidden" : "visible");
    $get('MiniaturasProximaPagina').style.visibility = (result.split('|')[1].trim() == "N" ? "hidden" : "visible");
    //$get('Indice_Minits').style.visibility = (result.split('|')[2].trim() == "" ? "hidden" : "visible");
    $get('Indice_Minits').value                       =  result.split('|')[2].trim();
    changeInnerHTML('DivExibicaoImagemProdutos', result.split('|')[3].trim());
    PageMethods.MoverImagemObra($get('Id_Empreend').value, 0, true, RetornouImgsObra);
}

function MoveImgObra(p_IdEmpreend, p_CodigoAtual, p_DeveAvancar) {
    PageMethods.MoverImagemObra(p_IdEmpreend, p_CodigoAtual, p_DeveAvancar, RetornouImgsObra);
}

function RetornouImgsObra(result) {
    changeInnerHTML('DivImagensObra', result.split('|')[0].trim());
    changeInnerHTML('DivTextoObra', result.split('|')[1].trim());
    if ($get('DivBtnVoltarObra') != null) {
        $get('DivBtnVoltarObra').style.visibility = (result.split('|')[2].trim() == "N" ? "hidden" : "visible");
        $get('btnAnteriorObra').style.visibility = (result.split('|')[2].trim() == "N" ? "hidden" : "visible");
        $get('DivBtnAvancarObra').style.visibility = (result.split('|')[3].trim() == "N" ? "hidden" : "visible");
        $get('btnProximaObra').style.visibility = (result.split('|')[3].trim() == "N" ? "hidden" : "visible");
    }
    ExibeGoogleMapsNaDiv('DivImagemGoogleMaps', $get('Latitude').value, $get('Longitude').value);
}

function RegistraCliqueMidia(id) {
    //alert(id);
    gMetodo = "_self";
    gVariavel = "Produtos.aspx?Id=" + id;
    PageMethods.RegistraClique("MidiaPrincipal", "Produtos.aspx?Id=" + id, id, OnSucceededRegistraBuscaMidia, null);
}
//Funcoes para Registro de clique
function RegistraLink(lnk,id)
{
    PageMethods.RegistraClique(lnk.id, lnk.href, id, OnSucceededRegistra, null);
    return true;
}
function OnSucceededRegistra(aRegistro, context)
{
    //alert(aRegistro);
}

//Funcoes para Registro de clique e abre popup/pagina especial para o Flash
function RegistraBuscaMidia(obj, Variaveis, id, MetodoPagina) {
    gMetodo = MetodoPagina;
    gVariavel = Variaveis;
    PageMethods.RegistraClique(obj, Variaveis, id, OnSucceededRegistraBuscaMidia, null);
    //return true;
}
function OnSucceededRegistraBuscaMidia(aRegistro, context) {
    if (gVariavel == "") return false;
    if (gMetodo == "_self") {
        window.location = gVariavel;
    }
    else if (gMetodo == "_blank") {
        newwindow = window.open(gVariavel);
        newwindow.focus();
    } else {
    if (gMetodo == "_popup") {
        if (gVariavel == "DirectTalk") gVariavel = "";
        if (gVariavel.length > 1)
            gVariavel = gVariavel.replace('&', '-');
        else
            gVariavel = gVariavel.replace(' ', '');
        gVariavel = "http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=2AB700776ECDA01433AE&origem=PortalAgra" + gVariavel;
        //abre(\"http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=2AB700776ECDA01433AE" + strAux + "\",\"Atendimento\",300,240,\"no\");
        newwindow = window.open(gVariavel, 'popupflashtopo', 'height=300,width=240');
    } else if (gMetodo == "_popupClienteLeft") {
        if (gVariavel == "DirectTalk") gVariavel = "";
        if (gVariavel.length > 1)
            gVariavel = gVariavel.replace('&', '-');
        else
            gVariavel = gVariavel.replace(' ', '');
        gVariavel = "http://www12.directtalk.com.br/CHAT/LayoutDT/Padrao/Inicio.aspx?idd=2AB700776ECDA01433AE" + gVariavel;
        //abre(\"http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=2AB700776ECDA01433AE" + strAux + "\",\"Atendimento\",300,240,\"no\");
        location.href = gVariavel;
        //newwindow = window.open(gVariavel, 'popupflashtopo', 'height=300,width=240');
    } else if (gMetodo == "_popupClienteDireito") {
        if (gVariavel == "DirectTalk") gVariavel = "";
        if (gVariavel.length > 1)
            gVariavel = gVariavel.replace('&', '-');
        else
            gVariavel = gVariavel.replace(' ', '');
        gVariavel = "http://www12.directtalk.com.br/chat/?idd=E13C00776D723014369B" + gVariavel;
        //gVariavel = "http://www12.directtalk.com.br/CHAT/LayoutDT/Padrao/Inicio.aspx?idd=2AB700776ECDA01433AE" + gVariavel;
        //abre(\"http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=2AB700776ECDA01433AE" + strAux + "\",\"Atendimento\",300,240,\"no\");
        location.href = gVariavel;
        //newwindow = window.open(gVariavel, 'popupflashtopo', 'height=300,width=240');
    } else if (gMetodo == "_popupHomeLeft") {
        if (gVariavel == "DirectTalk") gVariavel = "";
        if (gVariavel.length > 1)
            gVariavel = gVariavel.replace('&', '-');
        else
            gVariavel = gVariavel.replace(' ', '');
        gVariavel = "http://www12.directtalk.com.br/chat/?idd=E7E100774F90B01418DA" + gVariavel;
        //abre(\"http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=2AB700776ECDA01433AE" + strAux + "\",\"Atendimento\",300,240,\"no\");
        //newwindow = window.open(gVariavel, 'popupflashtopo', 'height=300,width=240');
        location.href = gVariavel;

    } else if (gMetodo == "_popupHomeRight") {
        if (gVariavel == "DirectTalk") gVariavel = "";
        if (gVariavel.length > 1)
            gVariavel = gVariavel.replace('&', '-');
        else
            gVariavel = gVariavel.replace(' ', '');
        gVariavel = "http://www12.directtalk.com.br/CHAT/LayoutDT/Padrao/Inicio.aspx?idd=2AB700776ECDA01433AE" + gVariavel;
        //abre(\"http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=2AB700776ECDA01433AE" + strAux + "\",\"Atendimento\",300,240,\"no\");
        newwindow = window.open(gVariavel, 'popupflashtopo', 'height=300,width=240');

    }
    else {
        newwindow = window.open(gVariavel, 'popupflashtopo');
    }
    if (window.focus && gMetodo != "_popupHomeLeft" && gMetodo != "_popupClienteLeft" && gMetodo != "_popupClienteDireito") {
            newwindow.focus();
        }
        return false;
    }
}

//Funcoes para Registro de clique
function RegistraBusca(obj,Variaveis, id) {
    PageMethods.RegistraClique(obj, Variaveis, id, OnSucceededRegistraBusca, null);
    return true;
}
function OnSucceededRegistraBusca(aRegistro, context) {
    //alert(aRegistro);
}

//Funcoes do Preenchimento da Busca
function PreencheBusca(p_ctl) {
    var strRegistra = '';
    $get('ItensMenuBusca').disabled = true;
    if (p_ctl != null) {
        var lTipo = p_ctl.id.split('_')[1];
        if (p_ctl.id.split('_')[0] == "Ordena") {
            $get('hOrdem').value = lTipo;
            $get('Ordena_Preco').style.backgroundColor = "Transparent";
            $get('Ordena_Tamanho').style.backgroundColor = "Transparent";
            $get('Ordena_Localidade').style.backgroundColor = "Transparent";
            $get(p_ctl.id).style.backgroundColor = "Red";
        } else {
          if (lTipo == "Cidade") {
              if (document.getElementById("hCidade").value != p_ctl.innerHTML) {
                  document.getElementById("hBairro").value = "";
                  document.getElementById("hTipoImovel").value = "";
                  document.getElementById("hDorm").value = "";
                  document.getElementById("hMetragem").value = "";
                  document.getElementById("hValor").value = "";
                  document.getElementById("hEstagio").value = "";
              }
              document.getElementById("hCidade").value = p_ctl.innerHTML;
              strRegistra = "Cidade=" + document.getElementById("hCidade").value + "&";
          } else { 
            if (lTipo == "Bairro") {                
                var MyBairro = p_ctl.innerHTML.toString();
                if (MyBairro.toString().indexOf('(') > 0) {
                    MyBairro = p_ctl.innerHTML.toString().substr(0, p_ctl.innerHTML.toString().indexOf('(')-1);
                } 
                if (document.getElementById("hBairro").value.toString().length > 0) {
                    if ($get("hBairro").value.toString().indexOf(MyBairro) >= 0) { 
                        $get("hBairro").value = $get("hBairro").value.toString().replace(","+MyBairro,"");
                        $get("hBairro").value = $get("hBairro").value.toString().replace(MyBairro+",","");
                        $get("hBairro").value = $get("hBairro").value.toString().replace(MyBairro,"");
                    } else {
                       if (document.getElementById("hBairro").value.toString().split(',').length < 3) {
                           if ($get('hBairro').value.toString().length > 0) $get('hBairro').value += ",";
                           $get('hBairro').value += MyBairro;
                       } else {
                           $get('ItensMenuBusca').disabled = false;
                           alert("Você pode escolher no máximo 03(três) bairros !");
                           return;
                       }
                    }
                } else {
                    if ($get('hBairro').value.toString().length > 0) $get('hBairro').value += ",";
                    $get('hBairro').value += MyBairro;
                }               
                //if (document.getElementById("hBairro").value != p_ctl.innerHTML) {
                //    document.getElementById("hTipoImovel").value = "";
                //    document.getElementById("hDorm").value = "";
                //    document.getElementById("hMetragem").value = "";
                //    document.getElementById("hValor").value = "";
                //    document.getElementById("hEstagio").value = "";
                //}
                //document.getElementById("hBairro").value = p_ctl.innerHTML;
                strRegistra = "Bairro=" + document.getElementById("hBairro").value.split('(')[0] + "&";
            } else {
              if (lTipo == "TipoImovel") {
                if (document.getElementById("hTipoImovel").value != p_ctl.innerHTML) {
                    document.getElementById("hDorm").value = "";
                    document.getElementById("hMetragem").value = "";
                    document.getElementById("hValor").value = "";
                    document.getElementById("hEstagio").value = "";
                }
                document.getElementById("hTipoImovel").value = p_ctl.innerHTML;
                strRegistra = "TipoImovel=" + document.getElementById("hTipoImovel").value.split('(')[0] + "&";
              } else {
                if (lTipo == "Dorms") {
                    if (document.getElementById("hDorm").value != p_ctl.innerHTML) {
                        document.getElementById("hMetragem").value = "";
                        document.getElementById("hValor").value = "";
                        document.getElementById("hEstagio").value = "";
                    }
                    document.getElementById("hDorm").value = p_ctl.innerHTML;
                     strRegistra = "Dorm=" + document.getElementById("hDorm").value.split('(')[0] + "&";
                } else {
                  if (lTipo == "Metragem") {
                      if (document.getElementById("hMetragem").value != p_ctl.innerHTML) {
                          document.getElementById("hValor").value = "";
                          document.getElementById("hEstagio").value = "";
                      }
                      document.getElementById("hMetragem").value = p_ctl.innerHTML;
                      strRegistra = "Metragem=" + document.getElementById("hMetragem").value.split('(')[0] + "&";
                  } else {
                    if (lTipo == "Valor") {
                        if (document.getElementById("hValor").value != p_ctl.innerHTML) {
                            document.getElementById("hEstagio").value = "";
                        }
                        document.getElementById("hValor").value = p_ctl.innerHTML;
                        strRegistra = "Valor=" + document.getElementById("hValor").value.split('(')[0] + "&";
                    } else {
                        document.getElementById("hEstagio").value = p_ctl.innerHTML;
                        strRegistra = "Estagio=" + document.getElementById("hEstagio").value.split('(')[0] + "&";
                    }                        
                  }    
                }
              }  
            }
          }              
        }
        RegistraBusca('Busca', strRegistra, 0);
        PageMethods.MontaResultadoAjax(document.getElementById("hCidade").value,
                                       document.getElementById("hBairro").value,
                                       document.getElementById("hTipoImovel").value,
                                       document.getElementById("hDorm").value,
                                       document.getElementById("hMetragem").value,
                                       document.getElementById("hValor").value,
                                       document.getElementById("hEstagio").value,
                                       document.getElementById("hOrdem").value,
                                       CargaResultadoFinalizada, null);
    } else {
      if ($get('hPorNome').value.toString().trim().length==0) {
          PageMethods.MontaResultadoAjax("São Paulo", "", "", "", "", "", "", "Preco", CargaResultadoFinalizada, null);
      } else {
        if ($get('hPorNome').value.toString().trim().indexOf("|")==-1) {
            PageMethods.MontaResultadoAjax("Nome like '%" + $get('hPorNome').value.toString().trim() + "%'", "", "", "", "", "", "", "Preco", CargaResultadoFinalizada, null);
        } else {
            PageMethods.MontaResultadoAjax($get('hPorNome').value.toString().trim(), "", "", "", "", "", "", "Preco", CargaResultadoFinalizada, null);
        }
      }
    }
    return true;
}
function CargaResultadoFinalizada(p_resultado, context) {
    $get('lQtde').innerHTML = p_resultado.split('|')[0];
    changeInnerHTML("MeioResultado", p_resultado.split('|')[1]);
    $get('ItensMenuBusca').disabled = false;
    PreencheMenu();
    return true;
}
function PreencheMenu() {
    if (document.getElementById("hCidade") == undefined) {
        PageMethods.MontaMenuAjax("São Paulo", "", "", "", "", "", "", CargaMenuFinalizada, null);
    } else {
        PageMethods.MontaMenuAjax(document.getElementById("hCidade").value,
                                  document.getElementById("hBairro").value,
                                  document.getElementById("hTipoImovel").value,
                                  document.getElementById("hDorm").value,
                                  document.getElementById("hMetragem").value,
                                  document.getElementById("hValor").value,
                                  document.getElementById("hEstagio").value,
                                  CargaMenuFinalizada, null);
    }
    return true;
}
function CargaMenuFinalizada(p_resultado, context) {
    changeInnerHTML("ItensMenuBusca", p_resultado);
}

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 MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.01
    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_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }

// Fun??o para abrir popup. Parametros:
// url = url da pagina a ser carregada no Popup
// janela = nome da janela
// larg = largura do popup em pixels
// alt = altura do popup em pixels
// scroll = para habilitar ou n?o o scroll no popup, valores: yes ou no
function abre(url,janela,larg,alt,scroll){
	if (!scroll) { scroll='auto' }
	window.open(url, janela, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + larg + ",height=" + alt);
	RegistraBusca(janela, url, 0);
}

function openAtendimento() {
    janela = "Atendimento";
    url = "PopUpChatHome.aspx";
    window.open(url, janela, 'width=650,height=450,scrollbars=no');
    //'http://www12.directtalk.com.br/server/directtalk_chatr.dll/user?S=I&id_s=2AB700776ECDA01433AE&origem=HotSite_VilaNovaLeopoldina'
    RegistraBusca(janela, url, 0);
}	

//Formata número tipo moeda usando o evento onKeyDown

function Formata(campo, tammax, teclapres, vdecimal) {
    var tecla = teclapres.keyCode;
    if (campo.value.indexOf(".") > -1) {
        campo.value = campo.value.replace(".", ",");
    }

    vr = Limpar(campo.value, "0123456789");

    tam = vr.length;
    dec = vdecimal;

    if (tam < tammax && tecla != 8) { tam = vr.length; }

    if (tecla == 8)
    { tam = tam - 1; }

    if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105) {

        if (tam <= dec)
        { campo.value = vr; }
        //alert("vr="+vr);
        if ((tam <= dec) && (tam == 0)) {
            campo.value = "0,00";
        } else if ((tam <= dec) && (tam == 1)) {
            campo.value = "0,0" + vr;
        } else if ((tam <= dec) && (tam == 2)) {
            campo.value = "0," + vr;
        }
        if ((tam > dec) && (tam <= 5)) {
            campo.value = vr.substr(0, tam - 2) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 6) && (tam <= 8)) {
            campo.value = vr.substr(0, tam - 5) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 9) && (tam <= 11)) {
            campo.value = vr.substr(0, tam - 8) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 12) && (tam <= 14)) {
            campo.value = vr.substr(0, tam - 11) + "." + vr.substr(tam - 11, 3) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 15) && (tam <= 17)) {
            campo.value = vr.substr(0, tam - 14) + "." + vr.substr(tam - 14, 3) + "." + vr.substr(tam - 11, 3) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - 2, tam);
        }
    }

}

function formatar_mascara(src, mascara) {
    //alert("formatar_mascara=" + src);
    var campo = src.value.length;
    var saida = mascara.substring(0, 1);
    var texto = mascara.substring(campo);
    if (texto.substring(0, 1) != saida) {
        src.value += texto.substring(0, 1);
    }
}
