// -----------------------------------------------------------------------------
// Globale Variablen
// Erforderliche Hauptversion von Flash
var requiredMajorVersion = 8;
// Erforderliche Unterversion von Flash
var requiredMinorVersion = 0;
// Erforderliche Flash-Revision
var requiredRevision = 0;
// Die unterstützte JavaScript-Version
var jsVersion = 1.0;
// Wichtig für AdTags
var hideamazon = 0;
// -----------------------------------------------------------------------------

// Client-Browsertyp ermitteln
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript-Hilfsprogramm ist zur Ermittlung der Versionsinformationen des Flash Player Plug-Ins erforderlich
function JSGetSwfVer(i){
	// NS/Opera-Version >= 3 auf Flash-Plug-In im Plug-In-Array prüfen
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 unterstützt Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 unterstützt Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// älteres WebTV unterstützt Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Ermittlung in allen anderen Fällen nicht möglich
	else {

		flashVer = -1;
	}
	return flashVer;
}
// Wenn der Funktionsaufruf ohne Parameter erfolgt, gibt diese Funktion einen Gleitkommawert zurück,
// bei dem es sich entweder um die Flash Player-Version oder um 0.0 handelt.
// Beispiel: Flash Player 7r14 gibt 7.14 zurück.
// Wenn reqMinorVer, reqMajorVer, reqRevision aufgerufen wird, wird 'true' zurückgegeben, sofern diese bzw. eine höhere Version verfügbar ist
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// Versionen rückwärts durchlaufen, bis die neueste Version gefunden wird
	for (i=25;i>0;i--) {
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);
		}
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];

			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// ist die Hauptrevision >= angeforderte Hauptrevision UND die Nebenversion >= angeforderte Nebenversion
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}
	return (reqVer ? false : 0.0);
}


function openSearch(id) {
	if (document.getElementById("openSearch").style.display != 'none') {
		document.getElementById("openSearch").style.display = 'none';
		document.getElementById("closeSearch").style.display = '';
		new Effect.SlideDown (id, {duration: 1});
	}
}			
function closeSearch(id) {
	if (document.getElementById("closeSearch").style.display != 'none') {
		document.getElementById("closeSearch").style.display = 'none';
		document.getElementById("openSearch").style.display = '';
		new Effect.SlideUp(id, {duration: 1});	
	}
}

function openSearchDetail(id,openId,closeId) {
	if (document.getElementById(openId).style.display != 'none') {
		document.getElementById(openId).style.display = 'none';
		document.getElementById(closeId).style.display = '';
		new Effect.SlideDown (id, {duration: 1.5});
		activeSD = 1;
	} else {
		activeSD = 0;
	}
}			
function closeSearchDetail(id,openId,closeId) {
	if (document.getElementById(openId).style.display == 'none') {
		document.getElementById(closeId).style.display = 'none';
		document.getElementById(openId).style.display = '';
		new Effect.SlideUp(id, {duration: 1});
		activeSD = 0;
		
	}
}

function toogleSearchDetails(id,openId,closeId) {
	if (document.getElementById(openId).style.display == 'none') {
		document.getElementById(closeId).style.display = 'none';
		document.getElementById(openId).style.display = '';
		document.getElementById(id).style.display = 'none';	
	}else{
		document.getElementById(closeId).style.display = '';
		document.getElementById(openId).style.display = 'none';
		document.getElementById(id).style.display = '';			
	}
}


function popupPicture(sUrl, sWidth, sHeight)
{
	var popup;
	//var sWidth=sWidth+10;
	//var sHeight=sHeight+10;
	
	popup = window.open(sUrl, 'PictureViewer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,screenX=10,screenY=10,resizable=yes,width=' + sWidth + ',height=' + sHeight, true);
	if(navigator.appName.indexOf('Netscape') != -1)
		popup.focus();
}



// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
		writeln('width=300-(document.body.clientWidth-document.images[0].width);');
		writeln('height=300-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
		close();		
	}
}

/*
 * Blendet das div mit der gegebenen ID aus
 * 
 * string text			ID des auszublendenden Elements
 */
function hideWindow(element) {
	document.getElementById(element).style.display = "none";
}

/* 
 * füt einen vorgeschlagenen Begriff in ein Textfeld ein
 *
 * string idInput 		ID des Textelds, in das der Begriff eingefüt werden soll
 * string idResults		ID des Divs für die Suchergebnisse 
 * string proposal		Inhalt, der in das Textfeld eingefügt werden soll
 * string submitForm	submit sendet das Formular nach dem Einfügen des Begriffs ab
 *						nosubmit schreibt den Begriff nur in das Eingabefeld, sendet das Formular nicht ab
 */
function insertProposal(idInput, proposal, submitForm) {
	document.getElementById(idInput).value = proposal;
	document.getElementById(idInput).focus();
	if(submitForm == 'submit') {
		document.suche.submit();
	}
	return false;
}

/*
 * Funktion zur Suche der Suchvorschläge
 * 
 * string text			Text, nach dem gesucht wird
 * string idInput		ID des Texteingabefelds
 * string idResults		ID des Divs für die Suchergebnisse
 * string submitForm	submit sendet das Formular nach dem Anklicken des Begriffs ab
 *						nosubmit schreibt den Begriff nur in das Eingabefeld, sendet das Formular nicht ab
 */
function searchSuggestionsRegions(text, idInput, idResults, submitForm) {
	// Reset des Timers für die Anzeige
	if (typeof(timeout_ajaxnamesearch1) != 'undefined') {
		window.clearTimeout(timeout_ajaxnamesearch1);
	}

	// bereinigen des Strings
	text 		= text.replace(/^\s+|\s+$/g,"");

	// unter 3 Zeichen wird nicht gesucht
	if (text.length < 3) {
		hideWindow(idResults);
		return;
	}
	// Aufruf der PHP-Funktion
	x_searchSuggestionsRegions(Base64.encode(text), idInput, idResults, submitForm, searchSuggestions_callback);
	
	// setzen des Timers zum Ausblenden des Vorschlagfensters
	timeout_ajaxnamesearch1 = window.setTimeout('hideWindow("' + idResults + '")', 10000);
}

/*
 * Funktion zur Suche der Suchvorschläge
 * 
 * string text			Text, nach dem gesucht wird
 * string idInput		ID des Texteingabefelds
 * string idResults		ID des Divs für die Suchergebnisse
 * string submitForm	submit sendet das Formular nach dem Anklicken des Begriffs ab
 *						nosubmit schreibt den Begriff nur in das Eingabefeld, sendet das Formular nicht ab
 */
function searchSuggestionsCategories(text, idInput, idResults, submitForm) {
	// Reset des Timers für die Anzeige
	if (typeof(timeout_ajaxnamesearch2) != 'undefined') {
		window.clearTimeout(timeout_ajaxnamesearch2);
	}
	
	// bereinigen des Strings
	text 		= text.replace(/^\s+|\s+$/g,"");

	// unter 3 Zeichen wird nicht gesucht
	if (text.length < 3) {
		hideWindow(idResults);
		return;
	}
	
	// Aufruf der PHP-Funktion
	x_searchSuggestionsCategories(Base64.encode(text), idInput, idResults, submitForm, searchSuggestions_callback);
	
	// setzen des Timers zum Ausblenden des Vorschlagfensters
	timeout_ajaxnamesearch2 = window.setTimeout('hideWindow("' + idResults + '")', 10000);
}

/*
 * Sajax Callback Function für searchSuggestionsCategories()
 *
 * erg					Ergebnis (JSON)
 * string idResults		ID des Elements, in den die Ergebnisse angezeigt werden sollen
 */
function searchSuggestions_callback(erg)
{
	erg = eval("(" + erg + ")");
	erg.content = Base64.decode(erg.content);

	searchSuggestionsDiv = document.getElementById(erg.idResults);
	
	// Abbruch, wenn das ErgebnisDiv nicht gefunden wird
	if (!searchSuggestionsDiv) {
		return;
	}
	
	// Ausblenden des ErgebnisDivs, wenn keine Ergebnisse vorliegen
	if (erg.content != "") {
		searchSuggestionsDiv.innerHTML = erg.content;
		searchSuggestionsDiv.style.display = '';
	}
}

/**
 * Checkt ob der Typ vorhanden ist, dann wird im Dropdown nach der ID gesucht und markiert.
 * 
 * string type ID vom Dropdown
 * int id ID des Wertes
 */
function chooseChoiceInDropdown(type, id)
{
	dropdown = document.getElementById(type);

	// ID ist gültig dann suchen
	if (dropdown) {
		// Dropdown iterieren und alle Sachen kontrollieren
		for (var i in dropdown.options) {
			// Werte vergleichen und den richtigen Anwählen
			dropdown.options[i].selected = false;
			if (dropdown.options[i].value == id) {
				dropdown.options[i].selected = true;
			}
		}
	}
	
	// Fenster noch ausblenden
	switch (type) {
		case 'link_cat_id':
				hideWindow('searchResultsCategories');
			break;
		case 'link_reg_id':
				hideWindow('searchResultsRegions');
			break;
		default:
			break;
	}
}

/**
 *
 *  Base64 encode / decode
 *  http://www.webtoolkit.info/
 *
 */

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            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 +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}