var pop_under = null;
var pop_cookie_name = "analscreen";
var pop_timeout = 720;


function pop_cookie_enabled(){
   var is_enabled = false;
   if (!window.opera && !navigator.cookieEnabled)
      return is_enabled;
   if (typeof document.cookie == 'string')
      if (document.cookie.length == 0){
         document.cookie = "test";
         is_enabled = document.cookie == 'test';
         document.cookie = '';
      } else {
         is_enabled = true;
      }
      return is_enabled;
}
   
function pop_getCookie(name){
   var cookie = " " + document.cookie;
   var search = " " + name + "=";
   var setStr = null;
   var offset = 0;
   var end = 0;
   if (cookie.length > 0){
      offset = cookie.indexOf(search);
      if (offset != -1){
         offset += search.length;
         end = cookie.indexOf(";", offset);
         if (end == -1){
            end = cookie.length;
         }
         setStr = unescape(cookie.substring(offset, end));
      }
   }
   return(setStr);
}
   
function pop_setCookie (name, value){
   var today = new Date();
   var expires = new Date(today.getTime() + 1000 * 60 * 60 * 24) ;
   document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/;";
}

function show_pop(){
   var pop_wnd = 'http://www.analscreen.net/pops.php';
   var fea_wnd = "scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0,height=785,width=925";
   var need_open = true;
   if (pop_under != null){
      if (!pop_under.closed)
         need_open = false;
   }
   if (need_open){
      if (pop_cookie_enabled()){
         val = pop_getCookie(pop_cookie_name);
         if (val != null){
            now = new Date();
            val2 = new Date(val);
            utc1 = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());
            utc2 = Date.UTC(val2.getFullYear(), val2.getMonth(), val2.getDate(), val2.getHours(), val2.getMinutes(), val2.getSeconds());
            if ((utc1 - utc2)/1000 < pop_timeout*60){
               need_open = false;
            }
         }
      }
   }
   if (need_open){
      under = window.open(pop_wnd, "", fea_wnd);
      under.blur();
      window.focus();
      if (pop_cookie_enabled()){
         now = new Date();
         pop_setCookie(pop_cookie_name, now);
      }
   }
   return true;
}

function pop_init(){
   if (window.captureEvents) {
      window.captureEvents(Event.CLICK);
      window.onclick=show_pop;
   } else {
      document.onclick=show_pop;
   }
   return true;
}
