/* create/read/deleteCookie are derived from code  
   Copyright (C) 1999 Dan Steinman
   Distributed under the terms of the GNU Library General Public License, according to 
   http://www.koders.com/javascript/fid459CB87882C39879D8E9AB49559B052C28F08863.aspx
 
   Other functions and modifications are (C) Greenpeace 2005, published under the GNU General Public License (http://www.gnu.org/copyleft/gpl.html)

   Nis Jorgensen, Greenpeace, 2006-03-08
*/


function createCookie(name,value,days) {
 if (days) {
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = "; expires="+date.toGMTString();
 }
 else expires = "";
 document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++) {
   var c = ca[i];
   while (c.charAt(0)==' ') c = c.substring(1,c.length)
   if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
 }
 return null;
}

function deleteCookie(name) {
  saveCookie(name,"",-1)
}

function read_cookie_value(cookie_name) {
  // Removing second implentation of the same functionality
  // Retaining the function, in case it is used anywhere
  return readCookie(cookie_name);
}


function doOnce (identifier) {

// Used for popups that should only
// be done on the first visit to a page
// Use different identifer strings for 
// different popups.
//
// Usage:
//   if (doOnce('MyPopup')) {
//       window.open (...)
//   }

    if (readCookie(identifier) == 'done') {
        return false      
    } else {
        createCookie(identifier, 'done');
        return true;
    }
}

function popunder(url,features) {
  win2=window.open(url,"",features);
  if (win2) {
    win2.blur();
    window.focus();
  }
}