{***************************************************************************}
{ TMS IntraWeb Component Pack Pro                                           }
{ for Delphi & C++Builder                                                   }
{                                                                           }
{ written by TMS Software                                                   }
{            copyright © 2002 - 2007                                        }
{            Email : info@tmssoftware.com                                   }
{            Web : http://www.tmssoftware.com                               }
{                                                                           }
{ The source code is given as is. The author is not responsible             }
{ for any possible damage done due to the use of this code.                 }
{ The component can be freely used in any application. The complete         }
{ source code remains property of the author and may not be distributed,    }
{ published, given or sold in any form as such. No parts of the source      }
{ code can be included in any other component or application without        }
{ written authorization of the author.                                      }
{***************************************************************************}

unit IWTMSPLAN;

interface

{$I TMSDEFS.INC}

{$R tmsiwmonthplan.res}

uses
  {$IFDEF LINUX}
  QImgList, QControls, QGraphics, QIWPicCntnr,
  {$ELSE}
  Windows, Graphics, ImgList, Controls, IWPicCntnr, IWTMSImg,
  {$ENDIF}
  {$IFDEF DELPHI6_LVL}
  Types,
  {$ENDIF}
  Classes, Math,
  IWControl, IWTypes, IWFont, IWFileReference, IWScriptEvents, IWHTMLTag,
  SysUtils, IWTMSBase
  {$IFDEF TMSIW6}
  , IWRenderContext, IWColor
  {$ENDIF}
  ;

const
  Months: array[1..12] of string = ('January','February','March','April','May','June','July','August','September','October','November','December');
  Days: array[1..7] of string = ('Sun','Mon','Tue','Wed', 'Thu', 'Fri', 'Sat');
type
  TIWMonthPlannerClickEvent = procedure(Sender: TObject; ADate: TDateTime) of object;

  TIWGradientDirection = (gdHorizontal, gdVertical);

  TIWMonthPlannerEvent = class;
  TTIWMonthPlanner = class;

  TIWEventMonthPlannerClick = procedure(ASender: TObject; Event: TIWMonthPlannerEvent) of object;

  TIWHintType = (htNotes, htStartEnd);
  TIWCaptionType = (ctTime,ctNone);

  TIWMonthPlannerEvent = class(TCollectionItem)
  private
    FSubject: string;
    FNotes: TStrings;
    FStartTime: TDateTime;
    FEndTime: TDateTime;
    FColor: TColor;
    FFont: TIWFont;
    FCanDelete: boolean;
    FID: integer;
    procedure SetSubject(const Value: string);
    procedure SetNotes(const Value: TStrings);
    procedure SetStartTime(const Value: TDateTime);
    procedure SetEndTime(const Value: TDateTime);
    function GetMonthPlanner: TTIWMonthPlanner;
    procedure SetFont(const Value: TIWFont);
    procedure SetCanDelete(const Value: boolean);
    procedure SetID(const Value: integer);
    procedure SetColor(const Value: TColor);
  protected
    procedure Changed;
    function GetDisplayName: string; override;
  public
    constructor Create(Collection: TCollection); override;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
    property MonthPlanner: TTIWMonthPlanner read GetMonthPlanner;
    property ID: integer read FID write SetID;
  published
    property CanDelete: boolean read FCanDelete write SetCanDelete;
    property Color: TColor read FColor write SetColor;
    property EndTime: TDateTime read FEndTime write SetEndTime;
    property Font: TIWFont read FFont write SetFont;
    property Notes: TStrings read FNotes write SetNotes;
    property StartTime: TDateTime read FStartTime write SetStartTime;
    property Subject: string read FSubject write SetSubject;
  end;

  TIWMonthPlannerEvents = class(TOwnedCollection)
  private
    FOwner: TTIWMonthPlanner;
    function GetEvent(Index: integer): TIWMonthPlannerEvent;
    procedure SetEvent(Index: integer; const Value: TIWMonthPlannerEvent);
  protected
  public
    function CreateEventClass: TCollectionItemClass; virtual;
    constructor Create(AOwner: TTIWMonthPlanner);
    function Add: TIWMonthPlannerEvent;
    function Insert(index: integer): TIWMonthPlannerEvent;
    property Events[index: integer]: TIWMonthPlannerEvent read GetEvent write SetEvent; default;
  published
  end;

  TTIWPlanGlyphs = class(TPersistent)
  private
    FOwner: TComponent;
    FNextYear: TBitmap;
    FPrevYear: TBitmap;
    FNextMonth: TBitmap;
    FPrevMonth: TBitmap;
    procedure SetNextYear(const Value: TBitmap);
    procedure SetPrevYear(const Value: TBitmap);
    procedure SetPrevMonth(const Value: TBitmap);
    procedure SetNextMonth(const Value: TBitmap);
  public
    constructor Create(AOwner: TComponent);
    destructor Destroy; override;
  published
    property NextMonth: TBitmap read FNextMonth write SetNextMonth;
    property PrevMonth: TBitmap read FPrevMonth write SetPrevMonth;
    property NextYear: TBitmap read FNextYear write SetNextYear;
    property PrevYear: TBitmap read FPrevYear write SetPrevYear;
  end;

  TTIWMonthPlanner = class(TIWControl)
  private
    FEvents: TIWMonthPlannerEvents;
    FDay: integer;
    FMonth: integer;
    FGlyphs: TTIWPlanGlyphs;
    FYear: integer;
    FHintType: TIWHintType;
    FShowNextMonth: Boolean;
    FShowPrevMonth: Boolean;
    FShowNextYear: Boolean;
    FShowPrevYear: Boolean;
    FCaptionType: TIWCaptionType;
    FCaptionColor: TColor;
    FCaptionFont: TIWFont;
    FHintAddEvent: String;
    //Modified 11/12/2003 - Hint Delete Item
    FHintDeleteEvent : String;
    //End Modified
    FColor: TColor;
    FHeightFixed: Boolean;
    FGridLineColor: TColor;
    FFont: TIWFont;
    FMonthColor: TColor;
    FMonthFont: TIWFont;
    FWeekendFont: TIWFont;
    FColorDaysOfWeek: TColor;
    FFontDaysOfWeek: TIWFont;
    FNameOfMonths: TStringList;
    FNameOfDays: TStringList;
    FGridLineWidth: Integer;
    FDateTimeFormatShortFrom: String;
    FDateTimeFormatShortTo: String;
    FDateTimeFormatFrom: String;
    FDateTimeFormatTo: String;
    FStateString: string;
    FHintPrevYear: String;
    FHintPrevMonth: String;
    FHintNextMonth: String;
    FHintNextYear: String;
    FBorderCollapse: Boolean;
    FOnEventClick: TIWEventMonthPlannerClick;
    FOnEventDelete: TIWEventMonthPlannerClick;
    FOnEventInsert: TIWMonthPlannerClickEvent;
    FOnClick: TIWMonthPlannerClickEvent;
    FOnPrevMonth: TIWMonthPlannerClickEvent;
    FOnNextMonth: TIWMonthPlannerClickEvent;
    FOnPrevYear: TIWMonthPlannerClickEvent;
    FOnNextYear: TIWMonthPlannerClickEvent;
    FTodayColor: TColor;
    FTodayBorderColor: TColor;
    FTodayBorder: Boolean;
    FDefaultEvent: TIWMonthPlannerEvent;
    FDefaultEvents: TIWMonthPlannerEvents;
    FMonthGradientStartColor: TColor;
    FMonthGradientEndColor: TColor;
    FMonthGradientDirection: TIWGradientDirection;
    FStartColor: TColor;
    FEndColor: TColor;
    FGradientDirection: TIWGradientDirection;
    FWeekendColor: TColor;
    FBackgroundImage: TIPicture;
    FHoverColor: TColor;
    procedure SetOnEventClick(const Value: TIWEventMonthPlannerClick);
    procedure SetIWMonthPlannerEvents(const Value: TIWMonthPlannerEvents);
    procedure SetColor(const Value: Tcolor);
    function JSDateToDate(AValue:string): TDateTime;
    procedure SetYear(const Value: integer);
    procedure SetBorderCollapse(const Value: Boolean);
    function GetDate: TDateTime;
    procedure SetDate(const Value: TDateTime);
    procedure SetTodayColor(const Value: TColor);
    procedure SetCaptionType(const Value: TIWCaptionType);
    procedure SetTodayBorderColor(const Value: TColor);
    procedure SetTodayBorder(const Value: boolean);
    procedure SetHintType(const Value: TIWHintType);
    procedure SetHeightFixed(const Value: boolean);
    procedure SetShowNextMonth(const Value: Boolean);
    procedure SetShowPrevMonth(const Value: Boolean);
    procedure SetShowNextYear(const Value: Boolean);
    procedure SetShowPrevYear(const Value: Boolean);
    procedure SetCaptionColor(const Value: TColor);
    procedure SetMonthColor(const Value: TColor);
    procedure SetFont(const Value: TIWFont);
    procedure SetMonthFont(const Value: TIWFont);
    procedure SetWeekendFont(const Value: TIWFont);
    procedure SetHintAddEvent(const Value: String);
    //Modified 11/12/2003 - Hint delete item
    procedure SetHintDeleteEvent(const Value : String);
    //End Modified
    procedure SetColorDaysOfWeek(const Value: TColor);
    procedure SetFontDaysOfWeek(const Value: TIWFont);
    procedure SetCaptionFont(const Value: TIWFont);
    procedure SetDefaultEvent(const Value: TIWMonthPlannerEvent);
    procedure SetGridLineColor(const Value: TColor);
    procedure SetDateTimeFormatShortFrom(const Value: String);
    procedure SetDateTimeFormatShortTo(const Value: String);
    procedure SetDateTimeFormatFrom(const Value: String);
    procedure SetDateTimeFormatTo(const Value: String);
    procedure SetNameOfDays(const Value: TStringList);
    procedure SetNameOfMonths(const Value: TStringList);
    procedure setMonthGradientStartColor(const Value: TColor);
    procedure setMonthGradientEndColor(const Value: TColor);
    procedure SetMonthGradientDirection(const Value: TIWGradientDirection);
    procedure SetStartColor(const Value: TColor);
    procedure SetEndColor(const Value: TColor);
    procedure SetGradientDirection(const Value: TIWGradientDirection);
    procedure SetWeekendColor(const Value: TColor);
    procedure SetBackgroundImage(const Value: TIPicture);
    procedure InitMonths;
    procedure InitDays;
    procedure BackgroundChanged(Sender: TObject);
    procedure SetGlyphs(const Value: TTIWPlanGlyphs);
    procedure SetHintPrevYear(const Value: String);
    procedure SetHintPrevMonth(const Value: String);
    procedure SetHintNextMonth(const Value: String);
    procedure SetHintNextYear(const Value: String);
    procedure SetHoverColor(const Value: TColor);
    procedure SetGridLineWidth(const Value: integer);
    procedure DrawGradient(Canvas: TCanvas; FromColor, ToColor: TColor; Steps: Integer; r:TRect; Direction: Boolean);
    function DispEndDate: TDateTime;
    function DispStartDate: TDateTime;
  protected
    function HTMLClr(color: TColor): string;
    procedure Notification(AComponent: TComponent; AOperation: TOperation); override;
    procedure Submit(const Value: string); override;
    procedure SetMonth(const Value: integer);
  public
    procedure SetValue(const AValue: String); override;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function CreateEvents: TIWMonthPlannerEvents; virtual;
    {$IFDEF TMSIW6}
    procedure IWPaint;override;
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    procedure Paint;override;
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}

    property Date: TDateTime read GetDate write SetDate;
  published
    property Events: TIWMonthPlannerEvents read FEvents write SetIWMonthPlannerEvents;
    property BackgroundImage: TIPicture read FBackgroundImage write SetBackgroundImage;
    property BorderCollapse: Boolean read FBorderCollapse write SetBorderCollapse;
    property CaptionColor: TColor read FCaptionColor write SetCaptionColor;
    property CaptionFont: TIWFont read FCaptionFont write setCaptionFont;
    property CaptionType: TIWCaptionType read FCaptionType write SetCaptionType;
    property Color: Tcolor read Fcolor write SetColor default clBlack;
    property DateTimeFormatShortFrom: String read FDateTimeFormatShortFrom write SetDateTimeFormatShortFrom;
    property DateTimeFormatShortTo: String read FDateTimeFormatShortTo write SetDateTimeFormatShortTo;
    property DateTimeFormatFrom: String read FDateTimeFormatFrom write SetDateTimeFormatFrom;
    property DateTimeFormatTo: String read FDateTimeFormatTo write SetDateTimeFormatTo;
    property DaysOfWeekColor: TColor read FColorDaysOfWeek write SetColorDaysOfWeek;
    property DaysOfWeekFont: TIWFont read FFontDaysOfWeek write SetFontDaysOfWeek;
    property DefaultEvent: TIWMonthPlannerEvent read FDefaultEvent write SetDefaultEvent;
    property Font: TIWFont read FFont write SetFont;
    property HeightFixed: Boolean read FHeightFixed write SetHeightFixed;
    property HintAddEvent: string read FHintAddEvent write SetHintAddEvent;
    //Modified 11/12/2003 - Hint Delete Item
    property HintDeleteEvent : string read FHintDeleteEvent write SetHintDeleteEvent;
    //End Modified
    property HintPrevYear: String read FHintPrevYear write SetHintPrevYear;
    property HintPrevMonth: String read FHintPrevMonth write SetHintPrevMonth;
    property HintNextMonth: String read FHintNextMonth write SetHintNextMonth;
    property HintNextYear: String read FHintNextYear write SetHintNextYear;
    property HintType: TIWHintType read FHintType write SetHintType;
    property HoverColor: TColor read FHoverColor write SetHoverColor;
    property Glyphs: TTIWPlanGlyphs read FGlyphs write SetGlyphs;
    property GradientStartColor: TColor read FStartColor write SetStartColor;
    property GradientEndColor: TColor read FEndColor write SetEndColor;
    property GradientDirection: TIWGradientDirection read FGradientDirection write SetGradientDirection;
    property GridLineColor: TColor read FGridLineColor write SetGridLineColor;
    property GridLineWidth: Integer read FGridLineWidth write SetGridLineWidth;
    property Month: integer read FMonth write SetMonth;
    property MonthColor: TColor read FMonthColor write SetMonthColor;
    property MonthFont: TIWFont read FMonthFont write SetMonthFont;
    property MonthGradientStartColor: TColor read FMonthGradientStartColor write SetMonthGradientStartColor;
    property MonthGradientEndColor: TColor read FMonthGradientEndColor write SetMonthGradientEndColor;
    property MonthGradientDirection: TIWGradientDirection read FMonthGradientDirection write SetMonthGradientDirection;
    property NameOfDays: TStringList read FNameOfDays write SetNameOfDays;
    property NameOfMonths: TStringList read FNameOfMonths write SetNameOfMonths;
    property OnEventClick: TIWEventMonthPlannerClick read FOnEventClick write SetOnEventClick;
    property OnEventDelete: TIWEventMonthPlannerClick read FOnEventDelete write FOnEventDelete;
    property OnEventInsert: TIWMonthPlannerClickEvent read FOnEventInsert write FOnEventInsert;
    property OnNextMonth: TIWMonthPlannerClickEvent read FOnNextMonth write FOnNextMonth;
    property OnPrevMonth: TIWMonthPlannerClickEvent read FOnPrevMonth write FOnPrevMonth;
    property OnNextYear: TIWMonthPlannerClickEvent read FOnNextYear write FOnNextYear;
    property OnPrevYear: TIWMonthPlannerClickEvent read FOnPrevYear write FOnPrevYear;
    property ShowNextMonth: boolean read FShowNextMonth write SetShowNextMonth;
    property ShowNextYear: boolean read FShowNextYear write SetShowNextYear;
    property ShowPrevMonth: boolean read FShowPrevMonth write SetShowPrevMonth;
    property ShowPrevYear: boolean read FShowPrevYear write SetShowPrevYear;
    property TodayBorder: boolean read FTodayBorder write SetTodayBorder;
    property TodayColor: TColor read FTodayColor write SetTodayColor;
    property TodayBorderColor: TColor read FTodayBorderColor write SetTodayBorderColor;
    property WeekendColor: TColor read FWeekendColor write SetWeekendColor;
    property WeekendFont: TIWFont read FWeekendFont write SetWeekendFont;
    property Year: Integer read FYear write SetYear;
  end;

implementation

uses
  IWAppForm, IWForm, IWServerControllerBase,
  SWSystem, SWStrings;

function IncMonth(D: TDateTime; Delta: Integer): TDateTime;
var
  daw,mow,yew: word;
  mo: Integer;
begin
  DecodeDate(d,yew,mow,daw);
  mo := mow;
  mo := mo + Delta;
  if mo < 1 then
  begin
    mow := 12;
    yew := yew - 1;
  end;

  if mo > 12 then
  begin
    mow := 1;
    yew := yew + 1;
  end;
  Result := EncodeDate(yew,mow,daw);
end;

function JSAdapt(s:string):string;
var
  i: integer;
begin
  Result := '';
  for i := 1 to length(s) do
  begin
    if s[i] = #39 then
      Result := Result + '\'#39
    else if s[i] = '"' then
           Result := Result + '\"'
         else
           Result := Result + s[i];
  end;
end;

function IncYear(D: TDateTime; Delta: Integer): TDateTime;
var
  daw, mow, yew: word;
begin
  DecodeDate(d,yew,mow,daw);
  yew := yew + Delta;
  Result := EncodeDate(yew,mow,daw);
end;

function DaysInMonth(mo,ye:word):word;
const
  adaysinmonth:array[1..13] of word = (31,28,31,30,31,30,31,31,30,31,30,31,29);
begin
  if (mo <> 2) then
    DaysInMonth := adaysinmonth[mo]
  else
  begin
   if (ye mod 4=0) then
     DaysInMonth := 29
   else
     DaysInMonth := 28;
   if (ye mod 100=0) then DaysInMonth := 28;
   if (ye mod 400=0) then DaysInmonth := 29;
  end;
end;

function GetFontStyle(style: TFontStyles):string;
var
  css :string;
begin
  css := '';
  if fsBold in style then
    css := 'font: bolder';
  if fsItalic in style then
  begin
    if (length(css) = 0) then
      css := 'font: italic'
    else
      css := css + ' italic';
  if (length(css) > 0) then
    css := css + ';';
  Result := css;
  end;
end;

{ TIWMonthPlannerEvent }

procedure TIWMonthPlannerEvent.Assign(Source: TPersistent);
begin
  CanDelete:= (Source as TIWMonthPlannerEvent).CanDelete;
  Color := (Source as TIWMonthPlannerEvent).Color;
  Font.Assign((Source as TIWMonthPlannerEvent).Font);
end;

procedure TIWMonthPlannerEvent.Changed;
begin
  TIWMonthPlannerEvents(GetOwner).Update(Self);
end;

constructor TIWMonthPlannerEvent.Create(Collection: TCollection);
begin
  inherited;
  FNotes := TStringList.Create;
  FFont := TIWFont.Create;
  FColor := clNone;
end;

destructor TIWMonthPlannerEvent.Destroy;
begin
  FreeAndNil(FNotes);
  FreeAndNil(FFont);
  inherited;
end;

function TIWMonthPlannerEvent.GetDisplayName: string;
begin
    if Subject <> '' then
    Result := Subject
  else
    Result := 'TIWMonthPlannerEvent' + IntToStr(Index);
end;

function TIWMonthPlannerEvent.GetMonthPlanner: TTIWMonthPlanner;
begin
  Result := TIWMonthPlannerEvents(Collection).FOwner;
end;

procedure TIWMonthPlannerEvent.SetColor(const Value: TColor);
begin
  FColor := Value;
end;

procedure TIWMonthPlannerEvent.SetEndTime(const Value: TDateTime);
begin
  FEndTime := Value;
end;

procedure TIWMonthPlannerEvent.SetFont(const Value: TIWFont);
begin
  FFont.Assign(Value);
end;

procedure TIWMonthPlannerEvent.SetNotes(const Value: TStrings);
begin
  FNotes.Assign(Value);
end;

procedure TIWMonthPlannerEvent.SetStartTime(const Value: TDateTime);
begin
  FStartTime := Value;
end;

procedure TIWMonthPlannerEvent.SetSubject(const Value: string);
begin
  FSubject := Value;
end;

procedure TIWMonthPlannerEvent.SetCanDelete(const Value: boolean);
begin
  FCanDelete := Value;
end;

procedure TIWMonthPlannerEvent.SetID(const Value: integer);
begin
  FID := Value;
end;

{ TTIWMonthPlanner }

constructor TTIWMonthPlanner.Create(AOwner: TComponent);
var
  year,month,day:word;
begin
  inherited;
  {$IFDEF TMSIW6}
  SetRenderSize(True);
  {TODO}
  {$ELSE}
  FSupportsSubmit := True;
  FSupportsInput := True;
  FRenderSize := True;
  FSupportedScriptEvents := 'OnClick,OnAbort,OnError,OnKeyDown,OnKeyPress,OnKeyUp,OnLoad';
  {$ENDIF}
  DecodeDate(Now,year,month,day);
  FMonth := month;
  FYear := year;
  FEvents := CreateEvents;
  FBorderCollapse := true;
  FColor := clWhite;
  FCaptionColor := clNavy;
  FMonthColor := clInfoBk;
  FTodayColor := clRed;
  FTodayBorderColor := clBlack;
  FTodayBorder := true;

  FGridLineColor := clSilver;
  FGridLineWidth := 1;

  FFont := TIWFont.Create;
  FFont.FontName := 'Arial';
  FFont.Size := 10;
  FFont.Color := clBlack;

  FMonthFont := TIWFont.Create;
  FMonthFont.FontName := 'Arial';
  FMonthFont.Size := 10;
  FMonthFont.Color := clPurple;

  FWeekendFont := TIWFont.Create;
  FWeekendFont.FontName := 'Arial';
  FWeekendFont.Color := clBlack;
  FWeekendFont.Size := 10;

  FFontDaysOfWeek := TIWFont.Create;
  FFontDaysOfWeek.FontName := 'Arial';
  FFontDaysOfWeek.Size := 10;
  FFontDaysOfWeek.Color := clRed;

  FCaptionFont := TIWFont.Create;
  FCaptionFont.FontName := 'Arial';
  FCaptionFont.Size := 10;
  FCaptionFont.Color := clWhite;

  FDefaultEvents := CreateEvents;
  FDefaultEvent := FDefaultEvents.Add;
  FDefaultEvent.Color := clGray;
  FDefaultEvent.Font.FontName := 'Arial';
  FDefaultEvent.Font.Size := 10;
  FDefaultEvent.Font.Color := clBlack;
  FDefaultEvent.CanDelete := true;

  FDateTimeFormatShortFrom := '"Today from" hh:mm am/pm';
  FDateTimeFormatShortTo := '"to " hh:mm am/pm';
  FDateTimeFormatFrom := '"from " mmm dd, yy hh:mm am/pm';
  FDateTimeFormatTo := '" to " mmm dd, yy hh:mm am/pm';

  FNameOfDays := TStringList.Create;
  FNameOfMonths := TStringList.Create;
  InitDays;
  InitMonths;
  FMonthGradientStartColor := clNone;
  FMonthGradientEndColor := clNone;
  FMonthGradientDirection := gdHorizontal;
  FStartColor := clNone;
  FEndColor := clNone;
  FHeightFixed := false;
  FGradientDirection := gdHorizontal;
  FBackgroundImage := TIPicture.Create;
  FBackgroundImage.OnChange := BackgroundChanged;
  FGlyphs := TTIWPlanGlyphs.Create(Self);
  FHoverColor := clLime;
  Width := 500;
  Height := 400;
  FHintAddEvent := 'Add Event';
  //Modified 11/12/2003 - Hint Delete Item
  FHintDeleteEvent := 'Delete Event';
  //End Modified

  if (csDesigning in ComponentState) then
  begin
    FHintPrevYear := 'Previous Year';
    FHintPrevMonth := 'Previous Month';
    FHintNextMonth := 'Next Month';
    FHintNextYear := 'Next Year';
  end;


  FStateString := '';
  FWeekendColor := clSilver;
end;

function TTIWMonthPlanner.CreateEvents: TIWMonthPlannerEvents;
begin
  Result := TIWMonthPlannerEvents.Create(Self);
end;

destructor TTIWMonthPlanner.Destroy;
begin
  FEvents.Free;
  FreeAndNil(FFont);
  FreeAndNil(FMonthFont);
  FreeAndNil(FWeekendFont);
  FreeAndNil(FFontDaysOfWeek);
  FreeAndNil(FCaptionFont);
  FDefaultEvent.Free;
  FDefaultEvents.Free;
  FNameOfDays.Free;
  FNameOfMonths.Free;
  FBackgroundImage.Free;
  FGlyphs.Free;
  inherited;
end;

function TTIWMonthPlanner.HTMLClr(color: TColor): string;
begin
  Result := ColorToRGBString(color);
end;

procedure TTIWMonthPlanner.setMonthGradientStartColor(const Value: TColor);
begin
  FMonthGradientStartColor := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.setMonthGradientEndColor(const Value: TColor);
begin
  FMonthGradientEndColor := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetMonthGradientDirection(const Value: TIWGradientDirection);
begin
  FMonthGradientDirection := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetHintType(const Value: TIWHintType);
begin
  FHintType := Value;
end;

procedure TTIWMonthPlanner.SetCaptionType(const Value: TIWCaptionType);
begin
  FCaptionType := Value;
end;

procedure TTIWMonthPlanner.SetColor(const Value: TColor);
begin
  FColor := Value;
  Invalidate;
end;

{$IFDEF TMSIW6}
procedure TTIWMonthPlanner.IWPaint;
{$ELSE}
procedure TTIWMonthPlanner.Paint;
{$ENDIF}
var
  i,firstday: Word;
  d: TDateTime;
  r,brdr: TRect;
  dx,dy,top,left: Integer;
  ColorText : TColor;
begin
  if not Assigned(FNameofDays) then
    Exit;
  if not Assigned(FNameofMonths) then
    Exit;

  Canvas.Font.Name := Font.FontName;
  Canvas.Font.Size := Font.Size;
  ColorText := Font.Color;

  with Canvas do
  begin
    r := GetClientRect;
    Brush.Color := Monthcolor;
    Pen.Color := MonthColor;
    r.Bottom := r.Top + TextHeight('gh');
    Rectangle(r);

    Canvas.Font.Color := MonthFont.Color;

    inflaterect(r,-1,-1);

    r.Left := r.Left + 2;

    if FShowPrevYear then
      TextOut(r.Left+1, r.Top,'<<');

    if FShowPrevMonth then
      TextOut(r.Left+25, r.Top,'<');

    if FShowNextMonth then
      TextOut(r.Right - TextWidth('>   >>'),r.Top,'>');

    if FShowNextYear then
     TextOut(r.Right - TextWidth('>>'), r.Top,'>>');


    if FNameOfMonths.Count >= FMonth then
    begin
      dx := (Width - TextWidth(FNameOfMonths.Strings[FMonth-1])) shr 1;
      TextOut(r.Left + dx, r.Top,FNameOfMonths.Strings[FMonth - 1]);
    end
    else
    begin
      dx := (Width - TextWidth(FNameOfMonths.Strings[0])) shr 1;
      TextOut(r.Left + dx, r.Top,FNameOfMonths.Strings[0]);
    end;

    r := GetClientRect;

    r.Top := r.Top + TextHeight('gh') -1;

    if not BackgroundImage.Empty then
    begin
      {$IFNDEF LINUX}
      StretchDraw(r,BackgroundImage)
      {$ENDIF}
    end
    else
    begin
      if not(FStartColor = clNone) and not (FEndColor = ClNone) then
      begin
        if (FGradientDirection = gdHorizontal) then
          DrawGradient(Canvas,FStartColor, FEndColor,80,r,True)
        else
          DrawGradient(Canvas,FStartColor, FEndColor,80,r,False);
      end
      else
      begin
        Brush.Color := Color;
        Brush.Style := bsSolid;
        Rectangle(r);
      end;
    end;

    r.Left := r.Left + 2;

    dx := Width div 7;
    dy := (Height - TextHeight('gh')) div 6;


    {$IFNDEF LINUX}
    SetBkMode(Handle,TRANSPARENT);
    {$ENDIF}

    Canvas.Font.Color := ColorText;
    for i := 0 to 6 do
    begin
      if FNameOfDays.Count > i then
        TextOut(r.Left + dx * i,r.Top,FNameOfDays.Strings[i]);
    end;

    if FGridLineWidth > 0 then
    begin
      Canvas.Pen.Color := FGridLineColor;
      top := R.Top;
      left := R.Left;

      for i := 0 to 4 do
      begin
        Top := Top + dy;
        Moveto(r.Left,Top);
        LineTo(r.Right,Top);
      end;

      for i := 0 to 5 do
      begin
        Canvas.Pen.Color := FGridLineColor;
        left := left + dx;
        MoveTo(left,r.top);
        LineTo(left,r.Bottom);
      end;

    end;

    d := EncodeDate(FYear,FMonth,1);
    firstday := DayOfWeek(d);
    r.Top := r.Top + dy;

    Brush.Color := TodayColor;

    {$IFNDEF LINUX}
    SetBkMode(Handle,TRANSPARENT);
    {$ENDIF}

    for i := 1 to DaysInMonth(FMonth,FYear) do
    begin
      if FDay = i then
      begin
        TextRect(Rect((firstday - 1) * dx,r.Top,firstday * dx,r.Top + dy),r.Left + (firstday - 1) * dx,r.Top,inttostr(i));

        if TodayBorder then
        begin
          Pen.Color := TodayBorderColor;
          brdr := Rect((firstday - 1) * dx,r.Top,firstday * dx,r.Top + dy);
          Brush.Style := bsClear;
          Rectangle(brdr);
        end;

      end
      else
        Textout(r.Left + (firstday - 1) * dx,r.Top, inttostr(i));

      inc(firstday);
      if firstday = 8 then
      begin
        firstday := 1;
        r.Top := r.Top + dy;
      end;
    end;

    r := GetCLientRect;

    inflaterect(r,-1,-1);
    Moveto(r.Left,r.Top);
    LineTo(r.Right,r.Top);
    LineTo(r.Right,r.Bottom);
    LineTo(r.Left,r.Bottom);
    LineTo(r.Left,r.Top);
  end;
end;

procedure TTIWMonthPlanner.DrawGradient(Canvas: TCanvas; FromColor, ToColor: TColor; Steps: Integer; r:TRect; Direction: Boolean);
var
  diffr,startr,endr: Integer;
  diffg,startg,endg: Integer;
  diffb,startb,endb: Integer;
  iend: Integer;
  rstepr,rstepg,rstepb,rstepw: Real;
  i,stepw: Word;

begin
  if Steps = 0 then
    Steps := 1;

  FromColor := ColorToRGB(FromColor);
  ToColor := ColorToRGB(ToColor);

  startr := (FromColor and $0000FF);
  startg := (FromColor and $00FF00) shr 8;
  startb := (FromColor and $FF0000) shr 16;
  endr := (ToColor and $0000FF);
  endg := (ToColor and $00FF00) shr 8;
  endb := (ToColor and $FF0000) shr 16;

  diffr := endr - startr;
  diffg := endg - startg;
  diffb := endb - startb;

  rstepr := diffr / steps;
  rstepg := diffg / steps;
  rstepb := diffb / steps;

  if Direction then
    rstepw := (R.Right - R.Left) / Steps
  else
    rstepw := (R.Bottom - R.Top) / Steps;

  with Canvas do
  begin
    for i := 0 to Steps - 1 do
    begin
      endr := startr + Round(rstepr*i);
      endg := startg + Round(rstepg*i);
      endb := startb + Round(rstepb*i);
      stepw := Round(i*rstepw);
      Pen.Color := endr + (endg shl 8) + (endb shl 16);
      Brush.Color := Pen.Color;
      if Direction then
      begin
        iend := R.Left + stepw + Trunc(rstepw) + 1;
        if iend > R.Right then
          iend := R.Right;
        Rectangle(R.Left + stepw,R.Top,iend,R.Bottom)
      end
      else
      begin
        iend := R.Top + stepw + Trunc(rstepw)+1;
        if iend > r.Bottom then
          iend := r.Bottom;
        Rectangle(R.Left, R.Top+stepw,R.Right,iend);
      end;
    end;
  end;
end;

procedure TTIWMonthPlanner.SetDateTimeFormatShortFrom(const Value: String);
begin
  FDateTimeFormatShortFrom := Value;
end;

procedure TTIWMonthPlanner.InitMonths;
begin
  FNameOfMonths.Add('January');
  FNameOfMonths.Add('February');
  FNameOfMonths.Add('March');
  FNameOfMonths.Add('April');
  FNameOfMonths.Add('May');
  FNameOfMonths.Add('June');
  FNameOfMonths.Add('July');
  FNameOfMonths.Add('August');
  FNameOfMonths.Add('September');
  FNameOfMonths.Add('October');
  FNameOfMonths.Add('November');
  FNameOfMonths.Add('December');
end;

procedure TTIWMonthPlanner.InitDays;
begin
  FNameOfDays.Add('Sun');
  FNameOfDays.Add('Mon');
  FNameOfDays.Add('Tue');
  FNameOfDays.Add('Wed');
  FNameOfDays.Add('Thu');
  FNameOfDays.Add('Fri');
  FNameOfDays.Add('Sat');
end;


procedure TTIWMonthPlanner.SetDateTimeFormatShortTo(const Value: String);
begin
  FDateTimeFormatShortTo := Value;
end;

procedure TTIWMonthPlanner.SetDateTimeFormatFrom(const Value: String);
begin
  FDateTimeFormatFrom := Value;
end;

procedure TTIWMonthPlanner.SetDateTimeFormatTo(const Value: String);
begin
  FDateTimeFormatTo := Value;
end;

procedure TTIWMonthPlanner.SetFont(const Value: TIWFont);
begin
  FFont.Assign(Value);
  Invalidate;
end;

procedure TTIWMonthPlanner.SetDefaultEvent(const Value:TIWMonthPlannerEvent);
begin
  FDefaultEvent.Assign(Value);
end;

procedure TTIWMonthPlanner.SetCaptionFont(const Value: TIWFont);
begin
  FCaptionFont.Assign(Value);
end;

procedure TTIWMonthPlanner.SetColorDaysOfWeek(const Value: TColor);
begin
  FColorDaysOfWeek := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetFontDaysOfWeek(const Value: TIWFont);
begin
  FFontDaysOfWeek.Assign(Value);
end;

procedure TTIWMonthPlanner.SetMonthFont(const Value: TIWFont);
begin
  FMonthFont.Assign(Value);
  Invalidate;
end;

procedure TTIWMonthPlanner.SetWeekendFont(const Value: TIWFont);
begin
  FWeekendFont.Assign(Value);
  Invalidate;
end;

procedure TTIWMonthPlanner.SetMonthColor(const Value: TColor);
begin
  FMonthColor := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetShowNextMonth(const Value: Boolean);
begin
  FShowNextMonth := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetShowPrevMonth(const Value: boolean);
begin
  FShowPrevMonth := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetShowNextYear(const Value: boolean);
begin
  FShowNextYear := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetShowPrevYear(const Value: boolean);
begin
  FShowPrevYear := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetWeekendColor(const Value: TColor);
begin
  FWeekendColor := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetYear(const Value: integer);
begin
  FYear := Value;
  Invalidate;
end;

function TTIWMonthPlanner.JSDateToDate(AValue:string):TDateTime;
var
  s:string;
  da,mo,ye:word;
  err: Integer;
begin
  Result := Now;

  s := AValue;

  if pos('/',s) > 0 then
  begin
    val(copy(s,1,pos('/',s)-1),da,err);
    delete(s,1,pos('/',s));
    if pos('/',s) > 0 then
    begin
      val(copy(s,1,pos('/',s)-1),mo,err);
      delete(s,1,pos('/',s));
      val(s,ye,err);
      if err = 0 then
      begin
        Result := EncodeDate(ye,mo+1,da);
        FDay := da;
        Month := mo+1;
        Year := ye;
      end;
    end;
  end;
end;

procedure TTIWMonthPlanner.Notification(AComponent: TComponent; AOperation: TOperation);
begin
  inherited;
end;

procedure TTIWMonthPlanner.SetMonth(const Value: integer);
begin
  FMonth := Value;
  Invalidate;
end;

function TTIWMonthPlanner.GetDate: TDateTime;
begin
  Result := EncodeDate(year,month,FDay);
end;

procedure TTIWMonthPlanner.SetDate(const Value:TDateTime);
var
  da,mo,ye: word;
begin
  DecodeDate(value,ye,mo,da);
  Year := ye;
  FDay := da;
  Month := mo;
end;

procedure TTIWMonthPlanner.SetBorderCollapse(const Value: Boolean);
begin
  FBorderCollapse := Value;
end;

procedure TTIWMonthPlanner.SetGridLineColor(const Value: TColor);
begin
  FGridLineColor := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetCaptionColor(const Value: TColor);
begin
  FCaptionColor := Value;
  Invalidate;
end;

function TTIWMonthPlanner.DispEndDate: TDateTime;
var
  da: integer;
begin
  da := daysinmonth(FMonth,FYear);
  Result := EncodeDate(FYear,FMonth,da);
end;

function TTIWMonthPlanner.DispStartDate: TDateTime;
begin
  Result := EncodeDate(FYear,FMonth,1);
end;

{$IFDEF TMSIW6}
function TTIWMonthPlanner.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWMonthPlanner.RenderHTML: TIWHTMLTag;
{$ENDIF}
const
  BoolStrs: array [boolean] of String = ('0', '-1');

var
  html,temp: string;
  i,j,k, cw1,cw2,heightHeader,widthFactor,rowH: integer;
  events,daysOfEvents, startTimeEvents, endTimeEvents,stringNotes: string;
  notesEvents, indexOfEvents, canDeleteOfEvents, colorOfEvents, fontStyleOfEvents: string;
  dateTimeShortFromOfEvents, dateTimeShortToOfEvents,dateTimeFromOfEvents, dateTimeToOfEvents: string;
  daw,mow,yew,endDaw,endMow,endYew: word;
  passEvent: boolean;
  gradientType,monthGradientType,imgName :string;
  dts,dte: TDateTime;
  dsep: char;

begin
  {$IFDEF TMSIW6}
  TIWComponent40Context(AContext).AddToInitProc('FindElem(''' + HTMLName + ''').value="'+
    IntToStr(FDay)+'/'+IntToStr(month-1)+'/'+IntToStr(year)+ '";' + EOL);
  {$ELSE}
  TIWAppForm(Form).AddToInitProc('FindElem(''' + HTMLName + ''').value="'+
    IntToStr(FDay)+'/'+IntToStr(month-1)+'/'+IntToStr(year)+ '";' + EOL);
  {$ENDIF}

  html := GetResourceText('TMSIWPLAN');

  if (FBorderCollapse) then
    widthFactor := 2 * 8 * 2
  else
   widthFactor := 1 * 8 * 2;                       

  if FHeightFixed then
  begin
    html := StringReplace(html, '<#HEIGHTFIXED>','<div style="overflow:hidden;height:' + IntToStr(Height div 7)+'px">',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html, '<#ENDHEIGHTFIXED>','</div>',[rfReplaceAll,rfIgnoreCase]);
  end
  else
  begin
    html := StringReplace(html, '<#HEIGHTFIXED>','',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html, '<#ENDHEIGHTFIXED>','',[rfReplaceAll,rfIgnoreCase]);
  end;

  html := StringReplace(html, '<#COMPNAME>',HTMLName , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#COLOR>', HTMLClr(Font.Color) , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#SELYEAR>',inttoStr(FYear), [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#SELDAY>', inttoStr(FDay) , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#SELMONTH>',inttostr(FMonth-1),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#SELCOLOR>',HTMLClr(FTodayColor), [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#SELBORDERCOLOR>',HTMLClr(FTodayBorderColor), [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#COLWIDTH>',IntToStr((Width - widthFactor)div 7)+'px',[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#HINTPREVYEAR>', ' title="'+HintPrevYear+'" ' , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#HINTPREVMONTH>', ' title="'+FHintPrevMonth+'" ' , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#HINTNEXTMONTH>', ' title="'+FHintNextMonth+'" ' , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html, '<#HINTNEXTYEAR>', ' title="'+FHintNextYear+'" ' , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#HOVERCOLOR>',HTMLClr(HoverColor), [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#HINTADDEVENT>',FHintAddEvent,[rfReplaceAll, rfIgnoreCase]);
  //Modified 11/12/2003 - Hint Delete Item
  html := StringReplace(html, '<#HINTDELETEEVENT>', FHintDeleteEvent,[rfReplaceAll, rfIgnoreCase]);
  //End Modified
  html := StringReplace(html, '<#GRIDLINES>', inttoStr(FGridLineWidth) , [rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#WEEKENDTEXTCOLOR>',HTMLClr(FWeekendFont.Color), [rfReplaceAll, rfIgnoreCase]);

  if FShowPrevYear then
    html := StringReplace(html, '<#INSBEGINY>','BEGINYEAR',[rfReplaceAll,rfIgnoreCase])
  else
    html := StringReplace(html, '<#INSBEGINY>','''<TD id="'+HTMLName+'calh" width="' + IntToStr((Width-16)div 7) + 'px"></TD>''',[rfReplaceAll,rfIgnoreCase]);

  if FShowNextYear then
    html := StringReplace(html, '<#INSENDY>','ENDYEAR',[rfReplaceAll,rfIgnoreCase])
  else
    html := StringReplace(html, '<#INSENDY>','''<TD id="'+HTMLName+'calh" width="' + IntToStr((Width-16)div 7) + 'px"></TD>''',[rfReplaceAll,rfIgnoreCase]);

  if FShowPrevMonth then
    html := StringReplace(html,'<#INSBEGIN>','BEGINMONTH',[rfReplaceAll, rfIgnoreCase])
  else
    html := StringReplace(html,'<#INSBEGIN>','''<TD id="'+HTMLName+'calh" width="' + IntToStr((Width-16)div 7) + 'px"></TD>''',[rfReplaceAll, rfIgnoreCase]);

  if FShowNextMonth then
    html := StringReplace(html,'<#INSEND>','ENDMONTH',[rfReplaceAll, rfIgnoreCase])
  else
    html := StringReplace(html,'<#INSEND>','''<TD id="'+HTMLName+'calh" width="' + IntToStr((Width-16)div 7) + 'px"></TD>''',[rfReplaceAll, rfIgnoreCase]);

  if FGlyphs.NextMonth.Empty then
  begin
    html := StringReplace(html, '<#NEXTMONTH>','&gt;',[rfReplaceAll, rfIgnoreCase]);
  end
  else
  begin
    {$IFDEF TMSIW71}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp',true);
    {$ELSE}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp');
    {$ENDIF}
    FGlyphs.NextMonth.SaveToFile(ImgName);
    html := StringReplace(html, '<#NEXTMONTH>','<IMG src="' + GetCacheDir(Self) + ExtractFileName(ImgName) + '">',[rfReplaceAll, rfIgnoreCase]);
  end;

  if FGlyphs.NextYear.Empty then
  begin
    html := StringReplace(html, '<#NEXTYEAR>','&gt;&gt;',[rfReplaceAll, rfIgnoreCase]);
  end
  else
  begin
    {$IFDEF TMSIW71}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp',true);
    {$ELSE}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp');
    {$ENDIF}
    FGlyphs.NextYear.SaveToFile(ImgName);
    html := StringReplace(html, '<#NEXTYEAR>','<IMG src="'+ GetCacheDir(Self) + ExtractFileName(ImgName) + '">',[rfReplaceAll, rfIgnoreCase]);
  end;

  if FGlyphs.PrevMonth.Empty then
  begin
    html := StringReplace(html, '<#PREVMONTH>','&lt;',[rfReplaceAll, rfIgnoreCase]);
  end
  else
  begin
    {$IFDEF TMSIW71}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp',true);
    {$ELSE}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp');
    {$ENDIF}
    FGlyphs.PrevMonth.SaveToFile(ImgName);
    html := StringReplace(html, '<#PREVMONTH>','<IMG src="'+ GetCacheDir(Self) + ExtractFileName(ImgName) + '">',[rfReplaceAll, rfIgnoreCase]);
  end;

  if FGlyphs.PrevYear.Empty then
  begin
    html := StringReplace(html, '<#PREVYEAR>','&lt;&lt;',[rfReplaceAll, rfIgnoreCase]);
  end
  else
  begin
    {$IFDEF TMSIW71}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp',true);
    {$ELSE}
    ImgName := TIWServerControllerBase.NewCacheFile('bmp');
    {$ENDIF}
    FGlyphs.PrevYear.SaveToFile(ImgName);
    html := StringReplace(html, '<#PREVYEAR>','<IMG src="'+ GetCacheDir(Self) + ExtractFileName(ImgName) + '">',[rfReplaceAll, rfIgnoreCase]);
  end;

  if FBorderCollapse then
  begin
    html := StringReplace(html,'<#BORDERCOLLAPSE>','collapse', [rfReplaceAll, rfIgnoreCase])
  end
  else
    html := StringReplace(html,'<#BORDERCOLLAPSE>','separate', [rfReplaceAll, rfIgnoreCase]);

  if FBackgroundImage.Empty then
  begin
    {$IFDEF TMSIW6}
      if (FStartColor = clNone) or (FEndColor = clNone) or (AContext.WebApplication.Browser <> brIE) then
    {$ELSE}
     if (FStartColor = clNone) or (FEndColor = clNone) or (WebApplication.Browser <> brIE) then
    {$ENDIF}
//    if (FStartColor = clNone) or (FEndColor = clNone) then
    begin
//      html := StringReplace(html,'<#BGCOLOR>','background-color:"'+HTMLClr(Color)+'"; ', [rfReplaceAll, rfIgnoreCase]);
      html := StringReplace(html,'<#BGCOLOR>','background-color:'+HTMLClr(Color)+'; ', [rfReplaceAll, rfIgnoreCase]);
      html := StringReplace(html,'<#BGIMAGE>','', [rfReplaceAll, rfIgnoreCase]);
      html := StringReplace(html,'<#GRADIENT>','', [rfReplaceAll, rfIgnoreCase]);

      if FWeekendColor <> clNone then
//        html := StringReplace(html,'<#WEEKENDCOLOR>','background-color:"'+HTMLClr(FWeekendColor)+'"; ', [rfReplaceAll, rfIgnoreCase])
        html := StringReplace(html,'<#WEEKENDCOLOR>','background-color:'+HTMLClr(FWeekendColor)+'; ', [rfReplaceAll, rfIgnoreCase])
      else
        html := StringReplace(html,'<#WEEKENDCOLOR>','', [rfReplaceAll, rfIgnoreCase]);
    end
    else
    begin
      html := StringReplace(html,'<#BGCOLOR>','', [rfReplaceAll, rfIgnoreCase]);
      html := StringReplace(html,'<#WEEKENDCOLOR>','', [rfReplaceAll, rfIgnoreCase]);
      if FGradientDirection = gdVertical then
        GradientType := '0'
      else
        GradientType := '1';
      html := StringReplace(html, '<#GRADIENT>','STYLE="FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType='
        + GradientType + ', StartColorStr='+HTMLClr(GradientStartColor) + ',EndColorStr='
        + HTMLClr(GradientEndColor) + ')" ', [rfReplaceAll, rfIgnoreCase]);
      html := StringReplace(html, '<#BGIMAGE>','', [rfReplaceAll, rfIgnoreCase]);
    end;
  end
  else
  begin
    html := StringReplace(html,'<#BGCOLOR>','', [rfReplaceAll, rfIgnoreCase]);
    html := StringReplace(html,'<#GRADIENT>','', [rfReplaceAll, rfIgnoreCase]);
    html := StringReplace(html,'<#WEEKENDCOLOR>','', [rfReplaceAll, rfIgnoreCase]);

    if FBackgroundImage.IsGIF then
    {$IFDEF TMSIW71}
      ImgName := TIWServerControllerBase.NewCacheFile('gif',true)
    {$ELSE}
      ImgName := TIWServerControllerBase.NewCacheFile('gif')
    {$ENDIF}
    else
    {$IFDEF TMSIW71}
      ImgName := TIWServerControllerBase.NewCacheFile('jpg',true);
    {$ELSE}
      ImgName := TIWServerControllerBase.NewCacheFile('jpg');
    {$ENDIF}

    FBackgroundImage.SaveToFile(ImgName);
    html := StringReplace(html, '<#BGIMAGE>',' BACKGROUND="' + GetCacheDir(Self) + ExtractFilename(ImgName)+'" ', [rfReplaceAll, rfIgnoreCase]);
  end;

  if (FMonthGradientStartColor = clNone) or (FMonthGradientEndColor = clNone) then
  begin
    html := StringReplace(html,'<#MONTHCOLOR>',HTMLClr(MonthColor), [rfReplaceAll, rfIgnoreCase]);
    html := StringReplace(html,'<#HEADER>','', [rfReplaceAll, rfIgnoreCase]);
  end
  else
  begin
    html := StringReplace(html,'background-color:<#MONTHCOLOR>;','', [rfReplaceAll, rfIgnoreCase]);
    if FMonthGradientDirection = gdVertical then
      monthGradientType := '0'
    else
      monthGradientType := '1';
    html := StringReplace(html, '<#HEADER>','STYLE="FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType='+monthGradientType + ', StartColorStr='+HTMLClr(FMonthGradientStartColor)+',EndColorStr='+HTMLClr(FMonthGradientEndColor)+')" ', [rfReplaceAll, rfIgnoreCase]);
  end;

  cw1 := Round(((Width - widthFactor)div 7) * 0.9);
  cw2 := Round(((Width - widthFactor) div 7) * 0.1);
  heightHeader := Round(((Height - widthFactor)div 7)div 2);
  rowH := ((Height - widthFactor) div 7) - 10;
                                                       
  if TodayBorder then
  //Modified 12/11/2003 - Show todayborder
  //    html := StringReplace(html,'<#TODAYBORDER>','BORDERCOLOR="' + HTMLClr(FTodayBorderColor) + '"',[rfReplaceAll, rfIgnoreCase])
    html := StringReplace(html,'<#TODAYBORDER>','border:1px solid ' + HTMLClr(FTodayBorderColor) + ';',[rfReplaceAll, rfIgnoreCase])
  //End modified
  else
    html := StringReplace(html,'<#TODAYBORDER>','',[rfReplaceAll, rfIgnoreCase]);
       
  html := StringReplace(html,'<#HEIGHTHEADER>',IntToStr(heightHeader),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#CW1>',IntToStr(cw1),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#CW2>',IntToStr(cw2),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#DW1>',IntToStr(cw1-10)+'px',[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#DW2>',IntToStr(cw2-5)+'px',[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#COL>',IntToStr((Width- widthFactor) div 7),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#ROWHEIGHT>',IntToStr(Height div 7)+'px',[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#FIXEDROW>',IntToStr(rowH)+'px',[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#CAPTIONCOLOR>',HTMLClr(FCaptionColor),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#DOWFONTCOLOR>',HTMLClr(FFontDaysOfWeek.Color),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#CAPTIONFONTCOLOR>',HTMLClr(FCaptionFont.Color),[rfReplaceAll, rfIgnoreCase]);

  {$IFDEF TMSIW6}
  html := StringReplace(html,'<#CAPTIONFONTSTYLE>',FCaptionFont.FontToStringStyle(AContext.WebApplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#DOWFONTSTYLE>',FFontDaysOfWeek.FontToStringStyle(AContext.WebApplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#MONTHFONTSTYLE>',FMonthFont.FontToStringStyle(AContext.WebApplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#WEEKENDFONTSTYLE>',FWeekendFont.FontToStringStyle(AContext.WebApplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#FONTSTYLE>',FFont.FontToStringStyle(AContext.WebApplication.Browser, nil),[rfReplaceAll,rfIgnoreCase]);
  {$ELSE}
  html := StringReplace(html,'<#CAPTIONFONTSTYLE>',FCaptionFont.FontToStringStyle(WebApplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#DOWFONTSTYLE>',FFontDaysOfWeek.FontToStringStyle(webapplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#MONTHFONTSTYLE>',FMonthFont.FontToStringStyle(webapplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#WEEKENDFONTSTYLE>',FWeekendFont.FontToStringStyle(webapplication.Browser, font),[rfReplaceAll, rfIgnoreCase]);
  html := StringReplace(html,'<#FONTSTYLE>',FFont.FontToStringStyle(webapplication.Browser, nil),[rfReplaceAll,rfIgnoreCase]);
  {$ENDIF}                                           

  html := StringReplace(html,'<#DOWCOLOR>',HTMLClr(FColorDaysOfWeek),[rfReplaceAll, rfIgnoreCase]);

  html := StringReplace(html,'<#GRIDLINECOLOR>',HTMLClr(FGridLineColor),[rfReplaceAll, rfIgnoreCase]);
  if CaptionType = ctTime then
    html := StringReplace(html,'<#CAPTIONTYPE>',#39+'Time'+#39, [rfReplaceAll, rfIgnoreCase])
  else
    html := StringReplace(html,'<#CAPTIONTYPE>',#39+'none'+#39, [rfReplaceAll, rfIgnoreCase]);

  for i := 0 to 6 do
  begin
    html := StringReplace(html,'<#DAY'+inttostr(i)+'>',FNameOfDays[i],[rfReplaceAll, rfIgnoreCase]);
  end;

  if FNameOfMonths.Count > 6 then
    InitMonths;

  for i := 0 to 11 do
  begin
    html := StringReplace(html,'<#MONTH'+inttostr(i)+'>',FNameOfMonths[i],[rfReplaceAll, rfIgnoreCase]);
  end;

  daysOfEvents := '';
  events := '';
  startTimeEvents := '';
  endTimeEvents := '';
  notesEvents := '';
  indexOfEvents := '';
  colorOfEvents := '';
  fontStyleOfEvents := '';
  canDeleteOfEvents := '';
  dateTimeShortFromOfEvents := '';
  dateTimeShortToOfEvents := '';
  dateTimeFromOfEvents := '';
  dateTimeToOfEvents := '';

  dts := DispStartDate;
  dte := DispEndDate;

  if FEvents.Count > 0 then
  begin
    for i:= 0 to FEvents.Count-1 do
    begin
      DecodeDate(FEvents[i].FStartTime,yew,mow,daw);
      DecodeDate(FEvents[i].FEndTime,endYew,endMow,endDaw);

      passEvent := true;

      if (FEvents[i].FEndTime < dts) or (FEvents[i].FStartTime > dte) then
        passevent := false;

      if (passEvent) then
      begin
        if (length(daysOfEvents) = 0) then
          daysOfEvents := daysOfEvents + #39 + IntToStr(daw) + #39
        else
          daysOfEvents := daysOfEvents + ',' + #39 + IntToStr(daw) + #39;

        if (length(colorOfEvents) = 0) then
        begin
          if ((FEvents[i].Color = FDefaultEvent.Color) or (FEvents[i].Color = clNone))  then
            colorOfEvents := colorOfEvents + #39 + HTMLClr(FDefaultEvent.Color) + #39
          else
            colorOfEvents := colorOfEvents + #39 + HTMLClr(FEvents[i].Color) + #39;
        end
        else
        begin
          if ((FEvents[i].Color = FDefaultEvent.Color) or (FEvents[i].Color = clNone)) then
            colorOfEvents := colorOfEvents + ',' + #39 + HTMLClr(FDefaultEvent.Color) + #39
          else
            colorOfEvents := colorOfEvents + ',' + #39 + HTMLClr(FEvents[i].Color) + #39;
        end;

        if (length(canDeleteOfEvents) = 0) then
          canDeleteOfEvents := canDeleteOfEvents + #39 + BoolStrs[FEvents[i].CanDelete] + #39
        else
          canDeleteOfEvents := canDeleteOfEvents + ',' + #39 + BoolStrs[FEvents[i].CanDelete] + #39;

        {$IFDEF TMSIW6}
        temp := FEvents[i].Font.FontToStringStyle(AContext.WebApplication.Browser, font);
        {$ELSE}
        temp := FEvents[i].Font.FontToStringStyle(WebApplication.Browser, font);
        {$ENDIF}
        for k := 0 to length(temp) do
        begin
          if (pos(#39,temp) > 0) then
            delete(temp,pos(#39,temp),1);
        end;
        if (length(fontStyleOfEvents) = 0) then
          fontStyleOfEvents := fontStyleOfEvents + #39 + temp + #39
        else
          fontStyleOfEvents := fontStyleOfEvents + ',' + #39 + temp + #39;

        if (length(events) = 0) then
          events := events + #39 + FEvents[i].FSubject + #39
        else
          events := events + ','+#39+ FEvents[i].FSubject + #39;

        dsep := DateSeparator;
        DateSeparator := '/';
        if (length(startTimeEvents) = 0) then
        begin
          startTimeEvents := startTimeEvents + #39 + FormatDateTime('dd/mm/yyyy',FEvents[i].FStartTime) + #39;
          endTimeEvents := endTimeEvents + #39 + FormatDateTime('dd/mm/yyyy',FEvents[i].FEndTime) + #39;
        end
        else
        begin
          startTimeEvents := startTimeEvents + ','+#39+ FormatDateTime('dd/mm/yyyy',FEvents[i].FStartTime) + #39;
          endTimeEvents := endTimeEvents + ',' + #39 + FormatDateTime('dd/mm/yyyy',FEvents[i].FEndTime) + #39;
        end;

        DateSeparator := dsep;

        if (length(indexOfEvents) = 0) then
          indexOfEvents := indexOfEvents + #39 + inttoStr(i) + #39
        else
          indexOfEvents := indexOfEvents + ',' + #39 + intToStr(i) + #39;

        stringNotes := '';
        for j := 1 to FEvents[i].FNotes.Count do
          stringNotes := stringNotes + JSAdapt(FEvents[i].FNotes.Strings[j - 1]);

        if (length(notesEvents) = 0) then
          notesEvents := notesEvents + #39 + stringNotes + #39
        else
          notesEvents := notesEvents + ',' + #39 + stringNotes + #39;


        if ((yew = endYew) and (mow = endMow) and (daw = endDaw)) then
        begin
          if (length(dateTimeShortFromOfEvents) = 0) then
          begin
            dateTimeShortFromOfEvents := dateTimeShortFromOfEvents + #39 + formatDateTime(FDateTimeFormatShortFrom,FEvents[i].FStartTime) + #39;
            dateTimeShortToOfEvents := dateTimeShortToOfEvents + #39 + formatDateTime(FDateTimeFormatShortTo, FEvents[i].FEndTime) + #39;
            dateTimeFromOfEvents := dateTimeFromOfEvents + #39 + ' ' + #39;
            dateTimeToOfEvents := dateTimeToOfEvents + #39 + ' ' + #39;
          end
          else
          begin
            dateTimeShortFromOfEvents := dateTimeShortFromOfEvents + ',' + #39 + formatDateTime(FDateTimeFormatShortFrom,FEvents[i].FStartTime) + #39;
            dateTimeShortToOfEvents := dateTimeShortToOfEvents + ',' + #39 + formatDateTime(FDateTimeFormatShortTo, FEvents[i].FEndTime) + #39;
            dateTimeFromOfEvents := dateTimeFromOfEvents + ',' + #39 + ' ' + #39;
            dateTimeToOfEvents := dateTimeToOfEvents + ',' + #39 + ' ' + #39;
          end;
        end
        else
        begin
          if (length(dateTimeFromOfEvents) = 0) then
          begin
            dateTimeShortFromOfEvents := dateTimeShortFromOfEvents + #39 + ' ' + #39;
            dateTimeShortToOfEvents := dateTimeShortToOfEvents + #39 + ' ' + #39;
            dateTimeFromOfEvents := dateTimeFromOfEvents + #39 + formatDateTime(FDateTimeFormatFrom,FEvents[i].FStartTime) + #39;
            dateTimeToOfEvents := dateTimeToOfEvents + #39 + formatDateTime(FDateTimeFormatTo, FEvents[i].FEndTime) + #39;
          end
          else
          begin
            dateTimeShortFromOfEvents := dateTimeShortFromOfEvents + ',' + #39 + ' ' + #39;
            dateTimeShortToOfEvents := dateTimeShortToOfEvents + ',' + #39 + ' ' + #39;
            dateTimeFromOfEvents := dateTimeFromOfEvents + ',' + #39 + formatDateTime(FDateTimeFormatFrom,FEvents[i].FStartTime) + #39;
            dateTimeToOfEvents := dateTimeToOfEvents + ',' + #39 + formatDateTime(FDateTimeFormatTo, FEvents[i].FEndTime) + #39;
          end;
        end;
      end;
    end;
    html := StringReplace(html,'<#DAYSOFEVENTS>','new Array('+daysOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#EVENTS>', 'new Array('+events+')', [rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#STARTTIMEEVENTS>', 'new Array('+startTimeEvents+')', [rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#ENDTIMEEVENTS>', 'new Array('+endTimeEvents+')', [rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#NOTESEVENTS>', 'new Array('+notesEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#INDEXOFEVENTS>','new Array('+indexOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#COLOROFEVENTS>','new Array('+colorOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#FONTSTYLEOFEVENTS>','new Array('+fontStyleOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#CANDELETEOFEVENTS>','new Array('+canDeleteOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMESHORTFROMOFEVENTS>','new Array('+dateTimeShortFromOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMESHORTTOOFEVENTS>','new Array('+dateTimeShortToOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMEFROMOFEVENTS>','new Array('+dateTimeFromOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMETOOFEVENTS>','new Array('+dateTimeToOfEvents+')',[rfReplaceAll,rfIgnoreCase]);
  end
  else
  begin
    html := StringReplace(html,'<#DAYSOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#EVENTS>', 'new Array()', [rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#STARTTIMEEVENTS>', 'new Array()', [rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#ENDTIMEEVENTS>', 'new Array()', [rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#NOTESEVENTS>', 'new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#INDEXOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#COLOROFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#FONTCOLOROFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#FONTSTYLEOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#CANDELETEOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMESHORTFROMOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMESHORTTOOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMEFROMOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#DATETIMETOOFEVENTS>','new Array()',[rfReplaceAll,rfIgnoreCase]);
  end;

  if (FHintType = htStartEnd) then
  begin
    html := StringReplace(html,'<#TYPEHINT>', #39+ 'StartEnd'+#39,[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#HINTEVENT>',HTMLName+'startTimeEvents[i]', [rfReplaceAll, rfIgnoreCase]);
    html := StringReplace(html,'<#HINTEVENT2>',HTMLName + 'endTimeEvents[i]', [rfReplaceAll, rfIgnoreCase]);
  end
  else
  begin
    html := StringReplace(html,'<#TYPEHINT>', #39+'Notes'+#39,[rfReplaceAll,rfIgnoreCase]);
    html := StringReplace(html,'<#HINTEVENT>',HTMLName + 'notesEvents[i]', [rfReplaceAll, rfIgnoreCase]);
    html := StringReplace(html,'<#HINTEVENT2>',' ', [rfReplaceAll, rfIgnoreCase]);
  end;

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(html);
  with Result.Contents.AddTag('INPUT') do
  begin
    AddStringParam('TYPE','hidden');
    AddStringParam('NAME',HTMLName);
    AddStringParam('ID',HTMLName+'_INPUT');
  end;
end;

procedure TTIWMonthPlanner.SetHintPrevMonth(const Value: String);
begin
  FHintPrevMonth := Value;
end;

procedure TTIWMonthPlanner.SetHintNextMonth(const Value: String);
begin
  FHintNextMonth := Value;
end;

procedure TTIWMonthPlanner.SetHintPrevYear(const Value: String);
begin
  FHintPrevYear := Value;
end;

procedure TTIWMonthPlanner.SetHintNextYear(const Value: String);
begin
  FHintNextYear := Value;
end;

procedure TTIWMonthPlanner.SetHeightFixed(const Value: Boolean);
begin
  FHeightFixed := Value;
end;

procedure TTIWMonthPlanner.SetNameOfDays(const Value: TStringList);
begin
  FNameOfDays.Assign(Value);
  Invalidate;
end;

procedure TTIWMonthPlanner.SetNameOfMonths(const Value: TStringList);
begin
  FNameOfMonths.Assign(Value);
  Invalidate;
end;

procedure TTIWMonthPlanner.SetStartColor(const Value: TColor);
begin
  FStartColor := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetBackgroundImage(const Value: TIPicture);
begin
  FBackgroundImage.Assign(Value);
end;

procedure TTIWMonthPlanner.SetEndColor(const Value: TColor);
begin
  FEndColor := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetGradientDirection(const Value: TIWGradientDirection);
begin
  FGradientDirection := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.SetGlyphs(const Value: TTIWPlanGlyphs);
begin
  FGlyphs.Assign(Value);
  Invalidate;
end;

procedure TTIWMonthPlanner.SetGridLineWidth(const Value: integer);
begin
  FGridLineWidth := Value;
  Invalidate;
end;

procedure TTIWMonthPlanner.Submit(const Value: string);
var
  temp: integer;
begin
  if Value = 'Prev' then
  begin
    FMonth := FMonth - 1;
    if (FMonth < 1) then
    begin
      FMonth := 12;
      FYear := FYear - 1;
    end;
    if Assigned(FOnPrevMonth) then
      FOnPrevMonth(Self,EncodeDate(FYear,FMonth,1));
    Exit;
  end;

  if Value = 'Next' then
  begin
    FMonth := FMonth + 1;
    if (FMonth > 12) then
    begin
      FMonth := 1;
      FYear := FYear + 1;
    end;
    if Assigned(FOnNextMonth) then
      FOnNextMonth(Self,EncodeDate(FYear,FMonth,1));
    Exit;
  end;

  if Value = 'PrevY' then
  begin
    FYear := FYear - 1;
    if Assigned(FOnPrevYear) then
      FOnPrevYear(Self, EncodeDate(FYear,FMonth,1));
    Exit;
  end;

  if Value = 'NextY' then
  begin
    FYear := FYear + 1;
    if Assigned(FOnNextYear) then
      FOnNextYear(Self, EncodeDate(FYear,FMonth,1));
    Exit;
  end;

  if (pos('Delete',Value) <> 0) then
  begin
    temp := StrToInt(Copy(Value,7,length(Value)-6));
    if Assigned(FOnEventDelete) then
      FOnEventDelete(Self,FEvents[temp]);
    Exit;
  end;

  if (pos('Add',Value) <> 0) then
  begin
    temp := StrToInt(Copy(Value,4,length(Value)-3));
    if Assigned(FOnEventInsert) then
      FOnEventInsert(Self, EncodeDate(FYear,FMonth,temp));
  end;

  if (pos('Detail',Value) <> 0) then
  begin
    temp := StrToInt(Copy(Value,7,length(Value)-3));
    if Assigned(FOnEventClick) then
      FOnEventClick(Self, FEvents[temp]);
  end;

  if Assigned(FOnClick) then
    FOnClick(Self,JSDateToDate(Value));
end;

procedure TTIWMonthPlanner.SetTodayColor(const Value: TColor);
begin
  FTodayColor := Value;
end;

procedure TTIWMonthPlanner.SetTodayBorderColor(const Value: TColor);
begin
  FTodayBorderColor := Value;
end;

procedure TTIWMonthPlanner.SetTodayBorder(const Value: boolean);
begin
  FTodayBorder := Value;
end;

procedure TTIWMonthPlanner.SetIWMonthPlannerEvents(
  const Value: TIWMonthPlannerEvents);
begin
  FEvents := Value;
end;

procedure TTIWMonthPlanner.SetOnEventClick(const Value: TIWEventMonthPlannerClick);
begin
  FOnEventClick := Value;
end;

procedure TTIWMonthPlanner.SetHintAddEvent(const Value: String);
begin
  FHintAddEvent := Value;
end;

//Modified 11/12/2003 - Hint Delete Item
procedure TTIWMonthPlanner.SetHintDeleteEvent(const Value : string);
begin
  FHintDeleteEvent := Value;
end;
//End Modified

procedure TTIWMonthPlanner.SetHoverColor(const Value: TColor);
begin
  FHoverColor := Value;
end;

procedure TTIWMonthPlanner.BackgroundChanged(Sender: TObject);
begin
  Invalidate;
end;

procedure TTIWMonthPlanner.SetValue(const AValue: String);
begin
  inherited;
//  Date := JSDateToDate(AValue);
end;

{ TIWMonthPlannerEvents }

function TIWMonthPlannerEvents.Add: TIWMonthPlannerEvent;
begin
  Result := TIWMonthPlannerEvent(inherited Add);
  if Assigned(FOwner.DefaultEvent) then
  begin
    Result.Assign(FOwner.DefaultEvent);
  end;
end;

constructor TIWMonthPlannerEvents.Create(AOwner: TTIWMonthPlanner);
begin
  inherited Create(AOwner, CreateEventClass);
  FOwner := AOwner;
end;

function TIWMonthPlannerEvents.CreateEventClass: TCollectionItemClass;
begin
  Result := TIWMonthPlannerEvent;
end;

function TIWMonthPlannerEvents.GetEvent(
  index: integer): TIWMonthPlannerEvent;
begin
  Result := TIWMonthPlannerEvent(inherited Items[index]);
end;

function TIWMonthPlannerEvents.Insert(
  index: integer): TIWMonthPlannerEvent;
begin
  Result := TIWMonthPlannerEvent(inherited Insert(Index));
  if Assigned(FOwner.DefaultEvent) then
  begin
    Result.Assign(FOwner.DefaultEvent);
  end;

  FOwner.Invalidate;
end;

procedure TIWMonthPlannerEvents.SetEvent(Index: integer;
  const Value: TIWMonthPlannerEvent);
begin
  inherited
  Items[Index] := Value;
end;
{ TTIWCalGlyphs }

constructor TTIWPlanGlyphs.Create(AOwner: TComponent);
begin
  inherited Create;
  FOwner := AOwner;
  FNextYear := TBitmap.Create;
  FPrevYear := TBitmap.Create;
  FNextMonth := TBitmap.Create;
  FPrevMonth := TBitmap.Create;
end;

destructor TTIWPlanGlyphs.Destroy;
begin
  FNextYear.Free;
  FPrevYear.Free;
  FNextMonth.Free;
  FPrevMonth.Free;
  inherited;
end;

procedure TTIWPlanGlyphs.SetNextMonth(const Value: TBitmap);
begin
  FNextMonth.Assign(Value);
end;

procedure TTIWPlanGlyphs.SetNextYear(const Value: TBitmap);
begin
  FNextYear.Assign(Value);
end;

procedure TTIWPlanGlyphs.SetPrevMonth(const Value: TBitmap);
begin
  FPrevMonth.Assign(Value);
end;

procedure TTIWPlanGlyphs.SetPrevYear(const Value: TBitmap);
begin
  FPrevYear.Assign(Value);
end;

end.

