// Project: Iduna
// Version: 1.0
// Author: Philippe Reiter
// Date: July-August, 2003

// Mythology (Greek):
// Iduna protected the precious apples of youth, which gave the 
// Greek gods immortality.

// ------------------------------ FUNCTIONS ------------------------------
// cookieMonster
// Cookie constructor and modifiers
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;
}

// Store a cookie
Cookie.prototype.store = function(){
   var cookieMonster = "";
   
   for(var property in this){
      if((property.charAt(0) == '$') || ((typeof this[property]) == 'function'))
         continue;
      if(cookieMonster !="") cookieMonster += '&';
         
      cookieMonster += property + ':' + escape(this[property]);
      }
   
   var cookie = this.$name + '=' + cookieMonster;
   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;
}

// Load a cookie
Cookie.prototype.load = function(){
   var cookies = this.$document.cookie;
   
   if(cookies == "") return false;
   
   var begin = cookies.indexOf(this.$name + '=');
   
   if(begin == -1) return false; // No such $name
   
   begin += this.$name.length + 1;
   
   var omega = cookies.indexOf(';', begin);
   
   if(omega == -1) omega = cookies.length;
   
   var cookieMonster = cookies.substring(begin, omega); // Extract name of cookie
   
   // (name.value) separated by &, name:value
   
   var cookieArray = cookieMonster.split('&');
   
   for(var i = 0; i < cookieArray.length; i++){
      cookieArray[i] = cookieArray[i].split(':');
   }
      
   for(var j = 0; j < cookieArray.length; j++){
      this[cookieArray[j][0]] = unescape(cookieArray[j][1]);
   }
   
   return true;
}

// Remove a cookie
Cookie.prototype.remove = function(){
   var cookieMonster = this.$name + '=';
   if(this.$path) cookieMonster += '; path=' + this.$path;
   if(this.$domain) cookieMonster += '; domain=' + this.$domain;
   cookieMonster += '; expires=Thu, 29-Dec-1982 00:00:00 GMT';
   
   this.$document.cookie = cookieMonster;
}

// Wyrd Cookie Management
// Note: Wyrd is Old English for "fate"
var guest = new Cookie(document, "Preferences", 744); // Keep cookie for a month

if(!(guest.load()) || !guest.lang || !guest.name){
   guest.name = "Guest";
   guest.lang = 'e';        
}
// English = e = false
// French = f = true

guest.store();
document.username = guest.name;
document.isFrench = (guest.lang == 'e') ? false : true;

// If cookies are disabled
if(document.cookie = ""){
  document.isFrench = false;
  document.username = "Guest";
}

function useWyrd(n,l){
   guest.name = n;
   guest.lang = false ? 'f' : 'e';
   // Options reversed --> change language
   guest.store();
   location.reload(true);
}

function printDate(){
  var today = new Date();
  
  var month_e = new Array(12);
  month_e[0] = "January";
  month_e[1] = "February";
  month_e[2] = "March";
  month_e[3] = "April";
  month_e[4] = "May";
  month_e[5] = "June";
  month_e[6] = "July";
  month_e[7] = "August";
  month_e[8] = "September";
  month_e[9] = "October";
  month_e[10] = "November";
  month_e[11] = "December";
  
  var month_f = new Array(12);
  month_f[0] = "janvier";
  month_f[1] = "février";
  month_f[2] = "mars";
  month_f[3] = "avril";
  month_f[4] = "mai";
  month_f[5] = "juin";
  month_f[6] = "juillet";
  month_f[7] = "août";
  month_f[8] = "septembre";
  month_f[9] = "octobre";
  month_f[10] = "novembre";
  month_f[11] = "décembre";
  
  if(document.isFrench)
     document.write("le "+today.getDate()+" "+month_f[today.getMonth()]+" "+today.getFullYear());
  else document.write(month_e[today.getMonth()]+" "+today.getDate()+", "+today.getFullYear());
}

function bilingual(eng_msg,fr_msg){
   if(document.isFrench)
      document.write(fr_msg);
   else document.write(eng_msg);
}

// ------------------------------------------------------------



     
      
   
   
   
   


   
   



  
  




