{% if (registry.has('theme_options') == constant('true')) %} 
  {% set theme_options = registry.get('theme_options') %}
  {% set config = registry.get('config') %} 

  <div id="popup-{{ module_id }}" class="popup {% if (not ajax) %} {{ 'mfp-hide' }} {% endif %}" style="{% if (content_width > 100) %} {{ 'max-width: ' ~ content_width ~ 'px;' }} {% endif %} {% if (background_color != '') %} {{ 'background-color: ' ~ background_color ~ ';' }} {% endif %} {% if (background_image != '') %} {{ 'background-image: url(image/' ~ background_image ~ ');background-position: ' ~ background_image_position ~ ';background-repeat: ' ~ background_image_repeat ~ ';' }} {% endif %}">
       
           {% if (type == 1) %}
           {% if (newsletter_popup_title != '') %} {{ '<h4>' ~ newsletter_popup_title ~ '</h4>' }}{% endif %}
           {{ '<div class="content">' ~ newsletter_popup_text ~ '</div>' }}
           {{ '<div class="newsletter">' }}
           {{ ' <input type="text" class="email" placeholder="' ~ newsletter_input_placeholder ~ '" />' }}
           {{ ' <a class="button subscribe">' ~ newsletter_subscribe_button_text ~ '</a>' }}
           {{ '</div>' }} 
                         
                {% if (theme_options.get( 'rodo_status' ) == '1') %} 
                  <div style="padding: 15px 0px 0px 0px">
                    <form id="agree_rodo_form">
                      <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' ) )) }} 
                      <input type="submit" class="submit hidden" value="Submit">
                    </form>
                  </div>
                {% endif %} 
            
                 <script type="text/javascript">
                 $(document).ready(function() {
                  function Subscribe() {
                    {% if (theme_options.get( 'rodo_status' ) == '1') %} 
                    if($('input[name="agree_rodo"]').is(':checked')) {
                    {% endif %} 
                    $.post('{{ subscribe_url }}', 
                      { 
                        email: $('#popup-{{ module_id }} .email').val() 
                      }, function (e) {
                        if(e.error === 1) {
                          var r = confirm(e.message);
                          if (r == true) {
                              $.post('{{ unsubscribe_url }}', { 
                                email: $('#popup-{{ module_id }} .email').val() 
                              }, function (e) {
                                $('#popup-{{ module_id }} .email').val('');
                                alert(e.message);
                              }, 'json');
                          }
                      } else if(e.error === 0) {
                        $('#popup-{{ module_id }} .email').val('');
                        alert(e.message);
                        $.magnificPopup.close();
                        } else {
                          $('#popup-{{ module_id }} .email').val('');
                          alert(e.message);
                        }
                      }
                    , 'json');
                    {% if (theme_options.get( 'rodo_status' ) == '1') %} 
                    } else {
                      $('#agree_rodo_form .submit').click();
                    }
                    {% endif %} 
                  }
                  
                  $('#popup-{{ module_id }} .subscribe').click(Subscribe);
                  $('#popup-{{ module_id }} .email').keypress(function (e) {
                      if (e.which == 13) {
                          Subscribe();
                      }
                  });
                 });
                 </script>     
            {% elseif (type == 2) %}
             {% if (custom_popup_title != '') %} {{ '<h4>' ~ custom_popup_title ~ '</h4>' }}{% endif %}
             {{ '<div class="content">' ~ custom_popup_text ~ '</div>' }}
             {% else %} 
             {% if (contact_form_popup_title != '') %} {{ '<h4>' ~ contact_form_popup_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">* {{ 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">* {{ 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">* {{ 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-{{ module_id }} #input-name').val().length < 3 || $('#popup-{{ module_id }} #input-name').val().length > 32){
                                $('#popup-{{ module_id }} #input-name').addClass("error");
                                valid = false;
                           } else {
                                $('#popup-{{ module_id }} #input-name').removeClass("error");
       
                           }
                           
                           if(IsEmail($('#popup-{{ module_id }} #input-email').val())) {
                                $('#popup-{{ module_id }} #input-email').removeClass("error");
                           } else {
                                $('#popup-{{ module_id }} #input-email').addClass("error");
                                valid = false;
                           }
                           
                           if($('#popup-{{ module_id }} #input-enquiry').val().length < 10 || $('#popup-{{ module_id }} #input-enquiry').val().length > 3000){
                                $('#popup-{{ module_id }} #input-enquiry').addClass("error");
                                valid = false;
                           } else {
                                $('#popup-{{ module_id }} #input-enquiry').removeClass("error");
                           }
                           
                           if(valid) {
                                $.ajax({
                                       type: "POST",
                                       url: "{{ contact_url }}",
                                       data: $("#popup-{{ 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>
        
            {% endif %}
   
       
       {% if (display_text_dont_show_again == 0 and not ajax) %} 
       <div class="dont-show-label">
           <label>
               <input type="checkbox" class="dont-show-me" />
               <span>{{ text_dont_show_again }}</span>
           </label>
       </div>
       {% endif %} 
       
       {% if (display_buttons_yes_no == 0 and not ajax) %} {{ '<div class="buttons-yes-no"><a href="http://google.com" class="button btn-default">' ~ no ~ '</a><a href="#" class="popup-modal-dismiss button">' ~ yes ~ '</a></div>' }} {% endif %} 
  </div>

  {% if (not ajax) %} 
  <script type="text/javascript">
  $(document).ready(function() {

    {% if (disable_on_desktop == 0) %} 
    if($(window).width() > 992) {
    {% endif %} 

       {% if (display_text_dont_show_again == 0 or show_only_once == 0) %} 
       $('#popup-{{ module_id }} .dont-show-me').change(function () {
            if ($(this).is(':checked')) {
                 localStorage.setItem('popup-module-{{ module_id }}', 'yes');
            } else {
                 localStorage.setItem('popup-module-{{ module_id }}', 'no');
            }
       });
       
       if (localStorage.getItem('popup-module-{{ module_id }}') != 'yes') {
            {% if (show_only_once == 0) %} 
            localStorage.setItem('popup-module-{{ module_id }}', 'yes');
            {% endif %} 
       {% endif %} 

            var show_after = parseInt('{{ show_after }}', 20);
            var autoclose_after = parseInt('{{ autoclose_after }}', 20);
            setTimeout(function () {
              $.magnificPopup.open({
                  items: {
                      src: '#popup-{{ module_id }}',
                      type: 'inline'
                  },
                  tLoading: '',
                  mainClass: 'popup-module mfp-with-zoom popup-type-{{ type }}',
                  removalDelay: 200,
                  {% if (display_buttons_yes_no == 0) %} {{ 'modal: true' }} {% endif %} 
              });
       
              if (autoclose_after > 0) {
                  setTimeout(function () {
                      $.magnificPopup.close();
                  }, autoclose_after);
              }
            }, show_after);
            
            {% if (display_buttons_yes_no == 0) %} 
            $(document).on('click', '.popup-modal-dismiss', function (e) {
                 e.preventDefault();
                 $.magnificPopup.close();
            });
            {% endif %} 
       
       {% if (display_text_dont_show_again == 0 or show_only_once == 0) %} 
       }
       {% endif %} 

    {% if (disable_on_desktop == 0) %} 
    }
    {% endif %} 

  });
  </script>
  {% endif %}
{% endif %}