/**
*	xmlHttp Objekt für AJAX Routinen
*/
var xmlHttp;
var lasttab;
var lastaction = null;

function banner_close() {
    document.getElementById("screenshot_banner_20").style.display = "none";
}

function switchmw(n) {
    switch (n) {
        case 1:
            document.getElementById("mwb1").className = "active";
            document.getElementById("mwb2").className = "";
            document.getElementById("statistik1").style.display = "block";
            document.getElementById("statistik2").style.display = "none";
            break;
        case 2:
            document.getElementById("mwb1").className = "";
            document.getElementById("mwb2").className = "active";
            document.getElementById("statistik1").style.display = "none";
            document.getElementById("statistik2").style.display = "block";
            break;
    }
}

function getFlashObj(movie) {
    if (window.document[movie]) {
        return window.document[movie];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movie]) {
            return document.embeds[movie];
        }
    } else {
        return document.getElementById(movie);
    }
}

function flashgetDimensions(movie, w) {
    var width = 990;
    var height = 160;
    var movieObj = getFlashObj(movie);
    //var width = movieObj.TGetProperty("/", 8);
    //var height = movieObj.TGetProperty("/", 9);
    return [width,height];
}
/**
*	findet die Koordinaten eines HTML-Elements
*/
function getDim(el) {
    if (document.getElementById) {
        for (var lx = 0, ly = 0; el != null;
			lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
        return {
            x: lx, y: ly
        }
    }
    if (document.layers) {
        return {
            x: el.x, y: el.y
        }
    }
}

function sammelmappenlogin() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Ihr Browser unterstützt AJAX nicht.");
        return;
    }
    xmlHttp.onreadystatechange = sammelmappenlogin_do;
    var el = document.forms["sammelmappenloginbox"].elements;
    xmlHttp.open("POST", "/scripts/contentbrowser.php?dologin=yes&box=yes&FROM="+el["FROM"].value+"&username=" + URLEncode(el["username"].value) + "&passwort=" + URLEncode(el["passwort"].value) + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
    return false;
}

function sammelmappenlogin_do() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        eval(xmlHttp.responseText);
    }
}

function seitenempfehlung() {
    var fehler = false;
    var f = document.forms;
    for (i = 0; i < f.length; i++) {
        if (f[i].parentNode.className == "seiteempfehlen_formular terminkasten") {
            f = f[i].elements;
            break;
        }
    }
    var query = "";
    for (i = 0; i < f.length; i++) {
        if (f[i].value == "" && ((f[i].tagName == "INPUT" && f[i].type == "text") || f[i].tagName == "TEXTAREA")) {
            f[i].style.backgroundColor = "red";
            fehler = true;
        }
        else {
            query += "&" + f[i].name + "=" + f[i].value;
        }
    }
    if (!fehler) {
        xmlHttp = GetXmlHttpObject();
        if (xmlHttp == null) {
            alert("Ihr Browser unterstützt AJAX nicht.");
            return;
        }
        xmlHttp.onreadystatechange = updateseitenempfehlung;
        xmlHttp.open("POST", "/scripts/contentbrowser.php?ACTION=seite_empfehlen" + query + "&page=" + location.href + "&rnd=" + Math.random(), true);
        xmlHttp.send(null);
    }
    else {
        alert("Bitte überprüfen Sie die Eingaben der rot markierten Felder.");
    }
    return false;
}

function updateseitenempfehlung() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        var f = document.forms;
        for (i = 0; i < f.length; i++) {
            if (f[i].parentNode.className == "seiteempfehlen_formular terminkasten") {
                f = f[i].parentNode;
                break;
            }
        }
        f.innerHTML = xmlHttp.responseText;
    }
}

function lupe(el, disp) {
    var pos = getDim(el);
    document.getElementById("lupe").style.top = pos.y+114 + "px";
    document.getElementById("lupe").style.left = pos.x+179 + "px";
    document.getElementById("lupe").style.display = disp;
}

/**
*	GetXmlHttpObject
*	AJAX Funktionen können hiermit initialisiert werden.
*/
function GetXmlHttpObject() {
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}
/**
*	Silverlight Movie Player
*/
var movie;
onload = function() {
    if (document.getElementById('menueswf22')) {
        var d = flashgetDimensions('menueswf22');
        d = d[1];
        //document.getElementById('menueswf22').height = d;
    }
    if (document.getElementById('fbanner2')) {
        var d = flashgetDimensions('fbanner2');
        d = d[1];
        //document.getElementById('fbanner2').height = d;
    }
    var h3 = document.getElementsByTagName("h3");
    var h3h = 0;
    for (i = 0; i < h3.length; i++) {
        if (h3[i].parentNode.tagName == "LI" && h3[i].clientHeight > h3h && h3[i].childNodes[0].innerHTML != "&nbsp;") {
            h3h = h3[i].clientHeight;
        }
    }
    for (i = 0; i < h3.length; i++) {
        if (h3[i].parentNode.tagName == "LI") {
            h3[i].style.height = h3h + "px";
            h3[i].style.paddingBottom = "0px";
        }
    }
    var pe1 = document.getElementById("silverlight_movie");
    var iswl = 'true';
    var thisbg = 'transparent';
    if (navigator.appVersion.search("Windows") != -1 && (navigator.appVersion.search("Safari") != -1 || navigator.appName.search("Opera") != -1)) {
        iswl = 'false';
        thisbg = 'white';
    }
    Silverlight.createObjectEx(
		{
		    source: '../templates/slideshow_silverlight.xml',
		    parentElement: pe1,
		    id: 'Ag123',
		    properties: { width: '100%', height: '100%', background: '#00000000', background: thisbg, isWindowless: iswl, framerate: '50', version: '0.90.0' },
		    events: { onError: null, onLoad: null },
		    context: null
		}
		);
    /**
    *	JQuery Tag Cloud
    */
    $("#tagcloud").tagcloud({ height: 270, width: 310, type: "cloud", sizemin: 8, sizemax: 24, colormin: "ccc", colormax: "000" });
    $("#tagcloud2").tagcloud({ height: 270, width: 310, type: "cloud", sizemin: 8, sizemax: 24, colormin: "ccc", colormax: "000" });
    /**
    *	JQuery Accordion - Guide Guide
    */
    $(".guideguide").hrzAccordion({ handlePosition: "right", openOnLoad: "1" });
    /**
    *	JQuery Newsticker
    */
    $(function() {
        $("#example_2").accessNews({
            headline: "Business as Usual",
            speed: "slow",
            slideBy: 4
        });
    });
    $(function() {
        $("#example_3").accessNews({
            headline: "Business as Usual",
            speed: "slow",
            slideBy: 3
        });
    });
    $(function() {
        $("#banner").accessNews({
            headline: "Banner",
            speed: "slow",
            slideBy: 4
        });
    });
    /**
    *	create imageFlow
    *	div ID, imagesbank, horizon, size, zoom, border, autoscroll_start, autoscroll_interval
    */
    if (document.getElementById("imageFlow")) {
        if (window.location.href.indexOf("locationguide/regionen/") != -1) {
            var str = window.location.href.split("/");
            str = str[str.length - 1].split(".");
            imf.create("imageFlow", '/locationguide/regionsimilar_' + str[0] + '.xml', 0.75, 0.15, 1.8, 10, 8, 4);
        }
        else if (window.location.href.indexOf("locationguide/location/") != -1) {
            var str = window.location.href.split("/");
            str = str[str.length - 1].split(".");
            imf.create("imageFlow", '/locationguide/similar_' + str[0] + '.xml', 0.75, 0.15, 1.8, 10, 8, 4);
        }
        else if (window.location.href.indexOf("produktionsspiegel/index.html") != -1) {
            imf.create("imageFlow", '/produktionsspiegel/random.xml', 0.75, 0.15, 1.8, 10, 8, 4);
        }
        else if (window.location.href.indexOf("actorsguide/index.html") != -1) {
            imf.create("imageFlow", '/actorsguide/random.xml', 0.75, 0.15, 1.8, 10, 8, 4);
        }
        else {
            imf.create("imageFlow", '/locationguide/random.xml', 0.75, 0.15, 1.8, 10, 8, 4);
        }
    }
    if (document.getElementById("screenshot_banner_20")) {
        tb_show('', '#TB_inline?height=372&amp;width=503&amp;modal=true&amp;inlineId=screenshot_banner_20', false);
    }
}

function movie_start(sender, args) {
    if (sender != null) {
        movie = sender;
    }
}
function movie_change(f) {
    if (movie != null) {
        movie.FindName("media").SetValue("Source", "../images/var/" + f);
    }
}
function changeFontsize(s) {
    switch (s) {
        case 3:
            document.body.style.fontSize = "1.1em";
            break;
        case 2:
            document.body.style.fontSize = "1em";
            break;
        case 1:
            document.body.style.fontSize = "0.9em";
            break;
    }
}
/**
*	Produktionsspiegel Tabs
*/
function produktionsspiegel_body_show(n) {
    var a = document.getElementById("produktionsspiegel_detail_tabs_firsttab" + n);
    if (lasttab == null) {
        lasttab = document.getElementById("produktionsspiegel_detail_tabs_firsttab1");
    }
    lasttab.className = lasttab.className.replace(/active/, "");
    a.className = a.className + " active";
    lasttab = a;
    for (i = 1; i <= 4; i++) {
        if (document.getElementById("produktionsspiegel_body_" + i)) {
            document.getElementById("produktionsspiegel_body_" + i).style.display = "none";
        }
    }
    document.getElementById("produktionsspiegel_body_" + n).style.display = "block";
}
function sendfeedback() {
    if (document.forms.feedback.elements.email.value == "" || document.forms.feedback.elements.email.value == "max@mustermann.de") {
        alert("Bitte geben Sie Ihre E-mail-Adresse ein.");
        return false;
    }
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Ihr Browser unterstützt AJAX nicht.");
        return;
    }
    xmlHttp.onreadystatechange = feedbackergebniszeigen;
    xmlHttp.open("GET", "/scripts/contentbrowser.php?ACTION=sendsitemapfeedback&text=" + URLEncode(document.forms.feedback.elements.feedback.value) + "&email=" + URLEncode(document.forms.feedback.elements.email.value) + "&captcha=" + document.forms.feedback.elements.captcha.value + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
    return false;
}
function feedbackergebniszeigen() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        eval(xmlHttp.responseText);
    }
}
/**
*	Locationguide Funktionen
*/
function lg_firesearch() {
    var f1 = null;
    var f2 = null;
    var f3 = null;
    var f4 = null;
    var count = 0;
    var fo = document.createElement("form");
    fo.id = "lgsearchform";
    fo.action = document.forms["guidefilter"].action;
    fo.method = "post";
    var el = document.getElementsByTagName("ul");
    for (i = 0; i < el.length; i++) {
        if (document.getElementById("produktionsspiegel_filter2")) {
            switch (i) {
                case 3:
                    f4 = el[i].childNodes;
                    break;
                case 2:
                    f2 = el[i].childNodes;
                    break;
                case 1:
                    f3 = el[i].childNodes;
                    break;
                case 0:
                    f1 = el[i].childNodes;
                    break;
            }
        }
        else {
            if (el[i].className.indexOf("produktionsspiegel_filter") != -1) {
                f2 = el[i].childNodes;
                if (count == 0) {
                    f1 = el[i].childNodes;
                }
                count++;
            }
        }
    }
    for (i = 0; i < f1.length; i++) {
        if (f1[i].childNodes.length > 0) {
            if (f1[i].childNodes[0].className == "active") {
                var ip = document.createElement("input");
                ip.type = "hidden";
                ip.name = "LGRubrik[]";
                ip.id = "LGRubrik[]";
                ip.value = f1[i].childNodes[0].innerHTML;
                fo.appendChild(ip);
            }
        }
    }
    for (i = 0; i < f2.length; i++) {
        if (f2[i].childNodes.length > 0) {
            if (f2[i].childNodes[1].className && f2[i].childNodes[1].className == "produktionsspiegel_filter3_linkactive") {
                var ip = document.createElement("input");
                ip.type = "hidden";
                ip.name = "LGRegion[]";
                ip.id = "LGRegion[]";
                ip.value = f2[i].childNodes[1].innerHTML;
                fo.appendChild(ip);
            }
        }
    }
    if (f3 != null) {
        for (i = 0; i < f3.length; i++) {
            if (f3[i].childNodes.length > 0) {
                if (f3[i].childNodes[0].className && f3[i].childNodes[0].className == "active") {
                    var ip = document.createElement("input");
                    ip.type = "hidden";
                    ip.name = "produktionsjahr[]";
                    ip.id = "produktionsjahr[]";
                    ip.value = f3[i].childNodes[0].innerHTML;
                    fo.appendChild(ip);
                }
            }
        }
    }
    if (f4 != null) {
        for (i = 0; i < f4.length; i++) {
            if (f4[i].childNodes.length > 0) {
                if (f4[i].childNodes[0].className && f4[i].childNodes[0].className == "produktionsspiegel_filter3_linkactive") {
                    var ip = document.createElement("input");
                    ip.type = "hidden";
                    ip.name = "preistraeger[]";
                    ip.id = "preistraeger[]";
                    ip.value = f4[i].childNodes[0].innerHTML;
                    fo.appendChild(ip);
                }
            }
        }
    }
    var ip = document.createElement("input");
    ip.type = "hidden";
    ip.name = "archiv_suchtext";
    ip.id = "archiv_suchtext";
    ip.value = document.forms["guidefilter"].elements["archiv_suchtext"].value;
    fo.appendChild(ip);
    if (document.getElementById("ag_detailsuche")) {
        var feldnamen = ["ag_nachname", "ag_ge_firma", "ag_ge_plz", "ag_ge_ort"];
        var feldnamen_default = ["Name", "Firma", "PLZ", "Ort"];
        for (i = 0; i < feldnamen.length; i++) {
            if (document.forms["guidefilter"].elements[feldnamen[i]].value != feldnamen_default[i] && document.forms["guidefilter"].elements[feldnamen[i]].value != "") {
                var ip = document.createElement("input");
                ip.type = "hidden";
                ip.name = feldnamen[i];
                ip.id = feldnamen[i]
                ip.value = document.forms["guidefilter"].elements[feldnamen[i]].value;
                fo.appendChild(ip);
            }
        }
    }
    if (document.getElementById("lgsearchform")) {
        document.getElementById("lgsearchform").removeNode(true);
    }
    document.body.appendChild(fo);
    document.getElementById("lgsearchform").submit();
}
function filteragkat(n) {
    document.getElementById("kategorie").value = n;
    for (i = 0; i < document.forms["adressguideform"].elements["offset"].length; i++) {
        document.forms["adressguideform"].elements["offset"][i].value = 1;
    }
    var feldnamen = ["ag_nachname", "ag_ge_firma", "ag_ge_plz", "ag_ge_ort"];
    for (i = 0; i < feldnamen.length; i++) {
        if (document.forms["adressguideform"].elements[feldnamen[i]]) {
            document.forms["adressguideform"].elements[feldnamen[i]].value = "";
        }
    }
    document.forms["adressguideform"].submit();
}

function merken(el, typus, nummer) {
    document.getElementById(typus + "_" + nummer).className = "gemerkt";
    document.getElementById(typus + "_" + nummer).innerHTML = "gemerkt";
    document.getElementById(typus + "_" + nummer).href = "javascript:void(null)";
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Ihr Browser unterstützt AJAX nicht.");
        return;
    }
    xmlHttp.onreadystatechange = merken2;
    xmlHttp.open("GET", "/scripts/contentbrowser.php?ACTION=sammelmappe_add&typus=" + typus + "&id=" + nummer + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
}
function merken2() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        eval(xmlHttp.responseText);
    }
}
function updatesammelmappe() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Ihr Browser unterstützt AJAX nicht.");
        return;
    }
    xmlHttp.onreadystatechange = updatesammelmappe2;
    xmlHttp.open("GET", "/scripts/contentbrowser.php?ACTION=sammelmappe_update&rnd=" + Math.random(), true);
    xmlHttp.send(null);
}
function updatesammelmappe2() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("sammelmappe_inhalt").innerHTML = xmlHttp.responseText;
    }
}
function sammelmappe_entfernen(nummer) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Ihr Browser unterstützt AJAX nicht.");
        return;
    }
    xmlHttp.onreadystatechange = updatesammelmappe2;
    xmlHttp.open("GET", "/scripts/contentbrowser.php?ACTION=sammelmappe_entfernen&id="+nummer+"&rnd=" + Math.random(), true);
    xmlHttp.send(null);
}
function user_change() {
    var el = document.forms["userdata"].elements;
    var str="";
    for (i = 0; i < el.length; i++) {
        str += "&" + el[i].name + "=" + URLEncode(el[i].value);
    }
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Ihr Browser unterstützt AJAX nicht.");
        return;
    }
    xmlHttp.onreadystatechange = user_change2;
    xmlHttp.open("POST", "/scripts/contentbrowser.php?ACTION=user_update&rnd=" + Math.random() + str, true);
    xmlHttp.send(null);
    return false;
}
function user_change2() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("nachricht").innerHTML = xmlHttp.responseText;
    }
}
function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}
/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

function utf8_encode(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;
    }

    // public method for url decoding
function utf8_decode(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;
    }
