var undefined;
var now = new Date();
var title;
if (window.encodeURI === undefined) {
   title = escape(document.title);
} else {
   title = window.encodeURI(document.title);
}
var imageUrl =
  "http://ping.nnselect.com/ping.gif" +
  "?d=" + now.getTime() +
  "&c=111" +
  "&u=" + escape(document.URL) +
  "&t=" + title;
if (document.images) {
  var image = new Image();
  image.src = imageUrl;
} else {
  document.write("<img src='" + imageUrl + "' height='1' width='1'>");
}


var THREE_YEARS_IN_MILLIS = (1000 * 60 * 60 * 24 * 365 * 3);

/* public */ function Cookie(name) {

  /* public */
  this.setCookie = setCookie;
  this.getCookie = getCookie;
  this.expireCookie = expireCookie;
  this.registerCallbackForWhenCookieExists = Cookie_registerCallbackForWhenCookieExists;

  /* private */
  this.m_name = name;
}

/* private */ function getExpirationDate(expireDate) {
  if (expireDate != null) {
    return expireDate;
  } else {
    return new Date(new Date().getTime() + THREE_YEARS_IN_MILLIS);
  }
}

/* private */ function getExpirationDateAsString(expireDate) {
  return getExpirationDate(expireDate).toGMTString();
}

/* public */ function setCookie(name, value, expireDate, domain) {
  var cookieDescription = name + "=" + escape(value);
  cookieDescription += "; path=/";
  cookieDescription += "; expires=" + getExpirationDateAsString(expireDate);
  if (domain != null) {
    cookieDescription += "; domain=" + escape(domain);
  }
  document.cookie = cookieDescription;
}

/* public */ function getCookie(name) {
  var key = name + "=";
  var startOfCookie = document.cookie.indexOf("; " + key);
  if (-1 != startOfCookie) {
    startOfCookie += 2;
  } else if (0 == document.cookie.indexOf(key)) {
    startOfCookie = 0;
  } else {
    return null;
  }
  var endOfCookie = document.cookie.indexOf(";", startOfCookie);
  if (endOfCookie == -1) {
    endOfCookie = document.cookie.length;
  }
  var value = document.cookie.substring(startOfCookie + key.length, endOfCookie);
  return unescape(value);
}

/* public */ function expireCookie(name, domain) {
  var expiredTime = new Date(new Date().getTime() - 1);
  setCookie(name, "", expiredTime, domain);
}

/* public */ function Cookie_registerCallbackForWhenCookieExists(callback) {
  waitForCookieFunctor = new WaitForCookieFunctor(this.m_name, callback);
  waitForCookieFunctor.execute();
}

/* private */ function WaitForCookieFunctor(cookieName, callback) {

  /* public */
  this.execute = WaitForCookieFunctor_execute;

  /* private */
  this.m_cookieName = cookieName;
  this.m_callback = callback;
}

/* private */ function WaitForCookieFunctor_execute() {
  waitForCookieFunctor = this;
  if (getCookie(this.m_cookieName) != null) {
    this.m_callback();
  } else {
    setTimeout("waitForCookieFunctor.execute()", 500);
  }
}


var DATE_THROTTLE_COOKIE_NAME = "nnselect";
var ONE_DAY_IN_MILLIS = 1000 * 60 * 60 * 24;

function DateThrottle() {
  // public
  this.shouldThrottle = DateThrottle_shouldThrottle;

  // private
  this.getOrCreate = DateThrottle_getOrCreate;
  this.getCookie = DateThrottle_getCookie;
  this.createCookie = DateThrottle_createCookie;
  this.updateCookie = DateThrottle_updateCookie;
  this.createCookieValue = DateThrottle_createCookieValue;
  this.getRandomNumberBetween = DateThrottle_getRandomNumberBetween;
  this.m_cookieName = DATE_THROTTLE_COOKIE_NAME;
}

function DateThrottle_shouldThrottle() {
  var cookieValue = parseInt(this.getOrCreate());
  var now = new Date().getTime();
  var dateToStartSurvey = cookieValue + (ONE_DAY_IN_MILLIS * 7);
  return (now < dateToStartSurvey);
}

function DateThrottle_getOrCreate() {
  var cookie = this.getCookie();
  if (cookie == null) {
    cookie = this.createCookie(); 
  }
  return cookie;
}

function DateThrottle_getCookie() {
  return getCookie(this.m_cookieName);
}

function DateThrottle_createCookie() {
  var now = new Date();
  var offset = ONE_DAY_IN_MILLIS * -8;
  var cookieValue = this.createCookieValue(now, offset);
  setCookie(this.m_cookieName, cookieValue);
  return cookieValue;
}

function DateThrottle_updateCookie() {
  var now = new Date();
  var cookieValue = this.createCookieValue(now, 0);
  setCookie(this.m_cookieName, cookieValue);
  return cookieValue;
}

function DateThrottle_createCookieValue(date, offset) {
  var cookieValue = date.getTime() + offset;
  return cookieValue.toString();
}

function DateThrottle_getRandomNumberBetween(min, max) {
  var range = max - min;
  var number = Math.round(Math.random() * range) + min;
  return number;
}

var dateThrottle = new DateThrottle();
if (!dateThrottle.shouldThrottle()) {
  dateThrottle.updateCookie();
  document.write("<iframe src='http://survey.nnselect.com/survey/is_panelist_111.html' name='nn_frame' height='0' width='0' scrolling='no' frameborder='0' marginWidth='0' marginHeight='0'></iframe>");
}

