function Abrir(url,h,w)
   {
   window.open(url,'Janela','height='+h+',width='+w+',scrollbars=yes,resizable=no,top=10,left=5');
   }

  function alertAR(msg){
           //exibe as msg de alerta personalizadas
           alert(msg+'\n_____________________________________________\nPaesi Adm.de Imóveis Ltda');
  }

  function abre_convite(conv){
           url= "site/aniversarios/imprime.php?conv="+conv;
           window.open(url,'convite','width=500,height=500,menubar=yes,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=5,left=5');
  }

  function limpa_busca(){
           document.formbusca.busca.value= "";
  }

  function FormataCPF(Campo, teclapres){
        var tecla = teclapres.keyCode;
        var vr    = new String(Campo.value);
        vr        = vr.replace(".", "");
        vr        = vr.replace(".", "");
        vr        = vr.replace("-", "");
        tam       = vr.length + 1;
        if (tecla != 9 && tecla != 8){
                if (tam > 3 && tam < 7)
                        Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
                if (tam >= 7 && tam <10)
                        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
                if (tam >= 10 && tam < 12)
                        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
                }
  }

  function FormataCEP(campo, teclapres){
           var tecla = teclapres.keyCode;
           var vr    = new String(campo.value);
           vr        = vr.replace("-", "");
           vr        = vr.replace("-", "");
           tam       = vr.length + 1;
           if (tecla != 9 && tecla != 8){
               if (tam > 5 && tam < 7){
                   campo.value = vr.substr(0, 6) + '-' + vr.substr(6, tam);
               }
           }
  }

  function FormataCNPJ(Campo, teclapres){
        var tecla = teclapres.keyCode;
        var vr    = new String(Campo.value);
        vr        = vr.replace(".", "");
        vr        = vr.replace(".", "");
        vr        = vr.replace("/", "");
        vr        = vr.replace("-", "");
        tam       = vr.length + 1 ;


        if (tecla != 9 && tecla != 8){
                if (tam > 2 && tam < 6)
                        Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
                if (tam >= 6 && tam < 9)
                        Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
                if (tam >= 9 && tam < 13)
                        Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
                if (tam >= 13 && tam < 15)
                        Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
                }
  }

 function FormataTELEFONE(campo, teclapres){
           //var tecla = teclapres.keyCode;
           var vr = new String(campo.value);
           vr = vr.replace("-", "");
           vr = vr.replace("-", "");
           tam = vr.length;
           if(tam >3 && tam <= 7){
              ini= vr.substring(0,3);
              fim= vr.substring(3,7);
              campo.value = ini+'-'+fim;
           }else{
                 if(tam >= 8){
                    ini= vr.substring(0,4);
                    fim= vr.substring(4,8);
                    campo.value = ini+'-'+fim;
                 }
           }
  }

 function FormataData(Campo, teclapres){
        var tecla = teclapres.keyCode;
        var vr = new String(Campo.value);
        vr = vr.replace("/", "");
        vr = vr.replace("/", "");
        tam = vr.length + 1;

        if (tecla != 9 && tecla != 8){
                if (tam > 2 && tam < 5)
                        Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
                if (tam >= 5 && tam <=10)
                        Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
        }
  }

  function FormataValor(objeto,teclapres,tammax,decimais){
        var tecla = teclapres.keyCode;
        var tamanhoObjeto = objeto.value.length;

        if((tecla == 8)&&(tamanhoObjeto == tammax)){
                tamanhoObjeto = tamanhoObjeto - 1 ;
        }
        if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax)){
                vr        = objeto.value;
                vr        = vr.replace( "/", "" );
                vr        = vr.replace( "/", "" );
                vr        = vr.replace( ",", "" );
                vr        = vr.replace( ".", "" );
                vr        = vr.replace( ".", "" );
                vr        = vr.replace( ".", "" );
                vr        = vr.replace( ".", "" );
                tam        = vr.length;
                if (tam < tammax && tecla != 8){
                        tam = vr.length + 1 ;
                }
                if ((tecla == 8) && (tam > 1)){
                        tam = tam - 1 ;
                        vr = objeto.value;
                        vr = vr.replace( "/", "" );
                        vr = vr.replace( "/", "" );
                        vr = vr.replace( ",", "" );
                        vr = vr.replace( ".", "" );
                        vr = vr.replace( ".", "" );
                        vr = vr.replace( ".", "" );
                        vr = vr.replace( ".", "" );
                }
                //Cálculo para casas decimais setadas por parametro
                if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
                        if (decimais > 0){
                                if ( (tam <= decimais) ){
                                        objeto.value = ("0," + vr) ;
                                }
                                if( (tam == (decimais + 1)) && (tecla == 8)){
                                        objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;
                                }
                                if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0")){
                                        objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
                                }
                                if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0")){
                                    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                 if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                        }else if(decimais == 0){
                                if ( tam <= 3 ){
                                         objeto.value = vr ;
                                }
                                if ( (tam >= 4) && (tam <= 6) ){
                                        if(tecla == 8)
                                        {
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 );
                                }
                                if ( (tam >= 7) && (tam <= 9) ){
                                        if(tecla == 8)
                                        {
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 );
                                }
                                if ( (tam >= 10) && (tam <= 12) ){
                                         if(tecla == 8)
                                        {
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 );
                                }
                                if ( (tam >= 13) && (tam <= 15) ){
                                        if(tecla == 8){
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
                                }
                        }
                }
        }else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)){
                        window.event.cancelBubble = true;
                        window.event.returnValue = false;
                }
  }

 function PopUp_Mensagem(url,url2){
               window.open(url2,'janela','width=800,heigth=800,menubar=yes,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=5,left=5')
               window.open(url,'Print','width=490,height=410,menubar=no,scrollbars=no,toolbar=no,location=no,resizable=yes,directories=no,top=5,left=5');


 }

 function PopUp_Nova(url){
               window.open(url,'janela','width=800,heigth=800,menubar=yes,scrollbars=yes,toolbar=yes,location=yes,directories=no,resizable=yes,top=5,left=5')
 }

 function PopUp_Foto(url,width,height){
               window.open(url,'janela','width='+width+',height='+height+',menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=5,left=5')
 }

 function PopUp_PDF(url){
               
               window.open(url,'janela','width=800,height=600,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=yes,top=5,left=5')
 }

 function Mostra_Foto(){
           document.getElementById("Foto").src="site/locacao/exibefoto.php?Cod_Foto="+document.exibefoto.Cod_Foto.value+"&IDImovel="+document.exibefoto.IDImovel.value;
 }

 function FormataValor(objeto,teclapres,tammax,decimais){
        var tecla = teclapres.keyCode;
        var tamanhoObjeto = objeto.value.length;

        if((tecla == 8)&&(tamanhoObjeto == tammax)){
                tamanhoObjeto = tamanhoObjeto - 1 ;
        }
        if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax)){
                vr        = objeto.value;
                vr        = vr.replace( "/", "" );
                vr        = vr.replace( "/", "" );
                vr        = vr.replace( ",", "" );
                vr        = vr.replace( ".", "" );
                vr        = vr.replace( ".", "" );
                vr        = vr.replace( ".", "" );
                vr        = vr.replace( ".", "" );
                tam        = vr.length;
                if (tam < tammax && tecla != 8){
                        tam = vr.length + 1 ;
                }
                if ((tecla == 8) && (tam > 1)){
                        tam = tam - 1 ;
                        vr = objeto.value;
                        vr = vr.replace( "/", "" );
                        vr = vr.replace( "/", "" );
                        vr = vr.replace( ",", "" );
                        vr = vr.replace( ".", "" );
                        vr = vr.replace( ".", "" );
                        vr = vr.replace( ".", "" );
                        vr = vr.replace( ".", "" );
                }
                //Cálculo para casas decimais setadas por parametro
                if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
                        if (decimais > 0){
                                if ( (tam <= decimais) ){
                                        objeto.value = ("0," + vr) ;
                                }
                                if( (tam == (decimais + 1)) && (tecla == 8)){
                                        objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;
                                }
                                if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0")){
                                        objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
                                }
                                if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0")){
                                    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                 if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                                if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) ){
                                         objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
                                }
                        }else if(decimais == 0){
                                if ( tam <= 3 ){
                                         objeto.value = vr ;
                                }
                                if ( (tam >= 4) && (tam <= 6) ){
                                        if(tecla == 8)
                                        {
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 );
                                }
                                if ( (tam >= 7) && (tam <= 9) ){
                                        if(tecla == 8)
                                        {
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 );
                                }
                                if ( (tam >= 10) && (tam <= 12) ){
                                         if(tecla == 8)
                                        {
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 );
                                }
                                if ( (tam >= 13) && (tam <= 15) ){
                                        if(tecla == 8){
                                                objeto.value = vr.substr(0, tam);
                                                window.event.cancelBubble = true;
                                                window.event.returnValue = false;
                                        }
                                        objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
                                }
                        }
                }
        }else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)){
                        window.event.cancelBubble = true;
                        window.event.returnValue = false;
                }
  }

  /*
    mostra e cculta o faq
    recebe o iddiv - id do div
  */
  function mostra_oculta_faq(iddiv){
           var div= document.getElementById(iddiv);
           if(div){
              if(div.style.display == 'none' || !div.style.display){
                 div.style.display = 'block';
              }else{
                    div.style.display = 'none';
              }
           }

  }

  function PopUp_Imprime(url){
               window.open(url,'janela','width=800,heigth=800,menubar=yes,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=5,left=5')

 }

  function imprime_formulario(url){
           window.open(url,'janela','width=790,heigth=550,menubar=yes,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=5,left=5')
           document.form.target = 'janela';
           document.form.action = url;
           document.form.submit();

  }

  function envia_formulario(url){

           document.form.action = url;
           document.form.submit();

  }

   function FormataCPF(Campo, teclapres){
        var tecla = teclapres.keyCode;
        var vr    = new String(Campo.value);
        vr        = vr.replace(".", "");
        vr        = vr.replace(".", "");
        vr        = vr.replace("-", "");
        tam       = vr.length + 1;
        if (tecla != 9 && tecla != 8){
                if (tam > 3 && tam < 7)
                        Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
                if (tam >= 7 && tam <10)
                        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
                if (tam >= 10 && tam < 12)
                        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
                }
  }

  function FormataCEP(campo, teclapres){
           var tecla = teclapres.keyCode;
           var vr    = new String(campo.value);
           vr        = vr.replace("-", "");
           vr        = vr.replace("-", "");
           tam       = vr.length + 1;
           if (tecla != 9 && tecla != 8){
               if (tam > 5 && tam < 7){
                   campo.value = vr.substr(0, 6) + '-' + vr.substr(6, tam);
               }
           }
  }

   function FormataFone(campo, teclapres){
           var tecla = teclapres.keyCode;
           var vr    = new String(campo.value);
           vr        = vr.replace("-", "");
           vr        = vr.replace("-", "");
           tam       = vr.length + 1;
           if (tecla != 9 && tecla != 8){
               if (tam > 0 && tam < 2){
                   campo.value = vr.substr(0, 1) + '(' + vr.substr(1, tam);
               }
               if (tam > 3 && tam < 5){
                   campo.value = vr.substr(0, 4) + ')' + vr.substr(4, tam);
               }
               if (tam > 8 && tam < 10){
                   campo.value = vr.substr(0, 9) + '-' + vr.substr(9, tam);
               }
           }
  }


  function FormataData(Campo, teclapres){
        var tecla = teclapres.keyCode;
        var vr = new String(Campo.value);
        vr = vr.replace("/", "");
        vr = vr.replace("/", "");
        tam = vr.length + 1;

        if (tecla != 9 && tecla != 8){
                if (tam > 2 && tam < 5)
                        Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
                if (tam >= 5 && tam <=10)
                        Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
        }
  }

  function busca_bairros(){
           cod_regiao= document.forms['busca'].all['Zona'].value;
           if(cod_regiao == '*0'){
           }else{
           window.open('site/locacao/bairros.php?op='+cod_regiao,"Bairros", 'height=480,width=310,scrollbar=yes');
                  }
  }

  function abre_bairros(cod_regiao){
           window.open('site/locacao/bairros.php?op='+cod_regiao,"Bairros", 'height=480,width=310,scrollbar=yes');

  }


   function valida_botao(bairros){
   var div= document.getElementById(bairros);
           cod_regiao= document.forms['busca'].all['Zona'].value;
           if(cod_regiao == '*0'){

               if(div.style.display == 'none' || !div.style.display){
                  div.style.display = 'block';
               }else{
                     div.style.display = 'none';
               }

           }else{
              div.style.display = 'block';
           }

}

    function enquete(cod){
               var div= document.getElementById('enquete');
               var div2= document.getElementById('fundo');

               div.style.display = 'none';
               div2.style.display = 'none';


    }

    function mudacor(num){
            var tr  = document.getElementById('produto_'+num);
            var item= document.getElementById('iditem['+num+']');
            if(item.checked == true){
               tr.style.background= "#000000";
            }
   }

   function envia_orcamento(formulario,url){
            document.formulario.action= url;
            document.formulario.submit();

   }

   function janela_detalhes(url){
           window.open(url,'janela','width=550,height=400,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=5,left=5');
   }

   function abreMapa(url){
           window.open(url,'janela','width=437,height=389,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=5,left=5');
   }
   
   function blur_codigo(){
           codText = document.getElementById('codigo');
           codRadi = document.getElementById('tipocodigo');
           strText = document.getElementById('produto');
           strRadi = document.getElementById('tipostring');
           strSel1 = document.getElementById('marca');
           strSeli = document.getElementById('tipo');
           
           if(codText.blur == true){
                   codRadi.checked = true;
           }else{
                   codRadi.checked = false;
           }
   }
   
   function visualizaFotosEvento(janelaPath){
        window.open(janelaPath,'fotosEventos','width=520,height=500,alwaysRaised=yes,dependent=yes,location=no,menubar=no,resizable=no,status=no,toolbar=no,scrollbars');
   }
   
   function limpaCamposBusca(idCampo){
        campo1 = document.getElementById('1');
        campo2 = document.getElementById('2');
        campo3 = document.getElementById('3');
        campo4 = document.getElementById('4');
        
        switch(idCampo){
             case 1:
                  campo2.value = '';
                  campo3.value = '';
                  campo4.value = '';
                  break;
             case 2:
                  campo1.value = '';
                  campo3.value = '';
                  campo4.value = '';
                  break;
             case 3:
                  campo2.value = '';
                  campo1.value = '';
                  campo4.value = '';
                  break;
             case 4:
                  campo2.value = '';
                  campo3.value = '';
                  campo1.value = '';
                  break;
        }
   }