var tabrows = new Array();
var tabselrow = -1;
var tabselected = new Object;
var tabx = screen.width<1024 ? 146 : 240; // set this one!
var taby = 200; // set this one!

function switchRows(r1, r2) {
	if( r1>=0 && r2>=0 ) {
		var r1pos = GetAbsPosition(document.getElementById(tabrows[r1].name));
		var r2pos = GetAbsPosition(document.getElementById(tabrows[r2].name));
		if( r1!=r2 ) {
			setRowPos(r1, r2pos);
			setRowPos(r2, r1pos);
		}
		return r2pos;
	}
	return null;
}

function setRowPos(r, pos) {
	var row = document.getElementById(tabrows[r].name);
	row.style.left = pos.x;
	row.style.top = pos.y;
}

function buttonClick(obj, again)
{
	for(var c=0; c<tabrows.length; c++)
	{
		var prevtab = null;
		for(var i=0; i<tabrows[c].tabnames.length; i++)
		{
			var tab = document.getElementById(tabrows[c].tabnames[i]);
			var div = document.getElementById(tabrows[c].tabdivs[i]);
			if( tabrows[c].tabnames[i]==obj.id )
			{
				var pos = switchRows(c, tabselrow); tabselrow = c;
				if( pos ) {
					selectTab(tab, prevtab, true, c==tabselrow ? true:false);
					div.style.left = pos.x;
					div.style.top  = pos.y+pos.cy;
					div.style.visibility = 'visible';
					
					tabselected.id = obj.id;
					tabselected.index = i;
					tabselected.row   = c;
				}
			}
			else {
				selectTab(tab, prevtab, false, c==tabselrow ? true:false);
				div.style.visibility = 'hidden';
				div.style.left = 0;
				div.style.top = 0;
			}
			prevtab = tab;
		}
	}
	if( !again ) buttonClick(obj, true);
}

function selectTab(tab, prevtab, sel, rowsel) {
	if( sel==true ) {
		tab.style.borderBottomWidth = '0px';
		tab.style.borderColor = '#000';
		tab.style.background = '#f9f9f9';
		tab.style.color = '#5E83A7';
		
		if( prevtab ) prevtab.style.borderRightColor = '#000';
	}
	else {
		if( rowsel==true ) {
			tab.style.borderBottomWidth = '1px';
			tab.style.borderBottomColor = '#000';
			tab.style.color = '#ff8000';
			
		}
		else tab.style.borderBottomWidth = '0px';
		tab.style.borderTopColor = '#ccc';
		tab.style.borderLeftColor = '#ccc';
		tab.style.borderRightColor = '#ccc';
		tab.style.background = '#fff';
		tab.style.color = '#FF8000';
		
	}
}

// Calculates the object's absolute position, and width and height
function GetAbsPosition(object) {
	var position = new Object;
	position.x = 0;
	position.y = 0;

	if( object ) {
		position.x = object.offsetLeft;
		position.y = object.offsetTop;
		
		if( object.offsetParent ) {
			var parentpos = GetAbsPosition(object.offsetParent);
			position.x += parentpos.x;
			position.y += parentpos.y;
		}
	}

	position.cx = object.offsetWidth;
	position.cy = object.offsetHeight;

	return position;
}

function showMore(id,parent)
{
	var roditelj = document.getElementById(parent);
	
	var obj = document.getElementById(id);
	obj.style.visibility = 'visible';
	obj.style.top = eval(roditelj.clientHeight + 197);
	obj.style.left = eval(roditelj.clientWidth - 208);
	
	var maintd = document.getElementById('maintd');
	var child_height = eval(obj).clientHeight;
	var parent_height = eval(roditelj).clientHeight;
	var position_y = obj.offsetTop;
	var length = parseInt(parent_height) + parseInt(child_height) + 50;
	maintd.style.height = length;
}

function hideMore(id)
{
	var obj = document.getElementById(id);
	obj.style.visibility = 'hidden';
	obj.style.top = 0;
	obj.style.left = 0;
}

function hideAll()
{
	for(var c=0; c<moreDivNames.length; c++)
		hideMore(moreDivNames[c]);
}

function setTdHeight(id)
{
	var maintd = document.getElementById('maintd');
	var height = eval(id).clientHeight;

	maintd.style.height = height + 100;
}

