var Pagetab_overzichtindex = -1;
var Pagetab_bewerkindex    = -1;
var Pagetab_afdrukkenindex = -1;
var Pagetab_kolommenindex  = -1;

////////////////////////////////////////////////////////////////////////////////

var pagetab = new Pagetabarray('pagetab','Pagetab_','Pagetab_');

function Pagetab(title,contentvooraf,contentmaak,contentververs,contentachteraf,kalenderdatumklik) {
  this.title=title;
  this.contentvooraf=contentvooraf;
  this.contentmaak=contentmaak;
  this.contentververs=contentververs;
  this.contentachteraf=contentachteraf;
  this.kalenderdatumklik=kalenderdatumklik;
  this.visible=true;
  this.enabled=true;
  this.special=false;
}
Pagetab.prototype.specialstring=function() {
  if (this.special) return 'Special'; else return '';
}

function Pagetabarray(name,idprefix,classprefix) {
  this.name=name; //must be identical to the name of the instance
  this.idprefix=idprefix; //must be unique when multiple pagetabarrays are in use on the same html-page
  this.classprefix=classprefix; //determines appearance through the class of the html-element
  this.array = new Array(); //array of Pagetab
  this.index=-1; //index of current front tab
}
Pagetabarray.prototype.length=function() {
  return this.array.length;
}
Pagetabarray.prototype.indexof=function(title) {
  var idx=-1;
  for (var i=0; i<this.array.length; i++)
  if (this.array[i].title==title) idx=i;
  return idx;
}
Pagetabarray.prototype.maak=function() {
  var t='';

  t+='<div class="'+this.classprefix+'tabdiv" id="'+this.idprefix+'tabdiv"></div>'+
     '<div class="'+this.classprefix+'contentdiv" id="'+this.idprefix+'contentdiv"></div>';
  return t;
}
Pagetabarray.prototype.tabclick=function(idx) {
  var oidx=this.index;
  if (oidx!=idx) this.contentachteraf();
  this.index=idx;
  if (oidx!=idx) this.contentvooraf();
  this.ververs();
}
Pagetabarray.prototype.tabververs=function() {
  var t='';

  t ='<ul class="'+this.classprefix+'ul">';
  for (var i=0; i<this.array.length; i++)
  if (this.array[i].visible)
  if (!this.array[i].enabled)
    t+='<li class="tabGrey'+this.array[i].specialstring()+'">'+this.array[i].title+'</li>';
  else
    if (i==this.index) t+='<li class="tabFront'+this.array[i].specialstring()+'">'+this.array[i].title+'</li>';
                  else t+='<li class="tabItem'+this.array[i].specialstring()+'" onclick="'+this.name+'.tabclick('+i+')">'+this.array[i].title+'</li>';
  t+='</ul>';
  getid(this.idprefix+'tabdiv').innerHTML=t;
}
Pagetabarray.prototype.contentvooraf=function() {
  var t=this.array[this.index].contentvooraf;
  if (t!='') t=eval(t+'()');
}
Pagetabarray.prototype.contentmaak=function() {
  var t=this.array[this.index].contentmaak;
  if (t!='') t=eval(t+'()');
  getid(this.idprefix+'contentdiv').innerHTML=t;

  this.contentververs();
}
Pagetabarray.prototype.contentververs=function() {
  var t=this.array[this.index].contentververs;
  if (t!='') eval(t+'()');
}
Pagetabarray.prototype.contentachteraf=function() {
  var t=this.array[this.index].contentachteraf;
  if (t!='') t=eval(t+'()');
}
Pagetabarray.prototype.kalenderdatumklik=function(dat) {
  var t=this.array[this.index].kalenderdatumklik;
  if (t!='') t=eval(t+'('+dat+')');
}
Pagetabarray.prototype.ververs=function() {
  this.tabververs();
  this.contentmaak();
}
Pagetabarray.prototype.add=function(title,contentvooraf,contentmaak,contentververs,contentachteraf,kalenderdatumklik) {
  var idx=this.array.length;
  this.array[idx]=new Pagetab(title,contentvooraf,contentmaak,contentververs,contentachteraf,kalenderdatumklik);
  return idx;
}
Pagetabarray.prototype.addtab=function(pagetabobject) {
  var idx=this.array.length;
  this.array[idx]=pagetabobject;
  return idx;
}
Pagetabarray.prototype.gettitle=function(index) {
  if ((index>=0)&&(index<this.array.length)) return this.array[index].title;
                                        else return '';
}
Pagetabarray.prototype.settitle=function(index,title) {
  if ((index>=0)&&(index<this.array.length))
  this.array[index].title=title;
}
Pagetabarray.prototype.getvisible=function(index) {
  if ((index>=0)&&(index<this.array.length)) return this.array[index].visible;
                                        else return false;
}
Pagetabarray.prototype.setvisible=function(index,visible) {
  if ((index>=0)&&(index<this.array.length))
  this.array[index].visible=visible;
}
Pagetabarray.prototype.getenabled=function(index) {
  if ((index>=0)&&(index<this.array.length)) return this.array[index].enabled;
                                        else return false;
}
Pagetabarray.prototype.setenabled=function(index,enabled) {
  if ((index>=0)&&(index<this.array.length))
  this.array[index].enabled=enabled;
}


