// Jacek Więicki 2006-04-30 (wersja 2006-07-09)

/** funkcja sprawdza rozdzielczość ekranu */
function checkScreen()
{
	var cookieName = "screen_alert_displayed";
	var cookieValue = readCookie(cookieName);

	var width = screen.width;
	var height = screen.height;
	
	if(width < 1024)
	{
		if(cookieValue != "true")
		{
			alert(
				"Portal przeznaczony jest do pracy w rozdzielczości ekranu 1024x768 pikseli lub wyższej.\n" +
				"Rozdzielczość Twojego monitora to " + width + "x" + height + " pikseli.\n" +
				"Zalecamy zwiększenie rozdzielczoęci lub przewijanie ekranu w celu zobaczenia całej szerokości Portalu.");
			setCookie(cookieName, "true");
		}
	}
}

/** zwraca pozycję obiektu w poziomie */
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

/** zwraca pozycję obiektu w pionie */
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/** wypisuje do dokumentu zakładki */
function writeTabs(tabNames, tabTitles, tabUrls, tabSelections, tabSpecials, tabIndex, width)
{
	var tabsDiv = document.getElementById("tabs_div");
	var tBody = document.createElement("tbody");
	var table = document.createElement("table");
	var row = document.createElement("tr");
	
	table.border = 0;
	table.cellPadding = 0;
	table.cellSpacing = 0;
	//table.setAttribute("name", "tabs_table");
	
	var activeRow = false;
	for(i = tabIndex; i < tabTitles.length; i++)
	{
		if(tabSelections[i])
		{
			activeRow = true;
			break;
		}
	}
	
	var firstChild = tabsDiv.firstChild;
	if(activeRow)
		tabsDiv.appendChild(table);
	else
	{
		if(firstChild != null)
			tabsDiv.insertBefore(table, firstChild);
		else
			tabsDiv.appendChild(table);
	}
	table.appendChild(tBody);
	tBody.appendChild(row);
	
	var emptyCell = document.createElement("td");
	var leftCell;
	var centreCell;
	var rightCell;
	
	var leftClass;
	var centreClass;
	var rightClass;
	
	for(i = tabIndex; i < tabTitles.length; i++)
	{
		if(tabSelections[i])
		{
			leftClass = "LTabLeft";
			centreClass = "LTab";
			rightClass = "LTabRight";
		}
		else
		{
			if(!tabSpecials[i])
			{
				leftClass = "LTabLeftLow";
				centreClass = "LTabLow";
				rightClass = "LTabRightLow";
			}
			else
			{
				leftClass = "LTabLeftLowSpecial";
				centreClass = "LTabLowSpecial";
				rightClass = "LTabRightLowSpecial";
			}
		}

		leftCell = document.createElement("td");
		leftCell.className = leftClass;
		//leftCell.innerHTML = "&nbsp;";
		leftCell.setAttribute("nowrap", "true");
		
		centreCell = document.createElement("td");
		centreCell.className = centreClass;
		if(tabSelections[i])
			centreCell.innerHTML = tabNames[i] + "&nbsp;&nbsp;";
		else
			centreCell.innerHTML = "<a href=\"" + tabUrls[i] + "\">" + tabNames[i] + "</a>&nbsp;&nbsp;";
		centreCell.setAttribute("nowrap", "true");
		centreCell.setAttribute("align", "center");
		centreCell.setAttribute("title", tabTitles[i]);
		
		rightCell = document.createElement("td");
		rightCell.className = rightClass;
		//rightCell.innerHTML = "&nbsp;";
		rightCell.setAttribute("nowrap", "true");
		
		row.appendChild(leftCell);
		row.appendChild(centreCell);
		row.appendChild(rightCell);
		
		row.appendChild(emptyCell);
		if(findPosX(emptyCell) > width)
		{
			table.setAttribute("width", "100%");
		
			row.removeChild(leftCell);
			row.removeChild(centreCell);
			row.removeChild(rightCell);
			row.removeChild(emptyCell);
			
			writeTabs(tabNames, tabTitles, tabUrls, tabSelections, tabSpecials, i, width);
		}
		else
			row.removeChild(emptyCell);
	}
}
