{% if (registry.has('theme_options') == constant('true')) %} 
  {% set theme_options = registry.get('theme_options') %}
  {% set config = registry.get('config') %} 
  <div class="clearfix"></div>
  <a class="button btn-default button-product-question">
       {% if (icon != '' and icon_position == 'left') %} {{ '<img src="image/' ~ icon~ '" align="left" class="icon-enquiry" alt="Icon">' }} {% endif %} 
       <span class="text-enquiry">{{ button_text }}</span>
       {% if (icon != '' and icon_position == 'right') %} {{ '<img src="image/' ~ icon~ '" align="right" class="icon-enquiry" alt="Icon">' }} {% endif %} 
  </a>

  <div id="popup-product-question-{{ module_id }}" class="popup mfp-hide">
       

   {% if (block_title != '') %} {{ '<h4>' ~ block_title ~ '</h4>' }}{% endif %} 
          <form action="" method="post" enctype="multipart/form-data" id="contact" class="form-contact">
               {% if (product_id is defined) %} 
               <input type="hidden" name="product_id" value="{{ product_id }}" />
               {% elseif (url is defined) %} 
               <input type="hidden" name="url" value="{{ url }}" />
               {% endif %} 

               <fieldset>
                 <div class="contact-label">
                   <label for="input-name" class="required"> {{ entry_name }}</label>
                   <div>
                     <input type="text" name="name" value="" id="input-name" class="form-control" />
                   </div>
                 </div>
                 <div class="contact-label">
                   <label for="input-email" class="required"> {{ entry_email }}</label>
                   <div>
                     <input type="text" name="email" value="" id="input-email" class="form-control" />
                   </div>
                 </div>
                 <div class="contact-label">
                   <label for="input-enquiry" class="required"> {{ entry_enquiry }}</label>
                   <div>
                     <textarea name="enquiry" rows="7" id="input-enquiry" class="form-control"></textarea>
                   </div>
                 </div>
               </fieldset>
               
        {% if (theme_options.get( 'rodo_status' ) == '1') %} 
          <div style="padding: 10px 0px 7px 0px"><input type="checkbox" name="agree_rodo" value="1" required="required">&nbsp;{{ theme_options.html_entity_decode(theme_options.get( 'rodo_text', config.get( 'config_language_id' ) )) }}</div>
        {% endif %} 

              <input class="btn btn-primary" type="submit" value="{{ button_submit }}" />
          </form>

          <script type="text/javascript">
               function IsEmail(email) {
                    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                    return regex.test(email);
               }

               $('#contact').bind('submit', function(){
                    var valid = true;
                  
                    if($('#popup-product-question-{{ module_id }} #input-name').val().length < 3 || $('#popup-product-question-{{ module_id }} #input-name').val().length > 32){
                         $('#popup-product-question-{{ module_id }} #input-name').addClass("error");
                         valid = false;
                    } else {
                         $('#popup-product-question-{{ module_id }} #input-name').removeClass("error");

                    }

                    if(IsEmail($('#popup-product-question-{{ module_id }} #input-email').val())) {
                         $('#popup-product-question-{{ module_id }} #input-email').removeClass("error");
                    } else {
                         $('#popup-product-question-{{ module_id }} #input-email').addClass("error");
                         valid = false;
                    }
                   

                    if($('#popup-product-question-{{ module_id }} #input-enquiry').val().length < 10 || $('#popup-product-question-{{ module_id }} #input-enquiry').val().length > 3000){
                         $('#popup-product-question-{{ module_id }} #input-enquiry').addClass("error");
                         valid = false;
                    } else {
                         $('#popup-product-question-{{ module_id }} #input-enquiry').removeClass("error");
                    }

                    if(valid) {
                         $.ajax({
                                type: "POST",
                                url: "{{ contact_url }}",
                                data: $("#popup-product-question-{{ module_id }} #contact").serialize(), // serializes the form's elements.
                                success: function(data)
                                {
                                    alert(data); // show response from the php script.
                                    $.magnificPopup.close();
                                }
                              });

                         return false;
                    } else {
                         return false;
                    }
               });
          </script>

  </div>

  <script>
      $(function(){
          $('.button-product-question').click(function(e){
              $.magnificPopup.open({
                  items: {
                      src: '#popup-product-question-{{ module_id }}',
                      type: 'inline'
                  },
                  tLoading: '',
                  mainClass: 'popup-module mfp-with-zoom',
                  removalDelay: 200,
              });
              
              return false;
              
          })
      })
  </script>
{% endif %}