/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
==============================================================

    FCGH.net JavaScript
    Copyright © 2010 James Barrante
    $ JS.Client.~Base.v2.php $
    $ Thu, 16 Sep 2010 23:05:22 +0200 $

==============================================================
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  
  
    if (!window.trim) {
        function trim(str) {
            while (str.substring(0,1) == ' ') {
                str = str.substring(1, str.length);
            };
            while (str.substring(str.length-1, str.length) == ' ') {
                str = str.substring(0, str.length-1);
            };
            return str;
        };    
    };



    function JS_Init_SiteStats() {
        // Anonyme Statistik: Bildschirmauflösung
        if (window.screen) {
            var SCX, SCY;
            if ((SCX = window.screen.width) && (SCY = window.screen.height)) {
                if ((!isNaN(SCX)) && (!isNaN(SCY))) {
                    if ((SCX > 0) && (SCY > 0)) {
                        var RES = (String(SCX)) + ":" + (String(SCY));
                        // alert((escape(RES)));
                        document.cookie = "Base[Display]=" + (escape(RES)) + "; path=\/";
                    };
                };
            };
        };
    };

    JS_Init_SiteStats();










                
    function JS_Main_Fix_Height() {
        if (document.getElementById) {
            var en, em;
            if (en = document.getElementById("N")) {
                if (em = document.getElementById("U")) {
                    var hn, hm;
                    em.style.height = "auto";
                    hn = en.offsetHeight ? en.offsetHeight : 1024;
                    hm = em.offsetHeight ? em.offsetHeight : 0;
                    
                    var hx = (hm < hn) ? hn : hm;
                    em.style.height = (hx) + "px";
                };
            };
        };
    };




    function JS_Nav_Highlight() {
        var CAA, URL;
        if (CAA = document.getElementById("N")) {
            if (URL = window.location.href) {
                if (CAA = CAA.getElementsByTagName("A")) {
                    for (var i = CAA.length-1; i > -1; i--) {
                        /*
                          wir müssen das pferd unbeding von hinten aufzäumen,
                          weil es sonst huddel mit der startseite "germania/" gibt:
                          dieser string ist halt überall drin...
                        */
                        if (CAA[i].parentNode.tagName == "LI") {
                            var CHK; // Prüfung ob URL == Link-HREF
                            CHK = (URL.substring(0, CAA[i].href.length) == CAA[i].href);
                            if (i == 0) {
                                CHK = (URL == CAA[i].href);
                            };
                            if (CHK) {
                                CAA[i].className = "HL";
                                break;
                            };
                        };
                    };
                };
            };
        };
    };






//############################################################################################################
//############################################################################################################
//############################################################################################################
//############################################################################################################


    function JS_AJAX() {
        var ax = false;
        if (window.XMLHttpRequest) {
            ax = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            try {
                ax = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    ax = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                };
            };
        };
        return ax;
    };


//############################################################################################################
//############################################################################################################
//############################################################################################################
//############################################################################################################
//## ANFANG AJAX-Funktion für die Fehlerberichterstattung


    function JS_AJAX_ErrorReporting() {
        var ax = JS_AJAX();
		
		if (ax !== null) {
		    var lnk;
		    if (lnk = document.getElementById("Z_GMER")) {
		        lnk.style.display = "block";
		        lnk.style.cursor = "pointer";

                var html = "<DIV ID=\"Z_GMER_C\"> <DIV ID=\"Z_GMER_M\"> <DIV ID=\"Z_GMER_N\"> <DIV ID=\"Z_GMER_MMUI\"> <FORM method=\"POST\" name=\"FCGH_ERRORREPORT\" autocomplete=\"on\"> <INPUT type=\"hidden\" name=\"Action\" value=\"User_Error\" /> <INPUT type=\"hidden\" name=\"ref\" value=\"\" /> <FIELDSET class=\"NIE\"><LEGEND>Es handelt sich um</LEGEND> <UL> <LI><LABEL><INPUT type=\"radio\" name=\"art\" value=\"Inhalt\" checked=\"checked\"> einen <STRONG>inhaltlichen Fehler</STRONG> (z. B. falsches Ergebnis oder falschgeschriebener Name)</LABEL></LI> <LI><LABEL><INPUT type=\"radio\" name=\"art\" value=\"Techni\"> einen <STRONG>technischen Fehler</STRONG> (z. B. Scriptfehler)</LABEL></LI> <LI><LABEL><INPUT type=\"radio\" name=\"art\" value=\"AndAnr\"> eine <STRONG>Anregung</STRONG> für den Webmaster</LABEL></LI> </UL> <INPUT type=\"hidden\" name=\"arx\" value=\"\" /> </FIELDSET> <FIELDSET class=\"NIE\"><LEGEND>Betreffende Seite (URL):</LEGEND> <DIV><INPUT class=\"T\" type=\"text\" name=\"url\" value=\"\" /></DIV> </FIELDSET> <FIELDSET class=\"NIE\"><LEGEND>Fehlerbeschreibung/Mitteilung</LEGEND> <DIV><TEXTAREA class=\"T\" name=\"txt\"></TEXTAREA></DIV> </FIELDSET> <FIELDSET class=\"NIE\"><LEGEND>Deine E-Mail-Adresse:</LEGEND> <DIV><STRONG>Diese Angabe ist optional.</STRONG> Wir können Dir natürlich nur antworten, wenn Du Deine Mail-Adresse hier einträgst. Mail-Adressen geben wir natürlich nicht weiter.</DIV> <DIV><INPUT class=\"T\" type=\"text\" name=\"eml\" value=\"\" /></DIV> </FIELDSET> <P>Die vertrauliche Behandlung dieser Mitteilung ist gewährleistet.</P> <TABLE cellpadding=\"0\" cellspacing=\"0\"> <TR> <TD><BUTTON type=\"button\" name=\"btn\" lang=\"cc\">Verwerfen</BUTTON></TD> <TD><BUTTON type=\"button\" name=\"btn\" lang=\"ok\"><STRONG>Meldung senden</STRONG></BUTTON></TD> </TR> </TABLE> </FORM> </DIV> </DIV> </DIV> </DIV>";
                lnk.innerHTML = html;                
                var ui = document.getElementById("Z_GMER_C");
                var frm = document.forms["FCGH_ERRORREPORT"];
                if (window.location.href) {
                    frm.elements["url"].value = window.location.href;
                    frm.elements["ref"].value = window.location.href;
                };
                
                for (var i = 0; i < frm.elements.length; i++) {
                    var x = frm.elements[i];
                    if (x.name) {
                        switch (x.name) {
                            case "btn":
                                if (x.lang == "cc") {
                                    x.onclick = function () {
                                        if (confirm("Formular verwerfen?")) {
                                            this.form.reset();
                                            if (ui) {
                                                ui.style.display = ui.style.display == "block" ? "none" : "block";
                                            };
                                        };
                                    };
                                };
                                
                                if (x.lang == "ok") {
                                    x.onclick = function() {
                                        if (ax && frm) {
                                            
                                            // Validierung
                                            var err = "";
                                            for (var i = 0; i < frm.elements.length; i++) {
                                                switch (frm.elements[i].name) {
                                                    case "art": 
                                                        if (frm.elements[i].checked) {
                                                            frm.elements["arx"].value = frm.elements[i].value;
                                                        };
                                                    break;
                                                    case "txt":
                                                        if (trim(frm.elements[i].value) == "") {
                                                            err += "Du musst schon eine Fehlerbeschreibung eingeben.\n";
                                                        };
                                                    break;
                                                    case "url":
                                                        if (trim(frm.elements[i].value) == "") {
                                                            err += "Das URL-Feld darf nicht leer sein.\n";
                                                        };
                                                    break;
                                                };
                                            };
                                            
                                            if (err.length > 0) {
                                                alert(err);
                                            } else {
                        		                this.innerHTML = "Moment...";
                        		                this.disabled = true;
                        		                this.style.color = "dimgray";
                        		                var str = "";
                        		                for (var i = 0; i < frm.elements.length; i++) {
                        		                    if (frm.elements[i].name) {
                        		                        str += frm.elements[i].name + "=" + encodeURI(frm.elements[i].value) + "&";
                        		                    };
                        		                };
                        		                
                                    		    var url = "http://fcgh.net/PHP/Client.Sub.Post.ErrorReporter.php";
                                    		    ax.open("POST", url, true);
                                                ax.setRequestHeader("Content-Type", "application\/x-www-form-urlencoded");
                                                ax.setRequestHeader("Content-Length", str.length);
                                                ax.setRequestHeader("Connection", "close");
                                    		    ax.send(str);
                            		        };
                            		    } else {
                            		        alert("STOPP. Konnte AJAX nicht initialisieren.\nBitte nicht erneut versuchen.");
                            		    };
                                    };
                                };
                                
                            break;
                        };
                    };
                };
                
    		    ax.onreadystatechange = function() {
    		        window.status = "Warte auf Server...";
    		        if (ax.readyState == 4) {
    		            if (ax.status == 200) {
		                    var cr = ax.responseText;
		                    try {
		                        if (lnk) {
		                            if (cr == "OK") {
    		                            lnk.style.display = "none";
		                                alert("Danke für Deine Benachrichtigung.\nNACH ABLAUF VON 48 STUNDEN:\nSollte ein erneuter Zugriff auf die Steckbriefe scheitern,\nwurde auf die Anfrage negativ reagiert und der übermittelte Domainname NICHT hinzugefügt.");
		                            } else {
		                                alert(cr);
		                            };
		                        };
		                        JS_AJAX_ErrorReporting();
    		                } catch(e) {
    		                    alert(e);
    		                };
    		                window.status = window.defaultStatus;
    		            } else {
    		                alert("Unbekannter Fehler bei der Datenverarbeitung.\nStatus: " + ax.status + "\nAntwort: " + ax.responseText);
    		                window.status = window.defaultStatus;
    		                JS_AJAX_ErrorReporting();
    		            };    		            
    		        };
    		    }; // endfn onreadystatechange
                
                if (ui) {
                    ui.style.display = "none";
                    // Verstecken verhindern
                    ui.onclick = function(e) {
                        e = new Event(e);
                        e.stop();
                    };                        
                    
                    lnk.onclick = function() {
                        ui.style.display = ui.style.display == "block" ? "none" : "block";
                    };
                };
		    }; // endif lnk
		}; // endif ax

    }; // endfn
    
    

//##  ENDE  AJAX-Funktion für die Fehlerberichterstattung
//############################################################################################################
//############################################################################################################
//############################################################################################################
//############################################################################################################
////
//############################################################################################################
//############################################################################################################
//############################################################################################################
//############################################################################################################
//## ANFANG Funktionen für die Startseite

    
        function JS_Kalender(n) {
            JS_DCAL_Init(n);
        };
        
        function JS_KalGeheZ(e) {
            var z;
            if (z = document.getElementById("KALENDERGEHEZU")) {
                z.style.display = z.style.display == "block" ? "none" : "block";
                var x = document.body;
                var zfn = function() {
                    if (z) {
                        if (window.event) {
                            var f = false;
                            switch (window.event.srcElement.tagName) {
                                case "SPAN":
                                case "H4":
                                
                                    var d = window.event.srcElement;
                                    var i = 0;
                                    while (d = d.parentNode || i < 10) {
                                        if (d.id) {
                                            if (d.id == "DCAL") {
                                                f = true;
                                                break;
                                            };
                                        };
                                        i++;
                                    };
                                
                                break;
                            }; 
                            if (!f) {
                                z.style.display = "none";
                            };
                        } else {
                            z.style.display = "none";
                        };
                    };
                };
                if (x.addEventListener) {
                    x.addEventListener("click", zfn, true);
                };
                if (x.attachEvent) {
                    x.attachEvent("onclick", zfn);
                };
            };
        };
    
        function JS_DCAL_Init(q) {
            var ax = JS_AJAX();
            if (ax) {
    		    ax.onreadystatechange = function() {
    		        // window.status += "..." + ax.readyState;
    		        if (ax.readyState == 4) {
        		        var tc = document.getElementById("DCAL");
        		        if (tc) {
        		            tc.innerHTML = ax.responseText;
        		        };
        		    };
    		    };
    		    var url = "http://fcgh.net/PHP/Client.Sub.Kalender.php?q=" + q;
    		    ax.open("GET", url, true);
                ax.send(null);
            };
        };


//############################################################################################################
//############################################################################################################



    
        function JS_RPIC_Init() {
            var ax = JS_AJAX();
            if (ax) {
    		    ax.onreadystatechange = function() {
    		        // window.status += "..." + ax.readyState;
    		        if (ax.readyState == 4) {
        		        var tc = document.getElementById("RPIC");
        		        if (tc) {
        		            tc.innerHTML = ax.responseText;
        		        };
        		    };
    		    };
    		    var url = "http://fcgh.net/PHP/Client.Sub.Rand_Pic.php";
    		    ax.open("GET", url, true);
                ax.send(null);    		    
            };
        };



//############################################################################################################
//############################################################################################################









        function JS_Anfahrt_Init(id) {
            var LI = document.getElementById(id);
            if (!LI || !document.createElement) {
                return;
            };
            window.ANFZ_NHTML = '<SPAN>Anfahrt<\/SPAN>';
            window.ANFZ_WHTML = '<SPAN><B style="color:green">Moment...<\/B><\/SPAN>';
            LI.innerHTML = window.ANFZ_NHTML;
            LI.onclick = function(e) {
                e = new Event(e);
                if (!e) { alert("Browser nicht unterstützt."); return false; };
                var DV, MD, AX, dvid = "ANFZ";
                // x- und y-Position von Link holen
                var x = e.page.x;
                    x = x < 162 ? 162 : x;
                var y = e.page.y;
                e.stop();
                DV = document.getElementById(dvid);
                if (typeof DV == null || !DV) {
                    DV = document.createElement("DIV");
                    MD = document.getElementById("H");
                    MD.appendChild(DV);
                    DV.id = dvid;

                    window.ANFZ_TRANS = new Fx.Style(DV, 'opacity', {
                    	duration: 500, 
                    	transition: Fx.Transitions.Quart.easeInOut
                    });
                };
                if (!DV) {
                    return false;
                };

                DV.style.top  = (Math.round(y - (352/7))) + "px";
                DV.style.left = (Math.round(x)) + "px";
                LI.innerHTML = window.ANFZ_WHTML;
                LI.disabled = true;
                
                AX = new JS_AJAX();
                AX.open("get", ZYX_ANFAHRT_AJAX_BASE);
                AX.onreadystatechange = function() {
                    if (AX.readyState !== 4) return;
                            DV.innerHTML = AX.responseText;
                            DV.style.display = "block";
                            window.ANFZ_TRANS.start(1);
                            LI.innerHTML = window.ANFZ_NHTML;
                            LI.disabled = false;
                            var focusinp = $("Z_SADDR");
                            if (focusinp) {
                                window.ANFZ_INPUT = focusinp;
                                window.setTimeout("window.ANFZ_INPUT.focus()",  777);
                            };
                            //LI.className = isshow ? 'C' : 'N';
                            var closebtn = $("Z_ANFCLOSE");
                            if (closebtn) {
                                closebtn.onclick = function() {
                                    window.ANFZ_TRANS.start(0);
                                };
                            };
                            var luftbbtn = $("Z_ANFLUFTB");
                            if (luftbbtn) {
                                luftbbtn.onclick = function() {
                                    window.location.href = window.ZYX_ANFAHRT_AJAX_LREF;
                                };
                            };
                            return false;
                };
                AX.send(null);
                return false;
            };
        };
        
    
    
    
        // Ausführung, wenn User eingeloggt
        function JS_UserAuth_User(W) {
            W.className = "JSOK";
            var USERLOGOUT = $("USERAUTH_LO");
            if (!USERLOGOUT) {
                return false;
            };
            USERLOGOUT.innerHTML = "<STRONG>Abmelden</STRONG>";
            USERLOGOUT.className = window.MSIE ? "JSIE" : "JSOK";
            USERLOGOUT.onclick = function() {
                var AUX = JS_AJAX();
                if (!AUX) {
                    return false;
                };
                var qs = String.fromCharCode(27);
                var qf = (Math.round(((new Date()).getTime())/1000));
                var qs = escape(qs);
                var qs = window.ZYX_FCGHNET_U_AUTHAPP + qs + "&MSIE=" + qf;
                AUX.onreadystatechange = function() {
                    var axdn = (AUX.readyState == 4) && (AUX.status == 200);
                    USERLOGOUT.innerHTML = axdn ? "Abmelden" : "Moment...";
                    if (!axdn) return;
                    if (window.location.href) {
                        var frm = document.forms["USERAUTH"];
                        frm.action = window.location.href + "?USERAUTH=0";
                    };
                    if (window.MSIE) {
                        document.cookie = window.ZYX_FCGHNET_U_LO_COOK;
                    };
                    frm.submit();
                };
                AUX.open("GET", qs, true);
                AUX.send(null);
                return true;
            };
        }; // -- endfn JS_UserAuth_User --
    
    
        // Ausfühung unabhängig vom Login-Status
        function JS_UserAuth_Init() {
            if (!document.getElementById) return false;
            var U  = $("U"); // Login-Felder
            var W  = $("W"); // Logout
            var IU = $("USERAUTH__UN"); // Benutzer
            var IP = $("USERAUTH__UP"); // Kennwort
            var IS = $("USERAUTH__US"); // merken
            var IN = $("USERAUTH__NH"); // neu hier?
            var IB = $("USERAUTH__BT");
            // Wenn User eingeloggt: JS_UserAuth_User, sonst weiter
            if (W) {
                JS_UserAuth_User(W);
                return;
            };
            // Wenn User NICHT eingeloggt:
            if (!U || !V ||!IB) {
                return false;
            };
            var frm = document.forms["USERAUTH"];
            if (!frm) {
                return false;
            };
            
            function JS_UserAuth_BB(e) {
                if (!e) var e = window.event;
                e = new Event(e);
                var srcobj = e.target;
                var nohide = [];
                    var ca = U.getElementsByTagName("*");
                    var cb = V.getElementsByTagName("*");
                    for (var i = 0; i < ca.length; i++) { nohide.push(ca[i]);   };
                    for (var i = 0; i < cb.length; i++) { nohide.push(cb[i]);   };
                var isbase = (nohide.indexOf(srcobj) > -1);
                if (window.MSIE) {
                    var isshow = V.style.display == "block";                    
                    if (isbase && isshow) return;
                    if (!isshow && isbase) V.style.display = "block";
                    if (isshow && !isbase) V.style.display = "none";
                    return;
                };
                var isshow = V.style.opacity; isshow = isshow !== "0";
                // ANZEIGEN     wenn: isbase && !isshow
                // AUSBLENDEN   wenn: !isbase
                // RETURN       wenn: isbase && isshow
                if ( isbase &&  isshow) return;
                if (!isshow &&  isbase) Transition.start(1);
                if ( isshow && !isbase) Transition.start(0);
            };
            
            window.USERAUTH_LoginButtonText = IB.innerHTML;
            // Bug in MSIE: Button-Type läßt sich nicht programmatisch setzen
            if (window.MSIE || window.opera) {
                IB.onclick = function() { window.JS_UserAuth_Authenticate(); };
            } else {
                IB.type = "submit";
            };
            window.JS_UserAuth_Authenticate = function() {
                var AUX = JS_AJAX();
                if (!AUX) {
                    alert("Stopp. Konnte den Vorgang nicht fortsetzen, weil ein erforderliches Objekt nicht geladen werden konnte. Dies liegt möglichereise daran, dass Dein Browser nicht mit fcgh.net kompatibel ist.");
                    return false;
                };
                var qs = String.fromCharCode(4);
                var qf = (Math.round(((new Date()).getTime())/1000));
                var qs = escape(IU.value + qs + IP.value + qs + (IS.checked ?'1':'0') + String.fromCharCode(7));
                var qs = window.ZYX_FCGHNET_U_AUTHAPX + qf + ".php?q=" + qs;
                if ((trim(IU.value) == "") || (trim(IP.value) == "")) {
                    alert("Bitte Benutzername und Kennwort eingeben!");
                    return false;
                };
                AUX.onreadystatechange = function() {
                    var axdn = (AUX.readyState == 4) && (AUX.status == 200);
                    IB.disabled = !axdn;
                    IB.innerHTML = axdn ? window.USERAUTH_LoginButtonText : "...";
                    if (!axdn) return;
                    //alert(AUX.responseText); return;
                    var txt = AUX.responseText.split("|");
                    if (txt[0] !== "0") {
                        alert(txt[1]);
                    } else {
                        if (window.location.href) {
                            var frm = document.forms["USERAUTH"];
                            frm.action = window.location.href + "?USERAUTH=0";
                        };
                        frm.submit();
                    };
                };
                AUX.open("GET", qs, true);
                AUX.send(null);
                return false;
            };
            
            // Opera tickt aus beim Versuch, ONSUBMIT zu belegen
            if (window.opera) {
                frm.onsubmit = "return (window.JS_UserAuth_Authenticate())";
            } else {
                try {
                    frm.onsubmit = function(){ return (window.JS_UserAuth_Authenticate()); };
                } catch(e) {
                    U.style.display = "none";
                    V.style.display = "none";
                };
            };
            U.className = "JSOK";
        };
        




        function JS_NAV_Highlight_Saison() {
            window.NAV_SAISHC = false;
            window.NAV_SAISHB = false;
            var C = document.getElementById("N");
            if (C && (C = C.getElementsByTagName("DIV"))) {
                var i, j = C.length;
                for (i = 0; i < j; i++) {
                    if (C[i].className !== "SAISON") {
                        continue;
                    };
                    C[i].onmouseover = function() {
                        var H = this.getElementsByTagName("H3");
                        if (H[0]) {
                            window.NAV_SAISHB = H[0].style.backgroundColor;
                            window.NAV_SAISHC = H[0].style.color;
                            H[0].style.color = "black";
                            H[0].style.backgroundColor = "silver";
                        };
                    };
                    C[i].onmouseout = function() {
                        var H = this.getElementsByTagName("H3");
                        if (H[0]) {
                            H[0].style.color = window.NAV_SAISHC;
                            H[0].style.backgroundColor = window.NAV_SAISHB;
                        };
                    };
                };
            };
        };
        
    
    
        function JS_Main_Fix_Height() {
            // wg. Legacy-Code noch drinne
        };
    
    
        function JS_Fix_AKVS() {
            var fn = function() {
                var ww = 0;
                var wh = 0;
                if (self.innerWidth) {
                    ww = self.innerWidth;
                    wh = self.innerHeight;
                } else if (document.documentElement && document.documentElement.clientWidth) {
                    ww = document.documentElement.clientWidth;
                    wh = document.documentElement.clientHeight;
                } else if (document.body) {
                    ww = document.body.clientWidth;
                    wh = document.body.clientHeight;
                };
                if (ww < 1) return;
                var AKVS = document.getElementById("akct");
                if (!AKVS) return;
                AKVS.style.right = (ww > 1124 ? '0'    : 'auto');
                AKVS.style.left  = (ww > 1124 ? 'auto' : '859px');
                AKVS.style.top   = (ww > 1124 ? '0'    : '92px');
            };
            fn();
            if (window.addEventListener) {
                window.addEventListener('resize', fn, false); 
            } else if (window.attachEvent) {
                window.attachEvent('onresize', fn);
            };
        };










//############################################################################################################
//############################################################################################################
//############################################################################################################
//############################################################################################################
//##  ENDE  Funktionen für die Startseite
////

/*

    "If you need more than 3 levels of indentation, 
    you're screwed anyway, and should fix your program."

    -- Linus Torvalds

    1337 kekeke... ;-)

*/

