
//	Event.observe(window, 'load', function(){

/* general layout and tooltips */

		// tips
		$$('.hint').each(function(element){
			if(element.getAttribute('title')){
				element.innerHTML += ' <img src="/files/layout/hint.gif">';
				new Tip(element, element.getAttribute('title'));
			}
		});

		// hide the original submit button
		$('submit_button').hide();

		// hack the labels
		$$('form.cmxform label').each(function(label){
			var span = document.createElement('span');
			Element.extend(span);
			if(BrowserDetect.browser == 'Firefox'){
				label.setStyle({
					display: '-moz-inline-box'
				});
			}
			span.setStyle({
				display: 'block',
				width: '120px'
			});
			span.innerHTML = label.innerHTML;
			label.innerHTML = '';
			label.appendChild(span);
		});

/* some global variables for the form */

		// vars
		var form = $$('form.cmxform')[0];							// the form
		var fieldsets = $$('form.cmxform fieldset');				// all the fieldsets
		var steps = $$('div.navigation-steps div.navigation-step'); // step indicators
		var current_tab = -1;										// current active fieldset nr

		// catch the submit and ignore it, we'll handle it from now
		Event.observe(form,'submit',function(event){
			Event.stop(event);
		});

		// catch the enter, stop the bubbling and activate the next group
		Event.observe(form,'keypress',function(event){
			if(event.keyCode == 13){
				go(current_tab+1);
				Event.stop(event);
			}
		});
		
		// hide the legends and border
		$$('form.cmxform legend').invoke('hide');
		$$('form.cmxform fieldset').invoke('setStyle',{border:'0px solid white'});

		// back button
		var button_back = $(document.createElement('button'));
		button_back.addClassName('navigation-step-back');
		button_back.innerHTML = '&laquo; TERUG';
		Event.observe(button_back,'click',function(){go(current_tab-1)});
		$$('div.submits')[0].appendChild(button_back);

		// forward button
		var button_forward = $(document.createElement('button'));
		button_forward.addClassName('navigation-step-forward');
		Event.observe(button_forward,'click',function(){go(current_tab+1)});
		$$('div.submits')[0].appendChild(button_forward);

		// validate, focus and stop at first error
		function validate(){
			var fields = fieldsets[current_tab].getElementsBySelector('input,textarea,select');
			var valid = true;
			for(i=0; i<fields.length; i++){
				if(!Validation.validate(fields[i])){
					valid = false;
					fields[i].focus();
					break;
				}
			}
			return valid;
		}

		// activate group
		function go(nr){

			// unless it's the init call, validate
			if(current_tab != -1){
				if(!validate())
					return;
			}

			// submit?
			if(nr == fieldsets.length){
				form.submit();
				return;
			}
			
			// hide all fieldsets
			fieldsets.each(function(fs){fs.hide()});

			// set the current fieldset nr and show it
			current_tab = nr;
			fieldsets[current_tab].show();

			// set the step visual
			$('form-steps').setStyle({backgroundPosition:'0px -'+(nr*44)+'px'});
			

			// enable or disable back
			disabled(button_back,current_tab == 0);

			// set forward button innerHTML
			button_forward.innerHTML = nr+1 == fieldsets.length ? 'VERSTUREN' : 'VERDER &raquo;';
	
			// focus the first element, with an assignment otherwise it wont work
			var focus_field = fieldsets[current_tab].getElementsBySelector('input')[0];
			focus_field.focus();
		}

		// init
		go(0);

		// helper function for disabling
		function disabled(e,disabled){
			if(disabled)
				e.addClassName('disabled');
			else
				e.removeClassName('disabled');
			e._disabled = disabled;
		}


//	});
