// libDateExtension 2.1 - UF 2009-07-02

Date.OneDay=1000*60*60*24;
Date.prototype.GetFutureDate = GetFutureDate;		// Parameter: Anzahl Tage in der Zukunft
Date.prototype.GetFutureMonth = GetFutureMonth;
Date.prototype.strdate = strdate;			// Parameter: Format-String, z.B. %d.%m.%Y
Date.prototype.GetDaysInMonth = GetDaysInMonth;         // Gibt die Anzahl an Tagen im Monat des Datums-Objekts zurück
Date.prototype.SetDate = SetDate;		        // Parameter: Jahr, Monat, Tag

Date.arrMonth=['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
Date.arrMonthShort=['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'];

function GetFutureDate () {

  if (!GetFutureDate.arguments.length) return (this);
  if (parseInt (GetFutureDate.arguments[0])==Number.NaN) return (this);

  var retValue=new Date (this);

  retValue.setTime (parseInt (Date.OneDay*GetFutureDate.arguments[0])+this.getTime ());

  return (retValue);
}

function GetFutureMonth () {

  if (!GetFutureMonth.arguments.length) return (this);
  if (parseInt (GetFutureMonth.arguments[0])==Number.NaN) return (this);

  var retValue=new Date (this);
  
  var intMonth=retValue.getMonth ();
  intMonth+=GetFutureMonth.arguments[0];
  if (intMonth>11) {
    intMonth=intMonth%12;
    retValue.setFullYear (retValue.getFullYear ()+1);
  }
  if (intMonth<0) {
    intMonth+=12;
    retValue.setFullYear (retValue.getFullYear ()-1);
  }
  retValue.setMonth (intMonth);
  
  return (retValue);
}

function strdate () {

  if (!strdate.arguments.length) return ('');
  
  if (this.getYear ()<999) intAddYears=1900; else intAddYears=0;

  var retValue=strdate.arguments[0];

  retValue=retValue.replace (/%m/g, (1+this.getMonth ()).toString ().strpad (2, '0', 1));
  retValue=retValue.replace (/%d/g, this.getDate ().toString ().strpad (2, '0', 1));
  retValue=retValue.replace (/%Y/g, (intAddYears+this.getYear ()));
  retValue=retValue.replace (/%y/g, (intAddYears+this.getYear ()).toString ().substr (2));

  retValue=retValue.replace (/%F/g, Date.arrMonth[(this.getMonth ())]);
  retValue=retValue.replace (/%M/g, Date.arrMonthShort[(this.getMonth ())]);

  return (retValue);
}


function GetDaysInMonth () {

  var objDate=new Date (this.getFullYear (), (this.getMonth ()+1)%12, 1);
  return (objDate.GetFutureDate (-1).getDate ());
  
}

function SetDate (paramYear, paramMonth, paramDay) {

  this.setDate (paramDay);
  this.setMonth ((paramMonth-1));
  this.setYear (paramYear);

}
