function checkEmail(id) {
	var email = document.getElementById(id);
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) {
	return false;
	}
	else
	{
	return true;}
}
function backFromNewsletter(msg)
{
	var msgErr = "Brak połączenia z serwerem. Prosimy spróbować później";
	var msgOk = "<strong>Dziękujemy!</strong> Twój wpis został pomyślnie dodany do naszej listy mailingowej";
	if(msg == 1){document.getElementById("infos").innerHTML = msgOk;myalert(msgOk)}
	else{document.getElementById("infos").innerHTML = msgErr};jQuery("#ajaxout").show("slow");jQuery("#news").hide("fast");
}
function saveData() {
	
    var email = document.getElementById("newsletteremail").value;
	var userip = document.getElementById("newsuserip").value;
	
	if(checkEmail("newsletteremail") != false && email != "adres@email.com" )
	{
		 $.ajax({type:"POST",url: "inc/letter_submit.php",data: ({email:email, ip: userip, confirm:'return'}),success: function(msg){backFromNewsletter(msg)} });
	}
	else
	{
		if(email == "adres@email.com" || email == '')
		{
			myalert("Wpisz edres e-mail");
			document.getElementById("newsletteremail").value = '';
			jQuery("#newsletteremail").focus()
			
		}
		else
		{
		myalert("Podaj poprawny adres email");
		jQuery("#newsletteremail").focus()
		}
	}
	return false;
}
function ajaxaddcomment() {
	
	var com_name = document.getElementById("commentauthor").value;
    var com_mail = document.getElementById("commentemail").value;
	var com_msg = document.getElementById("commententry").value;
	var com_forid = document.getElementById("commentforid").value;
	
	if(checkEmail("commentemail") != false && com_msg && com_name)
	{
	$.ajax({type:"POST",url:"inc/addcomment.php", data: ({author:com_name, email:com_mail, entry:com_msg, forid:com_forid, confirm:'return'}),success:function(msg){myalert(msg);jQuery("#addcomment").html('<h2>Dziękujemy komentarz został dodany</h2><p>Twój momentarz zostanie opublikowany, po akceptacji moderatora<p>')} });
	}
	else if(com_name && com_msg)
	{
		if(com_mail)
		{
		myalert('Email: '+com_mail+' wygląda na niepoprawny.');
		}
		else
		{
		myalert('Wpisz adres email.<br />NIe będzie wyświetlany');
		}
		jQuery("#commentemail").focus()
	}
	else if(com_name && com_mail)
	{
		myalert("Wpisz treść komentarza i spróbuj ponownie.");
		jQuery("#commententry").focus()
	}
	else if(com_msg && com_mail)
	{
		myalert("Podaj swoje imię i nazwisko");
		jQuery("#commentauthor").focus()
	}
	else
	{
		myalert("Prosimy, uzupełnij wszystkie pola");
		jQuery("#commentauthor").focus()
	}
	return false;
	
}
function backFromAddcoment(msg)
{
	alert(msg);
}
function sendemail() {
	
	var con_name = document.getElementById("contactname").value;
    var con_mail = document.getElementById("contactmail").value;
	var con_msg = document.getElementById("contactmsg").value;
	
	if(checkEmail("contactmail") != false && con_name && con_msg)
	{
	$.ajax({type:"POST", url:"inc/sendmail.php", data: ({author: con_name, email: con_mail, entry: con_msg, confirm:'return'}), success:function(msg){myalert(msg)} });
	}
	else if(con_name && con_msg)
	{
		if(con_mail)
		{
		myalert('Email: '+con_mail+' wygląda na niepoprawny.');
		}
		else
		{
		myalert('Wpisz adres email i spróbuj ponownie.');
		}
		jQuery("#contactmail").focus()
	}
	else if(con_name && con_mail)
	{
		myalert("Wpisz treść maila i spróbuj ponownie.");
		jQuery("#contactmsg").focus()
	}
	else if(con_msg && con_mail)
	{
		myalert("Podaj swoje imię i nazwisko");
		jQuery("#contactname").focus()
	}
	else
	{
		myalert("Prosimy, uzupełnij wszystkie pola");
		jQuery("#contactname").focus()
	}
	
	return false;
}
function myalert(msg)
{
	showGrowl(msg);

}

