
var panes = new Array();

function setupPanes(containerId, defaultTabId) {
    // go through the DOM, find each tab-container
    // set up the panes array with named panes
    // find the max height, set tab-panes to that height
    currentTab = 'pane1';
    panes[containerId] = new Array();
    var maxHeight = 0; var maxWidth = 0;
    var container = document.getElementById(containerId);
    var paneContainer = container.getElementsByTagName("div")[0];
    var paneList = paneContainer.childNodes;
    for (var i=0; i < paneList.length; i++ ) {
        var pane = paneList[i];
        if (pane.nodeType != 1) continue;
        if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
        if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
        panes[containerId][pane.id] = pane;
        pane.style.display = "none";
    }
    paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
    // make tab active class
    // hide other panes (siblings)
    // make pane visible
    if(currentTab !=paneId) {
      var tmpTabctrl = currentTab + "_ctrl";
      var tmpObj = document.getElementById(tmpTabctrl);
      if (tmpObj != null || tmpObj != undefined) {
        variableNames = tmpObj.value.split(',');
    		for(i=0; i<variableNames.length; i++) {
    			paramString = document.getElementById(variableNames[i]).value;
    			if(paramString == "") {
    			  alert(message);
    			  return false;
    			}
    		}
      }
      currentTab =paneId;
    }
    var xoops_url = document.getElementById('xoops_url').value;
    var noch = document.getElementById('nochange');
    var imageActive ="url(" + xoops_url + "/images/tab_clicked.png)";
		var imageInactive = "url(" + xoops_url + "/images/tab_normal.png)";
    activeTab.style.backgroundImage = imageActive;
    // work out which container this tab is part of. could also bounce on parent node
    for (var con in panes) {
        if (panes[con][paneId] != null) { // tab and pane are members of this container
            var pane = document.getElementById(paneId);
            pane.style.display = "block";
            var container = document.getElementById(con);
            var tabs = container.getElementsByTagName("table")[0];
            var tabList = tabs.getElementsByTagName("td");
            for (var i=0; i<tabList.length; i++ ) {
                var tab = tabList[i];
                if (tab != activeTab && tab != noch) tab.style.backgroundImage = imageInactive;;
            }
            for (var i in panes[con]) {
            	if(i != "each") {
                var pane = panes[con][i];
                if (pane == undefined) continue;
                if (pane.id == paneId) continue;
                try{
                    pane.style.display = "none"
                }catch(e){}
              }
            }
        }
    }
    return false;    
}

