var 	header_height = 170,
	window_height = 0,
	content_container = null,

	fixContentHeight = function(){
		if(!content_container) return;
		window_height = Math.max(	Math.max(document.body.scrollHeight, document.documentElement.scrollHeight), 
						Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), 
						Math.max(document.body.clientHeight, document.documentElement.clientHeight));
		content_container.setStyle('min-height', window_height - header_height);
	};

	window.addEvents({
		'load': fixContentHeight,
		'resize': fixContentHeight,
		'domready': function() {
			content_container = document.id('content').getElement('.container');
			fixContentHeight();
		}
	});


	window.addEvent('domready', function(){
		/*
		Form validators
		*/
		$$('form').each(function(el) {
			var validator = new Form.Validator(el, {
				scrollToErrorsOnSubmit: false,
				onElementFail: function(el) {
					if(el.get('type') == 'checkbox') {
						el.getParent('+').getElement('label').setStyle('color', 'red');
					} else {
						el.setProperty('title', 'Verplicht');
						if(!el.hasClass('date')) {
							new OverText(el);
						}
					}
				},
				onElementPass: function(el) {
					if(el.get('type') == 'checkbox') {
						el.getParent('+').getElement('label').setStyle('color', '');
					}
				}
			});
			
			var checks = el.getElements('input[type=checkbox]');
			if(checks) {
				checks.addEvent('click', function(){ validator.validate(true); });
			}
		});
		
			

		var form_cursus = document.id('form_cursus');
		var form_code_23 = document.id('form_code_23');
		if(form_cursus) {
			var update = function() {
				form_code_23.set('value', form_cursus.getElements('option:selected').get('rel'));
			};
			update();
			form_cursus.addEvents({
				'click': update,
				'change': update,
				'keyup': update
			});
			
		}

		/* DATEPICKERS */
		$$('input.date').each(function(date){
			var a = new Picker.Date(date, {
				pickerClass: 'datepicker_vista',
				format: '%d-%m-%Y',
				startView: 'years',
				yearPicker: true,
				startDate: '1/1/1985',
				maxDate: new Date()
			});
		});

		/*
		Header menu fixes!
		*/
		var navmain = $$('nav.main a');
		var navother = $$('nav.topleft a, nav.topright a');

		navother.each(function(item) {
			if(!item.get('color')) return;
			item.setStyle('background-color', item.get('color'));
		});
		navmain.each(function(item) {
			if(!item.get('color')) return;
			item.setStyle('border-bottom', '5px solid '+ item.get('color'));
			if(item.hasClass('active')) item.setStyle('background-color', item.get('color'));
		});
		navmain.addEvents({
			'mouseenter': function() {
				if(!this.get('color')) return;
				this.setStyle('background-color', this.get('color'));
			},
			'mouseleave': function() {
				if(this.hasClass('active')) return;
				this.setStyle('background-color', null);
			}
		});		
	});
