Event.observe(window, 'load', function() {
	childs = $A($$('.attachment')).map(Element.extend);
	    	
	childs.each(function(e) {
		Event.observe(e, 'click', function() { 
			$('attachment_' + this.id).toggle();
		});
	});
	
	pops = $($$('.att_pop')).map(Element.extend);
	
	pops.each(function(e) {
		Event.observe(e, 'click', function() {
			pid = e.getAttribute('pid');
			id = pid.split('.')[0];
			size = pid.split('.')[1].split('x');
			
			var left = (screen.width - size[0]) / 2;
			var top = (screen.height - size[1]) / 2;
			
			opt = 'resizable=0, menubar=0, scrollbars=0, status=0, toolbar=0, width=' + size[0] + ', height=' + size[1] + ', top=' + top + ', left=' + left;
			
			prev = window.open('about:blank', '', opt);
			
			prev.document.writeln('<html><head>');
			prev.document.writeln('<title>Pelster Bijlage Preview</title>');
			prev.document.writeln('<style type="text/css">* { margin:0; }</style>');
			prev.document.writeln('</head>');
			prev.document.writeln('<body onclick="window.close()">');
			prev.document.writeln('<img src="/103/preview.php?id=' + id + '" alt="Bijlage" title="Bijlage" />');
			prev.document.writeln('</body></html>');
			prev.document.close();
		});
	});
	
	// Search observe
	Event.observe('sf', 'focus', function() {
		if(this.value == 'Type hier uw zoekterm..') {
			this.value = '';
		} 
	});
	
	Event.observe('sf', 'blur', function() {
		if(this.value == '') {
			this.value = 'Type hier uw zoekterm..';
		}
	});
	
	if($('att_desc')) {
		Event.observe('att_desc', 'keyup', function() { 
			if(this.value.length > this.getAttribute('maxlength')) {
				this.value = this.value.substring(0, this.getAttribute('maxlength'));
			}
		});
	}
	
	if($('nl')) {
		// Newsletter observe
		Event.observe('nl', 'focus', function() {
			if(this.value == 'Type hier uw mailadres') {
				this.value = '';
			} 
		});
		
		Event.observe('nl', 'blur', function() {
			if(this.value == '') {
				this.value = 'Type hier uw mailadres';
			}
		});
	}
});
