$(document).ready(function(){
	$("input[@id=nl_submit]").each(function() {
		$(this).click(function(){
			var adres = $("input[@id=adres]").val();
			if (adres != '') {
				var html = $.ajax({type: "GET", url: "./ajax/insert_address.php?adres="+encodeURIComponent(adres), async: false}).responseText;
				$("#nl_text").html(html);
				$("input[@id=adres]").val('');
			}
		});
	});
	$("input[@id=nlout_submit]").each(function() {
		$(this).click(function(){
			var adres = $("input[@id=adres]").val();
			if (adres != '') {
				var html = $.ajax({type: "GET", url: "./ajax/delete_address.php?adres="+encodeURIComponent(adres), async: false}).responseText;
				$("#nl_text").html(html);
				$("input[@id=adres]").val('');
			}
		});
	});
	$('#myAccordion').Accordion(
				{
					headerSelector	: 'dt',
					panelSelector	: 'dd',
					activeClass		: 'myAccordionActive',
					hoverClass		: 'myAccordionHover',
					panelHeight		: 300,
					speed			: 400
				}
			);
	$("input[@id=poll_submit]").each(function() {
			$(this).click(function(){
				var poll = $(this).attr("poll");
				if (poll != '') {
					var pollco = $("input[@id=poll_"+poll+"_co]").val();
					var ip = $("input[@id=ip]").val();
					var voted = 0;
					for (var i = 0; i < pollco; i++) {
						if ($("input[@id=poll_"+poll+"_"+i+"]").attr('checked') == true) voted = $("input[@id=poll_"+poll+"_"+i+"]").attr("voted");
					}
					if (voted > 0) {
						var html = $.ajax({type: "GET", url: "./ajax/insert_poll.php?poll="+poll+"&q="+voted+"&ip="+ip, async: false}).responseText;
						if (html==0) $("#div_"+poll).html('Oddano już dzisiaj głos na tą sondę');
						else $("#div_"+poll).html('Dziękujemy za Twój głos');
					}
				}
			});
		});
	$("input[@id=adv_submit]").each(function() {
			$(this).click(function(){
				var time = $("select[@id=a_expiration_e]").val();
				var title = $("input[@id=a_title_c]").val();
				var text = $("textarea[@id=a_content_t]").val();
				if ((title != '') && (text != '')) {
					var ip = $("input[@id=ip]").val();
					var html = $.ajax({type: "GET", url: "./ajax/insert_adv.php?title="+encodeURIComponent(title)+"&txt="+encodeURIComponent(text)+"&ip="+ip+"&time="+time, async: false}).responseText;
					if (html==0) $("#div_adv").html('Dodano już dzisiaj ogłoszenie z tego numeru IP');
					else $("#div_adv").html('Dziękujemy za ogłoszenie. Wkrótce się ono pojawi');
				}
			});
		});
	$("div[@id^=_menu_]").each(function() {
			$(this).click(function(){
				var tpl = $(this).attr('tpl');
				var menuid = $(this).attr('menuid');
				$("div[@id=menu_"+menuid+"]").toggle();
				if ((tpl != '') && (tpl != undefined)) location.href=tpl;
			});
		});
	$("div[@id^=_menu2_]").each(function() {
			$(this).click(function(){
				var tpl = $(this).attr('tpl');
				var menuid = $(this).attr('menu2id');
				$("div[@id=menu2_"+menuid+"]").toggle();
				if ((tpl != '') && (tpl != undefined)) location.href=tpl;
			});
		});
	$("#nl_text").html('');
	$("div[@id^=menu_]").toggle();
	$("div[@id^=menu2_]").toggle();
});

