// Script for cookie to control whether user sees pop-up window or not
// liberally borrowed from  24 hour JavaScripts Site
// located at http://www.javascripts.com.
// ADD THIS <body onLoad="CheckCookie('http://url/page.html')">

var cookieName = "EmailSignup";

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) {
    endstr = document.cookie.length;
	}
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function SetLastHereOn() {
	var rightNow = new Date();
	var expireDate = new Date();
	expireDate.setTime(expireDate.getTime() + 120*(24 * 60 * 60 * 1000)); // dead in 120 days
	SetCookie(cookieName, rightNow.getTime(), expireDate, "/");
}

function CheckCookie(URL) {
	if (GetCookie(cookieName) == null) {
		// alert("Cookie not set.");
		popUp(URL);
		// SetLastHereOn();
	} /* else {
		lastVisit = 1 * GetCookie(cookieName);
		rightNow = new Date();
		lastVisit = new Date(lastVisit);
		timeElapse = (rightNow - lastVisit) / 86400;
		// alert(rightNow.toGMTString() + " : " + lastVisit.toGMTString() + " : " + timeElapse);
		if (timeElapse > 120) {
			popUp(URL);
		SetLastHereOn();
		}
	} */
}

function popUp(URL) {
	window.open(URL,"NoCookie","width=350,height=450,scrollbars=yes,resizable=no,toolbar=no");
}



