{***************************************************************************}
{ TMS IntraWeb Component Pack Pro                                           }
{ for Delphi & C++Builder                                                   }
{                                                                           }
{ written by TMS Software                                                   }
{            copyright © 2002 - 2008                                        }
{            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 IWTMSCtrls;

interface

{$I TMSDEFS.INC}
{$r tmsiwae.res}

uses
  {$IFDEF LINUX}
  QControls, QGraphics, QForms, QIWPicCntnr,
  {$ELSE}
  Controls, Graphics, Forms, Windows, IWPicCntnr,
  {$ENDIF}
  {$IFDEF DELPHI6_LVL}
  Types,
  {$ENDIF}
  Classes,
  {$IFDEF TMSIW51}
  IWBaseControl, IWColor,
  {$ENDIF}
  IWControl, IWTypes, SysUtils, IWCompButton,
  IWCompEdit, IWCompLabel, IWCompCheckbox, IWExtCtrls, IWHTMLTag, IWCompListbox,
  IWTMSBase,IWCompRectangle
  {$IFDEF TMSIW6}
  , IWRenderContext
  {$ENDIF}
  {$IFDEF TMSIW7}
  , IWBaseHTMLControl, IWScriptEvents
  {$ENDIF}
  {$IFDEF TMSIW9}
  ,IWXMLTag
  {$ENDIF}
  ;

type
  TTIWGradientDirection = (gdHorizontal, gdVertical);

  TTIWHTMLLabel = class(TIWCustomLabel)
  private
    FHTMLText: string;
    FDesignMode: Boolean;
    FDesignLive: Boolean;
    function GetBaseDir: string;
    procedure SetBaseDir(const Value: string);
    procedure SetHTMLText(const Value: string);
    {$IFNDEF TMSIW71}
    procedure SetDesignMode(const Value: Boolean);
    {$ENDIF}
    procedure SetDesignLive(const Value: Boolean);
  protected
    FAutoSize: Boolean;
    ic: TIWHTMLPictureCache;
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  public
    function GetDisplText: string; virtual;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property BaseDir: string read GetBaseDir write SetBaseDir;
    property DesignLive: Boolean read FDesignLive write SetDesignLive default True;
    {$IFNDEF TMSIW71}
    property DesignMode: Boolean read FDesignMode write SetDesignMode default True;
    {$ENDIF}
    property Font;
    property HTMLText: string read FHTMLText write SetHTMLText;
  end;

  TTIWGradientLabel = class(TIWCustomRectangle)
  private
    FColor : TIWColor;
    FColorTo : TIWColor;
    FDirection : TTIWGradientDirection;
    FAlignment: TAlignment;
    procedure SetColor(const Value : TIWColor);
    procedure SetColorTo(const Value : TIWColor);
    procedure SetDirection(const Value : TTIWGradientDirection);
    procedure SetAlignment(const Value : TAlignment);
    procedure DrawGradient(Canvas: TCanvas; FromColor, ToColor: TIWColor; Steps: Integer; r:TRect; Direction: Boolean);
  protected
    function HTMLClr(Color: TIWColor):string;
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
    property Alignment : TAlignment read FAlignment write SetAlignment;
    property Color : TIWColor read FColor write SetColor;
    property ColorTo : TIWColor read FColorTo write SetColorTo;
    property Direction : TTIWGradientDirection read FDirection write SetDirection;
  end; 


  TTIWNoSpamEmailLabel = class(TIWCustomRectangle)
  private
    FColor : TIWColor;
    FEmail : string;
    FSubject : string;
    FText : string;
    FAlignment: TAlignment;
    procedure SetColor(const Value : TIWColor);
    procedure SetAlignment(const Value: TAlignment);
//    procedure DrawGradient(Canvas: TCanvas; FromColor, ToColor: TIWColor; Steps: Integer; r:TRect; Direction: Boolean);
  protected
    function HTMLClr(Color: TIWColor):string;
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
    property Alignment : TAlignment read FAlignment write SetAlignment;
    property Color : TIWColor read FColor write SetColor;
    property Email : string read FEmail write FEmail;
    property Subject : string read FSubject write FSubject;
    property Text : string read FText write FText;
  end;

  TTIWHTMLCheckBox = class(TIWCustomCheckBox)
  private
    ic: TIWHTMLPictureCache;
    FHTMLText: string;
    FDesignMode: Boolean;
    FDesignLive: Boolean;
    function GetBaseDir: string;
    procedure SetBaseDir(const Value: string);
    procedure SetHTMLText(const Value: string);
    {$IFNDEF TMSIW71}
    procedure SetDesignMode(const Value: Boolean);
    {$ENDIF}
    procedure SetDesignLive(const Value: Boolean);
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;    
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property BaseDir: string read GetBaseDir write SetBaseDir;
    property Checked;
    property DesignLive: Boolean read FDesignLive write SetDesignLive default True;
    {$IFNDEF TMSIW71}
    property DesignMode: Boolean read FDesignMode write SetDesignMode default True;
    {$ENDIF}
    property Font;
    property HTMLText: string read FHTMLText write SetHTMLText;
  end;

  TTIWHTMLList = class(TIWControl)
  private
    FDesignMode: Boolean;
    FDesignLive: Boolean;
    FBaseDir: string;
    {$IFNDEF TMSIW71}
    procedure SetDesignMode(const Value: Boolean);
    {$ENDIF}
    procedure SetBaseDir(const Value: string);
    procedure SetDesignLive(const Value: Boolean);
  protected
    FNumbered: Boolean;
    FItems: TStrings;
    ic: TIWHTMLPictureCache;
    procedure SetItems(AValue: TStrings);
    procedure SetNumbered(const AValue: Boolean);
    {$IFDEF TMSIW72_NEW}
    function get_ShouldRenderTabOrder: Boolean; override;
    {$ENDIF}
  public
    // !!!!!!!!!!!!!  IMPORTANT NOTICE  !!!!!!!!!!!!!!!!!!!!!
    // IF YOU ENCOUNTER AN ERROR HERE, YOU'RE USING A VERSION OF INTRAWEB BELOW 7.2.32
    // AND THEREFORE SHOULD COMMENT THE LINE {$DEFINE TMSIW72_NEW} FROM TMSDEFS.INC
    // AS INSTRUCTED IN README.TXT !
    // IF THERE IS STILL AN ERROR, THIS MEANS YOU'RE USING AN OLDER VERSION THAN 7.2.18
    // AND SHOULD ALSO REMOVE {$DEFINE TMSIW}
    // SORRY FOR THIS INCONVENIENCE, BUT THIS IS DUE TO INTRAWEB API CHANGES
    // !!!!!!!!!!!!!  IMPORTANT NOTICE  !!!!!!!!!!!!!!!!!!!!!
    {$IFDEF TMSIW72}
    function get_HasTabOrder: boolean; override;
    {$ENDIF}
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    procedure Paint; override;
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
    property BaseDir: string read FBaseDir write SetBaseDir;
    property DesignLive: Boolean read FDesignLive write SetDesignLive default True;
    {$IFNDEF TMSIW71}
    property DesignMode: Boolean read FDesignMode write SetDesignMode default True;
    {$ENDIF}
    property Font;
    property Items: TStrings read FItems write SetItems;
    property Numbered: boolean read FNumbered write SetNumbered;
  end;

  TTIWEmailEdit = class(TIWCustomEdit)
  private
    FErrorMessage: string;
    FFlat: Boolean;
    FWarnOnly: Boolean;
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
    {$IFDEF TMSIW7}
    procedure HookEvents(AContext: TIWPageContext40; AScriptEvents: TIWScriptEvents); override;
    {$ENDIF}

  public
    constructor Create(AOwner: TComponent); override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
    property Flat: Boolean read FFlat write FFlat;
    property Text;
    property ErrorMessage: string read FErrorMessage write FErrorMessage;
    property WarnOnly: boolean read FWarnOnly write FWarnOnly;
  end;

  TTIWAdvEditType = (etString,etNumeric,etFloat,etUppercase,etMixedCase,etLowerCase, etHex);

  TTIWAdvEdit = class(TIWCustomEdit)
  private
    FBorderWidth: Integer;
    FColor: TIWColor;
    FBorderColor: TIWColor;
    FFlat: Boolean;
    FEditType: TTIWAdvEditType;
    FAlignment: TAlignment;
    FFocusColor: TIWColor;
    FSelectAll: Boolean;
    FSigned: Boolean;
    FDecimalPoint: char;
    {$IFNDEF TMSIW71}
    FNonEditableAsLabel: boolean;
    {$ENDIF}
    FAdvanceOnReturn: Boolean;
    FAdvanceOnUpDown: Boolean;
    FSubmitOnReturn: Boolean;
    procedure SetBorderColor(const Value: TIWColor);
    procedure SetBorderWidth(const Value: Integer);
    procedure SetColor(const Value: TIWColor);
    procedure SetFlat(const Value: Boolean);
    procedure SetAlignment(const Value: TAlignment);
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
    function HTMLClr(color: TColor): string;
    {$IFDEF TMSIW7}
    procedure HookEvents(AContext: TIWPageContext40; AScriptEvents: TIWScriptEvents); override;
    {$ENDIF}
    {$IFDEF TMSIW72_NEW}
    function get_ShouldRenderTabOrder: Boolean; override;
    {$ENDIF}
    {$IFDEF TMSIW9}
    function RenderAsync(AContext: TIWBaseHTMLComponentContext): TIWXMLTag; override;
    {$ENDIF}
  public
    {$IFDEF TMSIW72}
    function get_HasTabOrder: boolean; override;
    {$ENDIF}
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
    constructor Create(AOwner: TComponent); override;
  published
    property AdvanceOnReturn: Boolean read FAdvanceOnReturn write FAdvanceOnReturn;
    property AdvanceOnUpDown: Boolean read FAdvanceOnUpDown write FAdvanceOnUpDown;
    property Alignment: TAlignment read FAlignment write SetAlignment;
    property BorderColor: TIWColor read FBorderColor write SetBorderColor;
    property BorderWidth: Integer read FBorderWidth write SetBorderWidth;
    property Color: TIWColor read FColor write SetColor;
    property DecimalPoint: char read FDecimalPoint write FDecimalPoint;
    property Enabled;
    property EditType: TTIWAdvEditType read FEditType write FEditType;
    property FocusColor: TIWColor read FFocusColor write FFocusColor;
    property Flat: Boolean read FFlat write SetFlat;
    {$IFNDEF TMSIW71}
    property NonEditableAsLabel: boolean read FNonEditableAsLabel write FNonEditableAsLabel;
    {$ENDIF}
    property PasswordPrompt: boolean read FPasswordPrompt write FPasswordPrompt;
    property SelectAll: Boolean read FSelectAll write FSelectAll;
    property Signed: Boolean read FSigned write FSigned;
    property SubmitOnReturn: Boolean read FSubmitOnReturn write FSubmitOnReturn;
    property Text;
  end;

  TTIWAdvLUEdit = class(TTIWAdvEdit)
  private
    FLookupItems: TStringList;
    FCaseSensitive: Boolean;
    procedure SetLookupItems(const Value: TStringList);
  protected
    {$IFDEF TMSIW7}
    procedure HookEvents(AContext: TIWPageContext40; AScriptEvents: TIWScriptEvents); override;
    {$ENDIF}
  public
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property LookupItems: TStringList read FLookupItems write SetLookupItems;
    property CaseSensitive: Boolean read FCaseSensitive write FCaseSensitive;
  end;


  TTIWFilePicker = class(TIWCustomEdit)
  private
    FFlat: Boolean;
    FBorderColor: TColor;
    procedure SetFlat(const Value: Boolean);
    procedure SetBorderColor(const Value: TColor);
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
    function HTMLClr(color: TColor): string;
  public
    constructor Create(AOwner: TComponent); override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
    property BorderColor: TColor read FBorderColor write SetBorderColor;
    property Flat: Boolean read FFlat write SetFlat;
    property Text;
  end;

  TTIWDateLabel = class(TIWCustomLabel)
  private
    FDateFormat: string;
    procedure SetDateFormat(const Value: string);
  protected
  public
    constructor Create(AOwner: TComponent); override;
  published
    property DateFormat: string read FDateFormat write SetDateFormat;
  end;

  TTIWClock = class(TIWCustomLabel)
  private
  protected
    function HTMLClr(Color: TIWColor):string;
    {$IFDEF TMSIW9}
    function RenderAsync(AContext: TIWBaseHTMLComponentContext): TIWXMLTag; override;
    {$ENDIF}
  public
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    procedure Paint; override;
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
  end;

  TTIWHTMLRadioGroup = class(TIWRadioGroup)
  private
    ic: TIWHTMLPictureCache;
    FDesignMode: Boolean;
    FDesignLive: Boolean;
    FBaseDir: string;
    function GetItemIndex: Integer;
    procedure SetItemIndex(const Value: Integer);
    {$IFNDEF TMSIW71}
    procedure SetDesignMode(const Value: Boolean);
    {$ENDIF}
    procedure SetBaseDir(const Value: string);
    procedure SetDesignLive(const Value: Boolean);
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;    
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property BaseDir: string read FBaseDir write SetBaseDir;
    property DesignLive: Boolean read FDesignLive write SetDesignLive default True;
    {$IFNDEF TMSIW71}
    property DesignMode: Boolean read FDesignMode write SetDesignMode default True;
    {$ENDIF}
    property ItemIndex: Integer read GetItemIndex write SetItemIndex;
  end;

  TTIWCountryComboBox = class(TIWCustomComboBox)
  public
    constructor Create(AOwner: TComponent); override;
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;    
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  published
    property ItemIndex;
    property Items;
  end;

  TTIWStateComboBox = class(TIWCustomComboBox)
  public
    constructor Create(AOwner : TComponent); override;
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  end;

  TTIWPersistentEdit = class(TIWCustomEdit)
  private
    FPersist: Boolean;
  protected
    {$IFDEF TMSIW72_NEW}
    function get_ShouldRenderTabOrder: Boolean; override;
    {$ENDIF}
  public
    {$IFDEF TMSIW72}
    function get_HasTabOrder: boolean; override;
    {$ENDIF}
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
    constructor Create(AOwner: TComponent); override;    
  published
    property Font;
    property Persist: Boolean read FPersist write FPersist default true;
    property Text;
    property PasswordPrompt: boolean read FPasswordPrompt write FPasswordPrompt;
  end;

  TTIWRadioButton = class(TIWControl)
  private
    FMasterButton: TTIWRadioButton;
    FChecked: Boolean;
    procedure SetChecked(const Value: Boolean);
    procedure SetMasterButton(const Value: TTIWRadioButton);
  protected
    procedure SetValue(const AValue: string); override;
    {$IFDEF TMSIW6}
    procedure IWPaint; override;    
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
    {$IFDEF TMSIW9}
    function RenderAsync(AContext: TIWBaseHTMLComponentContext): TIWXMLTag; override;
    {$ENDIF}    
  public
    constructor Create(AOwner: TComponent); override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
    procedure Submit(const AValue: string); override;    
  published
    property Caption;
    property Checked: Boolean read FChecked write SetChecked;
    property Enabled;
    property Font;
    property MasterButton: TTIWRadioButton read FMasterButton write SetMasterButton;
    property OnClick;
  end;

  TCodeType = (ctScript,ctCSS,ctRaw);

  TTIWNVControl = class(TIWControl)
  private
    FIconName: string;
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;    
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
    property IconName: string read FIconName write FIconName;
  public
    procedure SetBounds(ALeft,ATop,AWidth,AHeight: Integer); override;
  end;

  TTIWClientCode = class(TTIWNVControl)
  private
    FCode: TStringList;
    FCodeType: TCodeType;
    procedure SetCode(const Value: TStringList);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
    property Code: TStringList read FCode write SetCode;
    property CodeType: TCodeType read FCodeType write FCodeType;
  end;

  TTIWClientDebugOut = class(TIWControl)
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  public
    constructor Create(AOwner: TComponent); override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  end;

  TTIWClientWatch = class(TIWControl)
  protected
    {$IFDEF TMSIW6}
    procedure IWPaint; override;
    {$ELSE}
    procedure Paint; override;
    {$ENDIF}
  public
    constructor Create(AOwner: TComponent); override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  end;

  TTIWScrollBarColors = class(TTIWNVControl)
  private
    FScrollbar3DLightColor: TIWColor;
    FScrollbarArrowColor: TIWColor;
    FScrollbarBaseColor: TIWColor;
    FScrollbarTrackColor: TIWColor;
    FScrollbarDarkshadowColor: TIWColor;
    FScrollbarFaceColor: TIWColor;
    FScrollbarHighlightColor: TIWColor;
    FScrollbarShadowColor: TIWColor;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
    property Scrollbar3DLightColor: TIWColor read FScrollbar3DLightColor write FScrollbar3DLightColor;
    property ScrollbarArrowColor: TIWColor read FScrollbarArrowColor write FScrollbarArrowColor;
    property ScrollbarBaseColor: TIWColor read FScrollbarBaseColor write FScrollbarBaseColor;
    property ScrollbarTrackColor: TIWColor read FScrollbarTrackColor write FScrollbarTrackColor;
    property ScrollbarDarkshadowColor: TIWColor read FScrollbarDarkshadowColor write FScrollbarDarkshadowColor;
    property ScrollbarFaceColor: TIWColor read FScrollbarFaceColor write FScrollbarFaceColor;
    property ScrollbarHighlightColor: TIWColor read FScrollbarHighlightColor write FScrollbarHighlightColor;
    property ScrollbarShadowColor: TIWColor read FScrollbarShadowColor write FScrollbarShadowColor;
  end;

  TTIWScrollBarPersistence = class(TTIWNVControl)
  private
    FScrollTop: Integer;
    FScrollLeft: Integer;
  protected
    procedure SetValue(const AValue: string); override;
  public
    constructor Create(AOwner: TComponent); override;
    {$IFDEF TMSIW6}
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
    {$ELSE}
    function RenderHTML: TIWHTMLTag; override;
    {$ENDIF}
  published
  end;


implementation

uses
  {$IFDEF LINUX}
  QImgList,
  {$ELSE}
  ImgList, ShellAPI, CommCtrl,
  {$ENDIF}
  IWApplication, IWServerControllerBase,IWResourceStrings,
  SWStrings, SWSystem, IWAppForm, IWServer //, IWBaseHTMLControl
  ;

{$IFNDEF DELPHI7_LVL}
function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string;
const
  cSimpleBoolStrs: array [boolean] of String = ('0', '-1');
begin
  Result := cSimpleBoolStrs[B];
end;
{$ENDIF}
  

procedure Draw3DCtrl(FCanvas: TCanvas; Left,Top,Right,Bottom: Integer);
begin
  with FCanvas do
  begin
    Pen.Color := clBlack;
    MoveTo(Left,Bottom);
    LineTo(Left,Top);
    LineTo(Right,Top);

    Pen.Color := clSilver;
    LineTo(Right,Bottom);
    LineTo(Left,Bottom);

    Pen.Color := clGray;
    LineTo(Left + 1,Bottom);
    LineTo(Left + 1,Top + 1);
    LineTo(Right - 1,Top + 1);
    Pen.Color := Brush.Color;
    Rectangle(Left+1,Top+1,Right-1,Bottom-1);
  end;
end;
  

{ TTIWHTMLLabel }

constructor TTIWHTMLLabel.Create(AOwner: TComponent);
begin
  inherited;
  ic := TIWHTMLPictureCache.Create;
  ic.DesignLive := True;
  FDesignMode := True;
  FDesignLive := True;
  AutoSize := false;
  {$IFDEF TMSIW6}
  SetRenderSize(true);
  RawText := true;
  {$ELSE}
  FRenderSize := True;
  {$ENDIF}
end;


{$DEFINE REMOVESTRIP}
{$DEFINE REMOVEDRAW}
{$IFDEF LINUX}
 {$I QHTMLENG.PAS}
{$ELSE}
 {$I iwhtmleng.pas}
{$ENDIF}

destructor TTIWHTMLLabel.Destroy;
begin
  ic.Free;
  inherited;
end;

function TTIWHTMLLabel.GetBaseDir: string;
begin
  Result := ic.BaseDir;
end;

function TTIWHTMLLabel.GetDisplText: string;
begin
  Result := Caption;
end;

{$IFDEF TMSIW6}
procedure TTIWHTMLLabel.IWPaint;
{$ELSE}
procedure TTIWHTMLLabel.Paint;
{$ENDIF}
var
  LWidth: Integer;
  fr: TRect;
  a,s,fa:string;
  xsize,ysize,hl,ml: integer;
  hr:trect;

begin
  with Canvas do
  begin
    Font.Assign(Self.Font);
    {$IFDEF TMSIW6}
    if Font.Color = clNone then
      Font.Color := clBlack;
    {$ENDIF}
    Brush.Style := bsSolid;
    Brush.Color := Self.Color;
    if FAutoSize then
    begin
      LWidth := Trunc(TextWidth(GetDisplText) * 1.10);
    end
    else
    begin
      LWidth := Width;
    end;

    fr := Rect(0, 0, LWidth, 1000);
    {$IFDEF TMSIW6}
    HTMLDrawEx(Canvas, GetDisplText, fr, nil, 0,0,-1,-1,0,false,false,false,false,false,false,True,1.0,
      clBlue,clNone,clNone,clGray,a,s,fa,xsize,ysize,hl,ml,hr
      {$IFNDEF LINUX}
      ,ic,nil
      {$ENDIF}
      );
    {$ELSE}
    HTMLDrawEx(FCanvas, GetDisplText, fr, nil, 0,0,-1,-1,0,false,false,false,false,false,false,True,1.0,
      clBlue,clNone,clNone,clGray,a,s,fa,xsize,ysize,hl,ml,hr
      {$IFNDEF LINUX}
      ,ic,nil
      {$ENDIF}
      );
    {$ENDIF}

    if FDesignMode then
    begin
      Brush.Style := bsClear;
      Pen.Style := psDot;
      Pen.Color := clBlack;
      Pen.Width := 1;
      Polygon([Point(0, 0), Point(Width - 1, 0), Point(Width - 1, Height - 1), Point(0, Height - 1)]);
      Pen.Style := psSolid;
    end;
  end;
end;

procedure TTIWHTMLLabel.SetBaseDir(const Value: string);
begin
  ic.BaseDir := Value;
end;

procedure TTIWHTMLLabel.SetDesignLive(const Value: Boolean);
begin
  FDesignLive := Value;
  ic.DesignLive := Value;
  Invalidate;
end;

{$IFNDEF TMSIW71}
procedure TTIWHTMLLabel.SetDesignMode(const Value: Boolean);
begin
  FDesignMode := Value;
  Invalidate;
end;
{$ENDIF}

procedure TTIWHTMLLabel.SetHTMLText(const Value: string);
begin
  FHTMLText := Value;
  Caption := FHTMLText;
end;

{ TTIWAdvEdit }

{$IFDEF TMSIW9}
function TTIWAdvEdit.RenderAsync(
  AContext: TIWBaseHTMLComponentContext): TIWXMLTag;
begin
  if (not Editable) and NonEditableAsLabel then
    GGetWebApplicationThreadVar.CallBackResponse.AddJavaScriptToExecute('<![CDATA[document.getElementById("'
      + HTMLName + 'DIV").firstChild.innerHTML = "' + Text + '";]]>');

  if (Visible) then
    GGetWebApplicationThreadVar.CallBackResponse.AddJavaScriptToExecute('<![CDATA[document.getElementById("'
      + HTMLName + 'DIV").style.visibility = "visible";]]>')
  else
    GGetWebApplicationThreadVar.CallBackResponse.AddJavaScriptToExecute('<![CDATA[document.getElementById("'
      + HTMLName + 'DIV").style.visibility = "hidden";]]>');

  GGetWebApplicationThreadVar.CallBackResponse.AddJavaScriptToExecute('<![CDATA[document.getElementById("'
    + HTMLName + 'DIV").style.top = "' + IntToStr(Top) + 'px";]]>');

  Result := inherited RenderAsync(AContext);
end;
{$ENDIF}


constructor TTIWAdvEdit.Create(AOwner: TComponent);
begin
  inherited;
  FBorderWidth := 1;
  FBorderColor := clBlack;
  FColor := clNone;
  BGColor := clNone;
  FFocusColor := clNone;
  FEditType := etString;
  {$IFDEF TMSIW6}
  SetRenderSize(True);
  {$ELSE}
  FRenderSize := True;
  {$ENDIF}
  FNeedsFormTag := True;
  {*TODO
  FSupportedScriptEvents := 'OnChange,OnSelect';
  }
  FDecimalPoint := ',';

  if not (csDesigning in Componentstate) then
  begin
    {$IFDEF TMSIW51}
    TIWServer.AddInternalFile('IW_JS_TMSAE','/js/TMSAE.js');
    {$ELSE}
    GIWServer.AddInternalFile('IW_JS_TMSAE');
    {$ENDIF}
  end;
end;

{$IFDEF TMSIW6}
procedure TTIWAdvEdit.IWPaint;
{$ELSE}
procedure TTIWAdvEdit.Paint;
{$ENDIF}
var
  R: TRect;
  FColor: TIWColor;
begin
  FColor := BGColor;

  if BGColor = clNone then
    FColor := clWhite;
    
  {$IFDEF TMSIW6}

  if not FFlat then
  begin
    Canvas.Font.Assign(Self.Font);
    Canvas.Brush.Color := FColor;
    Canvas.Pen.Color := BorderColor;
    Canvas.Pen.Width := BorderWidth;
    Draw3DCtrl(Canvas,0, 0, Width - 1, Height - 1);
    R := Rect(2, 2, Width - 2, Height - 2);
  end
  else
  begin
    Canvas.Font.Assign(Self.Font);
    Canvas.Brush.Color := FColor;
    Canvas.Pen.Color := BorderColor;
    Canvas.Pen.Width := BorderWidth;
    R := Rect(2, 2, Width - 2, Height - 2);
    Canvas.Rectangle(R);
  end;

  InflateRect(R,-1,-1);
  {$IFNDEF LINUX}
  SetBKMode(Canvas.Handle,TRANSPARENT);
  case Alignment of
  taLeftJustify: DrawText(Canvas.Handle,PChar(Text),Length(Text),R,DT_LEFT);
  taRightJustify: DrawText(Canvas.Handle,PChar(Text),Length(Text),R,DT_RIGHT);
  taCenter: DrawText(Canvas.Handle,PChar(Text),Length(Text),R,DT_CENTER);
  end;
  {$ENDIF}

  {$ELSE}
  if not FFlat then
  begin
    FCanvas.Font.Assign(Self.Font);
    FCanvas.Brush.Color := FColor;
    FCanvas.Pen.Color := BorderColor;
    FCanvas.Pen.Width := BorderWidth;
    Draw3DCtrl(FCanvas,0, 0, Width - 1, Height - 1);
    R := Rect(2, 2, Width - 2, Height - 2);
  end
  else
  begin
    FCanvas.Font.Assign(Self.Font);
    FCanvas.Brush.Color := FColor;
    FCanvas.Pen.Color := BorderColor;
    FCanvas.Pen.Width := BorderWidth;
    R := Rect(2, 2, Width - 2, Height - 2);
    FCanvas.Rectangle(R);
  end;

  InflateRect(R,-1,-1);
  {$IFNDEF LINUX}
  SetBKMode(FCanvas.Handle,TRANSPARENT);
  case Alignment of
  taLeftJustify: DrawText(FCanvas.Handle,PChar(Text),Length(Text),R,DT_LEFT);
  taRightJustify: DrawText(FCanvas.Handle,PChar(Text),Length(Text),R,DT_RIGHT);
  taCenter: DrawText(FCanvas.Handle,PChar(Text),Length(Text),R,DT_CENTER);
  end;
  {$ENDIF}

  {$ENDIF}

end;

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

{$IFDEF TMSIW7}
procedure TTIWAdvEdit.HookEvents(AContext: TIWPageContext40; AScriptEvents: TIWScriptEvents);
var
//  s:string;
//  focusColorStr, blurColorStr: string;
    advance, aor :string;
begin
  inherited HookEvents(AContext, AScriptEvents);

  advance := 'false';
  if (AdvanceOnUpDown) then
    advance := 'true';

  aor := 'false';
  if (AdvanceOnReturn) then
    aor := 'true';

  if (AContext.WebApplication.Browser = brIE) then
  begin
    AScriptEvents.HookEvent('OnKeyPress','AEKeyPress(this,'+IntTostr(Integer(FEditType))+',event,'+LowerCase(BoolToStr(Signed))
      +',"' + DecimalPoint + '",0,'''+BoolToStr(Editable)+''','+aor+');');
    AScriptEvents.HookEvent('OnKeyUp','AEKeyUp(this, event,'+advance+','+IntTostr(Integer(FEditType))+');');
    if AdvanceOnReturn then
      AScriptEvents.HookEvent('OnKeyDown','AEKeyReturn(this,event);');
    if SubmitOnReturn then
      AScriptEvents.HookEvent('OnKeyDown','AEKeySubmitReturn(this,event,"'+HTMLName+'");');
  end
  else
  begin
    AScriptEvents.HookEvent('OnKeyPress','return AEKeyPress(this,'+IntTostr(Integer(FEditType))+',event,'+LowerCase(BoolToStr(Signed))
      +',"' + DecimalPoint + '",0,'''+BoolToStr(Editable)+''','+aor+');');
    AScriptEvents.HookEvent('OnKeyUp','AEKeyUp(this,event,'+advance+','+IntTostr(Integer(FEditType))+');');
    if AdvanceOnReturn then
      AScriptEvents.HookEvent('OnKeyDown','return AEKeyReturn(this, event);');
    if SubmitOnReturn then
      AScriptEvents.HookEvent('OnKeyDown','AEKeySubmitReturn(this,event,"'+HTMLName+'");');
  end;


  {
  if FocusColor <> clNone then                         
  begin
    focusColorStr := HTMLClr(FocusColor);

    if BGColor = clNone then
      blurColorStr := '#FFFFFF'
    else
      blurColorStr := HTMLClr(BGColor);

    AScriptEvents.HookEvent('OnFocus','return AEColor(event,"'+focusColorStr+'");');
    AScriptEvents.HookEvent('OnBlur','return AEColor(event,"'+blurColorStr+'");');
  end;
  }
end;
{$ENDIF}

{$IFDEF TMSIW7}
procedure TTIWAdvLUEdit.HookEvents(AContext: TIWPageContext40; AScriptEvents: TIWScriptEvents);
begin
  inherited HookEvents(AContext, AScriptEvents);

  if (AContext.WebApplication.Browser = brIE) then
  begin
    AScriptEvents.HookEvent('OnKeyUp', 'return '+HTMLName+'autoComplete(this, document.getElementById('#39+HTMLName+'_ID'#39'),event);');
  end
  else
  begin
    AScriptEvents.HookEvent('OnKeyUp', 'return '+HTMLName+'autoComplete(this, document.getElementById('#39+HTMLName+'_ID'#39'),event);');
  end;

end;
{$ENDIF}

{$IFDEF TMSIW72}
function TTIWAdvEdit.get_HasTabOrder: Boolean;
begin
  {$IFDEF TMSIW72_NEW}
  Result := true;
  {$ELSE}
  Result := false;
  {$ENDIF}
end;  
{$ENDIF}

{$IFDEF TMSIW72_NEW}
function TTIWAdvEdit.get_ShouldRenderTabOrder: boolean;
begin
  Result := false;
end;
{$ENDIF}

{$IFDEF TMSIW6}
function TTIWAdvEdit.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWAdvEdit.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  i: integer;
  htmlres: string;
  iwlbl: TIWLabel;
{$IFNDEF TMSIW7}
  keyPress : string;
  keyUp : string;
  keyDown : string;
  scriptKU, scriptKD, scriptKP: string;  
{$ENDIF}
  focusColorStr : string;
  blurColorStr : string;
  bgColorStr : string;
  blurevent, focusevent, keydownevent, keypressevent, keyupevent : string;
  scriptFocus, scriptBlur,tabidx,cssstr : string;
  HText: string;

   //  Advanced edit control with following types:
   //  TTIWAdvEditType = (etString,etNumeric,etFloat,etUppercase,etMixedCase,etLowerCase,etHex);
   //                    0        1         2       3           4            5          6

   function MakeAlign(AAlignment: TAlignment):string;
   begin
     Result := '';
     case AAlignment of
     taRightJustify: Result := ' text-align:right;';
     taCenter: Result := ' text-align:center;';
     end;
   end;

begin
  {$IFDEF TMSIW6}
  TIWComponent40Context(AContext).AddScriptFile('/js/TMSAE.js');
  {$ELSE}
  AddScriptFile('/js/TMSAE.js');
  {$ENDIF}

  {$IFNDEF TMSIW7}
  keydownEvent := '';
  if (Length(ScriptEvents.Values['OnKeyDown']) > 0) then
    keydownEvent := 'function ' + HTMLName + 'keydownEvent() {'#13
      + ScriptEvents.Values['OnKeyDown'] + #13
      + '}'#13;

  keypressEvent := '';
  if (Length(ScriptEvents.Values['OnKeyPress']) > 0) then
    keypressEvent := 'function ' + HTMLName + 'keypressEvent() {'#13
      + ScriptEvents.Values['OnKeyPress'] + #13
      + '}'#13;

  keyupEvent := '';
  if (Length(ScriptEvents.Values['OnKeyUp']) > 0) then
    keyupEvent := 'function ' + HTMLName + 'keyupEvent() {'#13
    + ScriptEvents.Values['OnKeyUp'] + #13
    + '}'#13;
  {$ENDIF}

  blurEvent := '';
  if (Length(ScriptEvents.Values['OnBlur']) > 0) then
    blurEvent := ' function ' + HTMLName + 'blurEvent() {'#13
      + scriptEvents.Values['onBlur'] + #13
      + '}'#13;

  focusEvent := '';
  if (Length(ScriptEvents.Values['OnFocus']) > 0) then
    focusEvent := ' function ' + HTMLName + 'focusEvent() {'#13
      + scriptEvents.Values['onFocus'] + #13
      + '}'#13;

  if Editable or (not Editable and not NonEditableAsLabel) then
  begin
    if FocusColor = clNone then
    begin
      focusColorStr := '';
      blurColorStr := '';
    end
    else
    begin
      focusColorStr := 'this.style.background='''+HTMLClr(FocusColor)+''';';

      if BGColor = clNone then
        blurColorStr := 'this.style.background=''#FFFFFF'';'
      else
        blurColorStr := 'this.style.background='''+HTMLClr(BGColor)+''';';
    end;
    {$IFNDEF TMSIW7}

    {$IFDEF TMSIW6}
    if (AContext.WebApplication.Browser = brIE) then
    {$ELSE}
    if (WebApplication.Browser = brIE) then
    {$ENDIF}
    begin
      keyPress := 'AEKeyPress(this,'+IntTostr(Integer(FEditType))+',event,'+LowerCase(BoolToStr(Signed))
        +',"' + DecimalPoint + '",0,'''+BoolToStr(Editable)+''')';
      keyUp := 'return AEKeyUp(this,event,'+LowerCase(BoolToStr(AdvanceOnUpDown))+')';
      keyDown := 'return AEKeyReturn(this,event,'+LowerCase(BoolToStr(AdvanceOnReturn))+')';
    end
    else
    begin
      keyPress := 'return AEKeyPress(this,'+IntTostr(Integer(FEditType))+',event,'+LowerCase(BoolToStr(Signed))
        +',"' + DecimalPoint + '",0,'''+BoolToStr(Editable)+''')';
      keyUp := 'return AEKeyUp(this,event)';
      keyDown := 'return AEKeyReturn(this,event)';
    end;

                                                             
    scriptKU := '';                                                            
    if (Length(ScriptEvents.Values['OnKeyUp']) > 0) then
      scriptKU := ' ' + HTMLName + 'keyupEvent();';

    scriptKP := '';                                                 
    if (Length(ScriptEvents.Values['OnKeyPress']) > 0) then
      scriptKP :=  ' ' + HTMLName + 'keypressEvent();';                        

    scriptKD := '';
    if (Length(ScriptEvents.Values['OnKeyDown']) > 0) then
      scriptKD := ' ' + HTMLName + 'keydownEvent();';
    {$ENDIF}

    if BGColor = clNone then
      bgColorStr := ''
    else
      bgColorStr := 'background:' + HTMLClr(BGColor) + ';';

    scriptFocus := '';
    if (Length(ScriptEvents.Values['OnFocus']) > 0) then
      scriptFocus := ' ' + HTMLName + '_onfocus();';

    scriptBlur := '';
    if (Length(ScriptEvents.Values['OnBlur']) > 0) then
      scriptBlur := ' ' + HTMLName + '_onblur();';


    tabidx := '';
    {$IFDEF TMSIW72_NEW}
    if (TabOrder >= 0) then
      tabidx := ' tabindex="'+IntToStr(TabOrder+1)+'" ';
    {$ENDIF}

    cssstr := '';
    {$IFNDEF TMSIW9}
    if (Font.CSSStyle <> '') then
      cssstr := ' class="'+Font.CSSStyle+'"';
    {$ENDIF}

    {$IFDEF TMSIW7}
    HText := TextToHTML(Text);
    {$ELSE}
    HText := Text;
    {$ENDIF}

    htmlres :=
      //added
      '<script>' + blurEvent + focusEvent + keyupEvent + keydownEvent + keypressEvent + '</script>'
      //end added
      + '<input '+tabidx+' type="' + IIF(FPasswordPrompt, 'password', 'input')+'"' + cssstr
      + ' id="'+HTMLName+'" name="' + HTMLName +'"'
      + IIF(MaxLength > 0, ' maxlength=' + IntToStr(MaxLength))
      + ' style="' + bgColorStr +
      {$IFDEF TMSIW6}
      Font.FontToStringStyle(AContext.WebApplication.Browser) + 'width:'+IntToStr(width)+'px;'
      {$ELSE}
      Font.FontToStringStyle(WebApplication.Browser) + 'width:'+IntToStr(width)+'px;'
      {$ENDIF}
      + IIF(not Visible, 'visibility:hidden;')
      + IIF(FFlat, 'border-style:solid;border-width:'+inttostr(FBorderWidth)
      + 'px;border-color:'+HTMLClr(FBorderColor)+';')
      + IIF(FAlignment <> taLeftJustify,MakeAlign(FAlignment))
      + '"'
      + iif(enabled,'',' disabled')
      + ' size="' + IntToStr(Width div 7) + '"'
      + ' value="' + HText + '"'
      + IIF(ReadOnly, ' readonly', '')
      {$IFDEF TMSIW9}
      + IIF((Css <> EmptyStr),' class="' + Css + '"','')
      {$ENDIF}      
      {$IFNDEF TMSIW7}
      + IIF((FEditType <> etString) or SubmitOnReturn or AdvanceOnReturn or (not Editable and not NonEditableAsLabel), ' onKeyPress="' + scriptKP + keyPress+ '";')
      + IIF(AdvanceOnUpDown,' onKeyUp="' + scriptKU + keyUp + '"','')
      + IIF(AdvanceOnReturn,' onKeyDown="' + scriptKD + keyDown + '"','')
      {$ENDIF}
      + ' onFocus="'+ scriptFocus + focusColorStr +'" onBlur="'+ scriptBlur + blurColorStr +'"'
      + '>';

      if SupportsInput and Required then
      begin
        {$IFDEF TMSIW6}

          {$IFDEF TMSIW9}
            TIWComponent40Context(AContext).AddValidation('getSubmitForm().'+HTMLName+'.value.length==0'
             , Format(RSValidationRequeredField, [FriendlyName]));
          {$ELSE}
            TIWComponent40Context(AContext).AddValidation('GSubmitter.' + HTMLName + '.value.length==0'
             , Format(RSValidationRequeredField, [FriendlyName]));
          {$ENDIF}
          
        {$ELSE}
          TIWAppForm(Form).AddValidation('GSubmitter.' + HTMLName + '.value.length==0'
           , Format(RSValidationRequeredField, [FriendlyName]));
        {$ENDIF}
      end;
    end
    else
    begin
      iwlbl := TIWLabel.Create(Owner);
      with iwlbl do
      try
        Caption := Self.Text;
        if (PasswordPrompt) then
        begin
          Caption := '';
          for i := 1 to Length(Self.Text) do
           Caption := Caption + '*';
        end;
        Font.Assign(Self.Font);
        {$IFDEF TMSIW6}
        htmlres := GetControlHTML(iwlbl,AContext);
        {$ELSE}
        htmlres := GetControlHTML(iwlbl);
        {$ENDIF}
      finally
        Free;
      end;
    end;

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.AddStringParam('id',HTMLName+'DIV');

  //if css class is defined remove it from the outer div.
  //the class should only be set on the input tag
  //leave the class definition if the control is rendered as a label (browse mode)
  //to remove the css class, the new class should contain at least one character
  //assigning an empty string will not remove the class value
  {$IFDEF TMSIW9}
  if (Css <> EmptyStr) and (NonEditableAsLabel and Editable) then
    Result.AddStringParam('class', ' ');
  {$ENDIF}

  Result.Contents.AddText(htmlres);
end;


procedure TTIWAdvEdit.SetAlignment(const Value: TAlignment);
begin
  FAlignment := Value;
  Invalidate;
end;

procedure TTIWAdvEdit.SetBorderColor(const Value: TIWColor);
begin
  FBorderColor := Value;
  Invalidate;
end;

procedure TTIWAdvEdit.SetBorderWidth(const Value: Integer);
begin
  FBorderWidth := Value;
  Invalidate;
end;

procedure TTIWAdvEdit.SetColor(const Value: TIWColor);
begin
  FColor := Value;
  Invalidate;
end;

procedure TTIWAdvEdit.SetFlat(const Value: Boolean);
begin
  FFlat := Value;
  Invalidate;
end;


{ TTIWHTMLCheckBox }

constructor TTIWHTMLCheckBox.Create(AOwner: TComponent);
begin
  inherited;
  ic := TIWHTMLPictureCache.Create;
  ic.DesignLive := True;
  FDesignMode := True;
  FDesignLive := True;
end;

destructor TTIWHTMLCheckBox.Destroy;
begin
  ic.Free;
  inherited;
end;

function TTIWHTMLCheckBox.GetBaseDir: string;
begin
  Result := ic.BaseDir;
end;


{$IFDEF TMSIW6}
procedure TTIWHTMLCheckBox.IWPaint;
{$ELSE}
procedure TTIWHTMLCheckBox.Paint;
{$ENDIF}
var
  fr: TRect;
  a,s,fa:string;
  xsize,ysize,hl,ml: integer;
  hr:trect;

begin
  Draw3DCtrl(Canvas,2,2,15,15);

  with Canvas do
  begin
    Brush.Color := clWhite;
    Pen.Color := clWhite;
    Rectangle(4, 4, 13, 13);

    if FChecked then
    begin
      Pen.Color := clBlack;
      Brush.Color := clBlack;
      Polygon([Point(5, 7), Point(5, 9), Point(7, 11), Point(11, 7)
       , Point(11, 5), Point(7, 9), Point(5, 7)]);
    end;

    Font.Assign(Self.Font);
    if Font.Color = clNone then
      Font.Color := clBlack;

    Brush.Style := bsSolid;
    Brush.Color := Self.Color;

    fr := Rect(15, 0, Width, 1000);
    HTMLDrawEx(Canvas, caption, fr, nil, 0,0,-1,-1,0,false,false,false,false,false,false,True,1.0,
      clBlue,clNone,clNone,clGray,a,s,fa,xsize,ysize,hl,ml,hr
      {$IFNDEF LINUX}
      ,ic,nil
      {$ENDIF}
      );

    if FDesignMode then
    begin
      Brush.Style := bsClear;
      Pen.Style := psDot;
      Pen.Color := clBlack;
      Pen.Width := 1;
      Polygon([Point(0, 0), Point(Width - 1, 0), Point(Width - 1, Height - 1), Point(0, Height - 1)]);
      Pen.Style := psSolid;
    end;
  end;
end;

procedure TTIWHTMLCheckBox.SetBaseDir(const Value: string);
begin
  ic.BaseDir := Value;
end;

procedure TTIWHTMLCheckBox.SetDesignLive(const Value: Boolean);
begin
  FDesignLive := Value;
  ic.DesignLive := Value;
  Invalidate;
end;

{$IFNDEF TMSIW71}
procedure TTIWHTMLCheckBox.SetDesignMode(const Value: Boolean);
begin
  FDesignMode := Value;
  Invalidate;
end;
{$ENDIF}

procedure TTIWHTMLCheckBox.SetHTMLText(const Value: string);
begin
  FHTMLText := Value;
  Caption := Value;
end;

{ TTIWHTMLList }

constructor TTIWHTMLList.Create(AOwner: TComponent);
begin
  inherited;
  FItems := TStringList.Create;
  ic := TIWHTMLPictureCache.Create;
  ic.DesignLive := True;
  Height := 24;
  Width := 116;
  FDesignMode := True;
end;

destructor TTIWHTMLList.Destroy;
begin
  FreeAndNil(FItems);
  FreeAndNil(ic);
  inherited;
end;

{$IFDEF TMSIW6}
procedure TTIWHTMLList.IWPaint;
{$ELSE}
procedure TTIWHTMLList.Paint;
{$ENDIF}
var
  fr: TRect;
  a,s,fa,ds:string;
  xsize,ysize,offs,hl,ml,i: integer;
  hr:trect;
begin
  with Canvas do
  begin
    Font.Assign(Self.Font);

    if Font.Color = clNone then
      Font.Color := clBlack;

    Brush.Style := bsSolid;
    Brush.Color := Self.Color;

    if (Brush.Color = clNone) then
      Brush.Color := clWhite;

    Offs := 0;

    for i := 1 to FItems.Count do
    begin

      ds := FItems[i - 1];

      if FNumbered then
        ds := IntToStr(i) + ' ' + ds
      else
        ds := '* ' + ds;

      fr := Rect(0, Offs, Width, Offs + 1000);
      HTMLDrawEx(Canvas, ds, fr, nil, 0,0,-1,-1,0,false,false,false,false,false,false,True,1.0,
        clBlue,clNone,clNone,clGray,a,s,fa,XSize,YSize,hl,ml,hr
        {$IFNDEF LINUX}
        ,ic,nil
        {$ENDIF}
        );
      Offs := Offs + YSize + 4;
    end;

    if FDesignMode then
    begin
      Brush.Style := bsClear;
      Pen.Style := psDot;
      Pen.Color := clBlack;
      Pen.Width := 1;
      Polygon([Point(0, 0), Point(Width - 1, 0), Point(Width - 1, Height - 1), Point(0, Height - 1)]);
      Pen.Style := psSolid;
    end;
  end;
end;

{$IFDEF TMSIW72}
function TTIWHTMLList.get_HasTabOrder: boolean;
begin
  {$IFNDEF TMSIW72_NEW}
  Result := false;
  {$ELSE}
  Result := true;
  {$ENDIF}
end;
{$ENDIF}

{$IFDEF TMSIW72_NEW}
function TTIWHTMLList.get_ShouldRenderTabOrder: Boolean; 
begin
  Result := false;
end;
{$ENDIF}

{$IFDEF TMSIW6}
function TTIWHTMLList.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWHTMLList.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  i: Integer;
  html: string;
begin
  html := IIF(Numbered, '<ol>', '<ul>');
  for i := 0 to Items.Count - 1 do
  begin
    html := html + '<LI>' + Items[i] + '</LI>' + EOL;
  end;
  html := html + IIF(Numbered, '</ol>', '</ul>');

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(html);
end;

procedure TTIWHTMLList.SetBaseDir(const Value: string);
begin
  FBaseDir := Value;
  ic.BaseDir := Value;
end;

procedure TTIWHTMLList.SetDesignLive(const Value: Boolean);
begin
  FDesignLive := Value;
  ic.DesignLive := Value;
end;

{$IFNDEF TMSIW71}
procedure TTIWHTMLList.SetDesignMode(const Value: Boolean);
begin
  FDesignMode := Value;
  Invalidate;
end;
{$ENDIF}

procedure TTIWHTMLList.SetItems(AValue: TStrings);
begin
  FItems.Assign(AValue);
  Invalidate;
end;

procedure TTIWHTMLList.SetNumbered(const AValue: Boolean);
begin
  FNumbered := AValue;
  Invalidate;
end;

{ TTIWHTMLRadioGroup }

constructor TTIWHTMLRadioGroup.Create(AOwner: TComponent);
begin
  inherited;
  ic := TIWHTMLPictureCache.Create;
  ic.DesignLive := True;
  FDesignMode := True;
end;

destructor TTIWHTMLRadioGroup.Destroy;
begin
  FreeAndNil(ic);
  inherited;
end;

function TTIWHTMLRadioGroup.GetItemIndex: Integer;
begin
  Result := inherited ItemIndex;
end;

{$IFDEF TMSIW6}
procedure TTIWHTMLRadioGroup.IWPaint;
{$ELSE}
procedure TTIWHTMLRadioGroup.Paint;
{$ENDIF}
var
  fr: TRect;
  a,s,fa:string;
  xsize,ysize,offsx,offsy,hl,ml,i: integer;
  hr:trect;

begin
  with Canvas do
  begin
    Font.Assign(Self.Font);
    if Font.Color = clNone then
      Font.Color := clBlack;

    Brush.Style := bsSolid;
    Brush.Color := Self.Color;

    Offsx := 0;
    Offsy := 0;

    for i := 1 to FItems.Count do
    begin
      fr := Rect(OffsX,OffsY,OffsX + 12,OffsY + 12);

      {$IFNDEF LINUX}
      if ItemIndex = i - 1 then
        DrawFrameControl(Handle,fr,DFC_BUTTON, DFCS_BUTTONRADIO or DFCS_CHECKED)
      else
        DrawFrameControl(Handle,fr,DFC_BUTTON, DFCS_BUTTONRADIO);
      {$ENDIF}

      fr := Rect(OffsX + 12, OffsY, Width, OffsY + 1000);
      HTMLDrawEx(Canvas, FItems[i - 1], fr, nil, 0,0,-1,-1,0,false,false,false,false,false,false,True,1.0,
        clBlue,clNone,clNone,clGray,a,s,fa,XSize,YSize,hl,ml,hr
        {$IFNDEF LINUX}
        ,ic,nil
        {$ENDIF}
        );

      if Layout = glHorizontal then
        OffsX := OffsX + XSize + 16
      else
        OffsY := OffsY + YSize + 4;
        
    end;

    if FDesignMode then
    begin
      Brush.Style := bsClear;
      Pen.Style := psDot;
      Pen.Color := clBlack;
      Pen.Width := 1;
      Polygon([Point(0, 0), Point(Width - 1, 0), Point(Width - 1, Height - 1), Point(0, Height - 1)]);
      Pen.Style := psSolid;
    end;
  end;
end;

procedure TTIWHTMLRadioGroup.SetBaseDir(const Value: string);
begin
  FBaseDir := Value;
  ic.BaseDir := Value;
end;

procedure TTIWHTMLRadioGroup.SetDesignLive(const Value: Boolean);
begin
  FDesignLive := Value;
  ic.DesignLive := Value;
end;

{$IFNDEF TMSIW71}
procedure TTIWHTMLRadioGroup.SetDesignMode(const Value: Boolean);
begin
  FDesignMode := Value;
  Invalidate;
end;
{$ENDIF}

procedure TTIWHTMLRadioGroup.SetItemIndex(const Value: Integer);
begin
  inherited ItemIndex := Value;
  Invalidate;
end;



{ TTIWAdvLUEdit }

constructor TTIWAdvLUEdit.Create(AOwner: TComponent);
begin
  inherited;
  FLookupItems := TStringList.Create;
  FCaseSensitive := True;
  {$IFDEF TMSIW6}
  SetRenderSize(True);
  {$ELSE}
  FRenderSize := True;
  {$ENDIF}
end;

destructor TTIWAdvLUEdit.Destroy;
begin
  FreeAndNil(FLookupItems);
  inherited;
end;

{$IFDEF TMSIW6}
function TTIWAdvLUEdit.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWAdvLUEdit.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  i: integer;
  htmlres: string;
  iwlbl: TIWLabel;
{$IFNDEF TMSIW7}
  keyPress : string;
  keyUp : string;
  keyDown : string;
  scriptKU, scriptKD, scriptKP: string;
{$ENDIF}
  focusColorStr : string;
  blurColorStr : string;
  bgColorStr : string;
  blurevent, focusevent, keydownevent, keypressevent, keyupevent : string;
  scriptFocus, scriptBlur,tabidx,cssstr : string;
  HText: string;

  function MakeAlign(AAlignment: TAlignment):string;
  begin
    Result := '';
    case AAlignment of
    taRightJustify: Result := ' style=text-align:right;';
    taCenter: Result := ' style=text-align:center;';
    end;
  end;

  function MakeScript(Name:string): string;
  begin
    Result :=
       '<Script Language="JavaScript">'#13
        + 'function '+HTMLName+'autoComplete (field, select,event) {'#13
        //+ ' alert("here");'#13
				+ '  var agent = navigator.userAgent.toLowerCase();'#13
				+ '  var bw;'#13
				+ '  if (agent.indexOf("msie") > 0)'#13
				+ '    bw = "msie";'#13
				+ '  if (agent.indexOf("gecko") > 0)'#13
        + '    bw = "mozilla";'#13
				+ '  if (agent.indexOf("opera") > 0)'#13
				+ '    bw = "opera";'#13
				+ '  if (agent.indexOf("netscape") > 0)'#13
				+ '    bw = "netscape";'#13
				+ '  var key;'#13
      	+ '  var found = false;'#13
        + 'var s;'#13
        + 'var lookup = new String("");'#13
//        + IIF(AdvanceOnUpDown,HTMLName+'KeyUp(field)','') + #13
//        + IIF(AdvanceOnUpDown,HTMLName+'KeyUp(field,event)','') + #13
        + 's = field.value;'#13
        + IIF(FCaseSensitive,'','s = s.toUpperCase()') + #13
      	+ 'for (var i = 0; i < select.options.length; i++) {'#13
        + IIF(FCaseSensitive,'lookup = select.options[i]['#39'value'#39'];'#13,'lookup = select.options[i]['#39'value'#39'].toUpperCase();'#13) + #13
      	+ 'if (lookup.indexOf(s) == 0) {'#13
        + '	found=true; break;'#13
      	+ '	}'#13
      	+ '}'#13
      	+ 'if (found) { select.selectedIndex = i; }'#13
      	+ 'else { select.selectedIndex = -1; }'#13

        + 'if (bw == "msie"){'#13
				+ '  key = event.keyCode;'#13

      	+ 'if (field.createTextRange) {'#13
      	+ '	var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";'#13
      	+ '	if (cursorKeys.indexOf(key+";") == -1) {'#13
      	+ '		var r1 = field.createTextRange();'#13
      	+ '		var oldValue = r1.text;'#13
      	+ '		var newValue = found ? select.options[i]['#39'value'#39'] : oldValue;'#13
      	+ '		if (newValue != field.value) {'#13
      	+ '			field.value = newValue;'#13
      	+ '			var rNew = field.createTextRange();'#13
        + '			rNew.moveStart('#39'character'#39', oldValue.length) ;'#13
      	+ '			rNew.select();'#13
      	+ '			}'#13
      	+ '		}'#13
      	+ '	}'#13

				+ '  } else {'#13
				+ '    key = event.which;'#13

      	+ '	var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";'#13
      	+ '	if (cursorKeys.indexOf(key+";") == -1) {'#13
      	+ '		var newValue = found ? select.options[i]['#39'value'#39'] : field.value;'#13
//      	+ '		if (newValue != field.value) {'#13
      	+ '		if ((newValue != field.value) && (newValue.toLowerCase() != "undefined")) {'#13
      	+ '			field.value = newValue;'#13
      	+ '			}'#13
      	+ '	}'#13

      	+ '	}'#13
      	+ '}'#13

        + 'function ' + HTMLName + 'Focus(ctrl) {'#13;

        if FFocusColor <> FColor then
          Result := Result
          + 'ctrl.style.backgroundColor = '#39+HTMLClr(FFocusColor)+#39''#13;
        if FSelectAll then
          Result := Result
          + 'var rNew = ctrl.createTextRange();'#13
          + 'rNew.moveStart('#39'character'#39', 0) ;'#13
          + 'rNew.select();'#13;

      Result := Result
        + '}'
        + '</Script>';
  end;

begin

  {$IFDEF TMSIW6}
  TIWComponent40Context(AContext).AddScriptFile('/js/TMSAE.js');
  {$ELSE}
  AddScriptFile('/js/TMSAE.js');
  {$ENDIF}

    {$IFNDEF TMSIW7}
  keydownEvent := '';
  if (Length(ScriptEvents.Values['OnKeyDown']) > 0) then
    keydownEvent := 'function ' + HTMLName + 'keydownEvent() {'#13
      + ScriptEvents.Values['OnKeyDown'] + #13
      + '}'#13;

  keypressEvent := '';
  if (Length(ScriptEvents.Values['OnKeyPress']) > 0) then
    keypressEvent := 'function ' + HTMLName + 'keypressEvent() {'#13
      + ScriptEvents.Values['OnKeyPress'] + #13
      + '}'#13;

  keyupEvent := '';
  if (Length(ScriptEvents.Values['OnKeyUp']) > 0) then
    keyupEvent := 'function ' + HTMLName + 'keyupEvent() {'#13
    + ScriptEvents.Values['OnKeyUp'] + #13
    + '}'#13;
  {$ENDIF}

  blurEvent := '';
  if (Length(ScriptEvents.Values['OnBlur']) > 0) then
    blurEvent := ' function ' + HTMLName + 'blurEvent() {'#13
      + scriptEvents.Values['onBlur'] + #13
      + '}'#13;

  focusEvent := '';
  if (Length(ScriptEvents.Values['OnFocus']) > 0) then
    focusEvent := ' function ' + HTMLName + 'focusEvent() {'#13
      + scriptEvents.Values['onFocus'] + #13
      + '}'#13;

  if Editable or (not Editable and not NonEditableAsLabel) then
  begin
    if FocusColor = clNone then
    begin
      focusColorStr := '';
      blurColorStr := '';
    end
    else
    begin
      focusColorStr := 'this.style.background='''+HTMLClr(FocusColor)+''';';

      if BGColor = clNone then
        blurColorStr := 'this.style.background=''#FFFFFF'';'
      else
        blurColorStr := 'this.style.background='''+HTMLClr(BGColor)+''';';
    end;

    {$IFNDEF TMSIW7}

    {$IFDEF TMSIW6}
    if (AContext.WebApplication.Browser = brIE) then
    {$ELSE}
    if (WebApplication.Browser = brIE) then
    {$ENDIF}
    begin
      keyPress := 'AEKeyPress(this,'+IntTostr(Integer(FEditType))+',event,'+LowerCase(BoolToStr(Signed))+','''+DecimalPoint+''',0,'''+BoolToStr(Editable)+''')';
      keyUp := 'return '+HTMLName+'autoComplete(this, document.getElementById('#39+HTMLName+'_ID'#39'),event);return AEKeyUp(this,event,'+LowerCase(BoolToStr(AdvanceOnUpDown))+')';
      keyDown := 'return AEKeyReturn(this,event,'+LowerCase(BoolToStr(AdvanceOnReturn))+')';
    end
    else
    begin
      keyPress := 'return AEKeyPress(this,'+IntTostr(Integer(FEditType))+',event,'+LowerCase(BoolToStr(Signed))+','''+DecimalPoint+''',0,'''+BoolToStr(Editable)+''')';
      keyUp := 'return '+HTMLName+'autoComplete(this, document.getElementById('#39+HTMLName+'_ID'#39'),event);return AEKeyUp(this,event)';
      keyDown := 'return AEKeyReturn(this,event)';
    end;

    scriptKU := '';
    if (Length(ScriptEvents.Values['OnKeyUp']) > 0) then
      scriptKU := ' ' + HTMLName + 'keyupEvent();';

    scriptKP := '';                                                 
    if (Length(ScriptEvents.Values['OnKeyPress']) > 0) then
      scriptKP :=  ' ' + HTMLName + 'keypressEvent();';                        

    scriptKD := '';
    if (Length(ScriptEvents.Values['OnKeyDown']) > 0) then
      scriptKD := ' ' + HTMLName + 'keydownEvent();';
    {$ENDIF}

    if BGColor = clNone then
      bgColorStr := ''
    else
      bgColorStr := 'background:' + HTMLClr(BGColor) + ';';

    scriptFocus := '';
    if (Length(ScriptEvents.Values['OnFocus']) > 0) then
      scriptFocus := ' ' + HTMLName + '_onfocus();';

    scriptBlur := '';
    if (Length(ScriptEvents.Values['OnBlur']) > 0) then
      scriptBlur := ' ' + HTMLName + '_onblur();';


    tabidx := '';
    {$IFDEF TMSIW72_NEW}
    if (TabOrder >= 0) then
      tabidx := ' tabindex="'+IntToStr(TabOrder+1)+'" ';
    {$ENDIF}

    cssstr := '';
    {$IFNDEF TMSIW9}
    if (Font.CSSStyle <> '') then
      cssstr := ' class="'+Font.CSSStyle+'"';
    {$ENDIF}

    {$IFDEF TMSIW7}
    HText := TextToHTML(Text);
    {$ELSE}
    HText := Text;
    {$ENDIF}

    htmlres :=
      //added
      '<script>' + blurEvent + focusEvent + keyupEvent + keydownEvent + keypressEvent + '</script>'
      //end added
      + MakeScript(HTMLName)      
      + '<input '+tabidx+' type="' + IIF(FPasswordPrompt, 'password', 'input')+'"' + cssstr + ' id="'+HTMLName+'" name="' + HTMLName +'"'
      + IIF(MaxLength > 0, ' maxlength=' + IntToStr(MaxLength))
      + ' style="' + bgColorStr +
      {$IFDEF TMSIW6}
      Font.FontToStringStyle(AContext.WebApplication.Browser) + 'width:'+IntToStr(width)+'px;'
      {$ELSE}
      Font.FontToStringStyle(WebApplication.Browser) + 'width:'+IntToStr(width)+'px;'
      {$ENDIF}
      + IIF(FFlat, 'border-style:solid;border-width:'+inttostr(FBorderWidth)+ 'px;border-color:'+HTMLClr(FBorderColor)+';')
      + IIF(FAlignment <> taLeftJustify,MakeAlign(FAlignment))      
      + '"'
      + ' size="' + IntToStr(Width div 7) + '"'
      + ' value="' + HText + '"'
      + IIF(ReadOnly, ' readonly ', '')
      {$IFDEF TMSIW9}
      + IIF((Css <> EmptyStr),' class="' + Css + '"','')
      {$ENDIF}
      {$IFNDEF TMSIW7}
      + IIF((FEditType <> etString) or SubmitOnReturn or AdvanceOnReturn or (not Editable and not NonEditableAsLabel), ' onKeyPress="' + scriptKP + keyPress+ '";')
      + IIF(AdvanceOnUpDown,' onKeyUp="' + scriptKU + keyUp + '"','')
      + IIF(AdvanceOnReturn,' onKeyDown="' + scriptKD + keyDown + '"','')
      {$ENDIF}
      + ' onFocus="'+ scriptFocus + focusColorStr+'"; onBlur="'+ scriptBlur+blurColorStr+'"'
      + '>';

      //fill hidden dropdown with lookup items
    htmlres := htmlres + '<SELECT style="visibility:hidden" id="'+HTMLName+'_ID">';
    for i := 1 to FLookupItems.Count do
    begin
      htmlres := htmlres + '<OPTION VALUE="'+FLookupItems.Strings[i - 1]+'">'+FLookupItems.Strings[i - 1]+ '</OPTION>'#13;
    end;
    htmlres := htmlres + '</SELECT></DIV>';

      if SupportsInput and Required then
      begin
        {$IFDEF TMSIW6}
        
          {$IFDEF TMSIW9}
          TIWComponent40Context(AContext).AddValidation('getSubmitForm().' + HTMLName + '.value.length==0'
           , Format(RSValidationRequeredField, [FriendlyName]));
          {$ELSE}
          TIWComponent40Context(AContext).AddValidation('GSubmitter.' + HTMLName + '.value.length==0'
           , Format(RSValidationRequeredField, [FriendlyName]));
          {$ENDIF}

        {$ELSE}
          TIWAppForm(Form).AddValidation('GSubmitter.' + HTMLName + '.value.length==0'
           , Format(RSValidationRequeredField, [FriendlyName]));
        {$ENDIF}
      end;
    end
    else
    begin
      iwlbl := TIWLabel.Create(Owner);
      with iwlbl do
      try
        Caption := Self.Text;
        if (PasswordPrompt) then
        begin
          Caption := '';
          for i := 1 to Length(Self.Text) do
           Caption := Caption + '*';
        end;
        Font.Assign(Self.Font);
        {$IFDEF TMSIW6}
        htmlres := GetControlHTML(iwlbl,AContext);
        {$ELSE}
        htmlres := GetControlHTML(iwlbl);
        {$ENDIF}
      finally
        Free;
      end;
    end;

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.AddStringParam('id',HTMLName+'DIV');

  //if css class is defined remove it from the outer div.
  //the class should only be set on the input tag
  //leave the class definition if the control is rendered as a label (browse mode)
  //to remove the css class, the new class should contain at least one character
  //assigning an empty string will not remove the class value
  {$IFDEF TMSIW9}
  if (Css <> EmptyStr) and (NonEditableAsLabel and Editable) then
    Result.AddStringParam('class', ' ');
  {$ENDIF}
  
  Result.Contents.AddText(htmlres);

end;

procedure TTIWAdvLUEdit.SetLookupItems(const Value: TStringList);
begin
  FLookupItems.Assign(Value);
end;



{ TTIWFilePicker }

constructor TTIWFilePicker.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FBorderColor := clBlack;
end;

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


{$IFDEF TMSIW6}
procedure TTIWFilePicker.IWPaint;
{$ELSE}
procedure TTIWFilePicker.Paint;
{$ENDIF}
var
  r: TRect;
  BtnText: string;
begin
  {$IFDEF TMSIW6}
  with Canvas do
  begin
    if not FFlat then
      Draw3DCtrl(Canvas,0,0, Width - 80, Height)
    else
    begin
      Pen.Color := FBorderColor;
      Pen.Width := 1;
      Brush.Style := bsClear;
      Rectangle(0,0,Width - 80, Height);
    end;

    Font.Assign(Self.Font);
    Brush.Color := clWhite;
    TextRect(Rect(2, 2, Width - 82, Height - 2), 2, 2, Text);
    r := ClientRect;
    r := Rect(r.right - 80 ,r.top,r.right, r.top + 20);

    {$IFNDEF LINUX}
    DrawFrameControl(Handle,r,DFC_BUTTON,DFCS_BUTTONPUSH);
    SetBKMode(Handle,TRANSPARENT);
    BtnText := 'Browse ...';
    DrawText(Handle,PChar(BtnText),Length(BtnText),r,DT_CENTER or DT_SINGLELINE or DT_VCENTER);
    {$ENDIF}
  end;
  {$ELSE}
  with FCanvas do
  begin
    if not FFlat then
      Draw3DCtrl(FCanvas,0,0, Width - 80, Height)
    else
    begin
      Pen.Color := FBorderColor;
      Pen.Width := 1;
      Brush.Style := bsClear;
      Rectangle(0,0,Width - 80, Height);
    end;

    Font.Assign(Self.Font);
    Brush.Color := clWhite;
    TextRect(Rect(2, 2, Width - 82, Height - 2), 2, 2, Text);
    r := ClientRect;
    r := Rect(r.right - 80 ,r.top,r.right, r.top + 20);

    {$IFNDEF LINUX}
    DrawFrameControl(Handle,r,DFC_BUTTON,DFCS_BUTTONPUSH);
    SetBKMode(Handle,TRANSPARENT);
    BtnText := 'Browse ...';
    DrawText(Handle,PChar(BtnText),Length(BtnText),r,DT_CENTER or DT_SINGLELINE or DT_VCENTER);
    {$ENDIF}
  end;
  {$ENDIF}
end;


{$IFDEF TMSIW6}
function TTIWFilePicker.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWFilePicker.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
//  sz: Integer;
  htmlres: string;
begin
  //sz := (Width - 80) div 7;
  //htmlres := '<input ' + IIF(FFlat,'style="border-style:solid;border-width:1;border-color:'+HTMLClr(FBorderColor)+'" ','')+' type="file" name="'+ HTMLName + '" size="'+inttostr(sz)+'" value="">';
  htmlres := '<input style="' + IIF(FFlat,'border-style:solid;border-width:1;border-color:'
  +HTMLClr(FBorderColor)+'; ','')+'width:'+IntToStr(Width)+'px;" type="file" name="'
  + HTMLName + '" value="" '
  {$IFDEF TMSIW9}
  + IIF((Css <> EmptyStr),' class="' + Css + '"','')
  {$ENDIF}
  + '>';

  Result := TIWHTMLTag.CreateTag('DIV');
  //if css class is defined remove it from the outer div.
  //the class should only be set on the input tag
  {$IFDEF TMSIW9}
  if Css <> EmptyStr then
    Result.AddStringParam('class', ' ');
  {$ENDIF}  
  
  Result.Contents.AddText(htmlres);
end;

procedure TTIWFilePicker.SetFlat(const Value: Boolean);
begin
  FFlat := Value;
  Invalidate;
end;

procedure TTIWFilePicker.SetBorderColor(const Value: TColor);
begin
  FBorderColor := Value;
  Invalidate;
end;



{ TTIWEmailEdit }

{$IFDEF TMSIW7}
procedure TTIWEmailEdit.HookEvents(AContext: TIWPageContext40; AScriptEvents: TIWScriptEvents);
begin
  inherited HookEvents(AContext, AScriptEvents);      
    AScriptEvents.HookEvent('OnBlur','return '+HTMLName+'CheckEmail(this);');
end;
{$ENDIF}

constructor TTIWEmailEdit.Create(AOwner: TComponent);
begin
  inherited;

  FErrorMessage := 'Please enter a valid e-mail address.';

  {$IFDEF TMSIW6}
  SetRenderSize(True);
  Required := True;
  {$ELSE}
  FRenderSize := True;
  {$ENDIF}
  {$IFDEF TMSIW6}
  Bgcolor := clWebWhite;
  {$ENDIF}

end;

{$IFDEF TMSIW6}
procedure TTIWEmailEdit.IWPaint;
{$ELSE}
procedure TTIWEmailEdit.Paint;
{$ENDIF}
var
  R: TRect;
{$IFNDEF TMSIW6}
  FColor: TIWColor;
{$ENDIF}
begin

{$IFNDEF TMSIW6}
  FColor := Color;
  if FColor = clNone then
    FColor := clWhite;
{$ENDIF}    

  {$IFDEF TMSIW6}
  if not FFlat then
  begin
    Canvas.Font.Assign(Self.Font);
    if BGColor <> clNone then    
      Canvas.Brush.Color := BGColor
    else
      Canvas.Brush.Color := clWhite;
    Canvas.Pen.Color := clBlack;
    Canvas.Pen.Width := 1;
    Draw3DCtrl(Canvas,0, 0, Width - 1, Height - 1);
    R := Rect(2, 2, Width - 2, Height - 2);
  end
  else
  begin
    Canvas.Font.Assign(Self.Font);
    if BGColor <> clNone then    
      Canvas.Brush.Color := BGColor
    else
      Canvas.Brush.Color := clWhite;
    Canvas.Pen.Color := clBlack;
    Canvas.Pen.Width := 1;
    R := Rect(2, 2, Width - 2, Height - 2);
    Canvas.Rectangle(R);
  end;

  InflateRect(R,-1,-1);
  {$IFNDEF LINUX}
  SetBKMode(Canvas.Handle,TRANSPARENT);
  case Alignment of
  taLeftJustify: DrawText(Canvas.Handle,PChar(Text),Length(Text),R,DT_LEFT);
  taRightJustify: DrawText(Canvas.Handle,PChar(Text),Length(Text),R,DT_RIGHT);
  taCenter: DrawText(Canvas.Handle,PChar(Text),Length(Text),R,DT_CENTER);
  end;
  {$ENDIF}

  {$ELSE}
  if not FFlat then
  begin
    FCanvas.Font.Assign(Self.Font);
    FCanvas.Brush.Color := FColor;
    FCanvas.Pen.Color := clBlack;
    FCanvas.Pen.Width := 1;
    Draw3DCtrl(FCanvas,0, 0, Width - 1, Height - 1);
    R := Rect(2, 2, Width - 2, Height - 2);
  end
  else
  begin
    FCanvas.Font.Assign(Self.Font);
    FCanvas.Brush.Color := FColor;
    FCanvas.Pen.Width := 1;
    FCanvas.Pen.Color := clBlack;
    R := Rect(2, 2, Width - 2, Height - 2);
    FCanvas.Rectangle(R);
  end;

  InflateRect(R,-1,-1);
  {$IFNDEF LINUX}
  SetBKMode(FCanvas.Handle,TRANSPARENT);
  DrawText(FCanvas.Handle,PChar(Text),Length(Text),R,DT_LEFT);
  {$ENDIF}

  {$ENDIF}

end;


{$IFDEF TMSIW6}
function TTIWEmailEdit.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWEmailEdit.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  FlatStyle:string;

  function MakeScript: string;
  begin
     Result := '<script>'#13
      + 'function '+HTMLName+'CheckEmail(field) {'#13
      + IIF(not Required,'if (field.value == "") return false;'#13,'')
      + 'var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);'#13
      + 'if (!goodEmail){'#13
      + '  alert('#39+FErrorMessage+#39')'#13
      + IIF(not WarnOnly,'  field.focus();'#13,'')
      + IIF(not WarnOnly,'  field.select();'#13,'')
      + '  }'#13
      + '}'#13
      + '</script>';
  end;

begin
  FlatStyle := '';
  if FFlat then
    FlatStyle := 'border-style:solid;border-width:1';

  {$IFDEF TMSIW6}
  Result  := inherited RenderHTML(AContext);
  Result.Contents.AddText(MakeScript);
  Result.AddStringParam('onblur', 'return ' + HTMLName+'CheckEmail(this)');
  if FFlat then
    Result.AddStringParam('style',FlatStyle);
  {$ELSE}
  Result := TIWHTMLTag.CreateTag('DIV');
  //if css class is defined remove it from the outer div.
  //the class should only be set on the input tag
  {$IFDEF TMSIW9}
  if Css <> EmptyStr then
    Result.AddStringParam('class', ' ');
  {$ENDIF}

  Result.Contents.AddText(MakeScript);
  with Result.Contents.AddTagAsObject(inherited RenderHTML) do
  begin
    AddStringParam('onblur', 'return ' + HTMLName+'CheckEmail(this)');
    if FFlat then
      AddStringParam('style',FlatStyle);
  end;
  {$ENDIF}
end;


{ TTIWDateLabel }

constructor TTIWDateLabel.Create(AOwner: TComponent);
begin
  inherited;
  FDateFormat := 'dd/mm/yyyy';
  Caption := FormatDateTime(FDateFormat,Now);
end;

procedure TTIWDateLabel.SetDateFormat(const Value: string);
begin
  FDateFormat := Value;
  Caption := FormatDateTime(FDateFormat,Now);
end;

{ TTIWCountryComboBox }

constructor TTIWCountryComboBox.Create(AOwner: TComponent);
begin
  inherited;
  Items.Add('ALGERIA');
  Items.Add('AMERICAN OCEANIAN TERRITORIES');
  Items.Add('AMERICAN SAMOA');
  Items.Add('ANDORRA');
  Items.Add('ANGOLA');
  Items.Add('ANGUILLA');
  Items.Add('ANTIGUA AND BARBUDA');
  Items.Add('ARGENTINA');
  Items.Add('ARMENIA');
  Items.Add('ARUBA');
  Items.Add('AUSTRALIA');
  Items.Add('AUSTRIA');
  Items.Add('AZERBAIJAN');
  Items.Add('BAHAMAS');
  Items.Add('BAHRAIN');
  Items.Add('BANGLADESCH');
  Items.Add('BARBADOS');
  Items.Add('BELARUS');
  Items.Add('BELGIUM');
  Items.Add('BELIZE');
  Items.Add('BENIN');
  Items.Add('BERMUDA');
  Items.Add('BHUTAN');
  Items.Add('BOLIVIA');
  Items.Add('BOSNIA AND HERZEGOWINA');
  Items.Add('BOTSWANA');
  Items.Add('BRAZIL');
  Items.Add('BRITISH INDIAN OCEAN TERRITORY');
  Items.Add('BRUNEI DARUSSALAM');
  Items.Add('BULGARIA');
  Items.Add('BURKINA FASO');
  Items.Add('BURUNDI');
  Items.Add('CAMBODIA');
  Items.Add('CAMEROON');
  Items.Add('CANADA');
  Items.Add('CANARY ISLANDS');
  Items.Add('CAPE VERDE');
  Items.Add('CAYMAN ISLANDS');
  Items.Add('CENTRAL AFRICAN REPUBLIC');
  Items.Add('CEUTA');
  Items.Add('CHAD');
  Items.Add('CHANNEL ISLANDS (UK)');
  Items.Add('CHILE');
  Items.Add('CHINA');
  Items.Add('COLOMBIA');
  Items.Add('COMOROS');
  Items.Add('CONGO');
  Items.Add('COSTA RICA');
  Items.Add('CROATIA');
  Items.Add('CUBA');
  Items.Add('CYPRUS');
  Items.Add('CZECH REPUBLIC');
  Items.Add('DENMARK');
  Items.Add('DJIBOUTI');
  Items.Add('DOMINICA');
  Items.Add('DOMINICAN REPUBLIC');
  Items.Add('ECUADOR');
  Items.Add('EGYPT');
  Items.Add('EL SALVADOR');
  Items.Add('EMIRATE OF AFGHANISTAN');
  Items.Add('EQUATORIAL GUINEA');
  Items.Add('ERITREA');
  Items.Add('ESTONIA');
  Items.Add('ETHIOPIA');
  Items.Add('FALKLAND ISLANDS');
  Items.Add('FAROE ISLANDS');
  Items.Add('FIJI');
  Items.Add('FINLAND');
  Items.Add('FRANCE');
  Items.Add('FRENCH GUIANA');
  Items.Add('FRENCH POLYNESIA');
  Items.Add('GABON');
  Items.Add('GAMBIA');
  Items.Add('GEORGIA');
  Items.Add('GERMANY');
  Items.Add('GHANA');
  Items.Add('GIBRALTAR');
  Items.Add('GREECE');
  Items.Add('GREENLAND');
  Items.Add('GRENADA');
  Items.Add('GUADELOUPE');
  Items.Add('GUATEMALA');
  Items.Add('GUINEA');
  Items.Add('GUINEA-BISSAU');
  Items.Add('GUYANA');
  Items.Add('HAITI');
  Items.Add('HONDURAS');
  Items.Add('HONG KONG');
  Items.Add('HUNGARY');
  Items.Add('ICELAND');
  Items.Add('INDIA');
  Items.Add('INDONESIA');
  Items.Add('IRAN');
  Items.Add('IRAQ');
  Items.Add('IRELAND');
  Items.Add('ISRAEL');
  Items.Add('ITALY');
  Items.Add('IVORY COAST');
  Items.Add('JAMAICA');
  Items.Add('JAPAN');
  Items.Add('JORDAN');
  Items.Add('KAZAKHSTAN');
  Items.Add('KENYA');
  Items.Add('KIRGISTAN');
  Items.Add('KIRIBATI');
  Items.Add('KUWAIT');
  Items.Add('LAO PEOPLES DEMOCRATIC REPUBLIC');
  Items.Add('LATVIA');
  Items.Add('LEBANON');
  Items.Add('LESOTHO');
  Items.Add('LIBERIA');
  Items.Add('LIBYAN ARAB JAMAHIRYA');
  Items.Add('LIECHTENSTEIN');
  Items.Add('LITHUANIA');
  Items.Add('LUXEMBOURG');
  Items.Add('MACAU');
  Items.Add('MACEDONIA');
  Items.Add('MADAGASCAR');
  Items.Add('MALAWI');
  Items.Add('MALAYSIA');
  Items.Add('MALDIVES');
  Items.Add('MALI');
  Items.Add('MALTA');
  Items.Add('MARSHALL ISLANDS');
  Items.Add('MARTINIQUE');
  Items.Add('MAURITANIA');
  Items.Add('MAURITIUS');
  Items.Add('MAYOTTE');
  Items.Add('MEXICO');
  Items.Add('MICRONESIA');
  Items.Add('MOLDOVA');
  Items.Add('MONGOLIA');
  Items.Add('MONTSERRAT');
  Items.Add('MOROCCO');
  Items.Add('MOZAMBIQUE');
  Items.Add('MYANMAR');
  Items.Add('MONACO');
  Items.Add('NAMIBIA');
  Items.Add('NAURU');
  Items.Add('NEPAL');
  Items.Add('NETHERLANDS');
  Items.Add('NETHERLANDS ANTILLES');
  Items.Add('NEW CALEDONIA');
  Items.Add('NEW ZEALAND');
  Items.Add('NEW ZEALAND'#39'S OCEANIA');
  Items.Add('NICARAGUA');
  Items.Add('NIGER');
  Items.Add('NIGERIA');
  Items.Add('NORTHERN KOREA');
  Items.Add('NORTHERN MARIANA ISLANDS');
  Items.Add('NORWAY');
  Items.Add('OCEANIA');
  Items.Add('OMAN');
  Items.Add('PAKISTAN');
  Items.Add('PALAU');
  Items.Add('PANAMA');
  Items.Add('PAPUA NEW GUINEA');
  Items.Add('PARAGUAY');
  Items.Add('PERU');
  Items.Add('PHILIPPINES');
  Items.Add('PITCAIRN');
  Items.Add('POLAND');
  Items.Add('PORTUGAL');
  Items.Add('QATAR');
  Items.Add('REUNION');
  Items.Add('ROMANIA');
  Items.Add('RUSSIA');
  Items.Add('RWANDA');
  Items.Add('SAN MARINO');
  Items.Add('SAO TOME AND PRINCIPE');
  Items.Add('SAUDI ARABIA');
  Items.Add('SENEGAL');
  Items.Add('SERBIA');
  Items.Add('SEYCHELLES');
  Items.Add('SIERRA LEONE');
  Items.Add('SINGAPORE');
  Items.Add('SLOVAKIA');
  Items.Add('SLOVENIA');
  Items.Add('SOLOMON ISLANDS');
  Items.Add('SOMALIA');
  Items.Add('SOUTH AFRICA');
  Items.Add('SOUTH KOREA');
  Items.Add('SPAIN');
  Items.Add('SRI LANKA');
  Items.Add('ST. HELENA');
  Items.Add('ST. KITTS');
  Items.Add('ST. LUCIA');
  Items.Add('ST. PIERRE AND MIQUELON');
  Items.Add('ST. VINCENT');
  Items.Add('SUDAN');
  Items.Add('SURINAME');
  Items.Add('SVALBARD');
  Items.Add('SWAZILAND');
  Items.Add('SWEDEN');
  Items.Add('SWITZERLAND');
  Items.Add('SYRIAN ARAB REPUBLIC');
  Items.Add('TAIWAN');
  Items.Add('TAJIKISTAN');
  Items.Add('TANZANIA');
  Items.Add('THAILAND');
  Items.Add('TOGO');
  Items.Add('TONGA');
  Items.Add('TRINIDAD AND TOBAGO');
  Items.Add('TUNISIA');
  Items.Add('TURKEY');
  Items.Add('TURKMENISTAN');
  Items.Add('TURKS AND CAICOS ISLANDS');
  Items.Add('TUVALU');
  Items.Add('UGANDA');
  Items.Add('UKRAINE');
  Items.Add('UNITED ARAB EMIRATES');
  Items.Add('UNITED KINGDOM');
  Items.Add('URUGUAY');
  Items.Add('USA');
  Items.Add('UZBEKISTAN');
  Items.Add('VANUATU');
  Items.Add('VATICAN CITY STATE');
  Items.Add('VENEZUELA');
  Items.Add('VIET NAM');
  Items.Add('VIRGIN ISLANDS (BRITISH)');
  Items.Add('VIRGIN ISLANDS (U.S.)');
  Items.Add('WALLIS AND FUTUNA ISLANDS');
  Items.Add('WEST SAMOA');
  Items.Add('YEMEN');
  Items.Add('YUGOSLAVIA');
  Items.Add('ZAIRE');
  Items.Add('ZAMBIA');
  Items.Add('ZIMBABWE');
end;

{$IFDEF TMSIW6}
procedure TTIWCountryComboBox.IWPaint;
{$ELSE}
procedure TTIWCountryComboBox.Paint;
{$ENDIF}
var
  R : TRect;
begin
  with Canvas do
  begin
    Rectangle(4,4,Width,20);
    r := Rect(Width - 18,4,Width,20);
    {$IFNDEF LINUX}
    DrawFrameControl(Handle,r, DFC_SCROLL,DFCS_SCROLLCOMBOBOX );
    {$ENDIF}
  end;
end;


constructor TTIWPersistentEdit.Create(AOwner: TComponent);
begin
  inherited;
  FPersist := true;
end;

{$IFDEF TMSIW72}
function TTIWPersistentEdit.get_HasTabOrder: boolean;
begin
  {$IFNDEF TMSIW72_NEW}
  Result := false;
  {$ELSE}
  Result := true;
  {$ENDIF}
end;
{$ENDIF}

{$IFDEF TMSIW72_NEW}
function TTIWPersistentEdit.get_ShouldRenderTabOrder: Boolean;
begin
  Result := false;
end;
{$ENDIF}

{$IFDEF TMSIW6}
function TTIWPersistentEdit.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWPersistentEdit.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  htmlres: string;
  iwlbl: TIWLabel;
  tabidx: string;

   function MakeScript(Name:string): string;
   begin
    if (Persist) then
    begin
     Result :=
        '<Script Language="JavaScript">'#13
        +'function getCookieValue(s,n) {'#13
        +' s=removeBlanks(s)'#13
        +' var pairs=s.split(";")'#13
        +' for(var i=0;i<pairs.length;++i) {'#13
        +' var pairSplit=pairs[i].split("=")'#13
        +'  su = pairSplit[0];'#13
        +'  if (su.charAt(0) == "|")'#13
        +'      su  = su.substring(1,su.length);'#13
        +'  if(su==n) {'#13
        +'  if(pairSplit.length>1) return (pairSplit[1])'#13
        +'  else return ""'#13
        +'   }'#13
        +'  }'#13
        +' return ""'#13
        +'}'#13
        +'function removeBlanks(s) {'#13
        +' var temp=""'#13
        +' for(var i=0;i<s.length;++i) {'#13
        +' var c=s.charAt(i)'#13
        +'  if(c!=" ") temp += c;'#13
        +'  else temp += "|";'#13
        +'  }'#13
        +' return temp'#13
        +'}'#13
        +'function insertBlanks(s) {'#13
        +' var temp=""'#13
        +' for(var i=0;i<s.length;++i) {'#13
        +' var c=s.charAt(i)'#13
        +'  if(c!="|") temp += c;'#13
        +'  else temp += " ";'#13
        +'  }'#13
        +' return temp'#13
        +'}'#13

        + 'function ' + Name + 'LoadPersistent()'#13
        + ' {'#13
        + '  s = document.cookie;'#13
        + '  s = getCookieValue(s,"'+HTMLName+'");'#13
        + '  s = insertBlanks(s);'#13
        + '  document.getElementById("'+HTMLName+'ID").value = s;'#13
        + '  FindElem('#39+HTMLName+#39').value = s;'#13
        + ' }'#13

        + 'function ' + Name + 'SavePersistent(AValue)'#13
        + ' {'#13
        + '  expirationDate ="Thursday, 01-Dec-11 12:00:00 GMT"'#13
        + '  s = "'+HTMLName+'="+AValue+";expires="+expirationDate;'#13
        + '  document.cookie = s;'#13
        + ' }'#13
        + #13
        + '</script>';
     end;
   end;

begin
  if (Persist) then
  begin
    {$IFDEF TMSIW6}
    TIWComponent40Context(AContext).AddToInitProc(HTMLName+'LoadPersistent();');
    {$ELSE}
    if Text = '' then
      TIWAppForm(Form).AddToInitProc(HTMLName+'LoadPersistent();');
    {$ENDIF}
  end;

  tabidx := '';
  {$IFDEF TMSIW72_NEW}
  if (TabOrder >= 0) then
    tabidx := ' tabindex="'+IntToStr(TabOrder+1)+'"';
  {$ENDIF}

  if Editable then
  begin
    htmlres := MakeScript(HTMLName)
     + '<input'+tabidx+' type=' + IIF(FPasswordPrompt, 'password', 'input') + ' name="' + HTMLName +'" id="'+ HTMLName+'ID'+'"'
     + IIF(MaxLength > 0, ' maxlength=' + IntToStr(MaxLength))
     {$IFDEF TMSIW6}
     + ' style="' + Font.FontToStringStyle(AContext.WebApplication.Browser) + '"'
     {$ELSE}
     + ' style="' + Font.FontToStringStyle(WebApplication.Browser) + '"'
     {$ENDIF}
     + ' size=' + IntToStr(Width div 7)
     + ' value="' + Text + '"'
     + IIF(ReadOnly, ' readonly', '')
     {$IFDEF TMSIW9}
     + IIF((Css <> EmptyStr),' class="' + Css + '"','')
     {$ENDIF}
     //+ IIF((FEditType <> etString) or (Assigned(OnSubmit)), ' onKeyPress="'+HTMLName+'KeyPress('+HTMLName+','+IntTostr(Integer(FEditType))+',event)";')
     //+ IIF(FAlignment <> taLeftJustify,MakeAlign(FAlignment))
     //+ IIF(FColor <> clWindow, ' style="background-color:'+HTMLClr(FColor)+'";')
     +  IIF(Persist,' onBlur="'+HTMLName+'SavePersistent(this.value);"','')
     + '>';

    if SupportsInput and Required then
    begin
      {$IFDEF TMSIW6}

        {$IFDEF TMSIW9}
        TIWComponent40Context(AContext).AddValidation('getSubmitForm().' + HTMLName + '.value.length==0'
         , Format(RSValidationRequeredField, [FriendlyName]));
        {$ELSE}
        TIWComponent40Context(AContext).AddValidation('GSubmitter.' + HTMLName + '.value.length==0'
         , Format(RSValidationRequeredField, [FriendlyName]));
        {$ENDIF}

      {$ELSE}
      TIWAppForm(Owner).AddValidation('GSubmitter.' + HTMLName + '.value.length==0'
       , Format(RSValidationRequeredField, [FriendlyName]));

      {$ENDIF}
    end;
  end
  else
  begin
    iwlbl := TIWLabel.Create(Owner);
    with iwlbl do
    try
      Caption := Self.Text;
      Font.Assign(Self.Font);
      {$IFDEF TMSIW6}
      htmlres := GetControlHTML(iwlbl,AContext);
      {$ELSE}
      htmlres := GetControlHTML(iwlbl);
      {$ENDIF}
    finally
      Free;
    end;
  end;

  Result := TIWHTMLTag.CreateTag('DIV');
  //if css class is defined remove it from the outer div.
  //the class should only be set on the input tag
  {$IFDEF TMSIW9}
  if Css <> EmptyStr then
    Result.AddStringParam('class', ' ');
  {$ENDIF}  
  
  Result.Contents.AddText(htmlres);
end;


{ TTIWClock }

{$IFDEF TMSIW9}
function TTIWClock.RenderAsync(
  AContext: TIWBaseHTMLComponentContext): TIWXMLTag;
begin
  Result := TIWXMLTag.CreateTag('control');
  try
    Result.AddStringParam('id', HTMLName);
    Result.AddStringParam('type', 'TTIWCLOCK');

    RenderAsyncCommonProperties( AContext, Result );

  except
    FreeAndNil(Result);
  end;
end;
{$ENDIF}

{$IFDEF TMSIW6}
function TTIWClock.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWClock.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  htmlres: string;
begin
  {$IFDEF TMSIW6}
  TIWComponent40Context(AContext).AddToInitProc('tick'+HTMLName+'();');
  {$ELSE}
  TIWAppForm(Form).AddToInitProc('tick'+HTMLName+'();');
  {$ENDIF}

  htmlres := '<script language="JavaScript1.2"> '#13
    +  'function tick'+HTMLName +'() {'#13
    +  'lbl = document.getElementById("clk'+HTMLName+'")'#13
    +  'var now = new Date()'#13
    +  'var ms = "" + now.getMinutes()'#13
    + ' if (ms.length == 1) ms = "0" + ms;'#13
    +  'var ss = "" + now.getSeconds()'#13
    + ' if (ss.length == 1) ss = "0" + ss;'#13

    +  'lbl.innerHTML = now.getHours() + ":" + ms + ":" + ss;'#13
    +  'setTimeout("tick' + HTMLName + '()",500);'#13
    +  '}'
    +  '</script>';

    {$IFDEF TMSIW6}
    if (BGColor <> clNone) then
    htmlres := htmlres
      +  '<DIV style="background-color:' + HTMLClr(BGColor) + '" id="clk' + HTMLName + '"></DIV>'
    else
    {$ENDIF}
      htmlres := htmlres
        +  '<DIV id="clk' + HTMLName + '"></DIV>';

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(htmlres);
end;

function TTIWClock.HTMLClr(Color: TIWColor): string;
begin
  Result := ColorToRGBString(Color);
end;

{$IFDEF TMSIW6}
procedure TTIWClock.IWPaint;
begin
  Canvas.TextOut(2,2,TimeToStr(Now));
end;
{$ELSE}
procedure TTIWClock.Paint;
begin
  FCanvas.TextOut(2,2,TimeToStr(Now));
end;
{$ENDIF}

{ TTIWRadioButton }

{$IFDEF TMSIW9}
function TTIWRadioButton.RenderAsync(
  AContext: TIWBaseHTMLComponentContext): TIWXMLTag;
begin
  Result := TIWXMLTag.CreateTag('control');
  try
    Result.AddStringParam('id', HTMLName);
    Result.AddStringParam('type', 'TTIWRADIOBUTTON');

    RenderAsyncCommonProperties( AContext, Result );

  except
    FreeAndNil(Result);
  end;
end;
{$ENDIF}

constructor TTIWRadioButton.Create(AOwner: TComponent);
begin
  inherited;
  {$IFDEF TMSIW6}

  {$ELSE}
  FSupportsInput := True;
  FSupportsSubmit := True;  
  {$ENDIF}

  Color := clWhite;
end;

{$IFDEF TMSIW6}
procedure TTIWRadioButton.IWPaint;
{$ELSE}
procedure TTIWRadioButton.Paint;
{$ENDIF}
begin

  with Canvas do
  begin
    Brush.Color := clWhite;
    Ellipse(3, 3, 14, 14);
    Canvas.Font.Assign(Font);

    Brush.Color := Self.Color;
    TextRect(Rect(20, 2, Width - 1, Height - 2), 20, 2, Caption);
    if FChecked then begin
      Pen.Color := clBlack;
      Brush.Color := clBlack;
      Ellipse(6, 6, 11, 11);
    end;
  end;

end;

{$IFDEF TMSIW6}
function TTIWRadioButton.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWRadioButton.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  htmlres: string;
  ControlScript: string;
  MasterName: string;
  TempRB: TTIWRadioButton;
  i: integer;
begin
  {$IFDEF TMSIW6}
  TIWComponent40Context(AContext).AddToInitProc('FindElem(''' + HTMLName + ''').value="";'+EOL);
  {$ELSE}
  TIWAppForm(Form).AddToInitProc('GSubmitter.elements[''' + HTMLName + '''].value="";'+EOL);
  {$ENDIF}

  ControlScript := 'function '+ HTMLName + 'RT(ctrl,master,compname) {'#13;

  for i := 1 to Owner.ComponentCount - 1 do
  begin
    if (Owner.Components[i - 1] is TTIWRadioButton) then
    begin
      TempRB := TTIWRadioButton(Owner.Components[i - 1]);
      ControlScript := ControlScript
        + 'el = FindElem("' + TempRB.HTMLName + '");'#13
        + 'if (el != null)'#13
        + '  el.value=compname;'#13
    end;
  end;

  ControlScript := ControlScript
//    + 'el = FindElem(master);'#13
//    + 'if (el != null) { if (el.value != "") '#13
//    + ' el = FindElem(el.value);'#13
//    + ' if (el != null) el.value = compname; }'#13
//    + 'FindElem(master).value=compname;'#13
//    + 'FindElem(compname).value=compname;'#13
    + IIF(Assigned(OnClick),'return SubmitClick('+#39+HTMLName+#39','+'ctrl.value,'+#39'false'#39');'+#13,'')
    + '}'#13;

  {$IFDEF TMSIW6}
  TIWPageContext40(AContext.PageContext).AddToJavaScriptOnce(ControlScript);
  {$ELSE}
  TIWAppForm(Form).JavaScript.Add(ControlScript);
  {$ENDIF}

  if Assigned(FMasterButton) then
    MasterName := FMasterButton.HTMLName
  else
    MasterName := HTMLName;

  htmlres := '<INPUT type="radio" '+IIF(FChecked,'checked','')+' '+IIF(Enabled,'','disabled')
    +' name="g'+MasterName+'" onclick="'+HTMLName+'RT(this,'''+MasterName+''','''+HTMLName+''')">'+Caption;
  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(htmlres);


  with Result.Contents.AddTag('INPUT') do
  begin
    AddStringParam('TYPE','hidden');
    AddStringParam('NAME',HTMLName);
    AddStringParam('ID',HTMLName+'_INPUT');
  end;

end;

procedure TTIWRadioButton.SetChecked(const Value: Boolean);
var
  i: integer;
  TempRB: TTIWRadioButton;
begin
  Invalidate;
  FChecked := Value;

  if not FChecked then
    Exit;

  for i := 0 to Owner.ComponentCount - 1 do
  begin
    if Owner.Components[i] is TTIWRadioButton then
    begin
      TempRB := TTIWRadioButton(Owner.Components[i]);
      if TempRB = Self then
        Continue;

      if Self = TempRB.MasterButton then
        TempRB.Checked := False;

      if (FMasterButton = TempRB) or ((FMasterButton = TempRB.MasterButton)
      and (TempRB.MasterButton <> nil)) then
        TempRB.Checked := False;
    end;
  end;
end;

procedure TTIWRadioButton.SetMasterButton(const Value: TTIWRadioButton);
begin
  FMasterButton := Value;
  SetChecked(FChecked);
end;

procedure TTIWRadioButton.SetValue(const AValue: string);
var
  i: Integer;
  TempRB: TTIWRadioButton;
begin
  inherited;

  if Self = MasterButton then
  begin
    if AValue <> '' then
    begin
      for i := 1 to Owner.ComponentCount - 1 do
      begin
        if (Owner.Components[i - 1] is TTIWRadioButton) then
        begin
          TempRB := TTIWRadioButton(Owner.Components[i - 1]);
          if TempRB.MasterButton = Self then
            TempRB.SetChecked(TempRB.HTMLName = AValue);
        end;
      end;
    end;
  end
  else
  begin
    if Assigned(MasterButton) then
    begin
      if AValue <> '' then
      begin
        MasterButton.SetChecked(MasterButton.HTMLName = AValue);
        SetChecked(self.HTMLName = AValue);
      end;
    end;
  end;
end;

procedure TTIWRadioButton.Submit(const AValue: string);
begin
  inherited;
  if Assigned(OnClick) then
    OnClick(Self);
end;

{ TTIWClientCode }

constructor TTIWClientCode.Create(AOwner: TComponent);
begin
  inherited;
  FCode := TStringList.Create;
  FIconName := 'JS';
end;

destructor TTIWClientCode.Destroy;
begin
  FCode.Free;
  inherited;
end;

{$IFDEF TMSIW6}
function TTIWClientCode.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWClientCode.RenderHTML: TIWHTMLTag;
{$ENDIF}
begin
  case CodeType of
  ctScript:Result := TIWHTMLTag.CreateTag('SCRIPT');
  ctCSS:
    begin
      Result := TIWHTMLTag.CreateTag('STYLE');
      Result.AddStringParam('TYPE','text/css');
    end;
  else
    Result := TIWHTMLTag.CreateTag('DIV');
  end;

  Result.Contents.AddText(FCode.Text);
end;

procedure TTIWClientCode.SetCode(const Value: TStringList);
begin
  FCode.Assign(Value);
end;


{ TTIWScrollBarColors }

constructor TTIWScrollBarColors.Create(AOwner: TComponent);
begin
  inherited;
  FIconName := 'CSS';
  FScrollbar3DLightColor := clNone;
  FScrollbarArrowColor := clNone;
  FScrollbarBaseColor := clNone;
  FScrollbarTrackColor := clNone;
  FScrollbarDarkshadowColor := clNone;
  FScrollbarFaceColor := clNone;
  FScrollbarHighlightColor := clNone;
  FScrollbarShadowColor := clNone;
end;

destructor TTIWScrollBarColors.Destroy;
begin
//FCode.Free;
  inherited;
end;

{$IFDEF TMSIW6}
function TTIWScrollBarColors.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWScrollBarColors.RenderHTML: TIWHTMLTag;
{$ENDIF}
begin
  Result := TIWHTMLTag.CreateTag('STYLE');
  Result.AddStringParam('TYPE','text/css');

  Result.Contents.AddText('BODY {');
  if ScrollBarBaseColor <> clNone then
    Result.Contents.AddText('scrollbar-base-color:'+ColorToRGBString(ScrollbarBaseColor)+ ';');
  if Scrollbar3DLightColor <> clNone then
    Result.Contents.AddText('scrollbar-3dlight-color:'+ColorToRGBString(Scrollbar3DLightColor)+ ';');
  if ScrollbarArrowColor <> clNone then
    Result.Contents.AddText('scrollbar-arrow-color:'+ColorToRGBString(ScrollbarArrowColor)+ ';');
  if ScrollbarTrackColor <> clNone then
    Result.Contents.AddText('scrollbar-track-color:'+ColorToRGBString(ScrollbarTrackColor)+ ';');
  if ScrollbarDarkshadowColor <> clNone then
    Result.Contents.AddText('scrollbar-darkshadow-color:'+ColorToRGBString(ScrollbarDarkshadowColor)+ ';');
  if ScrollbarFaceColor <> clNone then
    Result.Contents.AddText('scrollbar-face-color:'+ColorToRGBString(ScrollbarFaceColor)+ ';');
  if ScrollbarHighlightColor <> clNone then
    Result.Contents.AddText('scrollbar-highlight-color:'+ColorToRGBString(ScrollbarHighlightColor)+ ';');
  if ScrollbarShadowColor <> clNone then
    Result.Contents.AddText('scrollbar-shadow-color:'+ColorToRGBString(ScrollbarShadowColor)+ ';');

  Result.Contents.AddText('     }');
end;


{ TTIWNVControl }

{$IFDEF TMSIW6}
procedure TTIWNVControl.IWPaint;
{$ELSE}
procedure TTIWNVControl.Paint;
{$ENDIF}
begin
{$IFDEF TMSIW6}
  with Canvas do
{$ELSE}
  with FCanvas do
{$ENDIF}
  begin
    Brush.Color := clBtnFace;
    Pen.Color := clGray;
    Rectangle(0,0,Width - 1,Height - 1);

    Pen.Color := clWhite;
    MoveTo(0,Height);
    LineTo(0,0);
    LineTo(Width,0);

    TextOut(8,6,FIconName);
  end;
end;

procedure TTIWNVControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
  inherited;
  if AWidth > 29 then
    Width := 29;

  if AHeight > 29 then
    Height := 29;
end;

{ TTIWClientDebugOut }

constructor TTIWClientDebugOut.Create(AOwner: TComponent);
begin
  inherited;

end;

{$IFDEF TMSIW6}
procedure TTIWClientDebugOut.IWPaint;
{$ELSE}
procedure TTIWClientDebugOut.Paint;
{$ENDIF}
begin
{$IFDEF TMSIW6}
  with Canvas do
{$ELSE}
  with FCanvas do
{$ENDIF}
  begin
    Brush.Color := clBtnFace;
    Pen.Color := clBtnFace;
    Rectangle(0,0,Width - 1,Height - 1);
    TextOut(8,6,'DebugOut');
  end;
end;

{$IFDEF TMSIW6}
function TTIWClientDebugOut.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWClientDebugOut.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  code: string;
begin
  code := '<OBJECT ID="DebugOut" WIDTH='+IntToStr(Width)+' HEIGHT='+IntToStr(Height)
     + ' CLASSID="CLSID:BBEC0C0E-BB45-405B-94BA-D637F502BE0E">'
     + '<PARAM NAME="Value" VALUE="">'
     + '<PARAM NAME="DoubleBuffered" VALUE="0">'
     + '<PARAM NAME="Enabled" VALUE="-1">'
     + '<PARAM NAME="Visible" VALUE="-1">'
     + '</OBJECT>';

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(code);
end;

{ TTIWClientWatch }

constructor TTIWClientWatch.Create(AOwner: TComponent);
begin
  inherited;

end;

{$IFDEF TMSIW6}
procedure TTIWClientWatch.IWPaint;
{$ELSE}
procedure TTIWClientWatch.Paint;
{$ENDIF}
begin
{$IFDEF TMSIW6}
  with Canvas do
{$ELSE}
  with FCanvas do
{$ENDIF}
  begin
    Brush.Color := clBtnFace;
    Pen.Color := clBtnFace;
    Rectangle(0,0,Width - 1,Height - 1);
    TextOut(8,6,'ClientWatch');
  end;
end;

{$IFDEF TMSIW6}
function TTIWClientWatch.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWClientWatch.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  code: string;
  LJScript: TStringList;
begin
     LJScript := TStringList.Create;

    try
      with LJScript do begin
        Add(''#13
				+ 'var DebugWindowContents;'#13
				+ 'var DebugOn=true;'#13
				+ 'var DebugStarted=false;'#13
				+ 'var DebugWnd;'#13
				+ 'var DebugCnt = 0;'#13
        + ''#13
				+ 'function DebugShowResults()'#13
				+ '{'#13
   			+ '	if ((DebugOn!=true) || (DebugStarted==false)) { return; }'#13
        + ''#13
				+ 'var sOption="toolbar=no,location=no,directories=no,menubar=no,";'#13
				+ 'sOption+="scrollbars=yes,width=550,height=300,left=100,top=25";'#13
				+ 'var winprint=window.open("","tmsdbgwnd",sOption);'#13
        + ''#13
        + 'var s = winprint.document.title;'#13
        + ''#13
        + 'if (s.indexOf("Javascript") != 0)'#13
        + '{'#13
				+ 'winprint.document.open();'#13
        + ''#13
				+ 'winprint.document.write("<html><body topmargin=0 leftmargin=0>");'#13
				+ 'winprint.document.write(DebugWindowContents.join('' ''));'#13
				+ 'winprint.document.write("</body></html>");'#13
        + ''#13
				+ 'winprint.document.write("<script>");'#13
				+ 'winprint.document.write("function clearlist() {");'#13
        + ''#13
				+ '//winprint.document.write(" el = document.getElementById(''dbg'');");'#13
				+ '//winprint.document.write(" el.innerHTML = '''';");'#13
        + ''#13
        + 'winprint.document.write(" var num = document.body.childNodes.length;");'#13
        + 'winprint.document.write(" for(i = num-1; i>=3; i--) {");'#13
        + 'winprint.document.write(" document.body.removeChild(document.body.childNodes[i]);}");'#13
        + ''#13
				+ 'winprint.document.write("}");'#13
				+ 'winprint.document.write("<");'#13
				+ 'winprint.document.write("/script>");'#13
        + ''#13
        + 'winprint.document.write("<style>");'#13
				+ 'winprint.document.write("div {font-family:verdana;font-size:8pt}");'#13
        + 'winprint.document.write("</style>");'#13
        + ''#13
				+ 'winprint.document.write("<font face=''verdana'' size=''1''>");'#13
				+ 'winprint.document.write("<table width=''100%'' style=''font-family:verdana;font-size:10;background:lightgrey;''><tr><td><input type=''checkbox'' id=''dbgchk'' checked>Enable&nbsp;&nbsp;<input type=''button'' value=''Clear'' onclick=''clearlist()''></tr></table>");'#13
				+ 'winprint.document.write("<div id=''dbg''>");'#13
				+ 'winprint.document.title = "Javascript watch";'#13
        + '}'#13
				+ 'winprint.focus();'#13
				+ 'DebugWnd = winprint;'#13
				+ '}'#13
        + ''#13
				+ 'function DebugInit()'#13
				+ '{'#13
				+ '	DebugWindowContents=new Array();'#13
				+ '	DebugStarted=true;'#13
				+ '}'#13
        + ''#13
				+ 'function DebugWrite(sVal)'#13
				+ '{'#13
				+ '	if (DebugOn!=true) { return; }'#13
				+ '	if (DebugStarted==false) { DebugInit(); }'#13
				+ '	DebugWindowContents.push(sVal + ''<br>'');'#13
				+ '}'#13
        + ''#13
			  + '	function OutputDebugString(s)'#13
				+ '{'#13
				+ '	el = DebugWnd.document.getElementById(''dbgchk'');'#13
				+ '	if (!el.checked)'#13
				+ '		return;'#13
				+ '		var now = new Date();'#13
				+ '		var ms = '''' + now.getMinutes();'#13
				+ '		if (ms.length == 1) ms = ''0'' + ms;'#13
				+ '		var ss = '''' + now.getSeconds()'#13
				+ '		if (ss.length == 1) ss = ''0'' + ss;'#13
				+ '		DebugCnt++;'#13
        + '    p = DebugWnd.document.createElement(''div'');'#13
        + '    p.innerHTML =  DebugCnt + '': '' +now.getHours()+'':''+ms+'':''+ss+'' >''+s;'#13
        + '    DebugWnd.document.body.appendChild(p);'#13
				+ '}'#13#13
        + '');
      end;

    {$IFDEF TMSIW6}
    TIWComponent40Context(AContext).AddToJavaScriptOnce(LJScript.Text);
    {$ELSE}
    AddToJavaScriptOnce(LJScript.Text);
    {$ENDIF}

      finally
    FreeAndNil(LJSCript);
  end;

  code := '<script>'
				+ 'DebugInit();'
				+ 'DebugShowResults();'
				+ '</script>';

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(code);
end;

{ TTIWStateComboBox }

constructor TTIWStateComboBox.Create(AOwner: TComponent);
begin
  inherited;
  Items.Add('Alabama');
  Items.Add('Alaska');
  Items.Add('Arizona');
  Items.Add('Arkansas');
  Items.Add('California');
  Items.Add('Colorado');
  Items.Add('Connecticut');
  Items.Add('Delaware');
  Items.Add('Florida');
  Items.Add('Georgia');
  Items.Add('Hawaii');
  Items.Add('Idaho');
  Items.Add('Illinois');
  Items.Add('Indiana');
  Items.Add('Iowa');
  Items.Add('Kansas');
  Items.Add('Kentucky');
  Items.Add('Louisiana');
  Items.Add('Maine');
  Items.Add('Maryland');
  Items.Add('Massachusetts');
  Items.Add('Michigan');
  Items.Add('Minnesota');
  Items.Add('Mississippi');
  Items.Add('Missouri');
  Items.Add('Montana');
  Items.Add('Nebraska');
  Items.Add('Nevada');
  Items.Add('New Hampshire');
  Items.Add('New Jersey');
  Items.Add('New Mexico');
  Items.Add('New York');
  Items.Add('North Carolina');
  Items.Add('North Dakota');
  Items.Add('Ohio');
  Items.Add('Oklahoma');
  Items.Add('Oregon');
  Items.Add('Pennsylvania');
  Items.Add('Rhode Island');
  Items.Add('South Carolina');
  Items.Add('South Dakota');
  Items.Add('Tennessee');
  Items.Add('Texas');
  Items.Add('Utah');
  Items.Add('Vermont');
  Items.Add('Virginia');
  Items.Add('Washington');
  Items.Add('West Virginia');
  Items.Add('Wisconsin');
  Items.Add('Wyoming');
end;

{$IFDEF TMSIW6}
procedure TTIWStateComboBox.IWPaint;
{$ELSE}
procedure TTIWStateComboBox.Paint;
{$ENDIF}
var
  R : TRect;
begin
  with Canvas do
  begin
    Rectangle(4,4,Width,20);
    r := Rect(Width - 18,4,Width,20);
    {$IFNDEF LINUX}
    DrawFrameControl(Handle,r, DFC_SCROLL,DFCS_SCROLLCOMBOBOX );
    {$ENDIF}
  end;
end;


 { TTIWScrollBarPersistence }

constructor TTIWScrollBarPersistence.Create(AOwner: TComponent);
begin
  inherited;
  FIconName := 'JS';
  {$IFNDEF TMSIW6}
  FSupportsSubmit := true;
  FSupportsInput := True;
  {$ENDIF}
end;

{$IFDEF TMSIW6}
function TTIWScrollBarPersistence.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWScrollBarPersistence.RenderHTML: TIWHTMLTag;
{$ENDIF}
begin
  Result := TIWHTMLTag.CreateTag('SPAN');

  with Result.Contents.AddTag('INPUT') do
  begin
    AddStringParam('TYPE','hidden');
    AddStringParam('NAME',HTMLName);
    AddStringParam('ID',HTMLName+'_INPUT');
  end;

  Result.Contents.AddText(#13'<SCRIPT language="javascript">'#13);
  Result.Contents.AddText('function '+HTMLName+'startPolling(){'#13);
  Result.Contents.AddText('  document.body.scrollTop = '+IntToStr(FScrollTop)+';'#13);
  Result.Contents.AddText('  document.body.scrollLeft = '+IntToStr(FScrollLeft)+';'#13);
  Result.Contents.AddText('  setInterval("'+HTMLName+'ScrollPos()",500)'#13);
	Result.Contents.AddText(' }'#13);

  Result.Contents.AddText('function '+HTMLName+'ScrollPos(){'#13);
  Result.Contents.AddText('document.getElementById("'+ HTMLName + '_INPUT").value=document.body.scrollTop;'#13);
  Result.Contents.AddText('document.getElementById("'+ HTMLName + '_INPUT").value += "|" + document.body.scrollLeft;'#13);
	Result.Contents.AddText(' }'#13);
  Result.Contents.AddText(#13'</SCRIPT>'#13);

  {$IFDEF TMSIW6}
  TIWComponent40Context(AContext).AddToInitProc(''+HTMLName+'startPolling();'#13);
  {$ELSE}
  TIWAppForm(Form).AddToInitProc(''+HTMLName+'startPolling();'#13);
  {$ENDIF}
end;

procedure TTIWScrollBarPersistence.SetValue(const AValue: string);
var
  sp: Integer;
  ss, su: string;
begin
  inherited;

  su :=  AValue;

  sp := pos('|', su);
  if sp > 0 then
  begin
    ss := copy(su, 1, sp - 1);
    Delete(su, 1, sp);
  end
  else
    ss := su;

  if (ss = '') then
    Exit;

  try
    FScrollTop :=  StrToInt(ss);
  except
    FScrollTop := 0;
  end;

  sp := pos('|', su);
  if sp > 0 then
  begin
    ss := copy(su, sp + 1, sp - Length(su));
    Delete(su, 1, sp);
  end
  else
    ss := su;

  if (ss = '') then
    Exit;

  try
    FScrollLeft :=  StrToInt(ss);
  except
    FScrollLeft := 0;
  end;
end;


{ TTIWGradientLabel }
constructor TTIWGradientLabel.Create(AOwner: TComponent);
begin
  inherited;
  Height := 20;
  Color := clSilver;
  ColorTo := clWhite;
  Font.FontName := 'Verdana';
end;

destructor TTIWGradientLabel.Destroy;
begin
  inherited;
end;

function TTIWGradientLabel.HTMLClr(Color: TIWColor): string;
begin
  Result := ColorToRGBString(Color);
end;

procedure TTIWGradientLabel.SetColor(const Value: TIWColor);
begin
  FColor := Value;
  Invalidate;
end;

procedure TTIWGradientLabel.SetColorTo(const Value: TIWColor);
begin
  FColorTo := Value;
  Invalidate;
end;

procedure TTIWGradientLabel.SetDirection(const Value : TTIWGradientDirection);
begin
  FDirection := Value;
  Invalidate;
end;

procedure TTIWGradientLabel.SetAlignment(const Value : TAlignment);
begin
  FAlignment := Value;
end;

{$IFDEF TMSIW6}
function TTIWGradientLabel.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWGradientLabel.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  html,GradientType: string;

  function MakeAlign(AAlignment: TAlignment):string;
  begin
    Result := '';
    case AAlignment of
    taRightJustify: Result := ' style=text-align:right;';
    taCenter: Result := ' style=text-align:center;';
    end;
  end;

begin
  {$IFDEF TMSIW6}
  if (AContext.WebApplication.Browser = brIE) then
  {$ELSE}
  if (WebApplication.Browser = brIE) then
  {$ENDIF}
  begin
    if Direction = gdHorizontal then
      GradientType := '1'
    else
      GradientType := '0';

    html := '<table height="' + IntToStr(Height) + 'px" width="' + IntToStr(Width)
          + 'px" cellpadding="0" cellspacing="0"><tr><td style="'
          {$IFDEF TMSIW6}
          + Font.FontToStringStyle(AContext.WebApplication.Browser) + '"'
          {$ELSE}
          + Font.FontToStringStyle(WebApplication.Browser) + '"'
          {$ENDIF}
          + MakeAlign(Alignment) + ' STYLE="FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=' + GradientType
          + ', StartColorStr=' + HTMLClr(Color)+',EndColorStr='+HTMLClr(ColorTo)+')" ><div style="overflow:hidden;height:'
          + IntToStr(Height) + 'px;width:' + IntToStr(Width) + 'px">' + Text + '</div></td></tr></table>';
  end
  else
  begin
    html := '<table height="' + IntToStr(Height) + 'px" width="' + IntToStr(Width)
          + 'px" cellpadding="0" cellspacing="0"><tr><td style="'
          {$IFDEF TMSIW6}
          + Font.FontToStringStyle(AContext.WebApplication.Browser)
          {$ELSE}
          + Font.FontToStringStyle(WebApplication.Browser)
          {$ENDIF}
          + '; background-color:' + HTMLClr(Color) + '"'
          + MakeAlign(Alignment) + '><div style="overflow:hidden;height:'
          + IntToStr(Height) + 'px;width:' + IntToStr(Width) + 'px">' + Text + '</div></td></tr></table>';
  end;

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(html);
end;

{$IFDEF TMSIW6}
procedure TTIWGradientLabel.IWPaint;
{$ELSE}
procedure TTIWGradientLabel.Paint;
{$ENDIF}
var
  r : TRect;
begin
  Canvas.Font.Name := Font.FontName;
  Canvas.Font.Size := Font.Size;
  Canvas.Font.Color := Font.Color;
  Canvas.Font.Style := Font.Style;

  with Canvas do
  begin

    r.Left := 0;
    r.Top := 0;
    r.Right := Width;
    r.Bottom := Height;
    if Direction = gdVertical then
      DrawGradient(Canvas,FColor, FColorTo,80,r,False)
    else
      DrawGradient(Canvas,FColor, FColorTo,80,r,True);
    Brush.Style := bsClear;
    TextOut(Width div 2 - TextWidth(Text) div 2,Height div 2 - TextHeight(Text) div 2,Text);
  end;
end;

procedure TTIWGradientLabel.DrawGradient(Canvas: TCanvas; FromColor, ToColor: TIWColor; 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;


{ TTIWNoSpamEmailLabel }

procedure Split(const Delimiter: Char; Input: string; const Strings: TStrings);
begin
  Assert(Assigned(Strings));
  Strings.Clear;

  while pos(delimiter, input) > 0 do
  begin
    strings.Add(copy(input, 1, pos(delimiter, input) - 1));
    system.delete(input, 1, pos(delimiter, input));
  end;

  Strings.Add(input);
end;

constructor TTIWNoSpamEmailLabel.Create(AOwner: TComponent);
begin
  inherited;
  Height := 20;
  Color := clNone;
  Font.FontName := 'Verdana';
  Text := 'email';
  Email := 'name@domain.com';
  Subject := '';
end;

destructor TTIWNoSpamEmailLabel.Destroy;
begin
  inherited;
end;

function TTIWNoSpamEmailLabel.HTMLClr(Color: TIWColor): string;
begin
  Result := ColorToRGBString(Color);
end;

{$IFDEF TMSIW6}
function TTIWNoSpamEmailLabel.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
{$ELSE}
function TTIWNoSpamEmailLabel.RenderHTML: TIWHTMLTag;
{$ENDIF}
var
  html: string;
  nm, LJScript: TStringList;
  pos: integer;

  function MakeAlign(AAlignment: TAlignment):string;
  begin
    Result := '';
    case AAlignment of
    taRightJustify: Result := ' style=text-align:right;';
    taCenter: Result := ' style=text-align:center;';
    end;
  end;


begin
    nm := TStringList.Create;
    LJScript := TStringList.Create;

    try
      with LJScript do begin
        Add('function nse_create(name,domain,label,subject) {'#13
        + ' document.write("<a href=''");'#13
        + ' document.write("mail");'#13
	      + ' document.write("to:");'#13
	      + ' document.write(name);'#13
        + ' document.write("@");'#13
	      + ' document.write(domain);'#13
	      + ' if (subject != "") document.write("?subject=" + subject);'#13
	      + '  document.write("''>" + label + "</a>"); }'#13
        + '');
      end;

    {$IFDEF TMSIW6}
    TIWComponent40Context(AContext).AddToJavaScriptOnce(LJScript.Text);
    {$ELSE}
    AddToJavaScriptOnce(LJScript.Text);
    {$ENDIF}

      finally
    FreeAndNil(LJSCript);
  end;


    html := html
        + '<table height="' + IntToStr(Height) + 'px" width="' + IntToStr(Width)
        + 'px"><tr><td style="'
        {$IFDEF TMSIW6}
        + Font.FontToStringStyle(AContext.WebApplication.Browser) + '"'
        {$ELSE}
        + Font.FontToStringStyle(WebApplication.Browser) + '"'
        {$ENDIF}
        + MakeAlign(Alignment) + ' ><div style="overflow:hidden;height:'
//        + IntToStr(Height) + 'px;width:' + IntToStr(Width) + 'px">' + Text + '</div></td></tr></table>';
        + IntToStr(Height) + 'px;width:' + IntToStr(Width) + 'px">';


    pos := AnsiPos('@', Email);
    if pos <> 0 then
    begin
      Split('@', Email, nm);

       html := html
         + '<script>nse_create("'+nm[0]+'","'+nm[1]+'","'+Text+'","'+Subject+'");</script>';
    end
    else
       html := html + 'No valid email address';

    html := html
         + '</div></td></tr></table>';

  Result := TIWHTMLTag.CreateTag('DIV');
  Result.Contents.AddText(html);

  nm.Free;
end;

{$IFDEF TMSIW6}
procedure TTIWNoSpamEmailLabel.IWPaint;
{$ELSE}
procedure TTIWNoSpamEmailLabel.Paint;
{$ENDIF}
var
  r : TRect;
begin
  Canvas.Font.Name := Font.FontName;
  Canvas.Font.Size := Font.Size;
  Canvas.Font.Color := Font.Color;
  Canvas.Font.Style := Font.Style;

  with Canvas do
  begin

    r.Left := 0;
    r.Top := 0;
    r.Right := Width;
    r.Bottom := Height;

    Brush.Style := bsClear;
    TextOut(Width div 2 - TextWidth(Text) div 2,Height div 2 - TextHeight(Text) div 2,Text);
  end;
end;



procedure TTIWNoSpamEmailLabel.SetAlignment(const Value: TAlignment);
begin
  FAlignment := Value;
end;

procedure TTIWNoSpamEmailLabel.SetColor(const Value: TIWColor);
begin
 FColor := Value;
end;

end.

