var prowizja_VAT_stawka = 22;

function licz() {
var a = "0123456789";
var taksa_notarialna = 0;
var oplata_skarbowa = 0;
var VAT_od_taksy = 0;
var prowizja = 0;
var prowizja_procent = 0;
var oplata_sadowa = 200;
var oplaty_dod = 0;
var suma = 0;
var cenaN=0;
//form = document.forms['kalkulator'];
//wartosc = document.forms['kalkulator'].elements['cenaN'].value;
wartosc = document.getElementById('cenaN').value;



i = wartosc.length - 1;
err = true;
j = 0;
for (var j = 0; j < a.length; j++) {
if (wartosc.charAt(i) == a.charAt(j))
err = false;
}
if (err)
document.getElementById('cenaN').value=wartosc.substring(0,i);

if ((wartosc.length == 1) && (wartosc == 0)) {
document.getElementById('cenaN').value = wartosc.substring(0,i);
}



cenaN = parseFloat(wartosc)
//cenaN = wartosc;



if (wartosc.length == 0)
cenaN = 0;

if (document.getElementById('oplata1').checked)
//if (document.forms['kalkulator'].elements['oplata1'].checked)
oplata_skarbowa = cenaN * 0.02;
else
oplata_skarbowa = cenaN * 0.02;

oplata_skarbowa = (Math.round(oplata_skarbowa * 100))/100;
if (!isNaN(oplata_skarbowa))
//document.forms['kalkulator'].elements['oplataskarbowa'].value = oplata_skarbowa.toString(10);
document.getElementById('oplataskarbowa').value = oplata_skarbowa.toString(10);



/*
//if (document.forms['kalkulator'].elements['oplata1'].checked) {
if (document.getElementById('oplata1').checked) {
	if ((cenaN > 0) && (cenaN <= 5000))
		taksa_notarialna = 200
	if ((cenaN > 5000) && (cenaN <= 15000))
		taksa_notarialna = (200 + ((cenaN - 5000)*0.03))/2;
	if ((cenaN > 15000) && (cenaN <= 30000))
		taksa_notarialna = (500 + ((cenaN - 15000)*0.02))/2;
	if ((cenaN > 30000) && (cenaN <= 60000))
		taksa_notarialna = (800 + ((cenaN - 30000)*0.01))/2;
	if ((cenaN > 60000) && (cenaN <= 1000000))
		taksa_notarialna = (1100 + ((cenaN - 60000)*0.005))/2;
	if (cenaN > 1000000)
		taksa_notarialna = (5800 + ((cenaN - 1000000)*0.0025))/2;

}
else if (document.getElementById('oplata2').checked) {
//else if (document.forms['kalkulator'].elements['oplata2'].checked) {
	if ((cenaN > 0) && (cenaN <= 5000))
		taksa_notarialna = 200/2
	if ((cenaN > 5000) && (cenaN <= 15000))
		taksa_notarialna = (200 + (cenaN - 5000)*0.03);
	if ((cenaN > 15000) && (cenaN <= 30000))
		taksa_notarialna = (500 + (cenaN - 15000)*0.02);
	if ((cenaN > 30000) && (cenaN <= 60000))
		taksa_notarialna = (800 + (cenaN - 30000)*0.01);
	if ((cenaN > 60000) && (cenaN <= 1000000))
		taksa_notarialna = (1100 + (cenaN - 60000)*0.005);
	if (cenaN > 1000000)
		taksa_notarialna = (5800 + (cenaN - 1000000)*0.0025);
}

taksa_notarialna = (Math.round(taksa_notarialna * 100))/100;


if (!isNaN(taksa_notarialna))
//document.forms['kalkulator'].elements['taksanotarialna'].value = taksa_notarialna.toString(10);
document.getElementById('taksanotarialna').value = taksa_notarialna.toString(10);
*/



	// Taksa notarialna OK
	//======================================
	if (cenaN <= 0)
		taksa_notarialna = 0;
	else if (cenaN <= 3000)
		taksa_notarialna = 100;
	else if (cenaN <= 10000)
		taksa_notarialna = 100 + (cenaN - 3000) * 0.03;
	else if (cenaN <= 30000)
		taksa_notarialna = 310 + (cenaN - 10000) * 0.02;
	else if (cenaN <= 60000)
		taksa_notarialna = 710 + (cenaN - 30000) * 0.01;
	else if (cenaN <= 1000000)
		taksa_notarialna = 1010 + (cenaN - 60000) * 0.005;
	else
		taksa_notarialna = 5710 + (cenaN - 1000000) * 0.0025;

	// zaokraglenie przed znizka i po znizce
	taksa_notarialna = Math.round(taksa_notarialna * 100) / 100;

	if (document.getElementById('oplata1').checked) taksa_notarialna = taksa_notarialna/2;
	if (document.getElementById('oplata2').checked) taksa_notarialna = taksa_notarialna/2;
	if (document.getElementById('ksiega').checked) taksa_notarialna = taksa_notarialna/2;

	// ponowne zaokraglenie po znizce
	taksa_notarialna =Math.round(taksa_notarialna * 100) / 100;

    if (!isNaN(taksa_notarialna)) document.getElementById('taksanotarialna').value = taksa_notarialna.toString(10);

	//form.elements['taksanotarialna'].value = strzero(opl_not / cena_waluty, 2);
//---------------------------


























prowizja_procent =document.getElementById('prowizjaprocent').value;

i = prowizja_procent.length - 1;



err = true;
j = 0;
for (var j = 0; j < a.length; j++) {
if (prowizja_procent.charAt(i) == a.charAt(j))
err = false;
}
if ((prowizja_procent.charAt(i) == ",") || (prowizja_procent.charAt(i) == ".")) {
document.getElementById('prowizjaprocent').value = prowizja_procent.substring(0,i) + ".";
err = false }


if (err)
document.getElementById('prowizjaprocent').value = prowizja_procent.substring(0,i);

if ((wartosc.length == 1) && (wartosc == 0)) {
//document.getElementById('prowizjaprocent').value = prowizja_procent.substring(0,i);
}



prowizja_procent = parseFloat(prowizja_procent);
if (prowizja_procent.length == 0)
prowizja_procent = 0;

prowizja = cenaN * prowizja_procent * 0.01;

prowizja = (Math.round(prowizja * 100))/100;
if (!isNaN(prowizja))
document.getElementById('prowizja').value = prowizja.toString(10);


	// VAT od taksy
    VAT_od_taksy = taksa_notarialna * 0.22;
    VAT_od_taksy = (Math.round(VAT_od_taksy * 100))/100;
    if (!isNaN(VAT_od_taksy)) document.getElementById('vatodtaksy').value= VAT_od_taksy.toString(10);


	// VAT od prowizji
	// =====================================
	prowizja_VAT = Math.round(prowizja * prowizja_VAT_stawka) / 100;




















if (document.getElementById('oplata1').checked && document.getElementById('ksiega').checked==false) {

oplata_sadowa = 0;
//document.forms['kalkulator'].elements['oplatasadowa'].value = "---";
document.getElementById('oplatasadowa').value = "---";
}
else if (document.getElementById('oplata2').checked || document.getElementById('ksiega').checked==true) {
	if ((cenaN > 0) && (cenaN <= 10000))
	oplata_sadowa = cenaN * 0.08;
	if ((cenaN > 10000) && (cenaN <= 50000))
	oplata_sadowa = 800 + ((cenaN - 10000) * 0.07);
	if ((cenaN > 50000) && (cenaN <= 100000))
	oplata_sadowa = 3600 + ((cenaN - 50000) * 0.06);
	if (cenaN > 100000)
	oplata_sadowa = 6600 + ((cenaN - 100000) * 0.05);

oplata_sadowa = oplata_sadowa * 0.2;
if (oplata_sadowa < 20)
oplata_sadowa = 20;
if (oplata_sadowa > 100000)
oplata_sadowa = 100000;
oplata_sadowa = (Math.round(oplata_sadowa * 100))/100;

oplata_sadowa=200; //zawsze od 1 marca

	if (!isNaN(oplata_sadowa) )
	document.getElementById('oplatasadowa').value = oplata_sadowa.toString(10);
	else
	document.getElementById('oplatasadowa').value = "";
}
oplaty_dod = taksa_notarialna + oplata_skarbowa + VAT_od_taksy + prowizja_VAT + oplata_sadowa + prowizja;
oplaty_dod = (Math.round(oplaty_dod * 100))/100;
if (!isNaN(oplaty_dod))
document.getElementById('oplatydod').value= oplaty_dod.toString(10);

suma = cenaN + oplaty_dod;
suma = (Math.round(suma * 100))/100;

if (!isNaN(suma))
//document.forms['kalkulator'].elements['suma'].value = suma.toString(10);
document.getElementById('suma').value= suma.toString(10);
}
function change(r1,r2) {
r1.checked = false;
r2.checked = false;
}

