window.addEvent('domready',function(){
	if($('articles')){
		var imgpopup = new ImgPopup();
		var imgsection = [];
		$('articles').getElements('a').each(function(el){
			el.addEvent('click',function(e){
				imgpopup.start(this.getProperty('href'));
				if(e){
					e.stop();
				}
			}.bindWithEvent(el));
			imgsection.push({
				url:el.getProperty('href'),
				caption:el.getProperty('title')
			});
		});
		imgpopup.addSection(imgsection);
	}
	if($('ageForm')){
		$('ageForm').getElement('a').addEvent('click',function(e){
			var day = $('ageForm').getElement('*[name=day]').value;
			var month = $('ageForm').getElement('*[name=month]').value;
			var year = $('ageForm').getElement('*[name=year]').value;
			if(day=='' || month=='' || year==''){
				new Event(e).stop();
				alert('Bitte geben Sie Ihr Geburtsdatum ein');
				return;
			}
			if(!isOldEnough(day,month,year)){
				new Event(e).stop();
				alert('Sie sind leider zu jung!');
			}
		});
	}
});

var isOldEnough = function(day,month,year){
	if(!day || !month || !year){
		return false;
	}
	var mustBorn = new Date(new Date().getFullYear()-18, new Date().getMonth(), new Date().getDate()).getTime();
	var born = new Date(year*1, month-1, day*1).getTime();
	if(born<=mustBorn){
		return true;
	}
	return false;
}
