var message = 'This website uses cookies to identify users, improve the user experience and requires cookies to work. By continuing to use this website, you consent to Columbia University\'s use of cookies and similar technologies, in accordance with the <a href="https://cuit.columbia.edu/content/columbia-university-website-cookie-notice">Columbia University Website Cookie Notice</a>.';

var icon = '<div id="cu-privacy-notice-icon"></div>';

function cuPivacyNoticeGetCookie() {
  var name = "cuPivacyNotice";
  var output = document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)');
  return output ? output.pop() : '';
}

function cuPivacyNoticeSetCookie(days) {
  var d = new Date();
  d.setTime(d.getTime() + (days*24*60*60*1000));
  var expires = "expires="+ d.toUTCString();
  document.cookie = "cuPivacyNotice=1;" + expires + ";path=/";
}

function cuPivacyNoticeClose() {
  document.getElementById("cu-privacy-notice").setAttribute("class", "dismissed");
  setTimeout(function() {
    document.getElementById("cu-privacy-notice").remove();
  }, 400);

  cuPivacyNoticeSetCookie(30); // (production) 30 days
  // cuPivacyNoticeSetCookie(0.000231481); // (dev) 20 seconds
}

function cuPivacyNoticeScroll(e) {
  if (window.scrollY > 20) {
    cuPivacyNoticeClose();
    if (window.removeEventListener) {
      window.removeEventListener('scroll', cuPivacyNoticeScroll, false);
    }
    else if (window.detachEvent) {
      window.detachEvent('onscroll', cuPivacyNoticeScroll);
    }
  }
}

var cookie = cuPivacyNoticeGetCookie();

if (!cookie) {
  document.writeln('<div id="cu-privacy-notice"><button class="cu-privacy-notice-close" onClick="cuPivacyNoticeClose()"><span class="sr-only">Close</span>' + icon + '</button>' + message + '</div>');

  setTimeout(function() {
    if (window.addEventListener) {
      window.addEventListener('scroll', cuPivacyNoticeScroll, false);
    }
    else if (window.attachEvent) {
      window.attachEvent('onscroll', cuPivacyNoticeScroll);
    }
  }, 1000);
}
