var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var other = (document.getElementById) ? true : false;
var lay_curr = 1;

function getlayer(lay) {
	if (ie4) {return document.all[lay];}
	if (ns4) {return document.layers[lay];}
	if (other) {return document.getElementById([lay]);}
}

function hidelayer(lay) {
	var l = getlayer(lay);
	if (ie4) {l.style.visibility = "hidden";}
	if (ns4) {l.visibility = "hide";}
	if (other) {l.style.display = "none";}
}

function showlayer(lay) {
	var l = getlayer(lay);
	//if (!l) alert(lay + ' does not exist!!');
	if (ie4) {l.style.visibility = "visible";}
	if (ns4) {l.visibility = "show";}
	if (other) {l.style.display = "block";}
}

/* TABULATOR */
function Tabulator(tabName, tabList, linkList, fckList, currTab, sCaption) {
	this.obj = tabName;
	this.tabList = tabList;
	this.linkList = linkList;
	this.fckList = fckList;
	this.currTab = currTab;
	this.sCaption = sCaption;
}

Tabulator.prototype.drawTabs = function() {
	var sTitle = '';
	var sContent = '<dl class="tablist">\n';
	if (this.sCaption) {
		sContent += '<dt>' + this.sCaption + '</dt>\n';
	}
	for (i=0; i<this.tabList.length; i++) {
		sTitle = this.tabList[i];
		sContent += '<dd id="tab_' + this.obj + (i+1) + '" class="' + ((i+1)==this.currTab ? 'active': '') + '">';
		
		if (this.linkList[i]) {
			sContent += '<a href="' + this.linkList[i] + '" '
				+ '>' + sTitle + '</a>';
		} else {
			sContent += '<a href="" '
				+ 'onclick="' + this.obj + '.SwitchTab(' + (i+1) + '); '
				+ 'return false;">' + sTitle + '</a>';
		}
		sContent += '</dd>\n';
	}
	sContent += '</dl>\n';
	document.write(sContent);
}

Tabulator.prototype.SwitchTab = function(tabID) {
	if (this.currTab) {
		hidelayer('opt_' + this.obj + this.currTab);
		l = getlayer('tab_' + this.obj + this.currTab);
		l.className = "";
	}
	this.currTab = tabID;
	
	l = getlayer('tab_' + this.obj + tabID);
	l.className = "active";
	showlayer('opt_' + this.obj + tabID);
	this.fckRefreshAll();
}
Tabulator.prototype.fckRefreshAll = function() {
	try {
		if (this.fckList) {
			for (i=0; i<this.fckList.length; i++) {
				sName = this.fckList[i];
				this.fckRefresh(sName);
			}
		}
	}
    catch (e) {
    }
}

Tabulator.prototype.fckRefresh = function(fckName) {
	try {
		fckFrame = getlayer(fckName + '___Frame');
		if (fckFrame) {
			fckFrame.contentWindow.FCK.RefreshEditor();
		}
	}
    catch (e) {
    }
}
