﻿		function roundNumber(num, dec) {
			var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
			return result;
		}
	
		function przelicz(ilosc) {
		var cena=0;
		if(isNaN(ilosc) || (ilosc < 1)){
			window.alert("podano złą wartość");
			return false;
			}
		else {
			if ((ilosc > 0) && (ilosc <= 4)) cena = roundNumber(ilosc * 818.85,2);
			if ((ilosc >= 5) && (ilosc <= 9)) cena = roundNumber(ilosc * 802.47,2);
			if ((ilosc >= 10) && (ilosc <= 14)) cena = roundNumber(ilosc * 777.91,2);
			if ((ilosc >= 15) && (ilosc <= 19)) cena = roundNumber(ilosc * 761.53,2);
			if ((ilosc >= 20) && (ilosc <= 24)) cena = roundNumber(ilosc * 745.15,2);
			if ((ilosc >= 25) && (ilosc <= 29)) cena = roundNumber(ilosc * 728.78,2);
			if ((ilosc >= 30) && (ilosc <= 49)) cena = roundNumber(ilosc * 720.59,2);
			if (ilosc >= 50) cena = roundNumber(ilosc * 696.02,2);

			document.getElementById('kwotaNetto').value = cena;
			document.getElementById('kwota').value = roundNumber((cena*22/100) + cena,2);
			document.getElementById('wartoscNetto').innerHTML = cena;
			document.getElementById('wartosc').innerHTML = roundNumber((cena*22/100) + cena,2);
			
			}
			return true;
		}

		function nextStep(step) {
			if (!przelicz(document.f.ilosc.value)) {
				return false;
			};

			if (step == 1) {
				if (validateForm(document.getElementById('f')) == false) {
					return false;
				};
			}
		
			if (step == 0) {
				if (document.f.zgoda.checked == false) {
					window.alert("Aby złożyć zamówienia należy zakceptować regulamin sklepu.");
					return false;
				};
			}
			
			document.getElementById('krok').value = parseInt(step)+1;
			document.f.submit();
			
			
		}

		function prevStep(step) {
			document.getElementById('krok').value = parseInt(step)-1;
		}
		
		function checkField(field, desc) {
			if (field.value == "") { //This checks to make sure the field is not empty
			   alert("Pole '" + desc +"' nie może być puste."); //Informs user of empty field
			   field.focus( ); //This focuses the cursor on the empty field
			   return false; //This prevents the form from being submitted
			}
			return true;   
		}
		
		function validateFirmForm(form) { //This is the name of the function
			if (!checkField(form.F_firm		, "Firma")) {return false;};
			if (!checkField(form.F_nipp		, "NIP")) {return false;};
			if (!checkField(form.F_forename	, "imię")) {return false;};
			if (!checkField(form.F_surname	, "nazwisko")) {return false;};
			if (!checkField(form.F_street	, "ulica")) {return false;};
			if (!checkField(form.F_street_n1	, "numer domu")) {return false;};
			if (!checkField(form.F_city		, "miejscowość")) {return false;};
			if (!checkField(form.F_postcode	, "kod pocztowy")) {return false;};
			return true;
		}
		
		function validateForm(form) { //This is the name of the function
			if (form.qType[1].checked == true) {
				if (!checkField(form.firmm		, "Firma")) {return false;};
				if (!checkField(form.NIPP		, "NIP")) {return false;};
			};
			if (!checkField(form.forename	, "imię")) {return false;};
			if (!checkField(form.surname	, "nazwisko")) {return false;};
			if (!checkField(form.street		, "ulica")) {return false;};
			if (!checkField(form.street_n1	, "numer domu")) {return false;};
			if (!checkField(form.city		, "miejscowość")) {return false;};
			if (!checkField(form.postcode	, "kod pocztowy")) {return false;};
			if (!checkField(form.city		, "miejscowość")) {return false;};
			if (!checkField(form.email		, "e-mail")) {return false;};
			if (form.qType[1].checked == true) {
				if (!(validateFirmForm(form))) {return false;};
			}
		}