function blad(txt) {
	if (txt) alert(txt); else alert('Wypełnij formularz!');
}
function zaznacz() {
	var temp4 = document.getElementById('produkty');
	if (temp4.length) {
		for(var i = 0; i < temp4.length; ++i) {
			temp4.options[i].selected = true;
		}
	} else {
		blad();
		return false;
	}
	if (!document.getElementById('wysylka_imie').value) {
		blad('Podaj imię !');
		document.getElementById('wysylka_imie').focus();
		return false;
	}
	if (!document.getElementById('wysylka_nazwisko').value) {
		blad('Podaj nazwisko !');
		document.getElementById('wysylka_nazwisko').focus();
		return false;
	}
	if (!document.getElementById('wysylka_kod_pocztowy').value) {
		blad('Podaj kod pocztowy !');
		document.getElementById('wysylka_kod_pocztowy').focus();
		return false;
	}
	if (!document.getElementById('wysylka_miejscowosc').value) {
		blad('Podaj miejscowość !');
		document.getElementById('wysylka_miejscowosc').focus();
		return false;
	}
	if (!document.getElementById('wysylka_ulica').value) {
		blad('Podaj ulicę !');
		document.getElementById('wysylka_ulica').focus();
		return false;
	}
	if (!document.getElementById('wysylka_nr_budynku_nr_lokalu').value) {
		blad('Podaj numer budynku i/lub lokalu !');
		document.getElementById('wysylka_nr_budynku_nr_lokalu').focus();
		return false;
	}
	if (!document.getElementById('kontakt_telefon').value) {
		blad('Podaj telefon !');
		document.getElementById('kontakt_telefon').focus();
		return false;
	}
	return true;
}
function dodaj() {
	var temp = document.getElementById('spis');
	var temp2 = document.getElementById('produkty');
	var temp3 = document.getElementById('kosz');
	var temp4 = document.getElementById('kosz2');

	var pro = temp.options[temp.selectedIndex].value;

/*
	if (pro == 'Panther P52 SPRAY (300 ml) - 60 zł') {
		alert('Produkt chwilowo niedostępny.');
		return;
	}
	if (pro == 'Panther P52 SUPER TRUCK (300 ml) - 290 zł') {
		alert('Produkt chwilowo niedostępny.');
		return;
	}
*/

	var tep = document.createElement('option');
	tep.value = pro;
	tep.text = pro;
	try {
		temp2.add(tep, null);
	}
	catch(e) {
		temp2.add(tep);
	}

	if (temp2.length) {
		temp2.style.display = '';
		temp4.style.display = '';
		temp4.style.width = '130px';
		temp3.style.display = 'none';
	} else {
		temp2.style.display = 'none';
		temp4.style.display = 'none';
		temp3.style.display = '';
	}
	przelicz();
}
function usun() {
	var temp2 = document.getElementById('produkty');
	var temp3 = document.getElementById('kosz');
	var temp4 = document.getElementById('kosz2');
	for(var i = 0; i < temp2.length; ++i) {
		if (temp2.options[i].selected) temp2.remove(i);
	}

	if (temp2.length) {
		temp2.style.display = '';
		temp4.style.display = '';
		temp4.style.width = '130px';
		temp3.style.display = 'none';
	} else {
		temp2.style.display = 'none';
		temp4.style.display = 'none';
		temp3.style.display = '';
	}

	przelicz();
}
function przelicz() {
	var temp = document.getElementById('lacznie');
	var temp2 = document.getElementById('lacznie2');
	var temp3 = document.getElementById('przesylka_ubezpieczenie');
	var temp4 = document.getElementById('produkty');
	var temp5 = document.getElementById('przesylka_typ');
	var temp6 = document.getElementById('przesylka_gratis');
	var temp7 = document.getElementById('kody');

	var kodyy = new Array();
	var kwora = 0;
	for(var i = 0; i < temp4.length; ++i) {
		kwora += cena(temp4.options[i].value);
		temp4.options[i].selected = true;
		kodyy.push(kod(temp4.options[i].value));
	}
	temp7.innerHTML = kodyy.join('+');

	if ((kwora > 60 && temp5.selectedIndex == 0) || (kwora > 60 && temp5.selectedIndex == 1)) {
		temp6.style.display='';
	} else {
		kwora += cena(temp5.options[temp5.selectedIndex].value);
		temp6.style.display='none';
	}

	if (temp3.checked && (temp5.selectedIndex == 0 || temp5.selectedIndex == 1 || temp5.selectedIndex == 2 || temp5.selectedIndex == 3)) {
		if (kwora < 100) {
			kwora += 6;
		} else if (kwora < 150) {
			kwora += 8;
		} else if (kwora < 200) {
			kwora += 9;
		} else kwora += Math.round(kwora * 0.04, 2);
	}

	temp.innerHTML = format(kwora)+' zł';
	temp2.value = kwora;
}
function format(cena) {
	return cena;
}
function cena(ko) {
	op = ko.split(' - ');
	op = op[1];
	op = op.split(' zł');
	ko = op[0];
	ko = Math.round(ko);
	return ko;
}
function kod(ko) {
	op = ko.split(' ');
	ko = op[1];
	if (op[2] == 'ECO-POWER') ko += 'E';
	if (op[2] == 'SPORT') ko += 'S';
	if (op[2] == 'SUPER') ko += 'ST';
	return ko;
}
