function TabGroup(activeStyle, inactiveStyle, tabActiveStyle, tabInactiveStyle){
   this.tabObjects  = []
   this.showObjects = []
   this.hideObjects = []
   this.showAllObjects = []
   this.hideAllObjects = []
   this.activeStyle = activeStyle
   this.inactiveStyle = inactiveStyle
   this.tabActiveStyle = tabActiveStyle
   this.tabInactiveStyle = tabInactiveStyle
   this.selectedPane = ""
}

TabGroup.prototype.add = function(tabArr, seltabArr, closetabArr){
   var len = this.tabObjects.length, cnt = 0
   this.tabObjects[len] = []
   if (typeof(tabArr)=="string"){
      var tabElem = document.getElementById(tabArr)
      if (!tabElem)
         alert("Missing tab: " + tabArr)
      else
	 this.tabObjects[len][0] = tabElem
   }
   else{
      for(var i in tabArr){
         var tabElem = document.getElementById(tabArr[i])
         if (!tabElem)
   	    alert("Missing tab: " + tabArr[i])
         else
	    this.tabObjects[len][cnt++] = tabElem
      }
   }
   cnt = 0, this.showObjects[len] = []
   if (typeof(seltabArr)=="string"){
      var sElem = document.getElementById(seltabArr)
      if (!sElem)
         alert("Missing select link: " + seltabArr)
      else{
         sElem.onclick = sElem.show = this.show
         sElem.pane = this
         sElem.paneInd = len
         sElem.active = false
         this.showObjects[len][0] = sElem
      }
   }
   else{
      for(var i in seltabArr){
         var sElem = document.getElementById(seltabArr[i])
         if (!sElem)
            alert("Missing select link: " + seltabArr[i])
         else{
            sElem.onclick = sElem.show = this.show
            sElem.pane = this
            sElem.paneInd = len
            this.showObjects[len][cnt++] = sElem
         }
      }
   }
   cnt = 0, this.hideObjects[len] = []
   if (typeof(closetabArr)=="string"){
      var cElem = document.getElementById(closetabArr)
      if (!cElem)
         alert("Missing close link: " + closetabArr)
      else{
            if (cElem.onclick==this.show)
               cElem.reverseClick = true
            else{
               cElem.reverseClick = false
               cElem.onclick = this.hide
            }
            cElem.pane = this
            cElem.paneInd = len
            this.hideObjects[len][0] = cElem
      }

   }
   else{
      for(var i in closetabArr){
         var cElem = document.getElementById(closetabArr[i])
         if (!cElem)
            alert("Missing close link: " + closetabArr[i])
         else{
            if (cElem.onclick==this.show)
               cElem.reverseClick = true
            else{
               cElem.reverseClick = false
               cElem.onclick = this.hide
            }
            cElem.pane = this
            cElem.paneInd = len
            this.hideObjects[len][cnt++] = cElem
         }
      }
   }
}

TabGroup.prototype.multiadd = function(indStart, indEnd, tabArr, seltabArr, closetabArr){
   if (parseInt(indStart)!=indStart || parseInt(indEnd)!=indEnd || indStart>indEnd){
      alert("Invalid start or end index in multiadd")
      return
   }
   for(var i=indStart; i<=indEnd; i++){
      var tabArrNew = [], seltabArrNew = [], closetabArrNew = []
      for(var j in tabArr) tabArrNew[j] = tabArr[j]+i
      for(var j in seltabArr) seltabArrNew[j] = seltabArr[j]+i
      if (closetabArr) { 
          for(var j in tabArr) closetabArrNew[j] = closetabArr[j]+i
      }
      this.add(tabArrNew, seltabArrNew, closetabArrNew)
   }

}

TabGroup.prototype.addShowFunc = function(funcName, showButName){
    var sElem = document.getElementById(showButName)
    if (!sElem){ alert("Missing element: "+showButName); return }
    var F = eval(funcName)
    for(var i in this.showObjects){
       for(var j in this.showObjects[i]){
          if (this.showObjects[i][j]==sElem){
             var ind = sElem.paneInd
             for(var p in this.tabObjects[ind]) this.tabObjects[ind][p].showFunction = F ? F : null
          }
       }
    }
    sElem.showFunction = F ? F : null
}

TabGroup.prototype.addHideFunc = function(funcName, hideButName){
    var sElem = document.getElementById(hideButName)
    if (!sElem){ alert("Missing element: "+hideButName); return }
    var F = eval(funcName)
    for(var i in this.showObjects){
       for(var j in this.showObjects[i]){
          if (this.showObjects[i][j]==sElem){
             var ind = sElem.paneInd
             for(var p in this.tabObjects[ind]) this.tabObjects[ind][p].hideFunction = F ? F : null
          }
       }
    }
    sElem.hideFunction = F ? F : null
}

TabGroup.prototype.show = function(){
   with(this.pane)
   {
     if (this.active && this.reverseClick){
        this.pane.hidePane(this.paneInd)
        this.active = false
     }
     else{
        this.pane.showPane(this.paneInd)
        this.active = true
     }
     for(var i in showObjects){
        for(var j in showObjects[i])
           if (showObjects[i][j]){
              if (i==this.paneInd){
                 if (activeStyle) showObjects[i][j].className = this.active ? activeStyle : inactiveStyle
                 
              }
              else{
                 if (inactiveStyle){ showObjects[i][j].className = inactiveStyle; showObjects[i][j].active = false }
              }
           }
     }
   }
}

TabGroup.prototype.showPane = function(paneInd){
  with(this){
     for(var i in tabObjects){
        for(var j in tabObjects[i]){
           if (tabObjects[i][j]){
              if (i==paneInd){
                 if (tabActiveStyle) tabObjects[i][j].className = tabActiveStyle
                 else if (activeStyle) tabObjects[i][j].className = activeStyle
                 else tabObjects[i][j].style.display = 'inline'
                 if (tabObjects[i][j].showFunction) tabObjects[i][j].showFunction(tabObjects[i][j])
                 selectedPane = tabObjects[i][j].id
              }
              else{
                 if (tabActiveStyle) tabObjects[i][j].className = tabInactiveStyle
                 else if (activeStyle) tabObjects[i][j].className = inactiveStyle
                 else tabObjects[i][j].style.display = 'none'
                 if (tabObjects[i][j].hideFunction) tabObjects[i][j].hideFunction(tabObjects[i][j])
              }
           }
        }
     }
  }
}

TabGroup.prototype.hide = function(){
   with(this.pane)
   {
     this.pane.hidePane(this.paneInd)
     for(var i in showObjects[this.paneInd]){
        showObjects[this.paneInd][i].className = inactiveStyle
     }
     this.active = false
   }
}

TabGroup.prototype.hidePane = function(paneInd){
   with(this){
     for(var i in tabObjects[paneInd]){
        if (tabObjects[paneInd][i]){
           if (tabActiveStyle) tabObjects[paneInd][i].className = tabInactiveStyle
           else if (activeStyle) tabObjects[paneInd][i].className = inactiveStyle
           else tabObjects[paneInd][i].style.display = 'none'
           if (tabObjects[paneInd][i].hideFunction) tabObjects[paneInd][i].hideFunction(tabObjects[paneInd][i])
        }
     }
   }
}

TabGroup.prototype.showAll = function(elemID){
   var sElem = document.getElementById(elemID)
   if (!sElem){ alert('Missing show all object:'+elemID);return;}
   sElem.pane = this
   sElem.vis  = 'show'
   sElem.onclick = this.visualizeAll
   this.showAllObjects[this.showAllObjects.length] = sElem
}

TabGroup.prototype.hideAll = function(elemID){
   var sElem = document.getElementById(elemID)
   if (!sElem){ alert('Missing hide all object:'+elemID);return;}
   sElem.pane = this
   sElem.vis  = 'hide'
   sElem.onclick = this.visualizeAll
   this.hideAllObjects[this.hideAllObjects.length] = sElem
}

TabGroup.prototype.visualizeAll = function(){
   with(this.pane)
   {
     for(var i in tabObjects){
        for(var j in tabObjects[i]){
           if (tabObjects[i][j]){
              if (tabActiveStyle) tabObjects[i][j].className = (this.vis=='show' ? tabActiveStyle : tabInactiveStyle)
              else if (activeStyle) tabObjects[i][j].className = (this.vis=='show' ? activeStyle : inactiveStyle)
              else tabObjects[i][j].style.display = (this.vis=='show' ? 'inline' : 'none')
           }
        }
     }

     for(var i in showObjects){
        for(var j in showObjects[i])
           if (showObjects[i][j]){
              showObjects[i][j].className = (this.vis=='show' ? activeStyle : inactiveStyle)
           }
     }

     for(var i in showAllObjects) showAllObjects[i].className = (this.vis=='show' ? activeStyle : inactiveStyle)
   }
}