AdvancedGroups = new Object();

AdvancedGroups.visible = false;
AdvancedGroups.cookie  = 'w4u_advanced_groups';

AdvancedGroups.init = function() {
  // Pokud dokument neobsahuje zadne pokrocile skupiny, metoda se ukonci
  if($('#display_advanced_groups').get(0) == undefined) {
    return this;
  }
  // Nacteni nastaveni
  this.load();
  this.changeVisibility();
}

AdvancedGroups.changeVisibility = function() {
  // Zobrazeni nebo skryti skupin podle stavu checkboxu
  if($('#display_advanced_groups').get(0).checked) {
    AdvancedGroups.show();
  } else {
    AdvancedGroups.hide();
  }
  return this;
}

AdvancedGroups.show = function() {
  $('.advanced_group').show();
  this.visible = true;
  this.save();
  return this;
}

AdvancedGroups.hide = function() {
  $('.advanced_group').hide();
  this.visible = false;
  this.save();
  return this;
}

AdvancedGroups.save = function() {
  var days = 30;
  var variable;
  var expires;
  var date = new Date();
  date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
  expires = date.toGMTString();
  document.cookie = this.cookie+'='+this.visible+'; expires='+expires+';';
  // console.log(this.visible);
}

AdvancedGroups.load = function() {  
  if (document.cookie.length>0) {
    var c_start=document.cookie.indexOf(this.cookie + "=");
    if (c_start!=-1) {
      c_start=c_start + this.cookie.length+1;
      var c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      var result = unescape(document.cookie.substring(c_start,c_end));
      if(result == 'true') {
        this.visible = true;
      } else {
        this.visible = false;
      }
    }
  }
  $('#display_advanced_groups').get(0).checked = this.visible;
}

