<!--
// Copyright (c) 2007
// Author: nguyenhoaivien <nguyenhoaivien@yahoo.com>
// Company: KCD Design & Advertising <kcd-design.com - nhvien@kcd-design.com>
// Date: 23/8/2007

var Tab = {
	useCookie: true, // Use cookie to store information
	define:function(tabid, dselected) {
		this[tabid + '-tabs'] = null;
		this.addEvent(window, function(){Tab.init(tabid, dselected)},'load');
	},
	show:function(tabid, target) {
		var active_page = tabid + '-activePage';
		if(typeof this[active_page] != 'undefined') {
			this[tabid + '-activeTab'].className = '';
			document.getElementById(this[active_page]).style.display = 'none';
		}
		target.className = 'active';
		if(selected = target.getAttribute('rel')) {
			this[active_page] = selected;
			this[tabid + '-activeTab'] = target;
			if(this.useCookie) this.setCookie('Tab-' + tabid, target.tabid);
			document.getElementById(selected).style.display='block';
		}
	},
	addEvent:function(target, func, task) {
		var task = window.addEventListener ? task : 'on' + task;
		if(target.addEventListener) target.addEventListener(task, func, false);
		else if(target.attachEvent) target.attachEvent(task, func);
	},
	init:function(tabid, dselected) {
		var wait = true;
		var items = document.getElementById(tabid).getElementsByTagName('li');
		this[tabid + '-tabs'] = items;
		if(this.useCookie && dselected=='auto') dselected = this.getCookie('Tab-' + tabid);
		for(var i=0; i < items.length; i++) {
			if(items[i].getAttribute('rel')) {this[tabid + '-tabs'][i].hasSubContent = true;}
			items[i].tabid = i;
			items[i].onmouseout = function(){if(Tab[tabid+'-activeTab'] != this) this.className='';  }
			items[i].onmouseover = function(){if(Tab[tabid+'-activeTab'] != this) this.className='over';  }
			items[i].onclick = function() { Tab.show(tabid, this); }
			if(wait && dselected=='auto') {
				wait = false;
				Tab.show(tabid, items[i]);
			} else if (parseInt(dselected)==i) {
				Tab.show(tabid, items[i]);
			}
		}
	},
	// cookie functions
	setCookie:function(sName, sValue, nDays) {
		var expires = "";
		if(nDays) {
			var d = new Date();
			d.setTime(d.getTime() + nDays*24*60*60*1000);
			expires = "; expires=" + d.toGMTString();
		}
		document.cookie = sName + "=" + sValue + expires + "; path=/";
	},
	getCookie:function(sName) {
		var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)");
		var res = re.exec(document.cookie );
		return res != null ? res[3] : null;
	},
	removeCookie:function(sName) {
		setCookie(name, "", -1);
	}
}
-->