(function()
{
 var Global=this,Runtime=this.IntelliFactory.Runtime,WebSharper,Formlet,TinyMce,AdvancedHtmlEditorConfiguration,HtmlEditorConfiguration,Controls,Control,_FSharpEvent_1,Formlet1,Base,_Result_1,Math,Utils,tinyMCE,Seq,Html,Default,List,Operators,Formlet2,SimpleHtmlEditorConfiguration;
 Runtime.Define(Global,{
  IntelliFactory:{
   WebSharper:{
    Formlet:{
     TinyMce:{
      AdvancedHtmlEditorConfiguration:Runtime.Class({},{
       get_Default:function()
       {
        return Runtime.New(AdvancedHtmlEditorConfiguration,{
         Width:{
          $:0
         },
         Height:{
          $:0
         },
         Plugins:{
          $:0
         },
         ToolbarLocation:{
          $:0
         },
         ToolbarAlign:{
          $:0
         },
         StatusbarLocation:{
          $:0
         },
         Buttons:{
          $:0
         }
        });
       }
      }),
      Controls:{
       AdvancedHtmlEditor:function(conf)
       {
        var x,inputRecord,f;
        x=(inputRecord=HtmlEditorConfiguration.get_Default(),Runtime.New(HtmlEditorConfiguration,{
         Theme:{
          $:1
         },
         Width:conf.Width,
         Height:conf.Height,
         Plugins:conf.Plugins,
         AdvancedToolbarLocation:conf.ToolbarLocation,
         AdvancedToolbarAlign:conf.ToolbarAlign,
         AdvancedStatusbarLocation:conf.StatusbarLocation,
         AdvancedButtons:conf.Buttons
        }));
        f=function(conf1)
        {
         return function(defContent)
         {
          return Controls.HtmlEditor(conf1,defContent);
         };
        };
        return f(x);
       },
       HtmlEditor:function(conf,defContent)
       {
        var f;
        f=function()
        {
         var state,oldValue,trigger,tId,tConf,tConf1,returnVal,matchValue1,h,matchValue2,w,matchValue3,s,matchValue4,ta,matchValue5,l,matchValue6,l1,matchValue7,bs,f2,action,body,x3,_this,f5,f6,reset;
         state=_FSharpEvent_1.New();
         oldValue={
          contents:{
           $:0
          }
         };
         trigger=function(v)
         {
          var t,matchValue,ov;
          t=function()
          {
           var x,f1;
           oldValue.contents={
            $:1,
            $0:v
           };
           x=Runtime.New(_Result_1,{
            $:0,
            $0:v
           });
           f1=function(arg00)
           {
            return state.event.Trigger(arg00);
           };
           return f1(x);
          };
          matchValue=oldValue.contents;
          if(matchValue.$==0)
           {
            return t(null);
           }
          else
           {
            ov=matchValue.$0;
            if(v!==ov)
             {
              return t(null);
             }
            else
             {
              return null;
             }
           }
         };
         tId="id"+Math.round(Math.random()*100000000);
         tConf=(tConf1=(returnVal=[{}],(null,returnVal[0].theme=Utils.ShowTheme(conf.Theme),returnVal[0].mode="exact",returnVal[0].elements=tId,returnVal[0].onchange_callback=function(tMce)
         {
          return trigger(tMce.getContent());
         },returnVal[0].oninit=function()
         {
          var e,x,f1;
          e=tinyMCE.get(tId);
          x=e.onKeyUp.add(function(e1)
          {
           var x1;
           x1=e1.getContent();
           return trigger(x1);
          });
          f1=function(value)
          {
           value;
          };
          return f1(x);
         },returnVal[0])),(matchValue1=conf.Height,matchValue1.$==0?null:(h=matchValue1.$0,tConf1.height=Global.String(h)+"px"),(matchValue2=conf.Width,matchValue2.$==0?null:(w=matchValue2.$0,tConf1.width=Global.String(w)+"px"),(matchValue3=conf.Plugins,matchValue3.$==0?null:(s=matchValue3.$0,tConf1.plugins=s),(matchValue4=conf.AdvancedToolbarAlign,matchValue4.$==0?null:(ta=matchValue4.$0,tConf1.theme_advanced_toolbar_align=ta),(matchValue5=conf.AdvancedStatusbarLocation,matchValue5.$==0?null:(l=matchValue5.$0,tConf1.theme_advanced_statusbar_location=l),(matchValue6=conf.AdvancedToolbarLocation,matchValue6.$==0?null:(l1=matchValue6.$0,tConf1.theme_advanced_toolbar_location=l1),(matchValue7=conf.AdvancedButtons,matchValue7.$==0?null:(bs=matchValue7.$0,(f2=(action=function(ix)
         {
          return function(row)
          {
           var prop,value,x,x1,f1,f3,reduction,f4;
           prop="theme_advanced_buttons"+(value=ix+1,Global.String(value));
           if(row.$==0)
            {
             tConf1[prop]="";
            }
           else
            {
             x=(x1=(f1=function(source)
             {
              return Seq.map(function(btype)
              {
               return Utils.ShowButtonType(btype);
              },source);
             },f1(row)),(f3=(reduction=function(x2)
             {
              return function(y)
              {
               return x2+","+y;
              };
             },function(source)
             {
              return Seq.reduce(reduction,source);
             }),f3(x1)));
             f4=function(x2)
             {
              tConf1[prop]=x2;
             };
             return f4(x);
            }
          };
         },function(list)
         {
          return Seq.iteri(action,list);
         }),f2(bs))),tConf1))))))));
         body=(x3=Default.TextArea(List.ofArray([(_this=Default.Attr(),_this.NewAttr("id",tId)),Default.Text(defContent)])),(f5=(f6=function()
         {
          tinyMCE.init(tConf);
          return trigger(defContent);
         },function(w1)
         {
          return Operators.OnAfterRender(f6,w1);
         }),(f5(x3),x3)));
         reset=function()
         {
          var tinyMce,x,f1;
          tinyMce=tinyMCE.get(tId);
          x=tinyMce.setContent(defContent);
          f1=function(value)
          {
           value;
          };
          f1(x);
          return trigger(defContent);
         };
         return[body,reset,state.event];
        };
        return Formlet2.BuildFormlet(f);
       },
       SimpleHtmlEditor:function(conf)
       {
        var x,inputRecord,f;
        x=(inputRecord=HtmlEditorConfiguration.get_Default(),Runtime.New(HtmlEditorConfiguration,{
         Theme:{
          $:0
         },
         Width:conf.Width,
         Height:conf.Height,
         Plugins:inputRecord.Plugins,
         AdvancedToolbarLocation:inputRecord.AdvancedToolbarLocation,
         AdvancedToolbarAlign:inputRecord.AdvancedToolbarAlign,
         AdvancedStatusbarLocation:inputRecord.AdvancedStatusbarLocation,
         AdvancedButtons:inputRecord.AdvancedButtons
        }));
        f=function(conf1)
        {
         return function(defContent)
         {
          return Controls.HtmlEditor(conf1,defContent);
         };
        };
        return f(x);
       }
      },
      HtmlEditorConfiguration:Runtime.Class({},{
       get_Default:function()
       {
        return Runtime.New(HtmlEditorConfiguration,{
         Theme:{
          $:0
         },
         Width:{
          $:0
         },
         Height:{
          $:0
         },
         Plugins:{
          $:0
         },
         AdvancedToolbarLocation:{
          $:0
         },
         AdvancedToolbarAlign:{
          $:0
         },
         AdvancedStatusbarLocation:{
          $:0
         },
         AdvancedButtons:{
          $:0
         }
        });
       }
      }),
      SimpleHtmlEditorConfiguration:Runtime.Class({},{
       get_Default:function()
       {
        return Runtime.New(SimpleHtmlEditorConfiguration,{
         Width:{
          $:0
         },
         Height:{
          $:0
         }
        });
       }
      }),
      Utils:{
       ShowButtonType:function(btype)
       {
        var s;
        if(btype.$==1)
         {
          return"italic";
         }
        else
         {
          if(btype.$==2)
           {
            return"underline";
           }
          else
           {
            if(btype.$==3)
             {
              return"strikethrough";
             }
            else
             {
              if(btype.$==4)
               {
                return"justifyleft";
               }
              else
               {
                if(btype.$==5)
                 {
                  return"justifycenter";
                 }
                else
                 {
                  if(btype.$==6)
                   {
                    return"justifyright";
                   }
                  else
                   {
                    if(btype.$==7)
                     {
                      return"justifyfull";
                     }
                    else
                     {
                      if(btype.$==8)
                       {
                        return"bullist";
                       }
                      else
                       {
                        if(btype.$==9)
                         {
                          return"numlist";
                         }
                        else
                         {
                          if(btype.$==10)
                           {
                            return"outdent";
                           }
                          else
                           {
                            if(btype.$==11)
                             {
                              return"indent";
                             }
                            else
                             {
                              if(btype.$==12)
                               {
                                return"cut";
                               }
                              else
                               {
                                if(btype.$==13)
                                 {
                                  return"copy";
                                 }
                                else
                                 {
                                  if(btype.$==14)
                                   {
                                    return"paste";
                                   }
                                  else
                                   {
                                    if(btype.$==15)
                                     {
                                      return"undo";
                                     }
                                    else
                                     {
                                      if(btype.$==16)
                                       {
                                        return"redo";
                                       }
                                      else
                                       {
                                        if(btype.$==17)
                                         {
                                          return"link";
                                         }
                                        else
                                         {
                                          if(btype.$==18)
                                           {
                                            return"unlink";
                                           }
                                          else
                                           {
                                            if(btype.$==19)
                                             {
                                              return"image";
                                             }
                                            else
                                             {
                                              if(btype.$==20)
                                               {
                                                return"cleanup";
                                               }
                                              else
                                               {
                                                if(btype.$==21)
                                                 {
                                                  return"help";
                                                 }
                                                else
                                                 {
                                                  if(btype.$==22)
                                                   {
                                                    return"code";
                                                   }
                                                  else
                                                   {
                                                    if(btype.$==23)
                                                     {
                                                      return"hr";
                                                     }
                                                    else
                                                     {
                                                      if(btype.$==24)
                                                       {
                                                        return"removeformat";
                                                       }
                                                      else
                                                       {
                                                        if(btype.$==25)
                                                         {
                                                          return"formatselect";
                                                         }
                                                        else
                                                         {
                                                          if(btype.$==26)
                                                           {
                                                            return"fontselect";
                                                           }
                                                          else
                                                           {
                                                            if(btype.$==27)
                                                             {
                                                              return"fontselect";
                                                             }
                                                            else
                                                             {
                                                              if(btype.$==28)
                                                               {
                                                                return"styleselect";
                                                               }
                                                              else
                                                               {
                                                                if(btype.$==29)
                                                                 {
                                                                  return"sub";
                                                                 }
                                                                else
                                                                 {
                                                                  if(btype.$==30)
                                                                   {
                                                                    return"sup";
                                                                   }
                                                                  else
                                                                   {
                                                                    if(btype.$==31)
                                                                     {
                                                                      return"forecolor";
                                                                     }
                                                                    else
                                                                     {
                                                                      if(btype.$==32)
                                                                       {
                                                                        return"backcolor";
                                                                       }
                                                                      else
                                                                       {
                                                                        if(btype.$==33)
                                                                         {
                                                                          return"forecolorpicker";
                                                                         }
                                                                        else
                                                                         {
                                                                          if(btype.$==34)
                                                                           {
                                                                            return"backcolorpicker";
                                                                           }
                                                                          else
                                                                           {
                                                                            if(btype.$==35)
                                                                             {
                                                                              return"charmap";
                                                                             }
                                                                            else
                                                                             {
                                                                              if(btype.$==36)
                                                                               {
                                                                                return"visualaid";
                                                                               }
                                                                              else
                                                                               {
                                                                                if(btype.$==37)
                                                                                 {
                                                                                  return"anchor";
                                                                                 }
                                                                                else
                                                                                 {
                                                                                  if(btype.$==38)
                                                                                   {
                                                                                    return"newdocument";
                                                                                   }
                                                                                  else
                                                                                   {
                                                                                    if(btype.$==39)
                                                                                     {
                                                                                      return"blackquote";
                                                                                     }
                                                                                    else
                                                                                     {
                                                                                      if(btype.$==40)
                                                                                       {
                                                                                        return"separator";
                                                                                       }
                                                                                      else
                                                                                       {
                                                                                        if(btype.$==41)
                                                                                         {
                                                                                          s=btype.$0;
                                                                                          return s;
                                                                                         }
                                                                                        else
                                                                                         {
                                                                                          return"bold";
                                                                                         }
                                                                                       }
                                                                                     }
                                                                                   }
                                                                                 }
                                                                               }
                                                                             }
                                                                           }
                                                                         }
                                                                       }
                                                                     }
                                                                   }
                                                                 }
                                                               }
                                                             }
                                                           }
                                                         }
                                                       }
                                                     }
                                                   }
                                                 }
                                               }
                                             }
                                           }
                                         }
                                       }
                                     }
                                   }
                                 }
                               }
                             }
                           }
                         }
                       }
                     }
                   }
                 }
               }
             }
           }
         }
       },
       ShowTheme:function(theme)
       {
        var s;
        if(theme.$==1)
         {
          return"advanced";
         }
        else
         {
          if(theme.$==2)
           {
            s=theme.$0;
            return s;
           }
          else
           {
            return"simple";
           }
         }
       }
      }
     }
    }
   }
  }
 });
 Runtime.OnInit(function()
 {
  WebSharper=Runtime.Safe(Global.IntelliFactory.WebSharper);
  Formlet=Runtime.Safe(WebSharper.Formlet);
  TinyMce=Runtime.Safe(Formlet.TinyMce);
  AdvancedHtmlEditorConfiguration=Runtime.Safe(TinyMce.AdvancedHtmlEditorConfiguration);
  HtmlEditorConfiguration=Runtime.Safe(TinyMce.HtmlEditorConfiguration);
  Controls=Runtime.Safe(TinyMce.Controls);
  Control=Runtime.Safe(WebSharper.Control);
  _FSharpEvent_1=Runtime.Safe(Control["FSharpEvent`1"]);
  Formlet1=Runtime.Safe(Global.IntelliFactory.Formlet);
  Base=Runtime.Safe(Formlet1.Base);
  _Result_1=Runtime.Safe(Base["Result`1"]);
  Math=Runtime.Safe(Global.Math);
  Utils=Runtime.Safe(TinyMce.Utils);
  tinyMCE=Runtime.Safe(Global.tinyMCE);
  Seq=Runtime.Safe(WebSharper.Seq);
  Html=Runtime.Safe(WebSharper.Html);
  Default=Runtime.Safe(Html.Default);
  List=Runtime.Safe(WebSharper.List);
  Operators=Runtime.Safe(Html.Operators);
  Formlet2=Runtime.Safe(Formlet.Formlet);
  return SimpleHtmlEditorConfiguration=Runtime.Safe(TinyMce.SimpleHtmlEditorConfiguration);
 });
 Runtime.OnLoad(function()
 {
 });
}());

