//kalender

function createCalendar(){
                var sHTML;
                var i;
                
                // Tabellen-Code zusammenstellen
                sHTML = '<table class="cal">';
                sHTML += '<tr><td class="head" id="calHead1">'
                sHTML += '</td>';
                sHTML += '<td class="head" id="calHead2" colspan="5"></td>';
                sHTML += '<td class="head" id="calHead3">'
                sHTML += '</td></tr>';
                sHTML += '<tr><td colspan="3" height="0px"> </td></tr>';
		  sHTML += '<tr><td>Mo</td><td>Di</td><td>Mi</td><td>Do</td><td>Fr</td><td>Sa</td><td>So</td></tr>';
                sHTML += '<tr>';
                
                // Tabelle mit 6 Zeilen und 7 Spalten erstellen
                for(i = 1; i <= 42; i++) {
                    sHTML += '<td class="mid" id="calCell' + i + '">&nbsp;' + i +'</td>';
                    
                    //Umbruch nach jeder 7. Zelle
                    if(i%7==0) {
                        sHTML += '</tr><tr>'; }
                    }
                    
                sHTML += '</tr></table>';
                
                // Kalender ausgeben
                document.write(sHTML);
            }
        
            
            
             function getCalendar(thisMonth, thisYear){  
                // aktuelles Datum in Variable speichern
                sDate = new Date();
                   
                // wenn Parameter leer, dann aktuellen Monat verwenden  
                if (thisMonth == null) {  
                iMonth = sDate.getMonth();  
                iYear = sDate.getFullYear(); }

                fillCalendar(thisMonth, thisYear);
                
            }
            
            
            function fillCalendar(month,year){
                var i,counter;
                var code;
                //var thisdate, thisday, thismonth, thisyear, thisweekday, thisfirstday;
                var prevdate;
                var nextdate;
                
                var actualDate = new Date();
                
                var month_array = new Array('Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
                
                
                // Monate ermitteln
                var thisMonth = new Date(year, month, 1);
                var prevMonth = new Date(year, month - 1, 1);
                if (month==11){
                    var nextMonth = new Date(year + 1, 0, 1);
                }else{
                    var nextMonth = new Date(year, month + 1, 1);
                }
                
                // Erster Wochentag und Anzahl Tage/Monat ermitteln  
                var firstWeekday = thisMonth.getDay();
                if (firstWeekday==0){
                    firstWeekday=7;
                }
                
                //var thisMonthDays = Math.floor((nextMonth.getTime() - thisMonth.getTime()) / (1000 * 60 * 60 * 24));
                
                var thisMonthDays = 31;
                if (month==3 || month==5 || month==8 || month==10){
                    thisMonthDays--;
                }
                if(month==1){
                    if(year%4==0){
                        thisMonthDays = 29;
                        if(year%100==0){
                            thisMonthDays = 28;
                            if(year%400==0){
                                thisMonthDays = 29;
                            }
                        }
                    }else{
                        thisMonthDays = 28;
                    }
                }
                
                // Link zu vorherigem Monat  
                var sPrev = '<a href="javascript: getCalendar(' + prevMonth.getMonth() + ',' + prevMonth.getFullYear() + ')" class="calendar">&lt;</a>';  
                hItem = document.getElementById("calHead1");
                hItem.innerHTML = sPrev;  
        
                // Überschrift aus Monats-Array  
                hItem = document.getElementById("calHead2"); 
                hItem.innerHTML = month_array[month] + ' ' + year;  
           
                // Link zu nächstem Monat  
                var sNext = '<a href="javascript: getCalendar(' + nextMonth.getMonth() + ',' + nextMonth.getFullYear() + ')" class="calendar">&gt;</a>';  
                hItem = document.getElementById("calHead3")  
                hItem.innerHTML = sNext;
              
                // Leere Tage am Anfang auffüllen  
                for(i=1; i < firstWeekday; i++){
                    hItem = document.getElementById("calCell" + i);
                    hItem.innerHTML = '&nbsp;';
                    }

                // Schleife über alle Tage des Monats
                startDay = 1;
                for(i = firstWeekday; i <= (thisMonthDays+firstWeekday); i++) {
                    // Zellinhalt zuweisen  
                    hItem = document.getElementById("calCell" + i);
                    if (startDay==actualDate.getDate() && month==actualDate.getMonth() && year==actualDate.getFullYear()){
                        var text = '<a href="index.php?p=date_event&y=' + year + '&m=';
                        if((month+1)<10){
                                                text += '0' + (month+1);
                                }else{
                                                text += (month+1);
                                }
                        text += '&d=';
                                if(startDay<10){
                                                text += '0' + startDay;
                                }else{
                                                text += startDay;
                                }
                                text += '"><span style="color:#ff0000;">' + startDay + '</span></a>';  
                        hItem.innerHTML = text;
                    }else{
                                var text = '<a href="index.php?p=date_event&y=' + year + '&m=';
                        if((month+1)<10){
                                                text += '0' + (month+1);
                                }else{
                                                text += (month+1);
                                }
                        text += '&d=';
                                if(startDay<10){
                                                text += '0' + startDay;
                                }else{
                                                text += startDay;
                                }
                                text += '"><span style="color:#ffffff;">' + startDay + '</span></a>';  
                        hItem.innerHTML = text;
                        
                    }
                    
                    
                    startDay++;  
                }
                
                // Leere Tage am Ende auffüllen  
                for(i = (thisMonthDays+firstWeekday); i <= 42; i++) {  
                    hItem = document.getElementById("calCell" + i)
                    hItem.innerHTML = '&nbsp;';
                } 
            }