<!DOCTYPE html>
<html lang="en">
<head>
  {% include '/common/meta_tags.html' %}
  <meta name="theme-color" content="#e90000">
  <title>{{title}}</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,300italic,700italic">
  <link rel="stylesheet" href="{{image_path}}/assets/main.min.css">
  <link rel="stylesheet" href="{{image_path}}/assets/survey.min.css">
</head>
<body>
  <header>
    <div class="logo">
      <img src="{{image_path}}/assets/icon.min.svg" width="33.3281" height="" draggable="false">
      <div class="name">
        <span class="domain">{{site_name}}</span>
        <span class="extension">.com</span>
      </div>
    </div>
    <h1>Find the Credit Card <span class="emphasis">that's Right for You!</span></h1>
  </header>
  <section class="content">
    <div class="wrapper">
      <div class="box profile" data-copyright="{{domain_name}} &copy; {{year}}, All Rights Reserved">
        <div class="survey--status">Survey Status</div>
        <div class="survey--progress-wrapper">
          <div class="survey--progress-bar" style="width: 14.2857%;"></div>
        </div>
        <div class="page" data-id="0" style="display: block;"></div>
      </div>
    </div>
  </section>
  {% include '/common/htmlshiv.html' %}
  <script>
    function showPage(page_id) {
      var current_page = document.querySelector('.page[style="display: block;"]');
      var new_page = document.querySelector('.page[data-id="' + (page_id || 1) + '"]');
      current_page.style.display = 'none';
      new_page.style.display = 'block';
    }
    
    function trackCoreg(coregArray){
    	fetch('/?action=ajaxsubmit&id={{id}}',{
      	  method: 'POST',
      	  headers: {
      	    'Accept': 'application/json',
      	    'Content-Type': 'application/x-www-form-urlencoded'
      	  },
      	  body: "coregs="+coregArray.join(",")
      }).then(function(response) {
        return response.json();
      }).then(function(data) {
    	  console.log(data);
    	  if(data.redirect){
    		window.location = "/?id=" + data.next;	  
		}
        var fragment = document.createDocumentFragment();
        var div = document.createElement('div');
        div.innerHTML = data.html;
        fragment.appendChild(div.children[0]);
        var current_page = document.querySelector('.page[style="display: block;"]');
        current_page.parentElement.insertBefore(fragment, current_page.nextSibling);
        showPage(data.next);
      });
    }
    document.addEventListener('DOMContentLoaded', function(){ 
    	trackCoreg([]);
    }, false);
  </script>
</body>
</html>
