
var kalDiv = "kalender" ;

    ImgList = new Array('nav_bg','bt_weiter','bg_newsletter','bg_bmi','bg_experten','bg_hilfe') ;
    MenuImgHigh = new Array() ;
    MenuImgLow = new Array() ;
    
    for (i=0;i<ImgList.length;i++) 
    {   
        MenuImgHigh[ImgList[i]] = new Image() ;
        MenuImgHigh[ImgList[i]].src = "img/" + ImgList[i] + "_high.gif" ;
   
        MenuImgLow[ImgList[i]] = new Image() ;
        MenuImgLow[ImgList[i]].src = "img/" + ImgList[i] + "_low.gif" ;     
    }

    function high(name,img) 
    {       
        document.images[name].src = MenuImgHigh[img].src ;      
    }

    function low(name,img) 
    {
        document.images[name].src = MenuImgLow[img].src     
    }
    
    function highButton(name,img) 
    {       
        document.getElementById(name).src = "img/"+ img +"_high.gif";       
    }

    function lowButton(name,img) 
    {
        document.getElementById(name).src = "img/"+ img +"_low.gif";            
    }   
    
    function changeBg(id,img)
    {
        document.getElementById(id).style.backgroundImage = "url(img/" + img + ".gif)" ;
    }
    
    
    function openWin(url,width,height)
    {
        Extern = window.open(url,"Extern","width=" + width + ",height=" + height + ",resizable=no,scrollbars=auto,toolbar=no,status=yes,menubar=no,locationbar=no,screenX=50,screenY=50");
    }
    
    
    function checkKontaktForm()
    {
       var error = false
       if (self.document.kontaktFormular.email.value.length==0)
       {
           alert("Bitte eine g&#252;ltige E-Mail Adresse eintragen!");
           error = true;
       }                                    
       if (!error)
       {
          self.document.kontaktFormular.submit();
       }
    }
    

    function openCalendar(calOpen,tag,monat,jahr)
    {
        showCal = (calOpen) ? "visible":"hidden" ;
        document.getElementById("kalender").style.visibility = showCal ;        
        if(calOpen)
        {
            renderCalendar(tag,monat,jahr,tag,monat,jahr) ;
        }   
    }
    
    
    function prevMonth(thisDay,thisMonth,thisYear,actualDay,actualMonth,actualYear)
    {
        var firstYear = 2000;
            thisMonth -- ;
            if(thisMonth < 0)
            {
                thisMonth = 11;
                thisYear -- ;
            }
            thisYear = (thisYear < firstYear) ? firstYear:thisYear ;
            renderCalendar(thisDay,thisMonth,thisYear,actualDay,actualMonth,actualYear) 
    }
    
    function nextMonth(thisDay,thisMonth,thisYear,actualDay,actualMonth,actualYear)
    {
        var lastYear = 2020;
            thisMonth ++ ;
            if(thisMonth > 11)
            {
                thisMonth = 0;
                thisYear ++ ;
            }
            thisYear = (thisYear > lastYear) ? lastYear:thisYear ;
            renderCalendar(thisDay,thisMonth,thisYear,actualDay,actualMonth,actualYear) 
    }
    
    function setDay(thisDay,thisMonth,thisYear)
    {
        alert("D: " + thisDay + ",M: " + thisMonth + ",Y: " + thisYear) ;
        openCalendar(false) ;
    }
    
    function renderCalendar(thisDay,thisMonth,thisYear,actualDay,actualMonth,actualYear)
    {
        document.getElementById(kalDiv).innerHTML = returnCalendar(thisDay,thisMonth,thisYear,actualDay,actualMonth,actualYear) ;
    }
    
    function returnCalendar(thisDay,thisMonth,thisYear,actualDay,actualMonth,actualYear)
    {
        //alert("returnCalendar " + thisDay + "," + thisMonth + "," + thisYear + "," + actualDay + "," + actualMonth + "," + actualYear)
        var names = new Array("Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember") ;
        var days  = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
            if (((thisYear % 4 == 0) && (thisYear % 100 != 0)) || (thisYear % 400 == 0))
            {
                days[1] = 29; 
            }
        var dow   = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat","","","","","") ;
        var lastMonth = (thisMonth == 0) ? 11:(thisMonth-1);
        var lastYear = (lastMonth == 11) ? (thisYear-1):thisYear;
        var nextMonth = (thisMonth == 11) ? 0:(thisMonth+1);     
        var nextYear = (nextMonth == 0) ? (thisYear+1):thisYear;
                        
        var column = 0;
        var rows = 0;
        var firstDay = new Date(thisYear,thisMonth,1);
        var startDay = firstDay.getDay();
        
        var thisHTML = "" ;
        
            if(kalDiv == "kalender")
            {
                thisHTML += "<p class=\"floatright\"><a href=\"javascript:openCalendar(false)\"><img src=\"img/kal_exit.gif\" width=\"16\" height=\"14\" alt=\"schliessen\" name=\"schliessen\" title=\"schliessen\"></a></p>" ;
            }                           
                        
            thisHTML += "<p class=\"calswitch\">\
                        <a href=\"javascript:prevMonth(" + thisDay + "," + thisMonth + "," + thisYear + "," + actualDay + "," + actualMonth + "," + actualYear + ")\"><img src=\"img/kal_pfeil_li.gif\" width=\"14\" height=\"14\" alt=\"vorheriger\" name=\"vorheriger\" title=\"vorheriger\"></a>\
                        " + names[thisMonth] + " " + thisYear + "\
                        <a href=\"javascript:nextMonth(" + thisDay + "," + thisMonth + "," + thisYear + "," + actualDay + "," + actualMonth + "," + actualYear + ")\"><img src=\"img/kal_pfeil_re.gif\" width=\"14\" height=\"14\" alt=\"naechster\" name=\"naechster\" title=\"naechster\"></a>\
                        </p>" ;
            
            thisHTML += "<table width=\"146\" border=\"1\" bordercolor=\"#ffffff\"><tr>" ;                              
            
            for (i=0; i<startDay; i++)
            {
                calDay = (days[lastMonth]-startDay+i+1) ;
                thisHTML += "<td class=\"inaktiv\"><a href=\"javascript:setDay(" + calDay + "," + lastMonth + "," + lastYear + ")\">" + calDay + "</a></td>" ;
                column++;
            }                               
            
            for (i=1; i<=days[thisMonth]; i++)
            {
            
                if ((i == actualDay)  && (thisMonth == actualMonth) && (thisYear == actualYear))
                {
                    thisHTML += "<td class=\"markiert\">" + i + "</td>" ;
                }    
                else
                {
                    thisHTML += "<td class=\"aktiv\"><a href=\"javascript:setDay(" + i + "," + thisMonth + "," + thisYear + ")\">" + i + "</a></td>" ;
                }    
                column++;
                if (column == 7)
                {
                    thisHTML += "</tr><tr>" ;
                    column = 0;
                    rows ++ ;
                }
            }
            
            if (column > 0)
            {
                 for (i=1; column<7; i++)
                 {
                     thisHTML += "<td class=\"inaktiv\"><a href=\"javascript:setDay(" + i + "," + nextMonth + "," + nextYear + ")\">" + i + "</a></td>" ;
                      column++;
                 }
            }
            else
            {
                rows--;
                i=1;
            }
            
            if(rows < 5)
            {
                thisHTML += "</tr><tr>" ;
                for (j=0; j<7; j++)
                {
                    thisHTML += "<td class=\"inaktiv\"><a href=\"javascript:setDay(" + i + "," + nextMonth + "," + nextYear + ")\">" + i + "</a></td>" ;                             
                    i++;
                }
            }
                                
            thisHTML += "</tr></table>" ;
            return thisHTML ;
    }   
    
    function showFileInput(show)
    {
        document.getElementById("fileinput").style.visibility = show ;
    }
    

// =======================================================================================================
// Register-Process: Product Selection Table

    function selectProduct(event) {
        var trigger = event.element();
        var parent = trigger.up();
        // Achtung: bei Schalter Testwoche nein gibt es keinen Button mit ID = 1, s. nutzerdaten_ohne.jsp
        var id = 1;
        if (parent.hasClassName('price-s')) id = 2;
        if (parent.hasClassName('price-m')) id = 3;
        if (parent.hasClassName('price-l')) id = 4;
        if (parent.hasClassName('price-xl')) id = 5;

        changeState(id);
        setSubmitButton(id);
    }

    function changeState(id) {
        var allClasses = new Array(".price-free", ".price-s", ".price-m", ".price-l", ".price-xl");
        var activeClassName = allClasses[id-1];
        var toClear = $$('#pricing td');
        toClear.each(function(el) {
            el.removeClassName('active');
        });
        $$('#pricing ' + activeClassName).each(function(el) {
            el.addClassName('active');
        });

        var clearAll = $$('#command input[name=teilnahme]');
        clearAll.each(function(box){
            box.setAttribute('checked', '');
        });

        var checkme = $('teilnahme' + id);
        $('teilnahme' + id).setAttribute('checked', 'checked');
    }

    function setSubmitButton(id) {
        target = $('regSubmit');
        if (id == 1) {
            target.down(1).update('Jetzt starten und abnehmen');
        } else {
            target.down(1).update('Zur Zahlung');        
        }
    }

// =======================================================================================================

// =======================================================================================================
// Recipe Details: Rating Box

    function initRatingBox() {
        var box = $('rating-box');
        var expander = $('rating-expand');
        var collapser = $('rating-collapse')
        // rating is hidden by the script so you can also use this feature when javascript is disabled.
        box.hide();
        expander.onclick = function() {
            box.show();
            return false;
        }
        collapser.onclick = function() {
            box.hide();
        }
    }

// =======================================================================================================

// =======================================================================================================
// Infothek: Expandable Boxes, Table-of-Content (toc) Scroller

    function expandBoxes(event) {
        var trigger = event.element();
        var target = trigger.up(0).next('.article-scrollbox');

        if (trigger.hasClassName('active')) {
            new Effect.BlindUp(target, {duration: 0.5, queue: {position: 'end', scope: 'anims', limit: 2}});
            Element.removeClassName.delay(0.6, trigger, 'active');
        } else {
            new Effect.BlindDown(target, {duration: 0.5, queue: {position: 'end', scope: 'anims', limit: 2}});
            Element.addClassName.delay(0.6, trigger, 'active');
        }
    }

    function myScrollTo(container, element) {
        var container = $(container);
        var element = $(element);
        var x, y;
        if (element.x && element.y) {
            x = element.x;
            y = element.y;
        } else {
            x = element.offsetLeft;
            y = element.offsetTop;
        }
        if (document.all) {
            container.scrollLeft = x;
            container.scrollTop = y;
        } else {
            container.scrollLeft = x-container.offsetLeft;
            container.scrollTop = y-container.offsetTop;
        }
    }

/*  ==========================================================================================================  */
/*  Smooth Scrolling
/*  ==========================================================================================================  */

    function setup_smoothScrolling() {
        var scrollLinks = $$('a[href^=#]');
        if (scrollLinks.length >= 1) {
            scrollLinks.each(function(link) {
                if (link.hash.substr(1) != '') {
                    link.onclick = function(){return false;}
                }
            });
        }
        scrollLinks.invoke('observe', 'click', smoothScrolling);
    }

    function smoothScrolling(event) {
        var target_id = this.hash.substr(1);
        if (target_id != '') { // could happen with the aweful href="#"...
            Effect.ScrollTo(target_id);
        }
    }

// =======================================================================================================
// =======================================================================================================
// Init Function to Call 'em all

    function init() {
        // Smooth Scrolling
        setup_smoothScrolling();
        
        if ($$('.expandable').size() >= 1) {
            $$('.expandable span').invoke('observe', 'click', expandBoxes);
            $$('.article-scrollbox').invoke('hide');
        }
        if ($('pricing')) {
            $$('#pricing a').invoke('observe', 'click', selectProduct);
            $$('#pricing a').each(function(l){
               l.onclick= function() {return false};
            });
        }
        if ($('toc')) {
            myScrollTo('toc', 'current-article');
        }
        if ($('rating-box')) {
            initRatingBox();
        }
    }

document.observe("dom:loaded", init);
    
    

