var bgWidth = 105; // konstanta
var bgHeight = 52; // + atimti konstantas - paddingus, jei reikia
var footHeight = 140; // footerio aukstis

var minWidth = 735; // minimalus lenteles plotis, atemus 1 bgWidth 
var minHeight = 364; // minimalus lenteles aukstis, atemus 1 bgHeight

function resizeTable (secPage) { // perduodamas submeniu resizinimas
	var bodyWidth= document.body.clientWidth;
	var countw = (bodyWidth) / bgWidth; 		 
	var elementWidth = Math.round (countw-1) * bgWidth;

	// min. plocio apsauga
	if (elementWidth > minWidth) {
		setWidth (elementWidth, 'tableID'); // const
		setMenuWidth (elementWidth);
	}
	else {
		setWidth (minWidth, 'tableID'); // const
		setMenuWidth (minWidth);
	}
	
	// aukscio kontroliavimas
	var bodyHeight = document.body.clientHeight - footHeight;
	
	// indexPage ?
	if (!secPage){
		var counth = (bodyHeight) / bgHeight;
		var elementHeight = Math.round (counth) * bgHeight;
		// min. aukscio apsauga
		if (elementHeight > minHeight) {
			setHeight (elementHeight, 'tableID'); // const
		}
		else {
			setHeight (minHeight, 'tableID'); // const
		}
	}
	// secPage = true
	else {
		var contHeight = getOffsetHeight ('tableID'); // const
		setHeight (0, 'fillID');
		if (contHeight >= bodyHeight) {
			// skaiciuojame pagal kontenta
			var counth = contHeight / bgHeight;
			var elementHeight = Math.round (counth-1) * bgHeight;
			setHeight (elementHeight, 'tableID'); // const
			setContentHeight ('contentID'); // const
		}
		else {
			// skaiciuojame pagal langa
			// + min. aukscio apsauga
			var counth = bodyHeight / bgHeight;
			var elementHeight = Math.round (counth) * bgHeight;
			if (elementHeight > minHeight) {
				setHeight (elementHeight, 'tableID'); // const
				setContentHeight ('contentID'); // const
			}
			else {
				setHeight (minHeight, 'tableID'); // const
				setContentHeight ('contentID'); // const
			}
		}
	}
}

// /////////////////////////////////////////////////////////////////
// WIDTH FUNCTIONS
// /////////////////////////////////////////////////////////////////
function setWidth (elementWidth, elementID) {
	var thisElement = document.getElementById (elementID);
	thisElement.style.width = elementWidth;
}
function setMenuWidth (elementWidth) {
	var menuSpacerCell = document.getElementById ('menuSpacerCell'); // const
	var menuCell = document.getElementById ('menuCell'); // const
	var count = (elementWidth - menuCell.offsetWidth) / (bgWidth * 2);
	menuSpacerCell.style.width = Math.round (count) * bgWidth;
}

// /////////////////////////////////////////////////////////////////
// HEIGHT FUNCTIONS
// /////////////////////////////////////////////////////////////////
function setContentHeight (elementID) {
	var offsetHeight = getOffsetHeight (elementID);
	var count = (offsetHeight) / bgHeight;
	var trueHeight = Math.round (count) * bgHeight; 
	setHeight (trueHeight, 'fillID'); // const 
}
function setHeight (elementHeight, elementID) {
	var thisElement = document.getElementById (elementID);
	thisElement.style.height = elementHeight;
}
function getOffsetHeight (elementID) {
	var thisElement = document.getElementById (elementID);
	return thisElement.offsetHeight;
}
// /////////////////////////////////////////////////////////////////
// OTHERS FUNCTIONS
// /////////////////////////////////////////////////////////////////
function openBrWindow (theURL,winName,features) {
  window.open(theURL,winName,features);
}

function printFlash() {
document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" WIDTH=460 HEIGHT=120>");
document.write("<PARAM NAME=movie VALUE=\"client/img/indexen.swf\"><PARAM NAME=quality VALUE=high><param name=\"wmode\" value=\"transparent\" />");
document.write("<EMBED src=\"client/img/indexen.swf\" wmode=transparent quality=high WIDTH=460 HEIGHT=120 TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT><br>");
}

function printNoFlash() {
document.write('<img src="client/img/flash_non_bug.png" width=390 height=120><br>');
}