<div class="modal-header">
   <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
   <h4 class="modal-title" id="myModalLabel">Orçamento: %%GLOBAL_Produton%%</h4>
   <script src="https://www.google.com/recaptcha/api.js?render=%%GLOBAL_SiteKey%%"></script>
</div>
<form class="contact_form" method="post" action="%%GLOBAL_ShopPath%%/remote.php?w=orcamento&products=%%GLOBAL_ProdutoIdn%%&id=%%GLOBAL_ProdutoIdn%%&acao=enviar">
  <div class="modal-body">
    <div class="form-group">
       <input type="text" class="form-control" id="nomede" placeholder="Nome" name="nomede">
       <input type="hidden" id="token" name="token">
    </div>
    <div class="form-group">
       <input type="text" class="form-control" id="emailde" placeholder="Email" name="emailde">
    </div>
    <div class="form-group">
       <input type="text" class="form-control" id="telefone" placeholder="Telefone" name="telefone">
    </div>
    <div class="form-group">
      <input type="text" class="form-control" id="emp" placeholder="Empresa" name="emp">
    </div>
    <div class="form-group">
     <input type="text" class="form-control" id="cid" placeholder="Cidade" name="cid">
    </div>
    <div class="form-group">
      <input type="text" class="form-control" id="qtd" placeholder="Quantidade" name="qtd">
    </div>
    <div class="form-group">
      <label for="exampleInputEmail1">Observações</label>
      <textarea rows="3" cols="30" class="form-control" name="obs" id=obs></textarea>
    </div>
    <div class="row">
       <div class="col-12">
          <div class="contact_msg" style="display: none"></div>
       </div>
    </div>
    <div class="col-12">
       <input type="submit" value="Perguntar" class="btn btn-success" name="post">
    </div>
  </div>
</form>

<script>
   (function ($) {
      'use strict';
      var form = $('.contact_form'),
      message = $('.contact_msg'),
      form_data;
      function done_func(response) {
        message.fadeIn()
        message.html(response);
        setTimeout(function () {
          message.fadeOut();
        }, 10000);
        form.find('input:not([type="submit"]), textarea').val('');
      }

      // fail function
      function fail_func(data) {
        message.fadeIn()
        message.html(data.responseText);
        setTimeout(function () {
          message.fadeOut();
        }, 10000);
      }

      form.submit(function (e) {
        e.preventDefault();
        form_data = $(this).serialize();
        $.ajax({
          type: 'POST',
          url: form.attr('action'),
          data: form_data
        })
        .done(done_func)
        .fail(fail_func);
      }); })(jQuery);
</script>
<script>
var interval = setInterval(function(){
  if(window.grecaptcha){
        grecaptcha.ready(function() {
       grecaptcha.execute('%%GLOBAL_SiteKey%%', {action: 'homepage'}).then(function(token) {
          // console.log(token);
          document.getElementById("token").value = token;
       });
       // refresh token every minute to prevent expiration
       setInterval(function(){
         grecaptcha.execute('%%GLOBAL_SiteKey%%', {action: 'homepage'}).then(function(token) {
           console.log( 'refreshed token:', token );
           document.getElementById("token").value = token;
         });
       }, 60000);

     });
    clearInterval(interval);
  }
}, 100);
</script>

