//LIGHTBOXGERAFFEL

//destroy the current shown lightbox elements
function hideTheseUglyBlackOverlay(){
	var objBody = document.getElementsByTagName("body").item(0);
	var enemy1=document.getElementById("overlay");
		objBody.removeChild(enemy1);
	var enemy2=document.getElementById("overlayLink");
		objBody.removeChild(enemy2);
   }

//creating needed HTML Elements for a "lightbox"
function showBigImage(object){
	
	var objBody = document.getElementsByTagName("body").item(0);
	//page overlay
	var bodyOverlay = document.createElement("div");
	bodyOverlay.setAttribute('id','overlay');
	bodyOverlay.style.display = 'block';
	bodyOverlay.style.background = '#000000';
	bodyOverlay.style.color = '#ffffff';
	bodyOverlay.style.textAlign = 'center';
	bodyOverlay.style.position = 'absolute';
	bodyOverlay.style.top = '0';
	bodyOverlay.style.left = '0';
	bodyOverlay.style.zIndex = '90';
 	bodyOverlay.style.width = '100%';
	bodyOverlay.style.height = '100%';
	bodyOverlay.style.opacity = 0.7;
	bodyOverlay.style.MozOpacity = 0.7;
	bodyOverlay.style.filter = "alpha(opacity=70)";
	
	//attach the overlay
   objBody.appendChild(bodyOverlay);
	
	//closing link an image decoration
	var closeLink = document.createElement("a");
	closeLink.setAttribute('href','#');
	closeLink.setAttribute('id','overlayLink');
	closeLink.setAttribute('title','Click to close');
	closeLink.onclick = function () {hideTheseUglyBlackOverlay(); return false;}
	closeLink.style.background = '#ffffff';
	closeLink.style.color = '#000000';
   closeLink.style.textDecoration = 'none';
	closeLink.style.fontStyle = 'italic';
	closeLink.style.border = 'solid 1px #000000';
	closeLink.style.padding = '4px 10px 10px 10px';
	closeLink.style.display = 'block';
	closeLink.style.textAlign = 'right';
	closeLink.style.position = 'absolute';
	closeLink.style.zIndex = '150';
	closeLink.style.top = '110px';
	closeLink.style.left = '50%';
	closeLink.style.margin = '0 0 0 -275px';
	var txt = document.createTextNode("Click to close");
	closeLink.appendChild(txt);	
	
	//showing image
	var imageShow = document.createElement("img");
	imageShow.src = object;
	imageShow.setAttribute('id','the-image');
	imageShow.setAttribute('alt',object);
	imageShow.style.display='block';
	imageShow.style.margin='6px 0 0 0';
	
	//attach the image
	closeLink.appendChild(imageShow);
	//attach the link
	objBody.appendChild(closeLink);	
	}

//attach our function to show the lightbox
function addAnEventHandlerOnThumbnailLinks(){
   var allElements = document.getElementsByTagName("a");
   // loop through all elements
	for (var i=0; i<allElements.length; i++){
		if ( allElements[i].getAttribute("href") && (allElements[i].className == "thumbnail") ){
			 allElements[i].onclick= function () {
					showBigImage(this);
					return false;
					}
		}
	}
   
}

//helper script to test and set one or more functions at onload.
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

//fire up the scripts
addLoadEvent(addAnEventHandlerOnThumbnailLinks);

//END OF LIGHTBOXGERAFFEL

//MAILBOT
//*******Maildecryption**************************************
	var index, i, txt, atPos, subtxt;
	function maildecrypt(mail){
	//Testen auf gueltige Mailadresse

	txt=mail;
	atPos=txt.indexOf("|");
	subtxt=txt.split("|");
	subtxt[0]=subtxt[0].split(".");
	subtxt[1]=subtxt[1].split(".");
	
	var index01clear=new Array();
	var index02clear=new Array();
	
	for(i=0;i<subtxt[0].length;i++){
	index01clear[i]=String.fromCharCode(subtxt[0][i]);
	}
	index01clear.reverse();
	a=index01clear.join("");
    
	for(i=0;i<subtxt[1].length;i++){
	index02clear[i]=String.fromCharCode(subtxt[1][i]);
	}
	index02clear.reverse();
	b=index02clear.join("");
	muaAction="mai"+"lto:"+a+"@"+b;

	window.document.location=muaAction;
	}
//**************************************************************	

//*******Mailencryption**************************************
var end01, end02, dummy;
function mailcrypt(){
	
	if(window.document.mail.mailtxt.value==""){
	alert("Bitte eine maildresse eingeben");
	}else{
	
	
	var email=window.document.mail.mailtxt.value;
   var atPos=email.indexOf("@");
   var atPos2=email.lastIndexOf("@");
   var dotPos=email.lastIndexOf(".");
   var emaillaenge=email.length;
   var diff=emaillaenge-dotPos;
	
	if(atPos==emaillaenge-1){
   alert(unescape("Ung%FCltige E-Mailadresse!"));
   window.document.mail.mailtxt.focus();return false;
   }else{
   	if(atPos<1){
   	alert(unescape("Ung%FCltige E-Mailadresse!"));
   	window.document.mail.mailtxt.focus();return false;
   	}else {
   	   if(atPos!=atPos2){
  			alert(unescape("Ung%FCltige E-Mailadresse!")); 
   		window.document.mail.mailtxt.focus(); return false;
   		}else {
   			if(atPos!=atPos2){
   			alert(unescape("Ung%FCltige E-Mailadresse!"));
   			window.document.mail.mailtxt.focus();return false;
   			}else {
   	   			if(diff<3||diff>5){
   					alert(unescape("Ung%FCltige E-Mailadresse!"));
   					window.document.mail.mailtxt.focus(); return false;
   					}else{
   					
   					txt=window.document.mail.mailtxt.value;//originale Adresse
	atPos=txt.indexOf("@");
	subtxt=txt.split("@");
	
	dummy=subtxt[0]+"(at)"+subtxt[1];
	//alert(dummy);
	
	end01=subtxt[0].length;
	var index01=new Array(end01);
	end02=subtxt[1].length;
	var index02=new Array(end02);
	
	//erster Mailteil
	i=0;
	for(i;i<end01;i++){
	index01[i]=subtxt[0].charCodeAt(i);
	}
	//alert(index01.length);
	index01.reverse();
	var a=index01.join(".");
	
	//zweiter Mailteil
	i=0;
	for(i;i<end02;i++){
	index02[i]=subtxt[1].charCodeAt(i);
	}
	index02.reverse();
	var b=index02.join(".");
	//alert(index02.length);
   //document.write("verschluesselt: <b> "+a+"|"+b+"</b>");
   var key=a+"|"+b;
   
   var resultcontainer=document.getElementById("mailresult");
   var mailLink = document.createElement("a");
	mailLink.setAttribute('href','#');
	mailLink.setAttribute('onclick','maildecrypt(\''+key+'\')');
	mailLink.setAttribute('title','mailto');
   var txt = document.createTextNode('Copy this mailto link');
   mailLink.appendChild(txt);
   resultcontainer.appendChild(mailLink);
   					}
  				}
 		}
	}
}
}//Mailadresse vorhanden Ende
}//Mailcrypt Ende
//*******************************************************************************************
//END OF MAILBOT

