//   document: The Document object that the cookie is stored for. Required.
//   name:     A string that specifies a name for the cookie. Required.
//   hours:    An optional number that specifies the number of hours from now
//             that the cookie should expire.
//   path:     An optional string that specifies the cookie path attribute.
//   domain:   An optional string that specifies the cookie domain attribute.
//   secure:   An optional Boolean value that, if true, requests a secure cookie.

function Cookie(document, name, hours, path, domain, secure)
{
  this.$document = document;
  this.$name = name;
  if (hours)
    this.$expiration = new Date((new Date()).getTime() + hours*3600000);
  else this.$expiration = null;
  if (path) this.$path = path; else this.$path = null;
  if (domain) this.$domain = domain; else this.$domain = null;
  if (secure) this.$secure = true; else this.$secure = false;
}


function _Cookie_store()
{
  var cookieval = "";
  for(var prop in this) {
    if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
      continue;
    if (cookieval != "") cookieval += '&';
      cookieval += prop + ':' + escape(this[prop]);
}

  var cookie = this.$name + '=' + cookieval;
  if (this.$expiration)
    cookie += '; expires=' + this.$expiration.toGMTString();
  if (this.$path) cookie += '; path=' + this.$path;
  if (this.$domain) cookie += '; domain=' + this.$domain;
  if (this.$secure) cookie += '; secure';

  this.$document.cookie = cookie;
}

function _Cookie_load()
{
  var allcookies = this.$document.cookie;
  if (allcookies == "") return false;

  var start = allcookies.indexOf(this.$name + '=');
  if (start == -1) return false;
    start += this.$name.length + 1;
  var end = allcookies.indexOf(';', start);
  if (end == -1) end = allcookies.length;
  var cookieval = allcookies.substring(start, end);

  var a = cookieval.split('&');
  for(var i=0; i < a.length; i++)
    a[i] = a[i].split(':');

  for(var i = 0; i < a.length; i++) {
    this[a[i][0]] = unescape(a[i][1]);
  }

  return true;
}

function _Cookie_remove()
{
  var cookie;
  cookie = this.$name + '=';
  if (this.$path) cookie += '; path=' + this.$path;
  if (this.$domain) cookie += '; domain=' + this.$domain;
  cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

  this.$document.cookie = cookie;
}

new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;


//set pop-up interval below in hours
var interval = 4;
//comment out the line below and uncomment the line after to
//change interval from hours to seconds for testing purposes
interval=1000*60*60*interval;
//interval=1000*interval

//begin new code

var lastvisit = new Cookie(document, "last_visit_time", 8760);
var today = new Date();
//default first page
var page = "http://www.townhall.com/columnists/opinionalert-popup.html";
var windowprops = "width=351,height=301,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
//total number of banners
var numOfBanners = 2;
//var page = "http://www.townhall.com/columnists/opinionalert-popup.html";
//var windowprops = "width=350,height=250,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
//if the user has no cookie, or if the cookie is empty, set
//a new cookie with today's date
if (!lastvisit.load()) {
  var pop = window.open(page, "", windowprops, true);
  currentVisitTime = new Date();
  lastvisit.lvtime=currentVisitTime.getTime();
  //set the banner to be seen next
  lastvisit.bannernum=2;
}

//store the cookie
lastvisit.store();

//amount of time passed between now and the time
//contained in the cookie
var vinterval=(today.getTime()-lastvisit.lvtime)

//if this amount of time is greater than the selected interval...
if (vinterval >= interval) {
  //trigger appropriate popup and increment popup number
  var viewNum=parseInt(lastvisit.bannernum);
  switch (viewNum){
  case 2:
    //url to second banner here
    page = "http://www.townhall.com/columnists/opinionalert-popup.html";
    //if the window size needs to be changed for the second banner,
    //uncomment the next line with the appropriate parameters
    windowprops = "width=351,height=301,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
  break;
  default:
  break;
}

window.focus();


var pop = window.open(page, "", windowprops, true);
pop.open;
//window.focus();
//reset the cookie with today's date
currentVisitTime = new Date();
lastvisit.lvtime=currentVisitTime.getTime();
//determine what the next banner seen should be
if (viewNum<numOfBanners){
lastvisit.bannernum=1+viewNum;
}else{
lastvisit.bannernum=1;
}
lastvisit.store();

}

//end new code


<!-- Begin -->
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=0,width=312,height=312,left = 550,top = 350');");
}
// End -->