var scroll = 500;
$(document).ready(function()
{
	$("input#wymaz").click(function()
	{
	$("input[@type=text]").val("");
	$("textarea[@name=adress]").val("Adres do korespondencji...");
	});
	
	$("input#wyslij").click(function()
	{
	poprawny = true;
	for(i=0;i<14;i++)
	{
	var that = $("input[@type=text]").eq(i);
	var text = $(that).val();
	if(text =="") { $(that).parent().css({border:"1px solid #A90000", backgroundColor:"#F8E5E5"}); poprawny =false; }
	if(text !="") $(that).parent().css({border:"1px solid #74F019",backgroundColor:"#DEF8CA"});
	}
	if($("#zgoda:checked").val()==undefined) { $("#zgoda").parent().css({border:"1px solid #A90000", backgroundColor:"#F8E5E5"}); poprawny =false; }
	else { $("#zgoda").parent().css({border:"1px solid #74F019",backgroundColor:"#DEF8CA"}); }
	if(poprawny==false) $("#form_info").html("Proszę uzupełnić poprawnie dane!");
	else {
		
		$.ajax({
		type: "POST",
		url: "formularz.php",
		data: "zgoda=1&nazwa_urzedu="+$("input[@name=nazwa_urzedu]").val()+"&ulica_urzedu="+$("input[@name=ulica_urzedu]").val()+"&nr_domu_urzedu="+$("input[@name=nr_domu_urzedu]").val()+"&nr_lokalu_urzedu="+$("input[@name=nr_lokalu_urzedu]").val()+"&kod_urzedu="+$("input[@name=kod_urzedu]").val()+"&powiat="+$("input[@name=powiat]").val()+"&gmina="+$("input[@name=gmina]").val()+"&telefon="+$("input[@name=telefon]").val()+"&fax="+$("input[@name=fax]").val()+"&email="+$("input[@name=email]").val()+"&adress="+$("textarea[@name=adress]").val()+"&imie="+$("input[@name=imie]").val()+"&telefony_kontaktowe="+$("input[@name=telefony_kontaktowe]").val()+"&email2="+$("input[@name=email2]").val()+"&stanowisko="+$("input[@name=stanowisko]").val(),
		beforeSend: function () {$("#form_info").html("Proszę czekać wysyłanie formularza!");},
		success: function(msg){$("#form_info").html(msg);}		
		});

		
	}
	});
$("img[@src=/images/img_19.png]").click(function()
{
$(".podmenu1").toggle("slow");
$(".podmenu2").hide();
$(".podmenu3").hide();
});
$("img[@src=/images/img_10.png]").click(function()
{
$(".podmenu2").toggle("slow");
$(".podmenu1").hide();
$(".podmenu3").hide();
});
$("img[@src=/images/img_12.png]").click(function()
{
$(".podmenu3").toggle("slow");
$(".podmenu1").hide();
$(".podmenu2").hide();
});

resize();
	
	$("#kontakt input[@type=submit]").click(function()
{
mail = $("#kontakt input[@name=email]").val();
imie =  $("#kontakt input[@name=imie]").val();
text = $("#kontakt textarea").val();
$.ajax({
		type: "POST",
		url: "kontakt.php",
		data: "mail="+mail+"&imie="+imie+"&text="+text,
		beforeSend: function () {$("#kontakt").html("Proszę czekać wysyłanie formularza!");},
		success: function(msg){$("#kontakt").html(msg);}		
		});

});

$("#ankieta input,button").click(function()
{
that = $(this).parent();
if($(that).attr("class")!="forms") that = $(that).parent();
if($(this).attr("name")=="newsletter"||$(this).attr("name")=="news_name"||$(this).attr("name")=="news_mail")
{
if($(this).val()=="tak") { $("input[@name=news_name],input[@name=news_mail]").removeAttr("disabled");$("input[@name=news_name],input[@name=news_mail]").val(""); }
if($(this).val()=="nie") { $("input[@name=news_name],input[@name=news_mail]").attr("disabled","disabled");$("input[@name=news_name],input[@name=news_mail]").val("Niedostępne");}
} else
{
$(that).next().show();
resize();
$(that).append("<br/><span class='warunek'>Warunkiem ukończenia ankiety jest wypełnienie każdego pytania</span>");
scroll += $(that).height();
$('html,body').animate({scrollTop: scroll}, 500);
}
});

$(".box_head").click(function()
{
sub = $(this).text();
that = $(this).parent();
text = "";
//while($(that).attr("align")==undefined||$(that).attr("align")!="ramka_news") that = $(that).parent();

//while($(that).attr("class")!="box_text") that = $(that).next();
//text = $(that).html();
if($(this).next().attr("class")=="box_text") text = $(this).next().html();
else if($(this).next().next().attr("class")=="box_text") text = $(this).next().next().html();
else if($(this).next().next().next().attr("class")=="box_text") text = $(this).next().next().next().html();
else if($(this).next().next().next().next().attr("class")=="box_text") text = $(this).next().next().next().next().html();


new Boxy("<p>"+text+"</p>", {title: sub, modal: true});
});

});

function resize()
{
height = $(".pole").height();
hei = $(".pole").eq(1).height();
if(hei!=null) {
	if(hei>height) 
		{
		$("#ramka_news").css('height',hei+85+'px');
		}
		else $("#ramka_news").css('height',height+85+'px');
	} else $("#ramka_news").css('height',height+85+'px');
};
