function bindEvent(element, name, func) {
	if (element.addEventListener) {
		element.addEventListener(name, func, false);
	} else if (element.attachEvent) {
		element.attachEvent("on" + name, func);
	}
}
function bindFunc() {
	var func = arguments[0], _this = arguments[1], args = [];
	for (var i=2; i<arguments.length; i++) 
		args.push(arguments[i]);
	return function() {
		for (var i=0; i<arguments.length; i++) 
			args.push(arguments[i]);
		return func.apply(_this, args);
	};
}
function bindTabs(tabName, tabPageName) {
	bindEvent(window, "load", function() {new Tabs(tabName, tabPageName);});
}
function bindActives(name) {
	bindEvent(window, "load", function () {new Actives(name);});
}
function Actives(name) {
	this.actives = document.getElementsByName(name);
	this.activeNow = null;
	this.setActive = function (index) {
		if (this.actives[index] != this.activeNow) {
			if (this.activeNow != null) {
				this.activeNow.className = "out";
			}
			this.activeNow = this.actives[index];
			this.activeNow.className = "on";
		}
		return false;
	};
	for (var i=0; i<this.actives.length; i++) {
		bindEvent(this.actives[i], "click", bindFunc(this.setActive, this, i));
		if (this.actives[i].className && this.actives[i].className == "on") {
			this.activeNow = this.actives[i];
		}
	}
}
function Tabs(tabName, tabPageName) {
	this.tabs = document.getElementsByName(tabName);
	this.tabPages = document.getElementsByName(tabPageName);
	this.tabNow = null;
	this.tabPageNow = null;
	this.sohTab = function (index) {
		if (this.tabNow != null) {
			this.tabNow.className = "out";
			this.tabPageNow.style.display = "none";
		}
		this.tabNow = this.tabs[index];
		this.tabPageNow = this.tabPages[index];
		this.tabNow.className = "on";
		this.tabPageNow.style.display = "";
	};
	for (var i=0; i<this.tabs.length; i++) {
		bindEvent(this.tabs[i], "click", bindFunc(this.sohTab, this, i));
		if (this.tabs[i].className && this.tabs[i].className == "on") {
			this.tabNow = this.tabs[i];
			this.tabPageNow = this.tabPages[i];
		}
	}
}
bindTabs("tab0","tab0Page");

//bindActives("tab0");
