/*
  Written by Carlos Solis.
  December 2003
  
  These functions manage an array of strings. It provides functions to insert 
  and delete strings from the array. It is not allowed to write duplicated
  strings.
  
  */
      
function StringM(){
  this.len    = 0;
  this.data   = new Array();
  this.exists = SM_exists;
  this.insert = SM_insert;
  this.remove = SM_remove;
  this.fixCookie     = SM_fixCookie;
  this.writeCookie   = SM_writeCookie;
  this.setFromCookie = SM_setFromCookie;
}

function SM_exists(sdata){
  for(var i=0; i<this.len; i++)
    if( this.data[i]== sdata)
       return true;
  return false;     
}

function SM_fixCookie(){
  var tmp = new Array();
  for(var i=0; i<this.len; i++)
   tmp[i] = this.data[i];
  return tmp.toString(); 
}

function SM_writeCookie(){
   document.cookie = "c_tree=" + this.fixCookie() + ";";   
}

function SM_setFromCookie(values){
    this.len = 0;
    for(var i=0; i<values.length; i++)
        this.data[this.len++] = values[i];    
}

function SM_insert(sdata){
   if(! this.exists(sdata)){
      this.data[this.len++] = sdata;   
      this.writeCookie();
    }
}

function SM_remove(sdata){  
  for(var i=0; i<this.len; i++)
    if( this.data[i]==sdata){
        for(var j=i+1; j<this.len; j++)
           this.data[j-1] = this.data[j]; 
        this.len--;
        this.writeCookie();
        return; 
     }    
}