function updateAjax(contener,url,loader) {
	
	$.ajax({
		
		type: "GET",
		url: url,
		beforeSend: function(req) {
			if(loader == true) {
				$(contener).addClass("tc");
				$(contener).html('<img src="images/ajax-loader.gif" alt="Proszę czekać"/>');
			}
		},
		success: function (resp) {
			$(contener).html(resp);
		},
		complete: function (req,status) {
			$(contener).removeClass("tc");			
		}
		
	})
	
}

// czy znaleziono blad
var foundErr;
var foundErrMail;
// wiadomosc o bledzie
var wiadomosc = "Wypełnij pola:\n";
var email;
//sprawdza czy pola maja znaki dozwolone
function checTextField(pole){
	var checkOK = "AĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŻŹaąbcćdeęfghijklłmnńoópqrsśtuvwxyzżź0123456789.,: \s\n\t";
	var checkStr = pole.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	if (!allValid) {
		alert("Proszę wpisywać tylko litery i liczby w pole "+pole.name);
		return (false);
	}
	else {
		return (true);
	}

}

function checkURL(pole) {
	
	var filter = /^(http:\/\/www\.mdasystems\.pl\/)[a-zA-Z0-9,_\.\-]*$/;
	if (!filter.test(pole.value)) {
		alert("Podany link jest nieprawidłowy.");
		return false;
	}
	else {
		return true;
	}
	
}

function checkPhoneField(pole){
	var checkOK = "0123456789-+ ";
	var checkStr = pole.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length) {
			allValid = false;
			break;
		}
	}
	if (!allValid) {
		alert("Proszę wpisywać tylko liczby w pole "+pole.name);
		return (false);
	}
	else {
		return (true);
	}

}

//sprawdza adres e-mail
function checkEmail(email) {
	var filter = /^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/;
	if (!filter.test(email.value)) {
		alert("Podano nieprawidłowy adres e-mail");
		return false;
	}
	else{
		return true;
	}
}

//funkcja glowna - do sprawdzania calego form
function check_form() {
	wiadomosc = "Wypełnij pola:\n";
	foundErr = false;
	foundErrMail = false;
	if (document.getElementById('nadawca').value == "") {
		wiadomosc = wiadomosc + "- adres nadawcy\n";
		foundErr = true;
	}
	else{
		if(!checkEmail(document.getElementById('nadawca')))
		{
			foundErrMail = true;
		}
	}
	if (document.getElementById('telefon').value == "") {
		wiadomosc = wiadomosc + "- telefon\n";
		foundErr = true;
	}
	//sprawdzanie czy sa wprowadzone prawidlowe znaki
	else{
		if(!checkPhoneField(document.getElementById('telefon')))
		{
			foundErrMail = true;
		}
	}

	
	if (document.getElementById('tytul').value == "") {
		wiadomosc = wiadomosc + "- tytuł\n";
		foundErr = true;
	}
	else{
		if(!checTextField(document.getElementById('tytul')))
		{
			foundErrMail = true;
		}
	}
	if (document.getElementById('tresc').value == "") {
		wiadomosc = wiadomosc + "- treść\n";
		foundErr = true;
	}
	else{
		/*if(!checTextField(document.getElementById('tresc')))
		{
			foundErrMail = true;
		}*/
	}

	if (foundErr) {
		alert(wiadomosc);
	} else {
		if(!foundErrMail){
			document.mojformularz.submit();
		}
	}
}

function recommend() {

	width = 450;
	height = 270;
	
	if (screen.width >= width) left = Math.round(screen.width/2) - width/2;
	else left = 0;
	
	if (screen.height >= height) top = Math.round(screen.height/2) - height/2;
	else top = 0;
	
	window.open('polec-znajomemu.html','Poleć nas znajomemu','width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top+',resizable=no,toolbar=no,location=yes,directories=no,status=no,menubar=no,copyhistory=no');
	
}