'use strict';

var extend = require('extend');
var domify = require('domify');

/**
 * Email repeat
 */
function EmailRepeat(element, config) {

  var options = {
    hintTemplate: require('./clientside-templates/email-hint.hogan')
  };

  extend(options, config);

  // Private variables
  var hintWrapper;
  var hint;

  /**
   * Set everything up
   */
  function create() {

    // Bail out if we don't have the proper element to act upon
    if (!element) {
      return;
    }

    hintWrapper = domify(options.hintTemplate.render());

    hint = hintWrapper.querySelector('.email-hint-value');

    element.addEventListener('change', updateHint);
    element.addEventListener('keyup', updateHint);
  }

  /**
   *
   */
  function updateHint() {

    // If the input field gets emptied out again, remove the hint
    if(element.value.length === 0) {
      hintWrapper.parentNode.removeChild(hintWrapper);
      return;
    }

    element.parentNode.insertBefore(hintWrapper, element.nextSibling);

    // Update the hint to match the input value
    hint.textContent = element.value;
  }

  /**
   * Tear everything down again
   */
  function destroy() {
    hintWrapper.parentNode.removeChild(hintWrapper);

    element.addEventListener('change', updateHint);
    element.addEventListener('keyup', updateHint);
  }

  var self = {
    create: create,
    destroy: destroy
  };

  return self;

}

module.exports = EmailRepeat;

@@ -741,24 +741,140 @@
 dateHint() %7B
+%0A    if(!hintWrapper.parentElement) %7B%0A      element.parentNode.insertBefore(hintWrapper, element.nextSibling);%0A    %7D
 %0A%0A    // If 
@@ -962,16 +962,45 @@
 th === 0
+ && hintWrapper.parentElement
 ) %7B%0A    
@@ -1075,80 +1075,8 @@
  %7D%0A%0A
-    element.parentNode.insertBefore(hintWrapper, element.nextSibling);%0A%0A
     
@@ -1225,24 +1225,62 @@
 destroy() %7B%0A
+    if(hintWrapper.parentElement) %7B%0A  
     hintWrap
@@ -1319,16 +1319,22 @@
 rapper);
+%0A    %7D
 %0A%0A    el

Fix email hint problems in IE8