$(document).ready(function(){
	/* BEGIN - UŻYTKOWNIK - wybór branży/formularz rejestracji/profil użytkownika */

	$('#fake_select, #select-branch-content div.accept').click( function(){
		$('#select-branch-content').toggle();
		if( $('#select-branch-content').css('display') == 'none' ){
			addWorkQuestion();
		}
	});


	$('#select-branch-content input').click( function(){
		var i = 0;
		branch = $(this).attr('id');
		$("#select-branch-content input:checked").each( function(){
			if( i > 2 ){ $('#select-branch-content input#'+branch ).removeAttr("checked"); }
			else{ i++; }
		});

		if( $('#select-branch-content input#'+branch ).attr('checked') == true  ){
			$('#select-branch-content input#'+branch ).parent().children('label').addClass('selected');
		}else{
			$('#select-branch-content input#'+branch ).parent().children('label').removeClass('selected');
		}

		if( i == 0 ){	$('#fake_select').html('wybierz branże');	}
		else{ $('#fake_select').html('wybranych: '+i); }

	});


	$('#u_licence_zarz_check').change( function(){
		if( !$(this).is(':checked') ){ $('input#u_licence_zarz').attr('disabled', 'disabled');  }
		else{ $('input#u_licence_zarz').removeAttr('disabled'); }
	});

	$('#u_licence_pos_check').change( function(){
		if( !$(this).is(':checked') ){ $('input#u_licence_pos').attr('disabled', 'disabled');  }
		else{ $('input#u_licence_pos').removeAttr('disabled'); }
	});

	$('#u_licence_rzecz_check').change( function(){
		if( !$(this).is(':checked') ){ $('input#u_licence_rzecz').attr('disabled', 'disabled');  }
		else{ $('input#u_licence_rzecz').removeAttr('disabled'); }
	});

	function addWorkQuestion(){
		var display = 'none';
		var work_place = '';

		$("#select-branch-content input:checked").each( function( i, k){

			branch = $(this).attr('id_user_branch');
			title = $(this).parent().children('label').html();

			if( $('input').is('#branch-'+branch+'-work_place') == true ){
				work_place_value = $('input#branch-'+branch+'-work_place').val();
			}else{
				work_place_value = '';
			}

			var work = '<div class="row"><div style="float:left;width: 220px;" class="label"><img src="/_images/content/ikona_kwadrat.gif" class="kwadrat_light_green"> '+title+': </div><div class="field"><input id="branch-'+branch+'-work_place" type="text" name="branch['+branch+'][work_place]" value="'+work_place_value+'" class="long"></div></div><div class="clear"></div>';
			work_place = work_place + work;
			display = 'block';
		});

		$('#work-place').children('div#work-branch').html('');
		$('#work-branch').append( $( work_place ) );
		$('#work-place').css('display', display );
	}

	$('#is_still_working, #is_still').change( function(){
		if( $(this).is(':checked') ){
			$('select#end_date-month').attr('disabled', 'disabled');
			$('select#end_date-year').attr('disabled', 'disabled');
		}
		else{
			$('select#end_date-month').removeAttr('disabled');
			$('select#end_date-year').removeAttr('disabled');
		}
	});

	/* END - UŻYTKOWNIK - wybór branży/formularz rejestracji/profil użytkownika */

});