$(document).ready(function(){
	
	$(".lightbox").lightbox();
	
	$("#GuestBookFormSwich").click(function(){
		$("#GuestBookForm").animate({ height: 'toggle', opacity: 'toggle' }, "slow");
		return false;
	});
	
	$("#CaptchaPic").click(function(){
		$(this).animate({ opacity: 'hide' }, "fast",null,function(){
			$("#CaptchaPic").attr({"src":""});
			$("#CaptchaPic").attr({"src":"/captcha.jpg?sid="+ Math.round(Math.random()*100000) });
			$(this).animate({ opacity: 'show' }, "slow");
		});
	});
	
	if($("#Survey").attr("id")!=undefined) {
		$("#Survey .Bars div").animate({ width: 'show' }, "slow",null,function(){
			$(this).css({display:"block"})
		});
	}
	
	var l = 0;
	$("table.tableFormat tr").not("td table tr").each(function(){
		if($(this).attr("class")!='niet') l++;
		if(l%2) $(this).addClass("lnp");
		else $(this).addClass("lp");
	});
	
	$("#Deanery .Rozw").click(function(){
		var id = $(this).attr("id");
		$("#Place"+id).animate({ height: 'toggle', opacity: 'toggle' }, "slow");
		return false;
	});
	
	$("table.harmonijka td").not("td table").each(function(){
		$(this).html( '<div class="harmTrzym">'+$(this).html()+'</div>' );
		$(this).css({"display":"block"})
	});
	
	$("caption").click(function(){
		$(this).parent().find("div.harmTrzym").animate({ height: 'toggle', opacity: 'toggle' }, "slow");
	})
	
});

/* -= Newsletter =- */
function CheckNewsletter(o) {
	$("#Newsletter .ErrorPlace").each(function(){
		$(this).css({display:"none"});
		$(this).text("");
	})
	var email = $("#NLF_email").val();
	var imnaz = $("#NLF_imie_nazwisko").val();
	var kod = $("#NLF_kod").val();
	if(email.length==0) return ShowNLFerror('email',NewsletterErrors[0]);
	
	if(!checkEmail(email)) return ShowNLFerror('email',NewsletterErrors[1]);
	if(imnaz.length==0 && o=='add') return ShowNLFerror('imie_nazwisko',NewsletterErrors[2]);
	
	if(kod.length<5) return ShowNLFerror('kod',NewsletterErrors[3]);
	return true;
}
function ShowNLFerror(p,t) {
	$("#ErrorPlace_"+p).html("<br/>"+t+"<br/><br/>");
	$("#ErrorPlace_"+p).animate({ height: 'show', opacity: 'show' }, "slow");
	return false;
}
function checkEmail(x){return/^[\w\.-]+@([\w-]+\.)*[a-z]{2,4}$/.test(x)}

/* -= Sonda =- */
function CheckVote() {
	
}

/* -= Zmiana Hasła =- */
function CheckChangePass() {
	$("#Deanery .ErrorPlace").each(function(){
		$(this).css({display:"none"});
		$(this).text("");
	})
	var oldpass = $("#CPF_oldpass").val();
	var newpass = $("#CPF_newpass").val();
	var newrepass = $("#CPF_newrepass").val();
	
	if(oldpass.length==0) return ShowNLFerror('oldpass',DeaneryErrors[0]);
	if(newpass.length==0) return ShowNLFerror('newpass',DeaneryErrors[1]);
	if(newrepass.length==0) return ShowNLFerror('newrepass',DeaneryErrors[2]);
	if(newpass!=newrepass) return ShowNLFerror('newrepass',DeaneryErrors[3]);
	return true;
}

/* -= Wysyłanie zapytania =- */
function CheckMailForm() {
	$("#Form .ErrorPlace").each(function(){
		$(this).css({display:"none"});
		$(this).text("");
	})
	var email = $("#F_email").val();
	var tel = $("#F_tel").val();
	var imnaz = $("#F_imie_nazwisko").val();
	var tresc = $("#F_tresc").val();
	var kod = $("#F_kod").val();
	
	if(email.length==0&&tel.length==0) return ShowNLFerror('email',FormErrors[0]);
	if(email.length>0&&!checkEmail(email)) return ShowNLFerror('email',FormErrors[1]);
	if(imnaz.length==0) return ShowNLFerror('imie_nazwisko',FormErrors[2]);
	if(tresc.length==0) return ShowNLFerror('tresc',FormErrors[3]);
	if(kod.length<5) return ShowNLFerror('kod',FormErrors[4]);
	return true;
}

function CheckOnLineForm() {
	$("#FormO .ErrorPlace").each(function(){
		$(this).css({display:"none"});
		$(this).text("");
	})
	
	var Kierunek = false;
	$("#FormO input:radio").each(function(){if($(this).attr("name")=='FO_Kierunek'&&$(this).attr("checked")) Kierunek = true;});
	if(!Kierunek) return ShowNLFerror('Kierunek',"Proszę wybrać kierunek.");
	if($("#FO_Nazwisko").val().length==0) return ShowNLFerror('Nazwisko',"Proszę wpisać nazwisko.");
	if($("#FO_Imiona").val().length==0) return ShowNLFerror('Imiona',"Proszę wpisać imię.");
	if($("#FO_PESEL").val().length==0) return ShowNLFerror('PESEL',"Proszę wpisać PESEL bądź inny nr ewidencyjny.");
	if($("#FO_DataUr").val().length==0) return ShowNLFerror('DataUr',"Proszę wpisać datę urodzenia.");
	if($("#FO_MiejsceUr").val().length==0) return ShowNLFerror('MiejsceUr',"Proszę wpisać miejsce urodzenia.");
	if($("#FO_KrajUr").val().length==0) return ShowNLFerror('KrajUr',"Proszę wpisać kraj urodzenia.");
	if($("#FO_ImieOjca").val().length==0) return ShowNLFerror('ImieOjca',"Proszę wpisać imię ojca.");
	if($("#FO_ImieMatki").val().length==0) return ShowNLFerror('ImieMatki',"Proszę wpisać imię matki.");
	
	if($("#FO_AdresZamKod").val().length==0) return ShowNLFerror('AdresZamKod',"Proszę wpisać kod pocztowy w adresie zamieszkania.");
	if($("#FO_AdresZamMiejscowosc").val().length==0) return ShowNLFerror('AdresZamMiejscowosc',"Proszę wpisać miejscowość w adresie zamieszkania.");
	if($("#FO_AdresZamUlica").val().length==0) return ShowNLFerror('AdresZamUlica',"Proszę wpisać ulicę w adresie zamieszkania.");
	if(!$("#FO_AdresZamTyp1").attr("checked")&&!$("#FO_AdresZamTyp2").attr("checked")) return ShowNLFerror('AdresZamTyp',"Proszę wybrać typ miejscowości w adresie zamieszkania.");
	
	if($("#FO_AdresKorKod").val().length==0) return ShowNLFerror('AdresKorKod',"Proszę wpisać kod pocztowy w adresie do korespondencji.");
	if($("#FO_AdresKorMiejscowosc").val().length==0) return ShowNLFerror('AdresKorMiejscowosc',"Proszę wpisać miejscowość w adresie do korespondencji.");
	if($("#FO_AdresKorUlica").val().length==0) return ShowNLFerror('AdresKorUlica',"Proszę wpisać ulicę w adresie do korespondencji.");
	if(!$("#FO_AdresKorTyp1").attr("checked")&&!$("#FO_AdresKorTyp2").attr("checked")) return ShowNLFerror('AdresKorTyp',"Proszę wybrać typ miejscowości w adresie do korespondencji.");
	
	if($("#FO_TelStac").val().length==0&&$("#FO_TelKom").val().length==0) return ShowNLFerror('Telefon',"Proszę wpisać telefon kontaktowy, stacjonarny lub komórkowy.");
	if($("#FO_Email").val().length>0&&!checkEmail($("#FO_Email").val())) return ShowNLFerror('Email',"Proszę POPRAWNIE wpisać adres email.");
	
	var jezyk = false;
	$("#FormO input:checkbox").each(function(){ if( $(this).attr("name").substr(0,9) =='FO_Jezyk_' && $(this).attr("checked") ) jezyk = true; });
	if(!jezyk) return ShowNLFerror('Jezyk',"Proszę wybrać język.");
	
	if(!$("#FO_Oswiadczenie1").attr("checked")) return ShowNLFerror('Oswiadczenie1',"Trzeba wyrazić zgodę.");
	if(!$("#FO_Oswiadczenie2").attr("checked")) return ShowNLFerror('Oswiadczenie2',"Trzeba wyrazić zgodę.");
	
	return true;
}