	$(document).ready(function() {
        $('.input :radio').focus(updateSelectedStyle);
        $('.input :radio').blur(updateSelectedStyle);
        $('.input :radio').change(updateSelectedStyle);
		$('.target').attr('target', '_blank');
		$('.snapback').attr('target', '_blank');
		$("#okresy_toggle").click(function() {
			$('#okresy').toggle('slow');
		});
		$("#commentForm").hide();
		$("#hide_more_comments").hide();
		$("#add_comment_button").click(function () {
			$("#commentForm").toggle("slow");
		});
		$("#hide_comment_button").click(function () {
			$("#commentForm").toggle("slow");
		});
		$("#expand_firm_edit").click(function () {
			$("#ul_firm_edit_box").toggle("slow");
		});
		$("#more_comments").hide();
		$("#show_more_comments").click(function () {
			$("#more_comments").toggle("slow");
			//$("#show_more_comments").toggle();
			delayone=setTimeout('$("#show_more_comments").toggle()',500);
			delay=setTimeout('$("#hide_more_comments").toggle()',500);
			//$("#hide_more_comments").toggle();
		});
		$("#hide_more_comments").click(function () {
			$("#more_comments").toggle("slow");
			//$("#hide_more_comments").toggle();
			delayone=setTimeout('$("#hide_more_comments").toggle()',500);
			delay=setTimeout('$("#show_more_comments").toggle()',500);
			//$("#hide_more_comments").toggle();
		});
		$("#add_comment_button").click(function () {
			$("#more_comments").toggle("slow");
			//$("#add_comment_button").toggle();
			delayone=setTimeout('$("#add_comment_button").toggle()',500);
			delay=setTimeout('$("#hide_comment_button").toggle()',500);
			//$("#hide_comment_button").toggle();
		});
		$("#hide_comment_button").click(function () {
			$("#more_comments").toggle("slow");
			//$("#hide_comment_button").toggle();
			delayone=setTimeout('$("#hide_comment_button").toggle()',500);
			delay=setTimeout('$("#add_comment_button").toggle()',500);
			//$("#hide_comment_button").toggle();
		});



		//$(".test")
		//.mouseover(function() {
		//
		//}
		//.mouseout(function() {
		//}

		$('#gallery a').lightBox({fixedNavigation:true});

		$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
		$('#gallery a').lightBox(); // Select all links in object with gallery ID
		$('a.lightbox').lightBox(); // Select all links with lightbox class
		// This, or...
		//$('a').lightBox(); // Select all links in the page
		// ... The possibility are many. Use your creative or choose one in the examples above
		$("#adv_search_options").hide();

		$('li.s_radio_li').click( function(){
			$('li.s_radio_li_change').addClass('s_radio_li');
			$('li.s_radio_li_change').removeClass('s_radio_li_change');
			$(this).addClass('s_radio_li_change');
			$(this).children("input[type=radio]").click();
		});


		//$('div#tabs li a').corner("top 5px");
		
		$('#sample-menu-border').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#left_advert_1').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#firm_login').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('.content_rounded').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#right_advert_2').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#left_project_list_seo_box').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#left_list_seo_box1').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#right_forum_seo_box').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
			
		$('#left_bottom_search_SEO_MostRead').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#random_projects').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
		$('#right_recent_topics').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
//		$('.sf-menu-seo li.sf-cut-seo a span').each(function(){$(this).text($(this).text().substr(0,35) + '...');});
		$('.onlynumeric').numeric();
		$('.numeric').numeric({allow:"&"});
		$('.alphanumeric_firm_name').alphanumeric({allow:"\\. ,!?%&-\\)\\(\\]\\[\\&\\^\\%"});
		$('.numericopenttime').numeric({allow:":-"});
		$('.alphanumeric').alphanumeric();
		$('.alphanumericspace').alphanumeric({allow:" "});
		$('.postalcode').numeric({allow:"-"});
		$('.phonenumber').numeric({allow:"-"});
		$('.email_chars').alphanumeric({allow:"\\.@_-"});
		$('.sample6').alphanumeric({ichars:'.1a'});
		/*$("select#address_voivodship").change(function(){
			$('#address_voivodship').attr("disabled","disabled");
			$('#address_district').attr("disabled","disabled");
			$('#address_community').attr("disabled","disabled");
			$.getJSON("ajax-firmy.html?&param="+$(this).val(), function(j){
				vor (var i = 0; i < j.length; i++) {
					options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
				}
				var optionsN = '';

				$("#address_district").html(options);ar options = '';
				f
				$('#address_district option:first').attr('selected', 'selected');
				optionsN += '<option value="NO">-wybierz powiat-</option>';
				$("#address_community").html(optionsN);
				$('#address_community option:first').attr('selected', 'selected');
			})
			delayone=setTimeout('$("#address_voivodship").removeAttr("disabled")',1500);
			delayone=setTimeout('$("#address_district").removeAttr("disabled")',1500);

		})*/


		$('select#address_voivodship').change(function(){
			$.ajax({
					async: true,
					data: {'param' : $(this).val()},
					dataType: 'html',
					beforeSend: function (XMLHttpRequest) {
						$('#address_voivodship').attr("disabled","disabled");
						$('#address_district').attr("disabled","disabled");
						$('#address_community').attr("disabled","disabled");
						$('#address_city').attr("disabled","disabled");
						$('#address_postal_code').attr("disabled","disabled");
						$('#address_street_building_number').attr("disabled","disabled");
						$('#address_street_name').attr("disabled","disabled");
						$('#send').attr("disabled","disabled");
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						$("#address_voivodship").removeAttr("disabled")
						$('#address_district').removeAttr("disabled");
						$('#address_community').removeAttr("disabled");
						
					},
					success: function(data, textStatus) {
						$("#address_district").html(data);
						$('#address_district option:first').attr('selected', 'selected');
						$('#data_container').html(data);
						optionsN = '<option value="NO">-wybierz powiat-</option>';
						$("#address_community").html(optionsN);
						$("#address_city").html(optionsN);
						$("#address_voivodship").removeAttr("disabled")
						$('#address_district').removeAttr("disabled");
						$('#address_community').removeAttr("disabled");
						$('#address_city').removeAttr("disabled");

						if(districtVal!='NO') {
							$("#address_district").val(districtVal);
							$("#address_district").trigger("change");
						}
					},
					type: 'POST',
					url: baseURLFirmy+"ajax-firmy.html"
			});
		});

		$('select#business_area_voivodship').change(function(){
			var param = '';
			var iterator = 0;
			$('#business_area_voivodship option').each(function(){
				if($(this).attr('selected')==true && $(this).val()!="NO") param = (param=='' ? '' : param + '&') + 'param['+(iterator++)+']='+$(this).val();
			});			
			$.ajax({
					async: true,
					data: param,
					dataType: 'html',
					beforeSend: function (XMLHttpRequest) {
						$('#business_area_district').attr("disabled","disabled");

					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {


					},
					success: function(data, textStatus) {
						$("#business_area_district").html(data);
						$('#business_area_district option:first').attr('selected', 'selected');
						$('#data_container').html(data);
						$('#business_area_district').attr("size","8");
						$("#business_area_voivodship").removeAttr("disabled")
						$('#business_area_district').removeAttr("disabled");
					},
					type: 'POST',
					url: baseURLFirmy+"ajax-firmy-ba.html"
			});
		});


		$('select#address_district').change(function(){
			$.ajax({
					async: true,
					data: {'param' : $(this).val()},
					dataType: 'html',
					beforeSend: function (XMLHttpRequest) {
						$('#address_voivodship').attr("disabled","disabled");
						$('#address_district').attr("disabled","disabled");
						$('#address_community').attr("disabled","disabled");
						$('#address_city').attr("disabled","disabled");
						$('#address_postal_code').attr("disabled","disabled");
						$('#address_street_building_number').attr("disabled","disabled");
						$('#address_street_name').attr("disabled","disabled");
						$('#send').attr("disabled","disabled");
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						$("#address_voivodship").removeAttr("disabled")
						$('#address_district').removeAttr("disabled");
						$('#address_community').removeAttr("disabled");
						
					},
					success: function(data, textStatus) {
						$("#address_community").html(data);
						$('#address_community option:first').attr('selected', 'selected');
						$("#address_voivodship").removeAttr("disabled")
						$('#address_district').removeAttr("disabled");
						$('#address_community').removeAttr("disabled");
						optionsN = '<option value="NO">-wybierz gminę-</option>';
						$("#address_city").html(optionsN);
						$('#address_city').removeAttr("disabled");
						if(communityVal!='NO') {
							$("#address_community").val(communityVal);
							$("#address_community").trigger("change");
							//communityVal='NO';
						}
					},
					type: 'POST',
					url: baseURLFirmy+"ajax-firmy.html"
			});
		});

		$('select#address_community').change(function(){
			$.ajax({
					async: true,
					data: {'param' : $(this).val()},
					dataType: 'html',
					beforeSend: function (XMLHttpRequest) {
						$('#address_voivodship').attr("disabled","disabled");
						$('#address_district').attr("disabled","disabled");
						$('#address_community').attr("disabled","disabled");
						$('#address_city').attr("disabled","disabled");
						$('#address_postal_code').attr("disabled","disabled");
						$('#address_street_building_number').attr("disabled","disabled");
						$('#address_street_name').attr("disabled","disabled");
						$('#send').attr("disabled","disabled");
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						

					},
					success: function(data, textStatus) {
						$("#address_city").html(data);
						$('#address_city option:first').attr('selected', 'selected');
						$("#address_voivodship").removeAttr("disabled")
						$('#address_district').removeAttr("disabled");
						$('#address_community').removeAttr("disabled");
						$('#address_city').removeAttr("disabled");
						if(cityVal!='NO') {
							$("#address_city").val(cityVal);
							$("#address_city").trigger("change");
							//cityVal='NO';
						}
						
					},
					type: 'POST',
					url: baseURLFirmy+"ajax-firmy.html"
			});
		});




		$('select#address_city').change(function(){
			$('#address_postal_code').removeAttr("disabled");
			$('#send').removeAttr("disabled");
			$('#address_street_building_number').removeAttr("disabled");
			$('#address_street_name').removeAttr("disabled");
		});
		if($('#address_voivodship').val()!='NO' )	{
//			alert($('#address_district').val());
			$('#address_voivodship').trigger('change');
		}

		if($('#address_voivodship').val()!='NO' )	{
//			alert($('#address_district').val());
			$('#address_voivodship').trigger('change');
		}
		if($('#business_area_voivodship').val()!='NO') {
			$('#business_area_voivodship').trigger('change');
		}

		if($('#business_area_voivodship').val()=='NO') {
			$('#business_area_district').attr("disabled","disabled");
		}


		$("#business_area_type_global").click(function() {
			$('#business_ares').hide();
			$('#business_area_district').attr("disabled","disabled");
			$("#business_area_voivodship").attr("disabled","disabled");
		});

		$("#business_area_type_local").click(function() {
			$("#business_area_voivodship").removeAttr("disabled")
			$('#business_area_district').removeAttr("disabled");
			$('#business_ares').show('slow');
		});


		if(typeof(startCatsAnimate)=='undefined') {
			startCatsAnimate=0;
		}

		if (startCatsAnimate) {
			$("#categories_firms").asmSelect({
				addItemTarget: 'bottom',
				animate: true,
				highlight: true,
				sortable: true
			})
		}

		if(typeof(startMapGoogle)=='undefined') {
			startMapGoogle=0;
		}

		if (startMapGoogle) {
			var geo;
			var mapa;
			mapaStart(startMapGoogle,startMapGoogleInfo,startMapGoogleInfoDwa);
		}

    })

    function updateSelectedStyle() {
        $('.input :radio').removeClass('focused').next().removeClass('focused');
        $('.input :radio:checked').addClass('focused').next().addClass('focused');
    }

	function in_array( needle, haystack ){
		var a=false;
		for(var i=0;i<haystack.length;i++) {
			if(needle == haystack[i]) {
				a=true;
				break;
			}
		}
		return a;
	}
