// JavaScript Document
function showDesc(id){ document.getElementById(id).style.display = 'block';}
function hideDesc(id){ document.getElementById(id).style.display = 'none';}
function switchDesc(id, init){ 
	var disp = document.getElementById(id).style.display
	if( disp=='none' || disp=='' )
		showDesc(id);
	else
		hideDesc(id);
}

function recount( o, p ){
	var p;
	var i=1;
	var sum=0;
	
	if( o ){
		if( ! /^[0-9]+$/.test(o.value) ) o.value = 1;
		var num = /^b\[([0-9]+)\]/.exec(o.name);
		document.getElementById('sum'+num[1]).innerHTML = (parseInt(o.value) * parseFloat(p)).toFixed(2) +" PLN";
	}
	
	while( p=document.getElementById("sum"+i) ){
		sum += parseFloat( p.innerHTML.match(/[0-9.]+/) );
		i++;
	}
	document.getElementById('sumInter').innerHTML = sum.toFixed(2) +" PLN";
	
	sum += parseFloat( document.getElementById("sFinal").innerHTML.match(/[0-9.]+/) );
	sum += parseFloat( document.getElementById("pFinal").innerHTML.match(/[0-9.]+/) );
	document.getElementById('sumTotal').innerHTML = sum.toFixed(2) +" PLN";
}

function final( f, p ){
	document.getElementById(f+'Final').innerHTML = p.toFixed(2) +" PLN";
	recount();
}

function setScrollerHeight() {
	if( navigator.appName.indexOf("Microsoft")!=-1 ){
		var winH = document.body.offsetHeight;
	}else{
		var winH = window.innerHeight;
	}

	var h = winH-200-45;
	document.getElementById('wR').style.height = h+"px";
}

function onLoadTrigger(){
	setScrollerHeight();
	recount();
}

window.onload = onLoadTrigger;
window.onresize = setScrollerHeight;

