//= require govuk/multivariate-test

var UkviABTest = UkviABTest || {};

UkviABTest.isSection = function(pathname) {
  return window.location.pathname === pathname;
}

UkviABTest.AddtoApplySection = function() {
  var html = "<p>You can <a " +
   "href='https://visas-immigration.service.gov.uk/product/eea-qp'>apply online "+
   "as a qualified person</a> but not if you’re a student or self-sufficient "+
    "person and you're either:"+
  "<ul>"+
    "<li>reliant on a family member for financial support</li>"+
    "<li>financially responsible for any other family members</li>"+
  "</ul></p>";

  $(html).insertBefore('h2:contains("Apply as a ‘family member’")');
}

UkviABTest.AddtoPermanentResidenceSection = function() {
  var html = "<p>If you're from the EEA, you can also <a "+
   "href='https://visas-immigration.service.gov.uk/product/eea-pr'>apply "+
    "online</a> but not if you’re a student or self-sufficient person and "+
    "you're either: "+
  "<ul>"+
    "<li>reliant on a family member for financial support</li>"+
    "<li>financially responsible for any other family members</li>"+
  "</ul></p>";

  $(html).insertBefore('h3:contains("Supporting documents")');
}

$(function(){
  if(UkviABTest.isSection("/eea-registration-certificate/apply")) {
    new GOVUK.MultivariateTest({
      name: 'ukvi_apply-201609',
      customDimensionIndex: 13,
      cohorts: {
        original: { callback: function() {}, weight: 90},
        applyTextAndLink: { callback: UkviABTest.AddtoApplySection, weight: 10}
      }
    });
  }

  if(UkviABTest.isSection("/eea-registration-certificate/permanent-residence")) {
    new GOVUK.MultivariateTest({
      name: 'ukvi_permResidence-201609',
      customDimensionIndex: 13,
      cohorts: {
        original: { callback: function() {}, weight: 90},
        applyTextAndLink: { callback: UkviABTest.AddtoPermanentResidenceSection, weight: 10}
      }
    });
  }
});

@@ -430,16 +430,20 @@
  either:
+%3C/p%3E
 %22+%0A  %22%3Cu
@@ -581,36 +581,32 @@
 %3C/li%3E%22+%0A  %22%3C/ul%3E
-%3C/p%3E
 %22;%0A%0A  $(html).in
@@ -954,17 +954,20 @@
  either:
- 
+%3C/p%3E
 %22+%0A  %22%3Cu
@@ -1113,20 +1113,16 @@
   %22%3C/ul%3E
-%3C/p%3E
 %22;%0A%0A  $(

Fix paragraph wrapping unordered list