//**** URL functions ***/
HTTP_GET_VARS=new Array();
strGET=document.location.search.substr(1,document.location.search.length);
if(strGET!='')
    {
    gArr=strGET.split('&');
    
    for(i=0;i<gArr.length;++i)
        {
        v='';vArr=gArr[i].split('=');
        if(vArr.length>1){v=vArr[1];}
        HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
        }
    }

function GET_URL_PARAM(v)
    {
    if(!HTTP_GET_VARS[v]){return '';}
    return HTTP_GET_VARS[v];
    }

//*** Calendar functions ***/
function CalendarRange(returnWindow, returnForm, returnTextField, instancename, startday, startmonth, startyear, howmanydays, activedays,returnRangeField) {
   //  methods
   //  ~~~
   this.setHowManyDays         = CalendarRange_setHowManyDays;
   this.setEndActicveDate      = CalendarRange_setEndActicveDate;
   this.setHowManyMonths       = CalendarRange_setHowManyMonths;
   this.setFullMonthsOnly      = CalendarRange_setFullMonthsOnly;
   this.setScrollable          = CalendarRange_setScrollable;
   this.nextMonth              = CalendarRange_nextMonth;
   this.prevMonth              = CalendarRange_prevMonth;
   this.draw                   = CalendarRange_draw;
   this.setDate                = CalendarRange_setDate;
   this.setKW                  = CalendarRange_setKW;
   this.getStartDateFromString = CalendarRange_getStartDateFromString;
   this.getStartDateFrom       = CalendarRange_getStartDateFrom;
   this.getEndDateFromString   = CalendarRange_getEndDateFromString;
   this.getEndDateFrom         = CalendarRange_getEndDateFrom;
   this.parseUserDateInput     = CalendarRange_parseUserDateInput;
   this.refReturnField         = CalendarRange_refReturnField;
   this.refReturnRange         = CalendarRange_refReturnRange;

   //  fields
   //  ~~~

   this.returnWindow = returnWindow;
   this.name = instancename;
   this.returnForm = returnForm;
   this.returnTextfield  = returnTextField;
   this.returnRangefield = returnRangeField;
   
   parameters= String(window.location.search).split("&");
   for(i= 1; i<parameters.length; i++) {
        if(parameters[i].indexOf("type=")==0) {
             this.returnTextfield = parameters[i].substr(5)
        }
        if(parameters[i].indexOf("formname=")==0) {
             this.returnForm = parameters[i].substr(9);
        }
   }

   this.startday   = startday*1;
   this.startmonth = startmonth-1;
   this.startyear  = startyear*1;

   // check start date parameters - default: today
   if ((!startday) || (!startmonth) || (!startyear)) {
      var tempstartdate = new Date();
      this.startday = tempstartdate.getDate();
      this.startmonth = tempstartdate.getMonth();
      this.startyear = tempstartdate.getFullYear();
   }

   // set the today
   this.todaydate = new Date();
   this.todayday = this.todaydate.getDate();
   this.todaymonth = this.todaydate.getMonth();
   this.todayyear = this.todaydate.getFullYear();
   // set startactivedate to default startdate
   this.startactiveday = this.startday;
   this.startactivemonth = this.startmonth;
   this.startactiveyear = this.startyear;
   this.startactivedate = new Date(this.startactiveyear,this.startactivemonth,this.startactiveday);
   // set endactivedate to default=startdate
   this.endactiveday = this.startday;
   this.endactivemonth = this.startmonth;
   this.endactiveyear = this.startyear;
   this.endactivedate = new Date(this.endactiveyear,this.endactivemonth,this.endactiveday);
     
   this.endday     = null;
   this.endmonth   = null;
   this.endyear    = null;

   this.lastdrawstartday   = null;
   this.lastdrawstartmonth = null;
   this.lastdrawstartyear  = null;
   this.lastdrawendday     = null;
   this.lastdrawendmonth   = null;
   this.lastdrawendyear    = null;

   this.howmanydays = 1;
   this.howmanymonths = 1;
   this.howmanymonthsmax = 4;

   this.selectedDay = this.name+"_df_"+this.startyear+"/"+this.startmonth+"/"+this.startday;
   this.multipleSelect = false;

   this.fullMonthsOnly = true;
   this.oneMonthOnly = true;
   this.scrollable = false;

   this.monthsTexts = new Array();
   this.weekdaysTexts = new Array();
   this.prevMonthHTML = "&lt;";
   this.nextMonthHTML = "&gt;";
   this.KWText="KW";
   
   this.closeOnSetDate = false;
   this.showShortYear = true;
   this.showWeekDayOnReturn = false;
   this.submitFormOnSetDate = true;
   this.showKW = false;
   this.showToday = false;   

   //  initializations
   //  ~~~
   this.setHowManyDays(howmanydays); 
   this.setEndActicveDate(activedays);

   // calc enddate
   var tempdate = new Date(this.startyear, this.startmonth, this.startday);
   var daycount = 0;
   while (daycount <= this.howmanydays) {
      daycount++;
      tempdate.setDate(tempdate.getDate()+1);
   }
   this.endday = tempdate.getDate();
   this.endmonth = tempdate.getMonth();
   this.endyear = tempdate.getFullYear();

   // try to auto-detect parent window (which ultimately holds the inputfield)
   // ~~
   if (this.returnWindow == null) {
     if (window.opener != null) {
       this.returnWindow = "window.opener.document";
     } else {
       this.returnWindow = "window.document";
     }
   }
}

function CalendarRange_prevMonth() {
   this.startmonth--;
   this.selectedDay = null;
   this.setHowManyDays(90);
   this.draw();
}

function CalendarRange_nextMonth() {
   this.startmonth++;
   this.selectedDay = null;
   this.setHowManyDays(90);
   this.draw();
}

function CalendarRange_setFullMonthsOnly(truefalse) {
  this.fullMonthsOnly = truefalse;
  // recalculate enddate
  this.setHowManyDays(90);
}

function CalendarRange_setScrollable(truefalse) {
   this.scrollable = truefalse;
}

function CalendarRange_setEndActicveDate(activedays){
   var tempdate = new Date(this.startactiveyear, this.startactivemonth, this.startactiveday);
   var daycount = 1;
   while (daycount < activedays) {
      daycount++;
      tempdate.setDate(tempdate.getDate()+1);
   }
   this.endactiveday = tempdate.getDate();
   this.endactivemonth = tempdate.getMonth();
   this.endactiveyear = tempdate.getFullYear();
   this.endactivedate = tempdate;
}

function CalendarRange_setHowManyDays(howmanydays) {
   if (this.fullMonthsOnly == true) {
      // show only full months
      this.startday = 1;
      var tempstartdate = new Date(this.startyear, this.startmonth, this.startday);
      this.howmanydays = 0;
      var savemonth = -1;
      var monthcount = 0;

      while (monthcount <= this.howmanymonths) {
         this.howmanydays++;
         if (tempstartdate.getMonth() != savemonth) {
            savemonth = tempstartdate.getMonth();
            monthcount++;
         }
         tempstartdate.setDate(tempstartdate.getDate()+1);
      }
      tempstartdate.setDate(tempstartdate.getDate()-2);
      this.endyear = tempstartdate.getFullYear();
      this.endmonth= tempstartdate.getMonth();
      this.endday  = tempstartdate.getDate();

   } else {
      // show minimal 14 days and max 4 months
      if (howmanydays < 14) {
         howmanydays = 14;
      }
      this.howmanydays = howmanydays;
      var tempstartdate = new Date(this.startyear, this.startmonth, this.startday);
      var tempenddate   = new Date(this.endyear, this.endmonth, this.endday);
      var prevmonth = tempstartdate.getMonth();
      var savemonth = -1;
      var monthcount = 0;

      if ((tempstartdate != null) && (tempenddate != null)) {
         while ((tempstartdate.getTime() < tempenddate.getTime()) && (howmanydays >= 0) && (tempstartdate.getMonth()-prevmonth < this.howmanymonths))
         {
            tempstartdate.setDate(tempstartdate.getDate()+1);
            howmanydays--;
         }
         while (monthcount <= this.howmanymonths) {
            if (tempstartdate.getMonth() != savemonth) {
               savemonth = tempstartdate.getMonth();
               monthcount++;
            }
           tempstartdate.setDate(tempstartdate.getDate()-1);
         }
         // change enddate to new enddate according to howmanydays
         if (tempstartdate.getTime() <= tempenddate.getTime()) {
            this.endyear = tempstartdate.getFullYear();
            this.endmonth= tempstartdate.getMonth();
            this.endday  = tempstartdate.getDate();
         }
      }
   }
}

function CalendarRange_setHowManyMonths(howmanymonths) {
   if (howmanymonths > this.howmanymonthsmax) {
      howmanymonths = this.howmanymonthsmax;
   }
   this.howmanymonths = howmanymonths;
}

function CalendarRange_getStartDateFrom(ioField) {
   eval("userInput = "+this.returnWindow+"."+this.returnForm+"."+ioField+".value;");
   this.getStartDateFromString(userInput);
}

function CalendarRange_getStartDateFromString(datestring) {
   var startdate = this.parseUserDateInput(datestring);
   this.startday   = startdate.getDate();
   this.startmonth = startdate.getMonth();
   this.startyear  = startdate.getFullYear();

   var enddate = new Date(this.endyear,this.endmonth,this.endday);
   if ((startdate != null) && (enddate != null)) {
      var daycount = 0;
      while (startdate.getTime() <= enddate.getTime()) {
        startdate.setDate(startdate.getDate()+1);
        daycount++;
      }
      // enddate after startdate
      if (daycount == 0) {
         this.endyear = this.startyear;
         this.endmonth= this.startmonth;
         this.endyear = this.startyear;
         this.setHowManyDays(1);
      } else {
         this.setHowManyDays(daycount);
      }
   }
}

function CalendarRange_getEndDateFrom(ioField) {
   eval("userInput = "+this.returnWindow+"."+this.returnForm+"."+ioField+".value;");
   this.getEndDateFromString(userInput);
}


function CalendarRange_getEndDateFromString(datestring) {
   var enddate = this.parseUserDateInput(datestring);
   this.endday   = enddate.getDate();
   this.endmonth = enddate.getMonth();
   this.endyear  = enddate.getFullYear();

   var startdate = new Date(this.startyear,this.startmonth,this.startday);
   if (startdate != null && enddate != null) {
      var daycount = 0;
      while (startdate.getTime() <= enddate.getTime()) {
        startdate.setDate(startdate.getDate()+1);
        daycount++;
      }
      // enddate after startdate
      if (daycount == 0) {
         this.startyear = this.endyear;
         this.startmonth= this.endmonth;
         this.startyear = this.endyear;
         this.setHowManyDays(1);
      } else {
         this.setHowManyDays(daycount);
      }
   }
}


function CalendarRange_parseUserDateInput(userInput){
   wDay = this.weekdaysTexts.join("|");
   reg_exp = eval("/^ *("+wDay+")\, */");
   clearedUserInput = userInput.replace(reg_exp,"");
   userInput_day = (clearedUserInput.substring(0,clearedUserInput.indexOf(".")));
   userInput_month = (clearedUserInput.substring((clearedUserInput.indexOf(".")+1),clearedUserInput.lastIndexOf(".")));
   userInput_year = (clearedUserInput.substring((clearedUserInput.lastIndexOf(".")+1),clearedUserInput.length));
   userInput_day *= 1; userInput_month *= 1; userInput_year *= 1;
   // attention: userInput_month is 1-12-ranged!
   // ~~~
   if(userInput_month!="") {
     userInput_month -= 1;
     if(userInput_month<0) {
       userInput_month = 11;
     } else if(userInput_month>11) {
       userInput_month = 0;
     }
   }
   if(userInput_year!="") {
     if(userInput_year<100) {
       if(userInput_year<50){
          userInput_year+=2000;
        } else {
          userInput_year+=1900;
        }
     } else if (userInput_year < 1000) {
       if(userInput_year<200){
          userInput_year+=1900;
        } else {
          userInput_year+=1000;
        }
     }
   }
   return new Date(userInput_year, userInput_month, userInput_day);
}

function CalendarRange_refReturnField() {
   return this.returnWindow+"."+this.returnForm+"."+this.returnTextfield;
}
function CalendarRange_refReturnRange() {
   return this.returnWindow+"."+this.returnForm+"."+this.returnRangefield;
}


//
// This function toggles the given date's style
//
function CalendarRange_setDate(cell) {
   // set the colors by style
   if (this.multipleSelect == true) {
      var tempday = document.getElementById(cell);
      tempday.className = (tempday.className == "active") ? "enabled" : "active";
   } else {
      // select only ONE day
      if (this.selectedDay != null) {
        tempday = document.getElementById(this.selectedDay);
        tempday.className = (tempday.className == "active") ? "enabled" : "active";
      }
      this.selectedDay = cell;
      tempday = document.getElementById(cell);
      tempday.className = (tempday.className == "active") ? "enabled" : "active";

      date = cell.substring((this.name.length)+4,cell.length);
      temp = date.split("/");
      year = temp[0];
      month = temp[1];
      day = temp[2];
      //  implicit typecasting...
      day *= 1; month *= 1; year *= 1;

      // prepare for display
      month = month + 1;
      if (day < 10) {
        day = "0"+day;
      }
      if (month < 10) {
        month = "0"+month;
      }

      // has to be after the previous step for interpreting purposes
      //if (this.showShortYear == true) {
      //   year -= 2000;
      //   if (year < 10) {
      //     year = "0"+year;
      //   }
      //}
      date = day+"."+month+"."+year;

      // calculate weekday & begin week with monday
      weekday = (new Date(year,month-1,day)).getDay()-2;
      if (weekday == -1) weekday = 6;
      if (weekday == -2) weekday = 5;

      document.forms[this.returnForm].datum.value = this.showWeekDayOnReturn?this.weekdaysTexts[weekday]+", ":"" + date;
      document.forms[this.returnForm].range.value = 1;
      //hsb
      //temp = this.refReturnField()+"datum.value = this.weekdaysTexts[weekday]+\", \"+date;";
      //eval(temp);
      if (this.submitFormOnSetDate == true){
            document.forms[this.returnForm].submit();
      }
      if (this.closeOnSetDate == true) {
        if (window.opener) {
          window.opener.focus();
          window.close();
        }
      }
   }
}
function CalendarRange_setKW(d){
      document.forms[this.returnForm].datum.value = d;
      document.forms[this.returnForm].range.value = 7;
      document.forms[this.returnForm].submit();
}

//
// This function fills the calendar table with the days of
// the selected month and year.
//
function CalendarRange_draw() {
   // saving some time - only redraw if inputs have changed
   if ((this.lastdrawstartday   != this.startday) ||
       (this.lastdrawstartmonth != this.startmonth) ||
       (this.lastdrawstartyear  != this.startyear) ||
       (this.lastdrawendday     != this.endday) ||
       (this.lastdrawendmonth   != this.endmonth) ||
       (this.lastdrawendyear    != this.endyear))
   {
      this.lastdrawstartday   = this.startday;
      this.lastdrawstartmonth = this.startmonth;
      this.lastdrawstartyear  = this.startyear;
      this.lastdrawendday     = this.endday;
      this.lastdrawendmonth   = this.endmonth;
      this.lastdrawendyear    = this.endyear;

      var div = document.getElementById(this.name);

      // create table if it does not already exist
      var table = document.getElementById(this.name+"_table");
      if (table == null) {
         table = document.createElement("TABLE");
         div.insertBefore(table,div.firstChild);
         table.setAttribute("cellSpacing", "0");
         table.style.width = "100%";
         table.id = this.name+"_table";
      }

      // Recycling: remove complete table body...it's recreated => fast delete
      var tbody = document.getElementById(this.name+"_tbody");
      if (tbody != null) {
           tbody.parentNode.removeChild(tbody);
      }

      // (re-)create tbody
      tbody = document.createElement("TBODY");
      table.appendChild(tbody);
      tbody.id = this.name+"_tbody";
      // update header and status texts
      tempdate = new Date(this.startyear,this.startmonth,this.startday);

         // show month name above weekdays
         if (this.oneMonthOnly == true) {
            // create row for month name
            current_row = document.createElement("TR");
            if (this.scrollable == true) {
               mycurrent_cell= document.createElement("TH");
               mycurrent_cell.innerHTML=this.prevMonthHTML;
               mycurrent_cell.className = "enabled";
               mycurrent_cell.id = this.name+"_heading_months_lt";
               mycurrent_cell.onclick = function() {
                  var calid = this.id.substring(0,this.id.indexOf("_heading_months_lt"));
                  var test = eval('calid')+".prevMonth();";
                  eval(test);
               }
               current_row.appendChild(mycurrent_cell);
            }
            mycurrent_cell= document.createElement("TH");
            mycurrent_cell.colSpan = 5;
            if (this.showKW == true)mycurrent_cell.colSpan = 6;
            mycurrent_cell.innerHTML = this.monthsTexts[tempdate.getMonth()]+"&nbsp;"+tempdate.getFullYear();
          //mycurrent_cell.setAttribute("align","center");
            mycurrent_cell.textAlign="center";
            mycurrent_cell.id = this.name+"_heading_months"+tempdate.getMonth();
            if (this.multipleSelect == true) {
               mycurrent_cell.className = "enabled";
               mycurrent_cell.onclick = function() {
                  var calid = this.id.substring(0,this.id.indexOf("_heading_months"));
                  var month = this.id.substring(this.id.indexOf("_heading_months")+15,this.id.length);
                  var test = eval('calid')+".selectMonth(month);";
                  eval(test);
               }
            } else {
               mycurrent_cell.className = "disabled";
            }
            current_row.appendChild(mycurrent_cell);

            if (this.scrollable == true) {
               mycurrent_cell = document.createElement("TH");
               mycurrent_cell.id = this.name+"_heading_months_gt";
               mycurrent_cell.innerHTML=this.nextMonthHTML;
               mycurrent_cell.className = "enabled";
               mycurrent_cell.onclick = function() {
                  var calid = this.id.substring(0,this.id.indexOf("_heading_months_gt"));
                  var test = eval('calid')+".nextMonth();";
                  eval(test);
               }
               current_row.appendChild(mycurrent_cell);
            }

            tbody.appendChild(current_row);
         }

         // write weekday names in first (or second) row
         var row = document.createElement("TR");

         if (this.showKW == true){
            var cell = document.createElement("TH");
            cell.id = this.name+"_heading_kw";
            cell.innerHTML = this.KWText;
            cell.className = "disabled";
            row.appendChild(cell);
         }         
         for (d = 0 ; d < 7 ; d++) {
            var cell = document.createElement("TH");
            cell.id = this.name+"_heading_"+d;
            //cell.innerHTML = "<b>"+this.weekdaysTexts[d]+"</b>";
            cell.innerHTML = this.weekdaysTexts[d];
            if (this.multipleSelect == true) {
               cell.className = "enabled";
               cell.onclick = function() {
                  var calid = this.id.substring(0,this.id.indexOf("_heading_"));
                  var day = this.id.substring(this.id.indexOf("_heading_")+9,this.id.length);
                  var test = eval('calid')+".selectDays(day);";
                  eval(test);
               }
            } else {
               cell.className = "disabled";
            }
            row.appendChild(cell);
         }

         tbody.appendChild(row);

        // Calculate skip between first table cell and first one with content (which
        // weekday does the calendar start with)
        // if it is 0 (sunday) set to 6 as the week begins on monday
        daystoskip = (tempdate.getDay()-1 < 0) ? 6 : tempdate.getDay()-1;

        var daysdrawn = 0;
        var newmonth = false;
        var oldtempcolspan = 0;
        var colspan = 1;

        var w = -1;
        var newWeekNeeded = true;
        while (newWeekNeeded == true) {
           w++;

           if ((tempdate.getDate() == 1 && newmonth == true) || (daysdrawn == 0)) {
              // a new month begins...

              // which weekday is the current date (e.g. 1st April 2005 is a Friday (5))?
              // if it is 0 (sunday) set to 6 as the week begins on monday
              daystoskip = (tempdate.getDay()-1 < 0) ? 6 : tempdate.getDay()-1;


                 if (this.oneMonthOnly == false) {
                    // create row for month name
                    current_row = document.createElement("TR");
                    mycurrent_cell= document.createElement("TD");
                    mycurrent_cell.colSpan = 7;
                    if (this.showKW == true) mycurrent_cell.colSpan = 8;
                    mycurrent_cell.innerHTML = "<b>"+this.monthsTexts[tempdate.getMonth()]+" - "+tempdate.getFullYear()+"</b>";
                    mycurrent_cell.id = this.name+"_heading_months"+tempdate.getMonth();
                    if (this.multipleSelect == true) {
                       mycurrent_cell.className = "enabled";
                       mycurrent_cell.onclick = function() {
                          var calid = this.id.substring(0,this.id.indexOf("_heading_months"));
                          var month = this.id.substring(this.id.indexOf("_heading_months")+15,this.id.length);
                          var test = eval('calid')+".selectMonth(month);";
                          eval(test);
                       }
                    } else {
                       mycurrent_cell.className = "disabled";
                    }
                    current_row.appendChild(mycurrent_cell);

                    tbody.appendChild(current_row);
                   }

            }

            current_row = document.getElementById(this.name+"_row_"+w);
            if (current_row == null) {
                current_row = document.createElement("TR");
                current_row.id = this.name+"_row_"+w;
                tbody.appendChild(current_row);
            }
            // draw KW 
            if (this.showKW == true){
                cell = document.createElement("TD");
                cell.className = "kw";
                cell.innerHTML = KalenderWoche(tempdate.getFullYear(),(tempdate.getMonth()+1),tempdate.getDate());
                kw_startMonday = getMondayDate(tempdate.getFullYear(),(tempdate.getMonth()+1),tempdate.getDate());
                cell.id=this.name+"_kw_"+kw_startMonday.getDate()+"."+(kw_startMonday.getMonth()+1)+"."+kw_startMonday.getFullYear();
                cell.onclick = function(){
                   var calid = this.id.substring(0,this.id.indexOf("_kw_"));
                   var setdate=this.id.substring(this.id.indexOf("_kw_")+4);
                   var test = eval('calid')+".setKW('"+setdate+"');";
                   eval(test);
                };
                cell.title=kw_startMonday.getDate()+"."+(kw_startMonday.getMonth()+1)+"."+kw_startMonday.getFullYear();
                current_row.appendChild(cell);
            }
            // draws week rows
            for(var d = 0; d < 7; d++) {

                 if ((tempdate.getDate() == 1 && newmonth == false) && (daysdrawn != 0)) {
                    newmonth = true;
                    // append remaining empty cells
                    for (var e = d; e < 7; e++) {
                       cell = document.createElement("TD");
                       cell.className = "disabled";
                       var nextdate=new Date(tempdate.getTime());
                       nextdate.setDate(nextdate.getDate()+(e-d));
                       cell.innerHTML = nextdate.getDate();
                       if (nextdate.getTime() >= this.startactivedate.getTime() && nextdate.getTime() <= this.endactivedate.getTime())
                            cell.className = "active";
                       if (current_row != null) {
                          current_row.appendChild(cell);
                       } else {
                        // cell.className = "active";
                       }
                    }
                    break;
                 }

              cell = document.createElement("TD");

              if(daystoskip <= 0 && daysdrawn < this.howmanydays) {
                newmonth = false;
                // Change table cells id to represent current displayed date
                cell.id = this.name+"_df_"+tempdate.getFullYear()+"/"+(tempdate.getMonth())+"/"+tempdate.getDate(); //+"-"+((w*7)+d+1);
                // increase already drawn days by one
                daysdrawn += 1;

                cell.innerHTML = tempdate.getDate();
                cell.className = "enabled";
                if (tempdate.getTime() >= this.startactivedate.getTime() && tempdate.getTime() <= this.endactivedate.getTime()){
                    cell.className = "active";
//alert("start="+this.startactivedate + " end="+this.endactivedate);
			}
                if (tempdate.getFullYear()==this.todayyear && tempdate.getMonth()== this.todaymonth && tempdate.getDate()==this.todayday) 
                    cell.className = "today";
                    
                tempdate.setDate(tempdate.getDate()+1);
                cell.onclick = function(){
                   var calid = this.id.substring(0,this.id.indexOf("_df"));
                   var test = eval('calid')+".setDate(this.id);";
                   eval(test);
                };

                //  deactivate cell
              } else {
                cell.className = "disabled";
                var prevdate=new Date(tempdate.getTime());
                prevdate.setDate(prevdate.getDate()-daystoskip);
                if (prevdate.getTime() >= this.startactivedate.getTime() && prevdate.getTime() <= this.endactivedate.getTime())
                    cell.className = "active";
                cell.innerHTML = prevdate.getDate();
                cell.onclick = null;
                daystoskip -= 1;
              }

              current_row.appendChild(cell);
            }
            var tempenddate   = new Date(this.endyear, this.endmonth, this.endday);
            if ((tempdate > tempenddate) || (daysdrawn >= this.howmanydays)) {
              newWeekNeeded = false;
            }

        }


    // auto-correction of div size
    document.getElementById(this.name).style.width = "auto";
   }
   // select initial date
   tempday = document.getElementById(this.selectedDay);
   if (tempday != null) {
      tempday.className = "active";
   }
} // - END function Calendar_draw();

function isLeapYear(y){if((y%4)==0 && (y%100)!=0 || (y%400)==0) return true;}

function KalenderWoche(j,m,t) {
  var Datum = new Date();
  m--;
  Datum = new Date(j,m,t,0,0,1);
  var tag = Datum.getDay(); if (tag == 0) tag = 7;
  var d = new Date(2004,0,1).getTimezoneOffset();
  var Sommerzeit = (Date.UTC(j,m,t,0,d,1) - Number(Datum)) /3600000;
  Datum.setTime(Number(Datum) + Sommerzeit*3600000 - (tag-1)*86400000);
  var Jahr = Datum.getYear(); if (1900 > Jahr) Jahr +=1900;
  var kw = 1;
  if (new Date(Jahr,11,29) > Datum) {
    var Start = new Date(Jahr,0,1);
    Start = new Date(Number(Start) + 86400000*(8-Start.getDay()));
    if(Start.getDate() > 4) Start.setTime(Number(Start) - 604800000);
    kw = Math.ceil((Datum.getTime() - Start) /604800000);
  }
  return kw;
}

function getMondayDate(j,m,t){
    // Start Datum
    var inputDate = new Date(j,m-1,t);
    // Wochentag
    var tag = inputDate.getDay();if (tag == 0) tag = 7; 
    tag--;
    // Zeit in Millis
    var inputMillis=inputDate.getTime();
    // von Millis Anzahl Tage abziehen
    var newMillis=inputMillis-(tag*(24*60*60*1000));
    //Millis wieder in datum wandeln
    var newDate= new Date(newMillis);
    return newDate;
}

function getDaysInMonth(j,m){
    switch (m){
        case 0:  return 31;
        case 1:  if (isLeapYear(j)) return 29; else return 28;
        case 2:  return 31;
        case 3:  return 30;
        case 4:  return 31;
        case 5:  return 30;
        case 6:  return 31;
        case 7:  return 31;
        case 8:  return 30;
        case 9:  return 31;
        case 10: return 30;
        case 11: return 31;
    }
}