﻿var hockkomma = String.fromCharCode(34);
var backslash = String.fromCharCode(92);
var backUndHk = backslash + hockkomma;

var bildindexHTTP = null;
var HTTPtimerID = null;

        
function getBild(admin) {
    /*-----------------------------------------------------
        Das Index-File für die gewählte Gruppe holen
        und den Bildwechsel steuern*/
    var idxPic = 0;
    var maxPic = 0;
        
    getBild.prototype.cboIndex = 0;
    getBild.prototype.BildOrdner = "pics/";
    getBild.prototype.BildGruppe = "";
    getBild.prototype.BildPrefix = "";
    getBild.prototype.BildNr = 0;

    getBild.prototype.nextBild = function() {
        if ( this.BildNr < ( maxPic - 1 ) ) {
            this.BildNr ++;
            this.zeigeBild();
            // Bei Gelegenheit, wenn am Ende der Bildergallerie,  cmd-Farbe grau machen
        } 
    }
    
    getBild.prototype.prevBild = function() {
        if ( this.BildNr > (0 ) ) {
            this.BildNr --;
            this.zeigeBild();
            // Bei Gelegenheit, wenn am Ende der Bildergallerie,  cmd-Farbe grau machen
        } 
    }
    
    getBild.prototype.zeigeBild = function() {
        var pic = this.BildOrdner + this.BildGruppe + "/" + idxPic[this.BildNr].nr;
        bild.src = pic;
        
        info1.innerHTML = idxPic[this.BildNr].ti
        info2.innerHTML = idxPic[this.BildNr].be
    }
    
    getBild.prototype.getBildIndex = function() { 
        for ( i = 0; i < maxPic; i++ ) {
            var o = new setTabelle(i)
            o.BildNr = idxPic[i].nr;
            o.BildTitel = idxPic[i].ti;
            o.BildBeschr = idxPic[i].be;
            o.setTr();
        }    
     }
    
    getBild.prototype.ausgeben = function() {
        if ( bildindexHTTP.readyState == 4 ) {
            var str = bildindexHTTP.responseText;
          
            str = getUmlaut(str);

            /*---------------------------------------------------------------
                JSON-Datei extrahieren*/   
            //str = escape(str); 
            try {
            idxPic = eval( "(" + str + ")" ) 
            maxPic = idxPic.length;
            
                if ( admin ) {
                    oBild.getBildIndex();
                    setListenHandler();         //Liegt in admin1.JS
                } else { 
                    oBild.zeigeBild(); 
                }
            } catch(e) {
                var inf = new setInfo();
                inf.text = 
                "Bild-Information kann nicht geladen werden!<br />" +
                "Versuchen sie es später noch einmal"
                inf.machMeldung();
            }
        }
    }    

    getBild.prototype.holeIndex = function() {
        var infoFile = this.BildOrdner + this.BildGruppe  + "/" + this.BildGruppe + ".JSON";
        
        if ( window.XMLHttpRequest ) {
            bildindexHTTP = new XMLHttpRequest();
        } else if ( window.ActiveXObject ) {
            bildindexHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if ( bildindexHTTP != null ) {
            with ( bildindexHTTP ) {
                var zeit = new Date();
                var ms = zeit.getMilliseconds();
                open("GET", infoFile +'?' +ms, "true");
                
                onreadystatechange = this.ausgeben;
                send(null);
            }
        }
    }
}

function HTTPabbrechen() {
    bildindexHTTP.abort();
    var inf = new setInfo();
    inf.machMeldung();
}

function setInfo() {

    setInfo.prototype.color = "#000000";
    setInfo.prototype.text = 
        "Ups... Verbindung unterbrochen.<br />" +
        "Möglicherweise wurden nicht alle Daten gespeichert."
    
    setInfo.prototype.machMeldung = function() {
        var info = document.getElementById("info");

        info.style.color = this.color;
        info.innerHTML = this.text
    }
}

function getUmlaut(s) {
    var expr = new RegExp( backUndHk );
    s = s.replace(/\\\"/g, hockkomma);
    
    s = s.replace(/&uuml;/g, "ü");
    s = s.replace(/&Uuml;/g, "Ü");

    s = s.replace(/&auml;/g, "ä");
    s = s.replace(/&Auml;/g, "Ä");

    s = s.replace(/&ouml;/g, "ö");
    s = s.replace(/&Ouml;/g, "Ö");

    return s;
}


function setUmlaut(s) {
    s = s.replace(/ü/g, "&uuml;");
    s = s.replace(/Ü/g, "&Uuml;");

    s = s.replace(/ä/g, "&auml;");
    s = s.replace(/Ä/g, "&Auml;");

    s = s.replace(/ö/g, "&ouml;");
    s = s.replace(/Ö/g, "&Ouml;");
    
    s = escape(s);
    return s;
}

function setNichtErlaubteZeichen(s) {
    s = s.replace(/\"/g, "'");
    s = s.replace(/\</g, " ");
    s = s.replace(/\>/g, " ");
    
    return s;
}

function handbuch(file) {
    var handbuchHTTP;
    var handbuch = document.getElementById("handbuch");
    
    if ( window.XMLHttpRequest ) {
        handbuchHTTP = new XMLHttpRequest();
    } else if ( window.ActiveXObject ) {
        handbuchHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if ( handbuchHTTP != null ) {
        with ( handbuchHTTP ) {
            open("GET", "infoTXT/" + file + ".txt", "true");
            onreadystatechange = getHandbuch;
            send(null);
        }
    }

function getHandbuch () {
    if ( handbuchHTTP.readyState == 4 ) {
        var str = handbuchHTTP.responseText;
        
        handbuch.innerHTML = str;
        with ( handbuch.style) {
            backgroundColor = "#ffffff";
            border = "solid 1px #eeeeee";
            borderBottomStyle = "none";
            borderRightStyle = "none";
        }
    }
}

    
}
