function gval(id) { return document.getElementById(id).value; }
function sval(id, val) { document.getElementById(id).value = val; }
function scol(id, col) { document.getElementById(id).style.background = '#'+col; }
function dott(num)
{
	num = Math.ceil(num).toString();
	var length = num.length;
	var string = "";
	var i;
	
	for(i = (length - 3); i >= 0; i = i - 3)
	{
		if(string != "") string = num.substr(i, 3) + "." + string; else string = num.substr(i, 3) + string;
	}
	string = num.substr(0, (length % 3)) + "." + string;
	if(string.substr(0, 1) == ".") string = string.substr(1, (string.length - 1));
	if(string.substr(0, 2) == "-.") string = '-'+string.substr(2, (string.length - 2));
	if(string.substr(0, 2) == "0.") string = "0";
	
	return string+",-";
}
function calc1()
{
	if(isNaN(gval("tc11")))
	{
		document.getElementById("calc2").style.display = "none";
		document.getElementById("calc3").style.display = "none";
		scol("tc11", "F3D3D3");
		return 0;
	}
	var pcena = parseInt(gval("tc11"), 10);
	
	var provize = pprovize = iprovize = 0;
	sval("tc12", dott(pcena));
	if(pcena <= 600000) provize = 30000;
	else if(pcena > 600000 && pcena <= 5000000) pprovize = 5;
	else if(pcena > 5000000) iprovize = 1;
	
	if(iprovize != 0)
	{
		sval("tc13", "individuálně");
		sval("tc14", "individuálně");
		sval("tc15", "individuálně");
	}
	else if(pprovize != 0)
	{
		sval("tc13", pprovize+"%");
		sval("tc14", dott(pcena + (pcena * pprovize / 100)));
		sval("tc15", dott(pcena + ((pcena * pprovize / 100) * 1.19)));
	}
	else
	{
		sval("tc13", dott(provize));
		sval("tc14", dott(pcena + provize));
		sval("tc15", dott(pcena + (provize * 1.19)));
	}
	sval("tc22", dott(pcena / 2));
	document.getElementById("calc2").style.display = "block";
	scol("tc11", "FFFFFF");
}
function calc2()
{
	var pcena = parseInt(gval("tc11"), 10);
	var zaloha = parseInt(gval("tc21"), 10);
	if(zaloha < 10000 || (zaloha > pcena / 2) || isNaN(gval("tc21")))
	{
		document.getElementById("calc3").style.display = "none";
		scol("tc21", "F3D3D3");
		return 0;
	}
	sval("tc31", dott(zaloha));
	if(zaloha == 100000)
		mes = new Array(0, 0, 0, 4, 4, 4);
	else
		mes = new Array(3, 3, 3, 4, 4, 4);
	var i, urok = 0;
	for(i = 0; i <= 5; i++)
	{
		urok = urok - (mes[i] * zaloha / 100)
		sval('tc41'+i, dott(pcena - zaloha + urok));
		sval('tc42'+i, dott(pcena + urok));
		sval('tc43'+i, dott(urok));
		if(urok == 0) scol('tc43'+i, "E7F8FE"); else scol('tc43'+i, "EBEBE4");
	}
	document.getElementById("calc3").style.display = "block";
	scol("tc21", "FFFFFF");
}