var url_prefix = "";
if (urls_optimieren == 1) url_prefix = root_verzeichnis;

function popup_bild(img_id)
{
	document.getElementById("body").style.cursor = "wait";
   	// Div entfernen falls schon vorhanden
	if (document.getElementById("popup") != null)
	{
		document.getElementById("body").removeChild(popup);
		popup = null;
	}

	// Gesamte Seite transparent schalten
   	document.getElementById('page').style.opacity = '0.15';
    document.getElementById('page').style.MozOpacity = '0.15';
    document.getElementById('page').style.KHTMLOpacity = '0.15';
    document.getElementById('page').style.filter = 'alpha(opacity:15)';

   	// Div dynamisch erzeugen
	popup = document.createElement("div");
   	popup.id = "popup";

    popup_width = 850;
    popup_height = 600;

	var scrolltop = window.pageYOffset;
	if (scrolltop == null) scrolltop = document.documentElement.scrollTop;
	if (scrolltop == null) scrolltop = document.body.scrollTop;
    if (scrolltop == null) scrolltop = 0;

	popup.style.left = (get_window_width() / 2) - (popup_width / 2) + "px";
   	popup.style.top = (get_window_height() / 2) - (popup_height / 2) + scrolltop + "px";

   	document.getElementById("body").appendChild(popup);
	popup.innerHTML = document.getElementById("bild" + img_id).innerHTML + "<br /><br /><a href='javascript:popup_schliessen()'>Fenster schließen</a>";
  	document.getElementById("body").style.cursor = "auto";
}

function popup_schliessen()
{
	// Div entfernen
	if (document.getElementById("popup") != null)
	{
		document.getElementById("body").removeChild(popup);
    	popup = null;

    	// Transparenz aufheben
    	document.getElementById('page').style.opacity = '1';
        document.getElementById('page').style.MozOpacity = '1';
        document.getElementById('page').style.KHTMLOpacity = '1';
        document.getElementById('page').style.filter = 'alpha(opacity:100)';
	}
}

function get_window_width()
{
    if (document.documentElement.clientWidth)
		window_width = document.documentElement.clientWidth;
	else
	if (document.body.offsetWidth)
		window_width = document.body.offsetWidth;
	else
		window_width = window.innerWidth;
	return window_width;
}

function get_window_height()
{
    if (document.documentElement.clientHeight)
		window_height = document.documentElement.clientHeight;
	else
	if (document.body.offsetHeight)
		window_height = document.body.offsetHeight;
	else
		window_height = window.innerHeight;
	return window_height;
}

var base64_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function base64_encode(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + base64_keyStr.charAt(enc1) + base64_keyStr.charAt(enc2) +
         base64_keyStr.charAt(enc3) + base64_keyStr.charAt(enc4);
   } while (i < input.length);

   return output;
}

