/* Kod w tym pliku zajmuje się dopasowywaniem
 * ekrany ankiety do rozmiarów okna 
 */

function myWindowHeight() {
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

function myWindowWidth() {
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}

var lastX = -1;
var lastY = -1;

function refreshStartSize() {
	var y = myWindowHeight();
	var x = myWindowWidth();
	if (x == lastX && y == lastY) {
		return;
	}
	lastX = x;
	lastY = y

	var topLeft = document.getElementById('topLeft');
	var topRight = document.getElementById('topRight');
	var topCenter = document.getElementById('topCenter');
	var topDiv = document.getElementById('top');
	
	var divBottom = document.getElementById('divBottom');
	var bottomLeft = document.getElementById('divBottomLeft');
	var bottomRight = document.getElementById('divBottomRight');
	
	topDiv.style.width = x + 'px';

	/* Ustawienie elementów w topie */

	topLeft.style.left = '0px';
	topRight.style.right = '0px';

	topLeft.style.top='0px';
	topRight.style.top='0px';
	topCenter.style.top='0px';

	var topY = topDiv.offsetHeight;
	
	topLeft.style.height = topY + 'px';
	topRight.style.height = topY + 'px';
	topCenter.style.height = topY + 'px';
			
	topCenter.style.left = topLeft.offsetWidth + 'px';

	topCenter.style.width = x - topLeft.offsetWidth - topRight.offsetWidth + 'px';
	
	divBottom.style.width = x + 'px';
	bottomRight.style.top = '0px';
	bottomLeft.style.top = '0px';
	bottomRight.style.right = '0px';
	bottomLeft.style.left = '0px';
	bottomLeft.style.width = x - bottomRight.offsetWidth + 'px';
	
	bottomRight.style.height = y - topDiv.offsetHeight + 'px';
	bottomLeft.style.height = y - topDiv.offsetHeight + 'px';
	
	var divContent = document.getElementById('divContent');
	var divNavi = document.getElementById('divNavi');
	
	divContent.style.width = x - bottomRight.offsetWidth + 'px';
	divNavi.style.width = x - bottomRight.offsetWidth + 'px';
	divContent.style.height = y - topDiv.offsetHeight - divNavi.offsetHeight + 'px';
	
	var divButtons = document.getElementById('divButtons');
	var divButtonsAdd = document.getElementById('divButtonsAdd');
	divButtons.style.left = '0px';
	divButtons.style.top = '0px';
	divButtonsAdd.style.right = '0px';
	divButtonsAdd.style.top = '0px';
	divButtonsAdd.style.width = '60%';
	
	var divStatus = document.getElementById('divProgress');
	divStatus.style.width = x - bottomRight.offsetWidth - 20 + 'px';
}

window.onresize = refreshStartSize;
refreshStartSize();

