function init_box() {
	/*
	number of fieldsets
	*/
	var fieldsetCount = $('#formElem').children().length;

	/*
	current position of fieldset / navigation link
	*/
	var current 	= 1;

	/** Save script **/
	var save_script_path = "ankieta/";
	/*
	sum and save the widths of each one of the fieldsets
	set the final sum as the total width of the steps element
	*/
	var stepsWidth	= 0;
    var widths 		= new Array();
	$('#steps .step').each(function(i){
        var $step 		= $(this);
		widths[i]  		= stepsWidth;
        stepsWidth	 	+= $step.width();
    });
	$('#steps').width(stepsWidth);

	/*
	to avoid problems in IE, focus the first input of the form
	*/
	$('#formElem').children(':first').find(':input:first').focus();

	/*
	show the navigation bar
	*/
	$('#navigation').show();

	/*
	when clicking on a navigation link
	the form slides to the corresponding fieldset
	*/
	$('#navigation_next').bind('click',function(e){
		var prev	= current;
		// transparent url(../images/next_disable.png) no-repeat
		var EQBF = current ;
		var EQBH = current -1 ;
		$('ul li:eq(' + EQBH + ')').removeClass('selected');
        $('ul li:eq(' + EQBF + ')').addClass('selected');
		if( current > 0 && current < $('#navigation a').length){
			$('#navigation_back').css({"background" : "url("+save_script_path+"images/prev.png) no-repeat"});
			if(current == $('#navigation a').length - 1){
				$('#navigation_next').css({"background" : "url("+save_script_path+"images/next_disable.png) no-repeat"});
			}else{
				$('#navigation_next').css({"background" : "url("+save_script_path+"images/next.png) no-repeat"});
			}
			current = current + 1;
			$('#steps').stop().animate({
				marginLeft: '-' + widths[current-1] + 'px'
			},500,function(){
				if(current == fieldsetCount)
					validateSteps();
				else
					validateStep(prev);
				$('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();
			});
			e.preventDefault();
		}else{
			$('#navigation_next').css({"background" : "url("+save_script_path+"images/next_disable.png) no-repeat"});
		}
	});

	$('#navigation_back').bind('click',function(e){
		var prev	= current;
		var EQBF = current - 2;
		var EQBH = current - 1;
		$('ul li:eq(' + EQBH + ')').removeClass('selected');
        $('ul li:eq(' + EQBF + ')').addClass('selected');
		if( current > 1 ){
		$('#navigation_next').css({"background" : "url("+save_script_path+"images/next.png) no-repeat"});
			if(current == 2 ){
				$('#navigation_back').css({"background" : "url("+save_script_path+"images/prev_disable.png) no-repeat"});
			}else{
				$('#navigation_back').css({"background" : "url("+save_script_path+"images/prev.png) no-repeat"});
			}
		current = current - 1;
        $('#steps').stop().animate({
            marginLeft: '-' + widths[current-1] + 'px'
        },500,function(){
			if(current == fieldsetCount)
				validateSteps();
			else
				validateStep(prev);
			$('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();
		});
       e.preventDefault();
		}else{
			$('#navigation_back').css({"background" : "url("+save_script_path+"images/prev_disable.png) no-repeat"});
		}
	});

    $('#navigation a').bind('click',function(e){
		var $this	= $(this);
		var prev	= current;
		$this.closest('ul').find('li').removeClass('selected');
        $this.parent().addClass('selected');
		/*
		we store the position of the link
		in the current variable
		*/
		current = $this.parent().index() + 1;

			if(current == 1 ){
				$('#navigation_back').css({"background" : "url("+save_script_path+"images/prev_disable.png) no-repeat"});
				$('#navigation_next').css({"background" : "url("+save_script_path+"images/next.png) no-repeat"});
			}else if (current == $('#navigation a').length) {
				$('#navigation_next').css({"background" : "url("+save_script_path+"images/next_disable.png) no-repeat"});
				$('#navigation_back').css({"background" : "url("+save_script_path+"images/prev.png) no-repeat"});
			}else{
				$('#navigation_back').css({"background" : "url("+save_script_path+"images/prev.png) no-repeat"});
				$('#navigation_next').css({"background" : "url("+save_script_path+"images/next.png) no-repeat"});
			}

		/*
		animate / slide to the next or to the corresponding
		fieldset. The order of the links in the navigation
		is the order of the fieldsets.
		Also, after sliding, we trigger the focus on the first
		input element of the new fieldset
		If we clicked on the last link (confirmation), then we validate
		all the fieldsets, otherwise we validate the previous one
		before the form slided
		*/

        $('#steps').stop().animate({
            marginLeft: '-' + widths[current-1] + 'px'
        },500,function(){
			if(current == fieldsetCount)
				validateSteps();
			else
				//validateStep(prev);
				validateSteps(current)
			$('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();
		});
        e.preventDefault();
    });

	/*
	clicking on the tab (on the last input of each fieldset), makes the form
	slide to the next step
	*/
	$('#formElem > fieldset').each(function(){
		var $fieldset = $(this);
		$fieldset.children(':last').find(':input').keydown(function(e){
			if (e.which == 9){
				$('#navigation li:nth-child(' + (parseInt(current)+1) + ') a').click();
				/* force the blur for validation */
				$(this).blur();
				e.preventDefault();
			}
		});
	});

	/*
	validates errors on all the fieldsets
	records if the Form has errors in $('#formElem').data()
	*/
	function validateSteps(to){
		var FormErrors = false;
		for(var i = 1; i < fieldsetCount; ++i){
			if(to>0) {
				if(i < to) {var error = validateStep(i);}
			}else{
				var error = validateStep(i);
			}
			if(error == -1)
				FormErrors = true;
		}
		$('#formElem').data('errors',FormErrors);
	}

	/*
	Set Data
	*/
	function getDataForm(){
		$('#formElem').children().find(':input:not(button)').each(function(){
			if($this.attr('checked')) {
				alert($this.attr('id'));
			}
		});
	}
	/*
	validates one fieldset
	and returns -1 if errors found, or 1 if not
	*/
	function validateStep(step){
		if(step == fieldsetCount) return;

		var error = 1;
		var hasError = false;
		$('#formElem').children(':nth-child('+ parseInt(step) +')').find(':input:not(button)').each(function(){

			var $this 		= $(this);

			var callerType = $this.attr("type");
			var callerName = $this.attr("name");

			if(callerType == "radio" || callerType == "checkbox") {        // Hack for radio/checkbox group button, the validation go the first radio/checkbox of the group
				if($("input[name='"+callerName+"']:checked").size() === 0) {
					var valueLength = '';

				}

			}else{
				var valueLength = jQuery.trim($this.val()).length;

			}


			if(valueLength == ''){
				if($this.attr('disabled')) {
					$this.parent().css('border-bottom','0px');
				}else{
					hasError = true;
					$this.parent().css('border-bottom','1px solid #994444');
				}


			}
			else
				$this.parent().css('border-bottom','0px');
		});
		var $link = $('#navigation li:nth-child(' + parseInt(step) + ') a');
		$link.parent().find('.error,.checked').remove();

		var valclass = 'checked';
		if(hasError){
			error = -1;
			valclass = 'error';
		}
		$('<span class="'+valclass+'"></span>').insertAfter($link);

		return error;
	}



	$('#registerButton').bind('click',function(){
		if($('#formElem').data('errors')){
			alert('Prosze o uzupelnienie oznaczonych na czerwono stron ankiety!');
			return false;
		}else{

			$('#formElem').submit();
		}
	});
}

