
// clsTreeEx

function TreeExLoad() {
  var cookie = GetCookie(this.Id);
  this.CNodes = cookie.split('|');
}

function TreeExSave() {
  if ( !this.Nodes ) return;
  var v = '';
  for(first=true,i=0; i<this.Nodes.length; i++) {
    var obj = (document.getElementById?document.getElementById(this.Nodes[i]):(document.all?document.all[this.Nodes[i]]:null));
    if ( obj ) 
	   if ( obj.className == this.CloseCls ) v=v+(first?'':'|')+this.Nodes[i]+':0';
      else if ( obj.className == this.OpenCls ) v=v+(first?'':'|')+this.Nodes[i]+':1';
           else v=v+(first?'':'|')+this.Nodes[i]+':2';
    first = false;
  }
  if ( this.ExDate ) SetCookie(this.Id, v, GetExpiresDate(this.ExDate,0,0));
  else SetCookie(this.Id, v);
}

function TreeExSetState(anId, aDefault) {
  var obj = (document.getElementById?document.getElementById(anId):(document.all?document.all[anId]:null));
  if ( !obj ) return;
  var state = aDefault;
  if ( this.CNodes ) for(i=0; i<this.CNodes.length; i++) {
    v = this.CNodes[i].split(':');
    if ( v && ( v[0] == anId )) state=v[1];
  }
  if ( state == 0 ) obj.className=this.CloseCls;
  else if ( state > 0 ) obj.className=this.OpenCls;
  else obj.className=this.DisableCls;
}

function clsTreeEx(anId, anOpenCls, aCloseCls, aDisableCls, anExDay) {
  this.Id         = anId;
  this.CNodes     = null;
  this.Nodes      = null;
  this.OpenCls    = anOpenCls;
  this.CloseCls   = aCloseCls;
  this.DisableCls = aDisableCls;
  this.ExDate     = anExDay;
  this.load       = TreeExLoad;
  this.save       = TreeExSave;
  this.setState   = TreeExSetState;
  this.load();
}

// clsTreeExList

function TreeExListCount() {
  return this.List.length;
}

function TreeExListAdd(aTreeId, anOpenCls, aCloseCls, anExDay) {
  this.List[this.List.length] = new clsTreeEx(aTreeId, anOpenCls, aCloseCls, anExDay);
}

function TreeExListGet(aTreeId) {
  for(i=0; i<this.List.length; i++) if ( this.List[i].Id == aTreeId ) return this.List[i];
  return null;
}

function TreeExListSetNodes(aTreeId, aNodes) {
  var tree = this.get(aTreeId);
  if ( tree ) tree.Nodes=aNodes;
}

function TreeExListSave(aTreeId) {
  var tree = this.get(aTreeId);
  if ( tree ) tree.save();
}

function TreeExListSetState(aTreeId, aNodeId, aDefault) {
  var tree = this.get(aTreeId);
  if ( tree ) tree.setState(aNodeId, aDefault);
}

function clsTreeExList() {
  this.List     = new Array();
  this.count    = TreeExListCount;
  this.add      = TreeExListAdd;
  this.get      = TreeExListGet;
  this.save     = TreeExListSave;
  this.setNodes = TreeExListSetNodes;
  this.setState = TreeExListSetState;
}

var TreeExList = new clsTreeExList();
