﻿/****************************************************************************************************************
*                                                                                                               *
*       Dieser Quellcode ist urheberrechtlich geschützt. Das Vervielfältigen oder Abändern ist untersagt.       *
*                                                                                                               *
*                                Copyright 2009 Volker Last - vlast@gmx.de                                      *
*                                                                                                               *
****************************************************************************************************************/

window_name = 'Galagos';

// Druckversion anzeigen
function printPage() {
	var printcontent = document.getElementById('printcontent');
	printcontent.value = encodeURIComponent(document.getElementById('maincontent').innerHTML);
	window.open('', 'druckfenster', 'width=660, height=700, scrollbars=1');
	document.getElementById('printform').submit();
}

// Bilder vorab laden
function preload(img) {
	var image = document.createElement('img');
	image.src = img;
}

// Bildwechsel
function changeImage(img_id, img_src) {
	var img = document.getElementById(img_id);
	img.src = img_src;
}

// Textgröße ändern

function setFontSize() {
	if(window.name.indexOf(window_name) == -1)
		window.name = 0+window_name;
	else {
		var content = document.getElementById('maincontent');
		var old_value = parseInt(content.style.fontSize.substring(0, content.style.fontSize.indexOf('px')));
		content.style.fontSize = (old_value+parseInt(window.name.substring(0, window.name.indexOf(window_name))))+'px';
		setFont(content, parseInt(window.name.substring(0, window.name.indexOf(window_name))));
	}
}

function increaseFont() {
	if(parseInt(window.name.substring(0, window.name.indexOf(window_name))) < 9) {
		var content = document.getElementById('maincontent');
		window.name = (parseInt(window.name.substring(0, window.name.indexOf(window_name)))+1)+window_name;
		var old_value = parseInt(content.style.fontSize.substring(0, content.style.fontSize.indexOf('px')));
		content.style.fontSize = (old_value+1)+'px';
		setFont(content, 1);
	}
}

function decreaseFont() {
	if(parseInt(window.name.substring(0, window.name.indexOf(window_name))) > -9) {
		var content = document.getElementById('maincontent');
		window.name = (parseInt(window.name.substring(0, window.name.indexOf(window_name)))-1)+window_name;
		var old_value = parseInt(content.style.fontSize.substring(0, content.style.fontSize.indexOf('px')));
		content.style.fontSize = (old_value-1)+'px';
		setFont(content, -1);
	}
}

function resetFont() {
	var content = document.getElementById('maincontent');
	var old_value = parseInt(content.style.fontSize.substring(0, content.style.fontSize.indexOf('px')));
	content.style.fontSize = (old_value-parseInt(window.name.substring(0, window.name.indexOf(window_name))))+'px';
	setFont(content, -parseInt(window.name.substring(0, window.name.indexOf(window_name))));
	window.name = 0+window_name;
}

function setFont(content, font_value) {
	var child_length = content.childNodes.length;
	for(var i = 0; i < child_length; ++i) {
		var child_node = content.childNodes[i];
		if(child_node.nodeType == 1) {
			if(child_node.tagName.toLowerCase() == 'font') {
				var old_value = child_node.style.fontSize;
				if(old_value != '') {
					old_value = parseInt(old_value.substring(0, old_value.indexOf('px')));
					child_node.style.fontSize = (old_value+font_value)+'px';
				}
			}
			if(child_node.hasChildNodes())
				setFont(child_node, font_value);
		}
		
	}
}

// Popup Bild öffnen
function showPopupNormal(img) {
	var windowcontent = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Detailansicht</title></head><body><table width="100%"><tr><td height="20" bgcolor="#484949" align="right"><a href="#" onclick="javascript:window.close();" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:0.7em; color:#FFFFFF; text-decoration:none;">Fenster schließen&nbsp;</a></td></tr><tr><td height="10"></td></tr><tr><td align="center"><img src="images/popup_'+img+'" /></td></tr></table></body></html>';
	
	var popupwindow = window.open('', 'popupfenster', 'width=520, height=520, top=200, left=300');
	popupwindow.document.open();
	popupwindow.document.write(windowcontent);
	popupwindow.document.close();
}

// Lightbox

var lightboxstate = false;
var bgdelay = 10;
var bgstepFF = 0;
var bgstepIE = 0;
var bgstepsFF = 10;
var bgstepsIE = 90;
var bgopacity = 90;
var bgcolor = '#111111';
var bginterval = '';
var ctdelay = 300;

window.onresize = placeImage;
document.onkeypress = closePopup;

function showPopup(imgname) {
	lightboxstate = true;
	
	var backgroundlink = document.createElement('a');
	backgroundlink.setAttribute('href', '#');
	backgroundlink.setAttribute('onclick', 'return closePopup();');
	
	var background = document.createElement('div');
	background.setAttribute('id', 'background');
	
	var container = document.createElement('div');
	container.setAttribute('id', 'container');
	
	var imagecontainer = document.createElement('div');
	imagecontainer.setAttribute('id', 'imagecontainer');
	
	var image = new Image();
	image.src = 'images/popup_'+imgname;
	image.id = 'image';
	
	var p = document.createElement('p');
	p.setAttribute('style', 'text-align:right; font-weight:bold;');
	
	var text = document.createTextNode('X Close');
	
	p.appendChild(text);
	imagecontainer.appendChild(image);
	imagecontainer.appendChild(p);
	container.appendChild(imagecontainer);
	backgroundlink.appendChild(container);
	backgroundlink.appendChild(background);
	document.body.appendChild(backgroundlink);
	
	var bg = document.getElementById('background');
	bg.style.zIndex = '1';
	bg.style.opacity = '.'+bgstepFF;
	bg.style.filter = 'alpha(opacity='+bgstepIE+')';
	bg.style.backgroundColor = bgcolor;
	bg.style.position = 'fixed';
	bg.style.left = '0px';
	bg.style.top = '0px';
	bg.style.width = '100%';
	bg.style.height = '100%';
	
	var ct = document.getElementById('container');
	ct.style.cursor = 'default';
	ct.style.visibility = 'hidden';
	ct.style.zIndex = '2';
	ct.style.position = 'fixed';
	ct.style.top = '0px';
	ct.style.left = '0px';
	ct.style.width = '100%';
	ct.style.height = '100%';
	
	var imgct = document.getElementById('imagecontainer');
	imgct.style.cursor = 'pointer';
	imgct.style.position = 'absolute';
	imgct.style.backgroundColor = '#ffffff';
	imgct.style.paddingLeft = '10px';
	imgct.style.paddingRight = '10px';
	imgct.style.paddingTop = '10px';
	imgct.style.paddingBottom = '20px';
	
	showBackground();
}

function waitForImage() {
	var img = document.getElementById('image');
	if(img.complete == true) {
		placeImage();
		window.setTimeout('showContainer()', ctdelay);
	} else
		window.setTimeout('waitForImage()', 100);
}

function placeImage() {
	if(lightboxstate) {
		var imgct = document.getElementById('imagecontainer');
		
		imgctX = imgct.clientWidth;
		imgctY = imgct.clientHeight;
		sizeX = window.document.documentElement.clientWidth;
		sizeY = window.document.documentElement.clientHeight;
		
		mL = (parseInt((sizeX-imgctX)/2) > 0 ? parseInt((sizeX-imgctX)/2) : 0);
		mT = (parseInt((sizeY-imgctY)/2) > 0 ? parseInt((sizeY-imgctY)/2) : 0);
		
		imgct.style.marginLeft = mL+'px';
		imgct.style.marginTop = mT+'px';
	}
}

function showBackground() {
	var bg = document.getElementById('background');
	
	if(bgstepFF < bgopacity) {
		bgstepFF += bgstepsFF;
		bg.style.opacity = '.'+bgstepFF;
	}
	
	if(bgstepIE < bgopacity) {
		bgstepIE += bgstepsIE;
		bg.style.filter = 'alpha(opacity='+bgstepIE+')';
	}
	
	if(bgstepFF >= bgopacity && bgstepIE >= bgopacity) {
		waitForImage();
		bgstepFF = 0;
		bgstepIE = 0;
	} else
		window.setTimeout('showBackground()', bgdelay);
}

function showContainer() {
	var ct = document.getElementById('container');
	ct.style.visibility = 'visible';
}

function closePopup() {
	if(lightboxstate) {
		lightboxstate = false;
		document.body.removeChild(document.body.lastChild);
		return false;
	}
}
// Lightbox Ende

function checkForm() {
	var error = '';
	if(document.getElementById('names').value == '')
		error += '- Ihr Name\n';
	if(document.getElementById('email').value == '')
		error += '- E-Mail\n';
	if(document.getElementById('subject').value == '')
		error += '- Betreff\n';
	
	if(error != '') {
		error = 'Bitte füllen Sie folgende Felder aus:\n\n'+error;
		alert(error);
		return false;
	} else
		return true;	
}
