
var currentTabId = 0;
/**
 * 
 */
function selectTab(tabId)
{
	try {
		if (tabId == currentTabId) {
			return;
		}
		var tabs = document.getElementById('tabs');
		var tabsTotal = tabs.getElementsByTagName('LI').length;
		var contentAreas = document.getElementById('contentAreas');
	} catch(error) {
		alert(error);
	}
	
	// Deselect all tabs
	for (var i = 0; i < tabs.getElementsByTagName('LI').length; i++) {
		try {
			var currentTab = tabs.getElementsByTagName('LI')[i];
			currentTab.className = '';
		} catch(e) {
			//alert('Error in selectTab ' + e.description);
		}
	}
	
	// Select tab that was clicked
	//alert('tabId == ' + tabId + '\ntabsTotal == ' + tabsTotal);
	try {
		var selectedClassName = (tabId == 0) ? 'firstSelected' : 'selected';
		addCssClass(tabs.getElementsByTagName('LI')[tabId], selectedClassName);
		if (tabId < tabsTotal - 1) {
			var nextClass = (tabId == tabsTotal - 2) ? 'nextLast' : 'next';
			addCssClass(tabs.getElementsByTagName('LI')[tabId + 1], nextClass);
		}
		if (tabId > 0) {
			if (tabId == 1) {
				addCssClass(tabs.getElementsByTagName('LI')[tabId - 1], 'prevFirst');
			} else {
				addCssClass(tabs.getElementsByTagName('LI')[tabId - 1], 'prev');
				//addCssClass(tabs.getElementsByTagName('LI')[0], 'borderless');
			}
		}
		if (tabId == (tabsTotal - 1)) {
			if (tabs.getElementsByTagName('LI')[tabId].className.indexOf('selected') > -1) {
				tabs.getElementsByTagName('LI')[tabId].className = 'lastSelected';
			}
		} else {
			//tabs.getElementsByTagName('LI')[tabsTotal - 1].className = 'last';
			if (tabs.getElementsByTagName('LI')[tabsTotal - 1].className.indexOf('nextLast') < 0) {
				addCssClass(tabs.getElementsByTagName('LI')[tabsTotal - 1], 'last');
			}
		}
	} catch(e) {
		//alert('2. ' + e.description);
	}
	
	try {
		// Hide all visible contentAreas
		for (var i = 0; i < contentAreas.childNodes.length; i++) {
			if (contentAreas.childNodes[i].nodeName == 'DIV') {
				contentAreas.childNodes[i].style.display = 'none';
			}
		}
		
		document.getElementById('contentArea'+currentTabId).style.display = 'none';
		document.getElementById('contentArea'+tabId).style.display = 'block';
	} catch(e) {
		alert('3. ' + e.description);
	}

	currentTabId = tabId;
}

/**
 * 
 */
function addCssClass(element, cssClassName)
{
	element.className += ' ' + cssClassName;
}