
$(document).ready(function() {   

	prepareSubmit = function(){
		/*
		$( '.submit-stage' ).click( function(){
			if( $( '#child-dolist:checked' ).length > 0 ){
				$( this ).closest( 'form' ).submit();						
			}
			return false;
		} );
		*/
	}
	prepareStages = function(){
		$( '.next-stage' ).click( function(){
			var stage = $( this ).closest( '.rc-stage' );
			stage.removeClass( 'show-stage' );
			stage.prev().addClass( 'show-stage' );
			stage.next().next().addClass( 'show-stage' );
			return false;						   
		} );
	}
	prepareShowChildContainer = function(){
		$( '#list-child .show-child' ).click( function(){
			$( '.child-container' ).toggle();
			return false;
		} );
		$( '#list-child .add-child' ).click( function(){
			if( $( '.child-container input[name=cname]' ).val() && $( '.child-container input[name=cssn]' ).val() ){
				$( '.child-container' ).toggle();
				
				var string = $( '.child-container input[name=cname]' ).val()+':'+$( '.child-container input[name=cssn]' ).val()+';';
				$( 'input[name=children]' ).val( $( 'input[name=children]' ).val() + string );
			
				if( $( '.child-list' ).hasClass( 'no-children' ) ){
					$( '.child-list' ).html('');
					$( '.child-list' ).removeClass( 'no-children' );
				}
				
				var string = '<li>' + $( '.child-container input[name=cssn]' ).val() + ', ' + $( '.child-container input[name=cname]' ).val() + '</li>';
				$( '.child-list' ).append( string );
				
				$( '.child-container input[name=cname]' ).val('');
				$( '.child-container input[name=cssn]' ).val('');												
				
			}
			return false;
		} );			
	}
	prepareOffice = function(){
		$( '.office-btn' ).click( function(){
			$( '.office-list' ).html( $( 'select[name=office]' ).val() );
			return false;
		 } );
	}
	prepareParent = function(){
		$( '.parent-btn' ).click( function(){
			$( '.name-list' ).html( $( 'input[name=parentname]' ).val()  );
			$( '.adress-list' ).html( $( 'input[name=parentstreet]' ).val() + '<br />' + $( 'input[name=parentzip]' ).val() + ' ' + $( 'input[name=parentarea]' ).val() );
			$( '.contact-list' ).html( 'E-post: ' + $( 'input[name=parentmail]' ).val() + '<br />Telefon: ' + $( 'input[name=parentphone]' ).val() );		
			return false;						
		 } );
	}
	prepareClear = function(){
		$( '.clear-form' ).click( function(){
			document.location.href = document.location.href;
			return false;
		 } );
	}		
	
	prepareClinicSelect = function() {
	    $( '#officename' ).change(function() {
	        $( '.office-list' ).text($(':selected', this).text());
	        $( '#clinicname' ).text($(':selected', this).text());
	    });
	}
				    	

	prepareStages();
	prepareSubmit();
	prepareShowChildContainer();
	prepareOffice();
	prepareParent();
	prepareClear();
	prepareClinicSelect();
	
});


valid = function() {
    return $( '#child-dolist:checked' ).length > 0;
}