var TabSelectCallback = null;

function TabObj (id, selected, className, selectedClassName, parent) {
	this.id = id;
	this.selected = selected;
	this.className = className;
	this.selectedClassName = selectedClassName;
	this.parent = parent;
	this.href = "";
	this.target = "_self";
	
	this.tabObj = GetObjRef ("Tab_" + id);
	this.tabContentObj = GetObjRef ("TabContent_" + id);
	
	if (this.tabObj != null) {
		this.tabObj.bind = this;
		this.tabObj.onclick = this.Onclick;
		
		this.tabObj.className = this.className;
		if (this.selected == true) {
			this.tabObj.className = this.selectedClassName;
		}
	}
	if (this.tabContentObj != null) {
		this.tabContentObj.style.display = "none";
		if (this.selected == true) {
			this.tabContentObj.style.display = "block";
		}
	}
	
}
	function TabObj_AddTabContent (id) {
		this.tabContentObj = GetObjRef ("TabContent_" + id);
	}
	function TabObj_Select () {
		if (this.href == null || this.href == "") {
			if (this.tabObj) {
				this.tabObj.className = this.selectedClassName;
			}
			if (this.tabContentObj) {
				this.tabContentObj.style.display = "block";
			}
		}
		else {
			window.open (this.href, this.target);
			return true;
		}
		return false;
	}
	function TabObj_Deselect () {
		if (this.tabObj) {
			this.tabObj.className = this.className;
		}
		if (this.tabContentObj) {
			this.tabContentObj.style.display = "none";
		}
	}
	function TabObj_SetSelect (selected) {
		this.selected = selected;
		if (this.selected == true) {
			return this.Select ();
		}
		else {
			return this.Deselect ();
		}
	}
	function TabObj_Onclick (e) {
		this.bind.parent.SelectTab (this.bind);
		ReturnTarget (e, false);
	}
	new TabObj ();
	TabObj.prototype.AddContent = TabObj_AddTabContent;
	TabObj.prototype.Select = TabObj_Select;
	TabObj.prototype.Deselect = TabObj_Deselect;
	TabObj.prototype.SetSelect = TabObj_SetSelect;
	TabObj.prototype.Onclick = TabObj_Onclick;
	

function TabsObj () {
	this.tab = [];
}
	function TabsObj_AddTab (tabObj) {
		this.tab[this.tab.length] = tabObj;
		return tabObj;
	}
	function TabsObj_SelectTab (thisTab) {
		var hasHref = false;
		for (var i=0; i<this.tab.length; i++) {
			if (this.tab[i] == thisTab) {
				hasHref = this.tab[i].SetSelect (true);
			}
		}
			for (var i=0; i<this.tab.length; i++) {
				if (this.tab[i] != thisTab) {
					this.tab[i].SetSelect (false);
				}
			}
		if (TabSelectCallback != null) {
			TabSelectCallback ();
		}
	}
	new TabsObj ();
	TabsObj.prototype.AddTab = TabsObj_AddTab;
	TabsObj.prototype.SelectTab = TabsObj_SelectTab;

