// Java Document
function Oblicz()
{
	var cena = 0;
	var suma = 0;
	var koszt = 0;
	var podatek = 0;
	var vat = 0;
	var taksa = 0;
	var oplata_sad = 0;
	var prowizja = 0;
	var prowizja_proc = 0;
	
	SprawdzCzyLiczba('cena');
	SprawdzCzyLiczba('prowizja_proc');
	
	cena = parseFloat(document.kalkulator.cena.value);
	prowizja_proc = parseFloat(document.kalkulator.prowizja_proc.value);
	podatek = cena * 0.02;
	taksa = ObliczTakse(cena);
	oplata_sad = ObliczOplataSadowa(cena);
	vat = taksa * 0.22;
	prowizja = prowizja_proc * cena / 100;
	suma = taksa + podatek + vat + oplata_sad + prowizja;
	koszt = cena + suma;
	

//	alert(form = document.forms['kalkulator'].elements['przedmiot'].checked); 
//	alert(); 
	document.kalkulator.podatek.value = podatek.toFixed(2);
	document.kalkulator.vat.value = vat.toFixed(2);
	document.kalkulator.taksa.value = taksa.toFixed(2);
	document.kalkulator.oplata_sad.value = oplata_sad.toFixed(2);
	document.kalkulator.suma.value = suma.toFixed(2);
	document.kalkulator.koszt.value = koszt.toFixed(2);
	document.kalkulator.prowizja.value = prowizja.toFixed(2);
}

function ObliczTakse(cena)
{
	var t = 0;
	if ((cena <= 3000) && (cena > 0))
	{
		t = 100;
	}
	if ((cena > 3000) && (cena <= 10000))
	{
		t = 100 + (cena - 3000) * 0.03;
	}
	if ((cena > 10000) && (cena <= 30000))
	{
		t = 310 + (cena - 10000) * 0.02;
	}
	if ((cena > 30000) && (cena <= 60000))
	{
		t = 710 + (cena - 30000) * 0.01;
	}
	if ((cena > 60000) && (cena <= 1000000))
	{
		t = 1010 + (cena - 60000) * 0.005;
	}
	if (cena > 1000000)
	{
		t = 5710 + (cena - 1000000) * 0.0025;
	}


	if (document.kalkulator.przedmiot2.checked)
		return t;
	else
		return t/2;
}

function ObliczOplataSadowa(cena)
{
	var oplata = 200;
			
	if (document.kalkulator.przedmiot2.checked || document.kalkulator.przedmiot3.checked)
		{
		oplata = oplata;
		}
	if (document.kalkulator.przedmiot.checked)
		{
		oplata = 0;
		}

	return oplata;
}

function WybierzPrzedmiot(nr)
{
	if (nr=="1")
	{
		document.kalkulator.przedmiot2.checked = false;
		document.kalkulator.przedmiot3.checked = false;
		document.kalkulator.przedmiot.checked = true;
	}
	else
	{
		if (nr=="2")
		{
			document.kalkulator.przedmiot2.checked = true;
			document.kalkulator.przedmiot3.checked = false;
			document.kalkulator.przedmiot.checked = false;
		}
		else
		{
			document.kalkulator.przedmiot2.checked = false;
			document.kalkulator.przedmiot3.checked = true;
			document.kalkulator.przedmiot.checked = false;

		}
	}
	Oblicz();
}

function SprawdzCzyLiczba(pole)
{
	var str = document.kalkulator.elements[pole].value;
	zmienna = new RegExp("[0-9]+");
	wynik = str.match(zmienna);
	if (wynik != null)
		document.kalkulator.elements[pole].value = wynik;
	else document.kalkulator.elements[pole].value = "";
}