function verify_mail(mail) {
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	if (emailPattern.test(mail)) {
		return true;
	} else {
		return false;
	}
}

function verify_register_form() {
	mail = document.getElementById('email').value;
	pass = document.getElementById('password').value;
	rpass = document.getElementById('repeat_password').value;
	fname = document.getElementById('firstname').value;
	lname = document.getElementById('lastname').value;
	accept = document.getElementById('accept').checked;
	city = document.getElementById('city').value;

	if ($('#cd').attr('value') == 1) {
		address = document.getElementById('address').value;
		postf = document.getElementById('postcode1').value;
		posts = document.getElementById('postcode2').value;
	}
	
	var errorInt = 0;
	var errorText = "W twoim formularzu wystąpiły błędy:<br /><ul>";
	
	if (mail.length == 0) { 
		errorText = errorText+"<li>Musisz podać adres e-mail</li>";
		errorInt++; 
	} else {
		if (!verify_mail(mail)) { 
			errorText = errorText+"<li>Podany adres e-mail jest nieprawidłowy</li>";
			errorInt++;
		}
	}
	
	if (pass.length < 6) { 
		errorText = errorText+"<li>Musisz podać hasło (conajmniej 6 znaków)</li>";
		errorInt++;
	} else {
		if (rpass.length == 0) {
			errorText = errorText+"<li>Musisz powtórzyć hasło</li>";
			errorInt++;
		}
	}
		
	if (pass.length >= 6 && rpass.length > 0 && pass != rpass) {
		errorText = errorText+"<li>Hasło i powtórzone hasło muszą być takie same</li>";
		errorInt++;
	}
	
	if (fname.length == 0) { 
		errorText = errorText+"<li>Musisz podać imię</li>";
		errorInt++;
	}
	
	if (lname.length == 0) { 
		errorText = errorText+"<li>Musisz podać nazwisko</li>";
		errorInt++; 
	}

	if (city.length == 0) {
		errorText = errorText+"<li>Musisz podać nazwę miejscowości</li>";
		errorInt++;
	}

	if ($('#cd').attr('value') == 1) {
		if (address.length == 0) { 
			errorText = errorText+"<li>Musisz podać adres</li>";
			errorInt++; 
		}
		
		if (postf.length == 0 || posts.length == 0) { 
			errorText = errorText+"<li>Musisz podać kod pocztowy</li>";
			errorInt++; 
		}
	}
	
	if (!accept) { 
		errorText = errorText+"<li>Musisz zaakceptować założenia regulaminu</li>";
		errorInt++; 
	}
		
	errorText = errorText+"</ul><br />";
	
	if (errorInt == 0) {
		return true;
	} else {
		document.getElementById('errorBlock').innerHTML = errorText;
		document.getElementById('errorBlock').style.display = 'block';
		return false;
	} 
}

function verify_edit_form() {
	mail = document.getElementById('email').value;
	pass = document.getElementById('password').value;
	rpass = document.getElementById('repeat_password').value;
	fname = document.getElementById('firstname').value;
	lname = document.getElementById('lastname').value;
	
	var errorInt = 0;
	var errorText = "W twoim formularzu wystąpiły błędy:<br /><ul>";
	
	if (mail.length == 0) { 
		errorText = errorText+"<li>Musisz podać adres e-mail</li>";
		errorInt++; 
	} else {
		if (!verify_mail(mail)) { 
			errorText = errorText+"<li>Podany adres e-mail jest nieprawidłowy</li>";
			errorInt++;
		}
	}
	
	if (pass.length > 0 && pass.length < 6) {
		errorText = errorText+"<li>Hasło musi zawierać conajmniej 6 znaków</li>";
		errorInt++;
	}
	
	if (pass.length >= 6 && rpass.length > 0 && pass != rpass) {
		errorText = errorText+"<li>Hasło i powtórzone hasło muszą być takie same</li>";
		errorInt++;
	}
	
	if (fname.length == 0) {
		errorText = errorText+"<li>Musisz podać imię</li>";
		errorInt++;
	}
	
	if (lname.length == 0) {
		errorText = errorText+"<li>Musisz podać nazwisko</li>";
		errorInt++; 
	}
	
	errorText = errorText+"</ul><br />";
	
	if (errorInt == 0) {
		return true;
	} else {
		document.getElementById('errorBlock').innerHTML = errorText;
		document.getElementById('errorBlock').style.display = 'block';
		return false;
	} 
}

function verify_fast_buy_form() {
	mail = document.getElementById('email').value;
	fname = document.getElementById('firstname').value;
	lname = document.getElementById('lastname').value;
	accept = document.getElementById('accept').checked;
	city = document.getElementById('city').value;

	if ($('#cd').attr('value') == 1) {
		address = document.getElementById('address').value;
		postf = document.getElementById('postcode1').value;
		posts = document.getElementById('postcode2').value;
	}
	
	var errorInt = 0;
	var errorText = "W twoim formularzu wystąpiły błędy:<br /><ul>";
	
	if (mail.length == 0) { 
		errorText = errorText+"<li>Musisz podać adres e-mail</li>";
		errorInt++; 
	} else {
		if (!verify_mail(mail)) { 
			errorText = errorText+"<li>Podany adres e-mail jest nieprawidłowy</li>";
			errorInt++;
		}
	}
		
	if (fname.length == 0) { 
		errorText = errorText+"<li>Musisz podać imię</li>";
		errorInt++;
	}
	
	if (lname.length == 0) { 
		errorText = errorText+"<li>Musisz podać nazwisko</li>";
		errorInt++; 
	}

	if (city.length == 0) {
		errorText = errorText+"<li>Musisz podać nazwę miejscowości</li>";
		errorInt++;
	}
	
	if ($('#cd').attr('value') == 1) { 
		if (address.length == 0) { 
			errorText = errorText+"<li>Musisz podać adres</li>";
			errorInt++; 
		}
		
		if (postf.length == 0 || posts.length == 0) { 
			errorText = errorText+"<li>Musisz podać kod pocztowy</li>";
			errorInt++; 
		}
	}
	
	if (!accept) { 
		errorText = errorText+"<li>Musisz zaakceptować założenia regulaminu</li>";
		errorInt++; 
	}
		
	errorText = errorText+"</ul><br />";
	
	if (errorInt == 0) {
		return true;
	} else {
		document.getElementById('errorBlock').innerHTML = errorText;
		document.getElementById('errorBlock').style.display = 'block';
		return false;
	} 
}

function payment(radio) {
	value = document.getElementById('pay_type').value = radio.value;
	if (value != '') {
		if (value == 'przelew') {
			document.getElementById('payment_form').action = 'platnosc-przelew.html';
		} else {
			document.getElementById('payment_form').action = 'https://www.platnosci.pl/paygw/UTF/NewPayment';
		}
		return true;
	} else {
		return false;
	}
}

function payment_sent() {
	var payment;
	var value = document.getElementById('pay_type').value;
	
	if (value == "c") payment = "Karta kredytowa (Visa, Master Club, Dinners Club)";
	if (value == "m") payment = "mTransfer";
	if (value == "w") payment = "Przelew24";
	if (value == "n") payment = "Multitransfer";
	if (value == "o") payment = "Pekao24Przelew";
	if (value == "i") payment = "Płacę z Inteligo";
	if (value == "d") payment = "Płać z Nordea";
	if (value == "p") payment = "Płać z iPKO";
	if (value == "h") payment = "Płać z BPH";
	if (value == "g") payment = "Płać z ING";
	if (value == "l") payment = "LUKAS e-przelew";
	if (value == "wp") payment = "Płać z Polbank";
	if (value == "wm") payment = "Płać z Millenium";
	if (value == "wk") payment = "Płać z Kredyt Bank";
	if (value == "wg") payment = "Płać z BGŻ";
	if (value == "wd") payment = "Płać z Deutsche Bank";
	if (value == "wr") payment = "Płać z Raiffeisen Bank";
	if (value == "wc") payment = "Płać z Citibank";
	if (value == "przelew") payment = "Zwykły przelew";
	
	return confirm("Jako płatność wybrałeś: " + payment + "\n\nCzy napewno chcesz przejść do płatności?\n");
}
