
var movediv = null;

var glidesspace = 144; //haelfte Flaeche geteilt durch Bildanzahl (abgerundet)
var glidetime = 1;
var gstep = 10;
var glidestep = 1;
var gliding = null;
var aktglide = 12;
var startglide = 0;

var maxleft = 1140;
var maxrleft = 12;
var minleft = -1140;

var mitte = 72;


var min = 67.2;
var max = 134;

var ad = max - min;

var half = 573;


var mw = 0;


function initStuff(){
    var schlitten = document.getElementById("schlitten");
    if(schlitten){
        for(var i = 0; i <= 8; i++){
            setBilder(i);
        }
    }
    initArtikelscroll();
}

function glideApp(richtung){
    mw = 0;
    if(gliding){
        return;
    }
    var schlitten = document.getElementById("schlitten");
    mleft = schlitten.offsetLeft;
//    alert(mleft);
    if((mleft >= maxrleft  && (richtung > 0))  || (mleft <= minleft && (richtung < 0))){
        return;
    }
    
    aktglide = schlitten.offsetLeft;
    startglide = aktglide;
    glidestep = gstep * richtung;
    if(!gliding){
        gliding = window.setInterval(glidingApp, glidetime);
    }
}

function glidingApp(){
    var schlitten = document.getElementById("schlitten");
    aktglide += glidestep;
    for(var i = 0; i <= 8; i++){
        setBilder(i);
    }
    if(glidestep < 0){
        if(aktglide < (startglide - glidesspace) || aktglide < minleft){
            aktglide = startglide - glidesspace;
            schlitten.style.left = aktglide + 'px';
            window.clearInterval(gliding);
            gliding = null;
            return;
        }
    }
    if(glidestep > 0){
        if(aktglide > (startglide + glidesspace) || aktglide > maxrleft){
            aktglide = startglide + glidesspace;
            schlitten.style.left = aktglide + 'px';
            window.clearInterval(gliding);
            gliding = null;
            return;
        }
    }
    schlitten.style.left = aktglide + 'px';
}


function setBilder(pos){
    var f = document.getElementById("b_" + pos);
    var b = document.getElementById("i_" + pos);
    var fl = f.offsetLeft;
    var fakt = aktglide - maxrleft + fl;
    var faktz = fl - fakt;
    faktz = fakt > 0 ? fakt : fakt * -1;
    var faktor = 100 / 730 * faktz;
    var width = 224 - (196 / (100 / faktor));
    width = parseInt(width);
    var op = parseInt((100 - faktor) / 10 ) + 1;
    op = op > 10 ? 10 : op;
    op = op < 0 ? 0 : op;
    b.style.opacity = op/10;
    b.style.filter = 'alpha(opacity=' + op*10 + ')';
//    b.style.width = width + 'px';
    var height = 336 - b.offsetHeight;

    var mar = parseInt(width / 2);
//    b.style.marginLeft = -mar + 'px';
//    var top = parseInt(height / 0.8);
//    b.style.top = top + 'px';

}


function unsetTbg(b){
    var op = 0;
    b.style.opacity = op/10;
    b.style.filter = 'alpha(opacity=' + op*10 + ')';
}
function setTbg(b){
    var op = 2;
    b.style.backgroundColor = '#ffffff';
    b.style.opacity = op/10;
    b.style.filter = 'alpha(opacity=' + op*10 + ')';
}

function debug(text){
    var deb = document.getElementById("debug");
    if(deb){
        deb.value = text;
    }
}


function getX(el) {
    x = el.offsetLeft;
    if (!el.offsetParent) return x;
    else return (x+getX(el.offsetParent));
}

function getY (el) {
    y = el.offsetTop;
    if (!el.offsetParent) return y;
    else return (y+getY(el.offsetParent));
}



var xpos=0;
var ypos=0;

var xstart=0;
var ystart=0;
var moving=false;

var xunt = 0;

document.onmousemove = mauspos;


function mauspos(e) {
    if (navigator.appName == 'Netscape') {
        xpos = e.pageX;
        ypos = e.pageY;
    } else {
        xpos = window.event.x;
        ypos = window.event.y;
    }
}

function movestart(el){
    ystart = ypos;
    xstart = xpos;
    var le = el.offsetLeft;
    xunt = xstart - le;
    moving=true;
}
function move(div){
    if(moving){
        xdif = xpos - xstart;
        xo = div.offsetLeft + xdif;
        div.style.left = xo + 'px';
        xstart = xpos;

        ydif = ypos - ystart;
        yo = div.offsetTop + ydif;
        div.style.top = yo + 'px';
        ystart = ypos;
    }
}



function setText(divname,text){
    var t = document.getElementById(divname);
    if(t){
        t.value = text;
    }
}



function moveend(){
    moving=false;
}


function moveArrright(element){
    var larr = document.getElementById("bfmfarr");
    var rarr = document.getElementById("bfmlarr");
    var gf = document.getElementById("tbr");
    xstart = xpos;
    if (navigator.appName == 'Netscape') {
        xstart = xpos - getX(gf);
    }
    var isleft = false;


    var rleft = element.offsetLeft + element.offsetWidth;
    var lleft = element.offsetLeft;
    var carr = xstart - element.offsetLeft;
    var hwidth = element.offsetWidth / 2;
    
    var prl = rarr.offsetLeft;
    var pll = larr.offsetLeft;

    if(prl < xstart){
        rarr.style.left = rleft + 'px';
    }else{
        if(pll > xstart){
            larr.style.left = lleft + 'px';
        }else{

            var rdiff = prl - xstart;
            var ldiff = xstart - pll;
            
            if(rdiff > ldiff){
                if(pll == (lleft)){
                    rarr.style.left = rleft + 'px';
                }else{
                    larr.style.left = lleft + 'px';
                }
            }else{
                if(prl == (rleft)){
                    larr.style.left = lleft + 'px';
                }else{
                    rarr.style.left = rleft + 'px';
                }
            }
        }
    }
    prl = rarr.offsetLeft;
    pll = larr.offsetLeft;
    var child;
    var cleft = 0;
    var cright = 0;
    var green = '#6aae23';
    var gray = '#dfe2e7';
    var blocks = 0;
    var von = 0;
    var bis = 0;
    var counter = 0;
    var bbis = true;
    for(var i = 0; i < element.parentNode.childNodes.length; i++){
        child = element.parentNode.childNodes[i];
        if(child.tagName == "TD"){
            cleft = child.offsetLeft;
            cright = child.offsetLeft + child.offsetWidth;
            if(cleft < pll || cright > prl){
                if(cright > prl){
                    if(bis == 0){
                        bis = getBis(counter);
                    }
                }
                child.style.backgroundColor = gray;
            }else{
                if(von == 0){
                    von = getVon(counter);
                }
                child.style.backgroundColor = green;
                blocks++;
            }
            counter++;
        }

    }
    if(bis == 0){
        bis = getBis((counter--));
    }

    var ergebnis = document.getElementById("bfmergebnis");
    
    var sblock = '1 Block ';
    if(blocks > 1){
        sblock = blocks + ' Blocks ';
    }
    var minutes = blocks * 90;
    ergebnis.innerHTML = '= ' + sblock + ' <label id="lblergebnis">(' + minutes + ' Minuten)</label> &agrave; 40 &euro;';

    var tvon = document.getElementById("txtVon");
    var tbis = document.getElementById("txtBis");
    var tblocks = document.getElementById("txtBlocks");
    tvon.value = von;
    tbis.value = bis;
    tblocks.value = blocks;

}


function validate(address) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test(address);
}

function istTelefon(telefon) {
    if (telefon.length > 22) {
        return false;
    }
    for (var i = 0; i < telefon.length; i++) {
        if ((telefon.charAt(i) < "0" || telefon.charAt(i) > "9") &&
            telefon.charAt(i) != "-" && telefon.charAt(i) != "/" && telefon.charAt(i) != " " &&
            telefon.charAt(i) != "(" && telefon.charAt(i) != ")" &&
            telefon.charAt(i) != "+") {
            return false;
        }
    }
    return true;
}

// function clickKategorie(textfeldname,)



function bestellung(sessionid,groesselist,farbeinput,artikelid,mengeinput){
    var lstGroesse = document.getElementById(groesselist);
    var txtFarbe = document.getElementById(farbeinput);
    var menge = document.getElementById(mengeinput).value;
    var selg = getSingleSelectWert(lstGroesse);

    var farbe = txtFarbe.value;

    var sonstiges = new Array();

    sonstiges[0] = "Artikeleigenschaft_ID:" + selg;
    sonstiges[1] = "Artikeleigenschaft_ID:"+farbe;

    //    Mitarbeiter[0] = new Object();
    //Mitarbeiter[0]["Name"] = "Müller";
    //Mitarbeiter[0]["Vorname"] = "Hans";
    //Mitarbeiter[0]["Wohnort"] = "Dresden";
    //
    //Mitarbeiter[1] = new Object();
    //Mitarbeiter[1]["Name"] = "Schulze";
    //Mitarbeiter[1]["Vorname"] = "Frauke";
    //Mitarbeiter[1]["Wohnort"] = "Berlin";
    //
    //for (var i = 0; i < Mitarbeiter.length; i++) {
    //  document.write("<dl><dt>Mitarbeiter " + (i + 1) + "<\/dt>");
    //  for (var Eigenschaft in Mitarbeiter[i])
    //    document.write("<dd>" + Eigenschaft + ": " + Mitarbeiter[i][Eigenschaft] + "<\/dd>");
    //  document.write("<\/dl>");
    //}

    ArtikelBestellung(sessionid,artikelid,menge,sonstiges);


    
}



function getSingleSelectWert(sObj) {
    with (sObj) return options[selectedIndex].value;
}


function getMultipleSelectWert(sObj, trenn) {
    var rVal = '';
    for (var i=0; i<sObj.options.length; i++) with (sObj.options[i])
        if (selected) rVal += trenn + value;
    return rVal.substring(trenn.length);
}





function colorchoiced(farbe,htmlfarbe){
    var farbshow = document.getElementById('lblFarbshow');
    var farbname = document.getElementById('lblFarbe');
    if(farbshow){
        farbshow.style.backgroundColor = htmlfarbe;
    }
    if(farbname){
        farbname.firstChild.nodeValue = farbe;
    }
}





//
//
//
//
//// complement
////temprgb=thisrgb;
////temphsv=RGB2HSV(temprgb);
////temphsv.hue=HueShift(temphsv.hue,180.0);
////temprgb=HSV2RGB(temphsv);
//
//function RGB2HSV(rgb) {
//    var hsv = new Object();
//    var max=max3(rgb.r,rgb.g,rgb.b);
//    var dif=max-min3(rgb.r,rgb.g,rgb.b);
//    hsv.saturation=(max==0.0)?0:(100*dif/max);
//    if (hsv.saturation==0) hsv.hue=0;
//    else if (rgb.r==max) hsv.hue=60.0*(rgb.g-rgb.b)/dif;
//    else if (rgb.g==max) hsv.hue=120.0+60.0*(rgb.b-rgb.r)/dif;
//    else if (rgb.b==max) hsv.hue=240.0+60.0*(rgb.r-rgb.g)/dif;
//    if (hsv.hue<0.0) hsv.hue+=360.0;
//    hsv.value=Math.round(max*100/255);
//    hsv.hue=Math.round(hsv.hue);
//    hsv.saturation=Math.round(hsv.saturation);
//    return hsv;
//}
//
//// RGB2HSV and HSV2RGB are based on Color Match Remix [http://color.twysted.net/]
//// which is based on or copied from ColorMatch 5K [http://colormatch.dk/]
//function HSV2RGB(hsv) {
//    var rgb=new Object();
//    if (hsv.saturation==0) {
//        rgb.r=rgb.g=rgb.b=Math.round(hsv.value*2.55);
//    } else {
//        hsv.hue/=60;
//        hsv.saturation/=100;
//        hsv.value/=100;
//        i=Math.floor(hsv.hue);
//        f=hsv.hue-i;
//        p=hsv.value*(1-hsv.saturation);
//        q=hsv.value*(1-hsv.saturation*f);
//        t=hsv.value*(1-hsv.saturation*(1-f));
//        switch(i) {
//        case 0: rgb.r=hsv.value; rgb.g=t; rgb.b=p; break;
//        case 1: rgb.r=q; rgb.g=hsv.value; rgb.b=p; break;
//        case 2: rgb.r=p; rgb.g=hsv.value; rgb.b=t; break;
//        case 3: rgb.r=p; rgb.g=q; rgb.b=hsv.value; break;
//        case 4: rgb.r=t; rgb.g=p; rgb.b=hsv.value; break;
//        default: rgb.r=hsv.value; rgb.g=p; rgb.b=q;
//        }
//        rgb.r=Math.round(rgb.r*255);
//        rgb.g=Math.round(rgb.g*255);
//        rgb.b=Math.round(rgb.b*255);
//    }
//    return rgb;
//}
//




function checkNumber(value){
    var bval = true;
    if(value.length > 0){
        for(var i = 0; i < value.length; i++){
            var zeichen = value[i];
            if(zeichen == '0' || zeichen == '1' || zeichen == '2' || zeichen == '3' || zeichen == '4' || zeichen == '5' || zeichen == '6' || zeichen == '7' || zeichen == '8' || zeichen == '9'){

            }else{
                bval = false;
            }
        }
    }
    return bval;
}



function removeWarenkorbitem(warenkorbitemid){
    REMOVEWI(warenkorbitemid);
    return true;
}

function updateWarenkorbitemMenge(wid,menge,wiepreis,wigesamtfeld,wlabel,wtxt,wialtgesamt){
    //
    if(menge.length == 0){
        menge = 0;
    }
    if(!checkNumber(menge)){
        menge = 0;
    }
    var gesamt = document.getElementById(wtxt);
    var gesamtlabel = document.getElementById(wlabel);
    var wigesamtlabel = document.getElementById(wigesamtfeld);

    var wialtgesamttxt = document.getElementById(wialtgesamt);
    var nwiges = wiepreis * menge;
    //    alert(wigesamtlabel.firstChild);

    var wia = wialtgesamttxt.value;
    var fdiff = (nwiges * 1) - (wia * 1);
    var diff = gesamt.value * 1 + fdiff;
    //    alert(gesamtlabel.firstChild);
    wialtgesamttxt.value = nwiges;
    wigesamtlabel.firstChild.nodeValue = nwiges.toFixed(2) ;

    gesamt.value = diff;
    gesamtlabel.firstChild.nodeValue = diff.toFixed(2);
    UpdateWIMenge(wid,menge);

}


function updateWarenkorbgesamt(txtWarenkorbid,txtWarenkorbgesamt,txtWarenkorbitemanzahl){
    var wkid = document.getElementById(txtWarenkorbid).value;
    var gesamtsumme = document.getElementById(txtWarenkorbgesamt).value;
    var itemanzahl = document.getElementById(txtWarenkorbitemanzahl).value;


    UpdateWSumme(wkid,gesamtsumme);

    return true;
}

function checkLogin(){
    var user = document.getElementById("user").value;
    var passwort = document.getElementById("pass").value;
    if(user.length == 0 || passwort.length == 0){
        showMessage("Logindaten nicht korrekt!","Bitte tragen Sie Name und Passwort ein.","no.gif");
        return false;
    }
    return true;
}

function showMessage(head,text,bild,feld){
    mhead = head;
    mtext = text;
    mbild = bild;
    mfeld = feld;

    showBlende("afterblendeshowMessage");
}



function afterblendeshowMessage(){
    head = mhead;
    text = mtext;
    bild = mbild;
    feld = mfeld;
    var zusatz = "";
    if(feld){
        document.getElementById(feld).style.visibility = 'hidden';
        zusatz = "showElement('" + feld + "');";
    }
    var  eltext = "    <img id=\"meldembild\" src=\"css/ressources/meldungen/" + bild +"\" alt=\"Meldung\"/>\n";
    eltext += "    <span style=\"position:absolute; left:20px;top:5px;font-weight: bold;line-height:24px;padding-left:79px;\">" + head + "</span><br/>\n";
    eltext += "    <div id=\"meldetext\">" + text + "</div>\n";
    //            eltext += "    <input id=\"messagebutton\" onclick=\"removeElement('messagelb');endBlende(); " + zusatz + "\" type=\"button\" name=\"mpvsubmit\" value=\"OK\" />\n";
    eltext += "    <input id=\"messagebutton\" onclick=\"removeElement('messagelb');endBlende(); " + zusatz + "\" type=\"button\" name=\"mpvsubmit\" value=\"OK\" />\n";
    var body = document.body;
    var div = document.createElement("DIV");
    div.id = "messagelb";
    div.style.zIndex = 300;
    //    div.style.position = 'absolute';
    div.innerHTML = eltext;
    body.appendChild(div);
}

function removeElement(name){
    var div = document.getElementById(name);
    var pdiv = null;
    if(div){
        pdiv = div.parentNode;
        if(pdiv){
            pdiv.removeChild(div);
        }
    }
}
























//news_magazin
var elArray = new Array();
var aktuellIMG = null;
var firstIMG = null;
var lastIMG = null;

var DoStart = 0;
var DoAktuell = 0;
var DoEnd  = 0;
var DoElement = null;
var DoWhatToDo = '';
var DoAnyAktion = null;
var DoAktionSpeed = 50;
var DoAktionStep = 1;
var DoAktionAuslauf = null;
var DoAktionLeavingSteps = 0;
var DoAktionSteps = 0;
var DoAktionminderer = 2.5;


function cgNewsSubSlide(richtung){
    if(richtung < 0){
        slideLeft();
    }else{
        slideRight();
    }
}
function slideLeft(){
    var start = DoStart; //aktuelle Left-Position
    var end = DoEnd; //Bildbreite
    var speed = 1; //Geschwindigkeit
    var step = 50; // Schrittweite
    var auslauf = 10; //die letzten xxx Schritte Auslaufen lassen
    var isl = document.getElementById('cgnewssubslider');
    if(isl){
        elArray = new Array();
        getDivs(isl);
        checkCGSlidePosition();
        start = DoStart;
        if(aktuellIMG){
            end = start - aktuellIMG.offsetWidth;
        }
        doAnythingTimed(isl,'scrolling',start,end,speed,step,auslauf);
    }
}

function slideRight(){
    var start = DoStart; //aktuelle Left-Position
    var end = DoEnd; //Bildbreite
    var speed = 1; //Geschwindigkeit
    var step = 50; // Schrittweite
    var auslauf = 10; //die letzten xxx Schritte Auslaufen lassen
    var isl = document.getElementById('cgnewssubslider');
    if(isl){
        elArray = new Array();
        getDivs(isl);
        checkCGSlidePosition();
        start = DoStart;
        if(aktuellIMG){
            end = start + aktuellIMG.offsetWidth;
        }
        doAnythingTimed(isl,'scrolling',start,end,speed,step,auslauf);
    }
}

function checkCGSlidePosition(){
    var isl = document.getElementById('cgnewssubslider');
    
    var img = null;
    var mleft = 0;
    var mright = 0;
    var margin = 0;
    var aktleft = 0;

    //    getDivs(isl);
    //    alert(elArray.length);
    for(var i = 0; i < elArray.length; i++){
        img = elArray[i];
        
        lastIMG = img;
        if(i == 0){
            firstIMG = img;
        }
        //        mleft = parseInt(img.style.marginLeft);
        //        mright = parseInt(img.style.marginRight);
        if(i == 0){
            margin += mleft;
        }
        //        alert(img.offsetLeft + "," + mleft + "," + mright + "," + isl.offsetLeft);
        aktleft = parseInt(img.offsetLeft - margin) *-1;
        
        if(isl.offsetLeft == (aktleft)){
            //            alert("OK");
            aktuellIMG = img;
        }
        
    //        if(i > 0){
    //            margin += mleft;
    //            margin += mright;
    //        }
    }
//    alert(firstIMG.offsetLeft + " - " + aktuellIMG.offsetLeft + " - " + lastIMG.offsetLeft);
}


function getDivs(div){
    
    if(div){
        if(div.nodeName == "DIV"){
            if(!div.id || div.id != 'cgnewssubslider'){
                elArray.push(div);
            }
        }
        if(div.childNodes){
            for(var i = 0; i < div.childNodes.length; i++){
                var child = div.childNodes[i];
                getDivs(child);
            }
        }
    }
}


function doAnythingTimed(element,what,start,end,speed,step,auslauf){
    DoAktionAuslauf = null;
    DoAktionStep = 1;
    DoAktionSpeed = 50;
    if(!element || !what){
        return;
    }
    if(DoAnyAktion){
        return;
    }
    if(speed){
        DoAktionSpeed = speed;
    }
    if(step){
        DoAktionStep = step;
    }
    
    if(auslauf){
        DoAktionAuslauf = auslauf;
    }

    DoStart = start;
    DoAktuell = start;
    DoEnd = end;
    DoElement = element;
    var richtung = DoAktionStep > 0;
    if(what == 'scrolling'){
        if(DoStart > DoEnd){
            DoAktionSteps = parseInt((DoStart - DoEnd) / DoAktionStep);
            richtung = true;
        }else{
            DoAktionSteps = parseInt((DoEnd - DoStart) / DoAktionStep);
            richtung = false;
        }
        //        alert("S" + richtung);
        DoAktionLeavingSteps = 0;
        


        //        DoAktionAuslauf = 100 / DoAktionSteps  * DoAktionAuslauf;
        DoAnyAktion = window.setInterval(scrollDiv, DoAktionSpeed,richtung);
    }

}

function scrollDiv(richtung){
    //    alert(richtung);
    var bl = document.getElementById('backlink');
    var nl = document.getElementById('nextlink');
    var bildschrift = null;
    bl.style.visibility = 'visible';
    nl.style.visibility = 'visible';
    if(richtung){
        DoAktuell -= DoAktionStep;
        //        alert(DoAktuell + "," + DoEnd);
        if(DoAktuell <= DoEnd){
            DoElement.style.left = DoEnd + 'px';
            checkCGSlidePosition();
            //            alert(lastIMG.offsetLeft + " - " + aktuellIMG.offsetLeft);
            if(lastIMG === aktuellIMG){
                
                bl.style.visibility = 'hidden';
            }
            DoStart = DoEnd;

            //            bildschrift = document.getElementById('bildschrift');
            //            bildschrift.innerText = aktuellIMG.getAttribute('itext');
            window.clearInterval(DoAnyAktion);
            DoAnyAktion = null;
            return;
        }
        //        alert(DoAktionAuslauf);
        //        alert(DoAktionStep + ',' + DoAktionAuslauf + ',' + DoAktionSteps + ',' + DoAktionLeavingSteps);
        if(DoAktionAuslauf >= (DoAktionSteps - DoAktionLeavingSteps)){
            //                       alert("OK");
            DoAktionStep -= DoAktionminderer;
            
            if(DoAktionStep < 1){
                DoAktionStep = 1;
            }
        }

        DoElement.style.left = DoAktuell + 'px';
    }else{
        DoAktuell += DoAktionStep;
        //        alert(DoAktionStep + "," + DoEnd);
        if(DoAktuell >= DoEnd ){
            DoElement.style.left = DoEnd + 'px';
            checkCGSlidePosition();
            if(firstIMG === aktuellIMG){
                nl.style.visibility = 'hidden';
            }
            DoStart = DoEnd;
            //            bildschrift = document.getElementById('bildschrift');
            //            bildschrift.innerText = aktuellIMG.getAttribute('itext');
            window.clearInterval(DoAnyAktion);
            DoAnyAktion = null;
            return;
        }
        //               alert(DoAktionStep + ',' + DoAktionAuslauf + ',' + DoAktionSteps + ',' + DoAktionLeavingSteps);
        if(DoAktionAuslauf >= (DoAktionSteps - DoAktionLeavingSteps)){
            //        if(DoAktionLeavingSteps >= DoAktionAuslauf){
            //            alert(DoAktionStep + ',' + DoAktionAuslauf + ',' + (DoAktionSteps *-1) + ',' + DoAktionLeavingSteps);
            DoAktionStep -= DoAktionminderer;
            if(DoAktionStep < 1){
                DoAktionStep = 1;
            }
        }
        DoElement.style.left = DoAktuell + 'px';
    }
    
    DoAktionLeavingSteps++;
}



function checkSubscript(){
    var elements = new Array();
    var bestaetigung = document.getElementById("subscription.Bestaetigung");
    var bestaetigunglabel = document.getElementById("subscription.Bestaetigunglabel");
    elements.push(bestaetigunglabel);

    var Anrede = document.getElementById("subscription.Anrede"); //<option id="Mrs.opt" value="Mrs.">Mrs.</option>
    
    var Name = document.getElementById("subscription.Name");
    var Namelabel = document.getElementById("subscription.Namelabel");
    elements.push(Namelabel);

    var Company = document.getElementById("subscription.Company");
    var Companylabel = document.getElementById("subscription.Company");
    elements.push(Companylabel);

    var Street = document.getElementById("subscription.Street");
    var Streetlabel = document.getElementById("subscription.Streetlabel");
    elements.push(Streetlabel);

    var Plz = document.getElementById("subscription.Plz");
    var Plzlabel = document.getElementById("subscription.Plzlabel");
    elements.push(Plzlabel);

    var City = document.getElementById("subscription.City");
    var Citylabel = document.getElementById("subscription.Citylabel");
    elements.push(Citylabel);

    var Country = document.getElementById("subscription.Country");
    var Countrylabel = document.getElementById("subscription.Countrylabel");
    elements.push(Countrylabel);

    var Phone = document.getElementById("subscription.Phone");
    var Phonelabel = document.getElementById("subscription.Phonelabel");
    elements.push(Phonelabel);

    var Email = document.getElementById("subscription.Email");
    var Emaillabel = document.getElementById("subscription.Emaillabel");
    elements.push(Emaillabel);

    var Bankeinzug = document.getElementById("subscription.Bankeinzug");
    var Bankeinzuglabel = document.getElementById("subscription.Bankeinzuglabel");
    elements.push(Bankeinzuglabel);

    var Kontonummer = document.getElementById("subscription.Kontonummer");
    var Kontonummerlabel = document.getElementById("subscription.Kontonummerlabel");
    elements.push(Kontonummerlabel);

    var Blz = document.getElementById("subscription.Blz");
    var Blzlabel = document.getElementById("subscription.Blzlabel");
    elements.push(Blzlabel);

    var Bank = document.getElementById("subscription.Bank");
    var Banklabel = document.getElementById("subscription.Banklabel");
    elements.push(Banklabel);

    var Rechnung = document.getElementById("subscription.Rechnung");
    var Rechnunglabel = document.getElementById("subscription.Rechnunglabel");
    elements.push(Rechnunglabel);

    var Creditcard = document.getElementById("subscription.Creditcard");
    var Creditcardlabel = document.getElementById("subscription.Creditcardlabel");
    elements.push(Creditcardlabel);

    var Mastercard = document.getElementById("subscription.Mastercard");
    var Mastercardlabel = document.getElementById("subscription.Mastercardlabel");
    elements.push(Mastercardlabel);

    var Visacard = document.getElementById("subscription.Visacard");
    var Visacardlabel = document.getElementById("subscription.Visacardlabel");
    elements.push(Visacardlabel);

    var Cardnumber = document.getElementById("subscription.Cardnumber");
    var Cardnumberlabel = document.getElementById("subscription.Cardnumberlabel");
    elements.push(Cardnumberlabel);

    var Gueltigbis = document.getElementById("subscription.Gueltigbis");
    var Gueltigbislabel = document.getElementById("subscription.Gueltigbislabel");
    elements.push(Gueltigbislabel);

    //    var confirmvalid = document.getElementById("bestaetigung");
    //    var confirmlabel = document.getElementById("bestaetigunglabel");
    //    elements.push(confirmlabel);
    
    

    var inaktivcolor = "#000000";
    var aktivcolor = "#990000";
    for(var i = 0;i < elements.length; i++){
        elements[i].style.color = inaktivcolor;
        elements[i].style.fontWeight = "normal";
    }
    var isError = false;
    if(!checkField(Name)){
        Namelabel.style.color = aktivcolor;
        Namelabel.style.fontWeight = "bold";
        isError = true;
    }
    if(!checkField(Street)){
        Streetlabel.style.color = aktivcolor;
        Streetlabel.style.fontWeight = "bold";
        isError = true;
    }
    if(!checkField(Plz)){
        Plzlabel.style.color = aktivcolor;
        Plzlabel.style.fontWeight = "bold";
        isError = true;
    }
    if(!checkField(City)){
        Citylabel.style.color = aktivcolor;
        Citylabel.style.fontWeight = "bold";
        isError = true;
    }
    if(!checkField(Country)){
        Countrylabel.style.color = aktivcolor;
        Countrylabel.style.fontWeight = "bold";
        isError = true;
    }
    if(!checkField(Email)){
        Emaillabel.style.color = aktivcolor;
        Emaillabel.style.fontWeight = "bold";
        isError = true;
    }
    


    
    var head = "Please check your input!";
    var bild = "no.gif";

    if(isError){
        showMessage(head,'You have to fill out the red fields.',bild);
        return false;
    }
    isError = false;
    if(Bankeinzug.checked){
        if(!checkField(Kontonummer)){
            Kontonummerlabel.style.color = aktivcolor;
            Kontonummerlabel.style.fontWeight = "bold";
            isError = true;
        }
        if(!checkField(Blz)){
            Blzlabel.style.color = aktivcolor;
            Blzlabel.style.fontWeight = "bold";
            isError = true;
        }

        if(!checkField(Bank)){
            Banklabel.style.color = aktivcolor;
            Banklabel.style.fontWeight = "bold";
            isError = true;
        }
        head = "Please check your input!";
        if(isError){

            Bankeinzuglabel.style.color = aktivcolor;
            Bankeinzuglabel.style.fontWeight = "bold";
            showMessage(head,'You have to fill out the red fields.',bild);
            return false;
        }

    }


    isError = false;
    if(Creditcard.checked){
        if(!Mastercard.checked && !Visacard.checked){

            Mastercardlabel.style.color = aktivcolor;
            Mastercardlabel.style.fontWeight = "bold";
            Visacardlabel.style.color = aktivcolor;
            Visacardlabel.style.fontWeight = "bold";
            isError = true;
        }
        if(!checkField(Cardnumber)){
            Cardnumberlabel.style.color = aktivcolor;
            Cardnumberlabel.style.fontWeight = "bold";
            isError = true;
        }
        if(!checkField(Gueltigbis)){
            Gueltigbislabel.style.color = aktivcolor;
            Gueltigbislabel.style.fontWeight = "bold";
            isError = true;
        }
        head = "Please check your input!";
        if(isError){
            Creditcardlabel.style.color = aktivcolor;
            Creditcardlabel.style.fontWeight = "bold";
            showMessage(head,'You have to fill out the red fields.',bild);
            return false;
        }

    }
    if(!bestaetigung.checked){
        bestaetigunglabel.style.color = aktivcolor;
        bestaetigunglabel.style.fontWeight = "bold";
        showMessage("Please confirm your subscript!",'You have to confirm your subscript.',bild);
        return false;
    }

    return true;

}



function checkField(field){
    if(field){
        if(field.value){
            var trimf = trim(field.value);
            if(trimf.length > 0){
                return true;
            }
        }
    }
    return false;
}

function trim (zeichenkette) {
    // Erst führende, dann Abschließende Whitespaces entfernen
    // und das Ergebnis dieser Operationen zurückliefern
    return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}


var slideaktion = null;
var slidemaxheight = 200;
var slidestep = 8;
var slidetime = 10;
var slider = null;
var slidetimeout = 1000;
var closer = null;

function openinfoslider(slidername,maxheight){
    slidemaxheight = maxheight
    slider = document.getElementById(slidername);
    if(slider){
        if(!slideaktion){
            //        var akt = slider.offsetheight;
            slideaktion = window.setInterval(infosliding, slidetime, 1, slidemaxheight);
        }
    }
}

function infosliding(richtung,end){
    var akth = slider.offsetHeight;
    if(richtung > 0){
        akth += slidestep;
        if(akth > end){
            window.clearInterval(slideaktion);
            slideaktion = null;
            
            closeslider();
        }
        slider.style.height = akth + 'px';
    }else{
        akth -= slidestep;
        if(akth < end){

            slider.style.height = end + 'px';
            window.clearInterval(slideaktion);
            slideaktion = null;

        }
        //        alert(akth);
        slider.style.height = akth + 'px';
    }
}

function stopclosing(){
    if(closer){
        if(closer){
            window.clearTimeout(closer);
        }
    }
}

function closeslider(){
    //    closer = null;
    if(closer){
        window.clearTimeout(closer);
    }
    closer = window.setTimeout(directcloseslider, slidetimeout);
    
}

function directcloseslider(){
    slideaktion = window.setInterval(infosliding, slidetime, -1, 0);
}



function checkKasseKontakt(){

    var lblarray = new Array();
    var lblVorname = document.getElementById("lblVorname");
    lblarray.push(lblVorname);
    var txtVorname = document.getElementById("txtVorname");
    var lblName = document.getElementById("lblName");
    lblarray.push(lblName);
    var txtName = document.getElementById("txtName");
    var lblStrasse = document.getElementById("lblStrasse");
    lblarray.push(lblStrasse);
    var txtStrasse = document.getElementById("txtStrasse");
    var lblPlzOrt = document.getElementById("lblPlzOrt");
    lblarray.push(lblPlzOrt);
    var txtPlz = document.getElementById("txtPlz");
    var txtOrt = document.getElementById("txtOrt");



    var lblTelefon = document.getElementById("lblTelefon");
    lblarray.push(lblTelefon);
    var txtTelefon = document.getElementById("txtTelefon");
    var lblMail = document.getElementById("lblMail");
    lblarray.push(lblMail);
    var txtMail = document.getElementById("txtMail");

    var labelcolor = "#898989";
    var errorcolor = "#aa0000";
    clearLabels(lblarray,labelcolor);
    var error = false;




    if(txtMail){
        if(txtMail.value.replace(" ","").length == 0){
            error = true;
            lblMail.style.color = errorcolor;
            txtMail.focus();
        }
    }


    if(txtTelefon){
        if(txtTelefon.value.replace(" ","").length == 0){
            error = true;
            lblTelefon.style.color = errorcolor;
            txtTelefon.focus();
        }
    }
    if(txtOrt){
        if(txtOrt.value.replace(" ","").length == 0){
            error = true;
            lblPlzOrt.style.color = errorcolor;
            txtOrt.focus();
        }
    }
    if(txtPlz){
        if(txtPlz.value.replace(" ","").length == 0){
            error = true;
            lblPlzOrt.style.color = errorcolor;
            txtPlz.focus();
        }
    }
    if(txtStrasse){
        if(txtStrasse.value.replace(" ","").length == 0){
            error = true;
            lblStrasse.style.color = errorcolor;
            txtStrasse.focus();
        }
    }
    if(txtName){
        if(txtName.value.replace(" ","").length == 0){
            error = true;
            lblName.style.color = errorcolor;
            txtName.focus();
        }
    }
    if(txtVorname){
        if(txtVorname.value.replace(" ","").length == 0){
            error = true;
            lblVorname.style.color = errorcolor;
            txtVorname.focus();
        }
    }

    if(error){
        showMessage('Die Eingabe ist nicht korrekt!','Sie haben nicht alle Pflichtfelder ausgefüllt.','no.gif');

    }


    return !error;
}

function clearLabels(array,color){
    var labelstyle;
    for(var i = 0; i < array.length; i++){
        labelstyle = array[i].style;
        labelstyle.color = color;
    }
}



var Initvalue = null;

function goFocus(element,initvalue){
    Initvalue = initvalue;
    element.select();
}

function loFocus(element){
    if(Initvalue){
        if(element.value.length == 0 || element.value == Initvalue){
            element.value = Initvalue;
        }
    }
}

function showSearchExtra(input){
    var text = input.value;

    if(text.length > 1){

        var site = 'typo3conf/ext/empfauzeh/mvc/index.php?seite=EingabeAdvanced&txtSuche=' + text;

        $.get(site,
            function(data) {
                //            alert(data);
                showExtradiv(data);
            //            nbinnen.innerHTML = data;

            });
    }
}


function showExtradiv(content){
    var extra = document.getElementById('extradiv');
    if(extra){
        extra.innerHTML = content;
        extra.style.visibility = 'visible';
    }
}

function hideExtradiv(){
    var extra = document.getElementById('extradiv');
    if(extra){
        extra.style.visibility = 'hide';
    }
}


function initArtikelscroll(){
    var thumbcol = document.getElementById("thumbcol");
    var artthdiv = document.getElementById("artthdiv");
    var scrollhoch = document.getElementById("scrollhoch");
    var scrollrunter = document.getElementById("scrollrunter");
//    alert("OK");
    if(thumbcol){
        var op = 5;
        scrollhoch.style.opacity = op/10;
        scrollhoch.style.filter = 'alpha(opacity=' + op*10 + ')';

        scrollrunter.style.opacity = op/10;
        scrollrunter.style.filter = 'alpha(opacity=' + op*10 + ')';

        var max = artthdiv.offsetHeight;
        var inh = thumbcol.offsetHeight;
        op = 10;
        alert(inh);
        if(inh > max){
            var ttop = thumbcol.offsetTop;
            alert(ttop);
            var diff = inh - max;
            if(ttop < 0){
                scrollrunter.style.opacity = op/10;
                scrollrunter.style.filter = 'alpha(opacity=' + op*10 + ')';
            }
            if(ttop > -diff){
                scrollhoch.style.opacity = op/10;
                scrollhoch.style.filter = 'alpha(opacity=' + op*10 + ')';
            }

        }
    }

}

var scakt = null;
var scricht = 0;
function scrollThumb(richtung){
    scricht = richtung;
    var thumbcol = document.getElementById("thumbcol");
    var artthdiv = document.getElementById("artthdiv");
    if(thumbcol){
        var max = artthdiv.offsetHeight;
        var inh = thumbcol.offsetHeight;
        var diff = inh - max;
        var atop = thumbcol.offsetTop;
        var step = 6;
        //        step *= richtung;
        if(richtung < 0){

            if(atop > -diff){
                //                scrollingthumb(step,thumbcol);
                if(!scakt){
                    scakt = window.setInterval(scrollingthumb, 1, step, thumbcol);
                }
            }else{
                window.clearTimeout(scakt);
                scakt = null;
            }
        }else{
            if(atop < 0){
                //                scrollingthumb(step,thumbcol);
                if(!scakt){
                    scakt = window.setInterval(scrollingthumb, 1, step, thumbcol);
                }
            }else{
                window.clearTimeout(scakt);
                scakt = null;
            }
        }
    }

}

function scollstop(){
    if(scakt){
        window.clearInterval(scakt);
            scakt = null;
    }
}
function scrollingthumb(step,thumbcol){

    var max = artthdiv.offsetHeight;
    var inh = thumbcol.offsetHeight;
    var diff = inh - max;
    var atop = thumbcol.offsetTop;
    step *= scricht;
    if(scricht < 0){
        if(atop > -diff){
        }else{
            thumbcol.style.top = -diff + 'px';
            window.clearInterval(scakt);
            scakt = null;
        }
    }else{
        if(atop < 0){
        }else{
             thumbcol.style.top = -6 + 'px';
            window.clearInterval(scakt);
            scakt = null;
        }
    }
    var aktpos = thumbcol.offsetTop;
    aktpos += step;
    thumbcol.style.top = aktpos + 'px';
}
