// +----------------------------------------------------------------------+
// | Source file version 1.0                                              |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002 - 2003 OÜ HansaNet (http://www.hansanet.ee)       |
// +----------------------------------------------------------------------+
// | This source file is property of OÜ HansaNet. Modifying and           |
// | distribution of any kind is prohibited without written permission    |
// | from OÜ HansaNet.                                                    |
// +----------------------------------------------------------------------+
// | Authors: Reio Piller <reio@hansanet.ee>                              |
// +----------------------------------------------------------------------+

// TabSystem class
function TabSystem() {

	// vars
	this.collections = new Array();
	
	// funcs
	this.InitCollections = tabInitCollections;
	this.AddCollection = tabAddCollection;
}

function tabInitCollections() {
	this.collections.reverse();
	var count = this.collections.length;
	for (var i = 0 ; i < count ; i++) {
		this.collections[i].Init();
	}
}

function tabAddCollection(collection) {
   this.collections[this.collections.length] = collection;	
}

// TabCollection class
function TabCollection(collection_id, pages, active_page_id) {
	
	// vars
	this.body_rel = null;
	this.active_page;
	this.collection_id = collection_id;
	this.pages = new Array();
	
	// funcs
	this.Init = tabInitCollection;
	this.GetPageIndex = tabGetPageIndex;
	this.SetSubCollection = tabSetSubCollection;
	this.Change = tabChange;
	this.Show = tabShowCollection;
	this.Hide = tabHideCollection;
	
	// contructor
	var count = pages.length;
	for (var i = 0 ; i < count ; i++) {
		this.pages[i] = new TabPage(pages[i][0], pages[i][1]);
		if (this.pages[i].id == active_page_id) {
			this.active_page = this.pages[i];
		}
	}
	
}

function tabInitCollection() {
	this.body_rel = getObjectById(this.collection_id + '_body');
	var count = this.pages.length;
	for (var i = 0 ; i < count ; i++) {
		this.pages[i].body_rel = this.body_rel;
		this.pages[i].Init();
	}
	this.active_page.Show();
}

function tabGetPageIndex(page_id) {
	var count = this.pages.length;
	for (var i = 0 ; i < count ; i++) {
		if ( this.pages[i].id == page_id) {
			return i;
		}
	}
	return null;
}

function tabSetSubCollection(page_id, sub_collection_id) {
	var count = this.pages.length;
	for (var i = 0 ; i < count ; i++) {
		if (this.pages[i].id == page_id) {
			this.pages[i].sub_collection_id = sub_collection_id;
			return;
		}
	}
}

function tabChange(new_page_id) {
	if (this.active_page.id != null) {
		this.active_page.Hide();
	}
	var i = this.GetPageIndex(new_page_id);
	this.pages[i].Show();
	this.active_page = this.pages[i];

	switchEditors(document.getElementById(new_page_id+"_body"),"on");

}

function tabShowCollection() {
	this.active_page.Show();
	var count = this.pages.length;
	for (var i = 0 ; i < count ; i++) {
		if (this.pages[i].id == this.active_page.id) {
			showObject(this.pages[i].head_a);
		}
		else {
			showObject(this.pages[i].head_b);
		}
	}
}

function tabHideCollection() {
	this.active_page.Hide();
	var count = this.pages.length;
	for (var i = 0 ; i < count ; i++) {
		hideObject(this.pages[i].head_b);
	}
}

// TabPage class
function TabPage(id, sub_collection_id) {
	
	// vars
	this.id = id;
	this.sub_collection_id = sub_collection_id;
	this.head_rel = null;
	this.head_a = null;
	this.head_b = null;
	this.body_rel = null;
	this.body = null;

	// funcs
	this.Init = tabInitPage
	this.Show = tabShowPage;
	this.Hide = tabHidePage;
	this.SetHeadSize = tabSetHeadSize;
	this.SetBodySize = tabSetBodySize;
	
}

function tabInitPage() {
	this.head_rel = getObjectById(this.id + '_head');
	this.head_a = getObjectById(this.id + '_head_a');
	this.head_b = getObjectById(this.id + '_head_b');
	this.body = getObjectById(this.id + '_body');
	this.sub_collection = eval(this.sub_collection_id);
	this.Show();
	this.Hide();
}

function tabShowPage() {
	showObject(this.head_a);
	hideObject(this.head_b);
	showObject(this.body);
	this.SetHeadSize();
	this.SetBodySize();
	if (this.sub_collection) {
		this.sub_collection.Show();
	}
}

function tabHidePage() {
	if (this.sub_collection) {
		this.sub_collection.Hide();
	}
	hideObject(this.head_a);
	showObject(this.head_b);
	hideObject(this.body);
}

function tabSetHeadSize() {
	this.head_rel.style.width = this.head_a.clientWidth;
	this.head_rel.style.height = this.head_a.clientHeight;
}

function tabSetBodySize() {
	this.body_rel.style.width = this.body.clientWidth;
	this.body_rel.style.height = this.body.clientHeight;
}
function postGrpValues() {}