
var localpath;

var GlobalConfirmDialog;

function popup(href) {
  window.open(href, "showpost", "width=720,height=560,resizable=yes,scrollbars=yes,location=no");
}

function showform(id, link) {
	
	if ($(id)) {
		$(id).setStyle('display', 'block');
		$(id).fade('hide');
		$(id).fade('in');
	}
	
	if ($(link)) {
		$(link).setStyle('display', 'none');
	}
	
}

function closeform(id, link) {
	
	if ($(id)) {
		$(id).setStyle('display', 'none');
	}
	
	if ($(link)) {
		$(link).setStyle('display', 'block');
	}
	
}

window.addEvent('domready', function(){
	
	$$('div.spoilertitle').each(function(element) {
		var id = element.get('id').replace('Title', '');
		if ($(id)) {
			var toggle_span = new Element('span', {
				'html': '&nbsp;&nbsp;'
			});
			var toggle_icon = new Element('img', {
				'src': localpath + 'media/stylesheet/plus.png',
				'width': '14',
				'height': '14',
				'alt': 'x',
				'style': 'vertical-align: -2px; border: none; cursor: pointer;',
				'title': 'Spoiler ein-/ausblenden'
			});
			toggle_icon.addEvent('click', function() {
				if ($(id)) {
					if ($(id).getStyle('display') == 'none') {
						$(id).setStyle('display', 'block');
						$(id).setStyle('opacity', 0);
						var effect = new Fx.Tween($(id));
						effect.addEvent('complete', function() {
							toggle_icon.set('src', localpath + 'media/stylesheet/minus.png');
						});
						effect.start('opacity', 1);
					} else {
						var effect2 = new Fx.Tween($(id));
						effect2.addEvent('complete', function() {
							$(id).setStyle('display', 'none');
							toggle_icon.set('src', localpath + 'media/stylesheet/plus.png');
						});
						effect2.start('opacity', 0);
					}
				}
			});
			toggle_icon.inject(toggle_span, 'bottom');
			toggle_span.inject(element, 'bottom');
		}
	});
	
	$$('div.toc').each(function(element) {
		var id = element.get('id') + 'list';
		
		if ($(id)) {
			var toggle_span = new Element('span', {
				'html': '&nbsp;&nbsp;'
			});
			var toggle_icon = new Element('img', {
				'src': localpath + 'media/stylesheet/minus.png',
				'width': '14',
				'height': '14',
				'alt': 'x',
				'style': 'vertical-align: -2px; border: none; cursor: pointer;',
				'title': 'Inhaltsverzeichnis ein-/ausblenden'
			});
			toggle_icon.addEvent('click', function() {
				if ($(id)) {
					if ($(id).getStyle('display') == 'none') {
						$(id).setStyle('display', 'block');
						$(id).setStyle('opacity', 0);
						var effect = new Fx.Tween($(id));
						effect.addEvent('complete', function() {
							toggle_icon.set('src', localpath + 'media/stylesheet/minus.png');
						});
						effect.start('opacity', 1);
					} else {
						var effect2 = new Fx.Tween($(id));
						effect2.addEvent('complete', function() {
							$(id).setStyle('display', 'none');
							toggle_icon.set('src', localpath + 'media/stylesheet/plus.png');
						});
						effect2.start('opacity', 0);
					}
				}
			});
			var title = $$('#' + element.get('id') + " div")[0];
			toggle_icon.inject(toggle_span, 'bottom');
			toggle_span.inject(title, 'bottom');
		}
	});
	
});

function showConfirmDialog(link, title, text) {
	var linkelem = $(link);
	if (linkelem) {
		
		GlobalConfirmDialog = new AjaxPopup();
		GlobalConfirmDialog.addTitle(title);
		GlobalConfirmDialog.addSubmitButton('Fortfahren', function() {
			location= linkelem.getProperty('href');
		});
		GlobalConfirmDialog.addCancelButton('Abbrechen');
		GlobalConfirmDialog.addOverlay();
		GlobalConfirmDialog.displayStatic('<p>' + text + '</p>');
		
	}
	
}
