
/* tabbed interface routine */

/* 2do: make cache of elements instead of array of ids */

function cTabs () {
	
	this.tabs = new Array();
	this.panels = new Array();
	
	this.tabClassActive = "active";
	this.tabClassPassive = "passive";
	
	this.showThisTab = function (elem) {

		var tabId = elem.id;
		var panelId = "panel_" + elem.id;
	
		this.hidePanels();
		this.showPanel(panelId);
		
		this.deactivateTabs();
		this.activateTab (tabId);
		
	}
	
	this.showTab = function (id) {
		
		var tabId = id;
		var panelId = "panel_" + id;
	
		this.hidePanels();
		this.showPanel(panelId);
		
		this.deactivateTabs();
		this.activateTab (tabId);		
	}
	
	this.registerTab = function (tabId) {
		this.tabs.push(tabId);
		this.panels.push("panel_" + tabId);
	}
	

	this.hidePanels = function () {		
		
		for (var n in this.panels) {
			
			elem = document.getElementById (this.panels[n]);
			
			if (elem != null) {				
				elem.style.display = "none";		
				}
		}
	}
	
	this.showPanel = function (id) {
		elem = document.getElementById (id);
		elem.style.display = "block";
	}
	
	this.setTabActiveClass = function (tabclass) {
		this.tabClassActive = tabclass;
	}
	
	this.setTabPassiveClass = function (tabclass) {
		this.tabClassPassive = tabclass;	
	}
	
	this.activateTab = function (id) {
		var elem = document.getElementById (id);
		elem.className = this.tabClassActive;
	}
	
	this.deactivateTabs = function () {
		
		for (var n in this.tabs) {
			elem = document.getElementById (this.tabs[n]);
			
			if (elem != null) {
				elem.className = this.tabClassPassive;
				}
		}
		
	}

}





