<?php
include ("_dirinfo.php");
include (PATH_TO_ROOT."init.php");
//include (PATH_TO_ROOT."_support/class.UserSession.php");

$db->ChangeDatabase(DB_WARPIT_HELP);

$used_lang = '1';
?>


var helpWindowFormPanel_<?php echo $_POST['id']; ?> = new Ext.FormPanel({
        labelAlign: 'top',     
        bodyStyle:'padding:5px',
        title: '<?php echo $_POST['title'];?>',
        defaults: {width: 250},
        closable: true,
     //   layout:'form',
     autoHeight: true,
        border:false,
        listeners:{
            beforeshow:function()
            {
                helpWindowFormPanel_<?php echo $_POST['id']; ?>.getForm().load({
                  url: 'webhelp/_ajaxManipulators/helpDataManipulator.php ',
                  params: {
                      action : 'loadForm',
                      table: '<?php echo $_POST['table']; ?>',
                      id: '<?php echo $_POST['id']; ?>'
                  } 
                });
              
            }
        },
        margins:'3 0 3 3',
        cmargins:'3 3 3 3',
        items: [
                         
               {
                    xtype:'textfield', 
                    fieldLabel: 'Title',
                    anchor: '100%',
                    value: '<?php echo $_POST['title'];?>',
                    name: 'title'
                }/*, {
                    xtype:'textfield',
                    fieldLabel: 'Order',
                    value: '<?php echo $_POST['orderBy'];?>',
                    name: 'orderBy'
                }*/,
                
                 /*{
                    xtype:'htmleditor',
                    fieldLabel:'Text',
                    height:200,
                    anchor: '100%',
                    //labelStyle: 'width:50px',
                    value: '<?php echo str_replace('\'', '&#47;',str_replace('\n', '<br />', $help['text']));?>',
                    name: 'text'
                 }*/
                 
                 {
                    xtype:'htmleditor',
                    fieldLabel:'Text',
                    anchor: '100%',
                    /*plugins: [
                        new Ext.ux.form.HtmlEditor.Word()
                    ],*/
                    id: 'texthtmleditor_<?php echo $_POST['id']; ?>',
                    //height:500,
                    //labelStyle: 'width:50px',
                    name: 'text',
                 }, 
                 {
                    xtype: 'checkbox',
                    name: 'totd',
                    anchor: '100%',
                    checked: <?php echo ($_POST['totd'] == 1)?'true':'false'; ?>,
                    fieldLabel: 'Tip of the day',
                    value: <?php echo ($_POST['totd'] == 1)?'true':'false'; ?>  
                }             
         ],
         tbar: ['->',{
           text:'Insert image',
           icon: '_plugins/tinyMCE/jscripts/tiny_mce/plugins/imagemanager/pages/im/img/insertimage.gif',
           handler: function(){
               mcImageManager.browse({
                            'oninsert': function(rtn)
                            {
                               Ext.getCmp('texthtmleditor_<?php echo $_POST['id']; ?>').setValue(Ext.getCmp('texthtmleditor_<?php echo $_POST['id']; ?>').getValue() + 
                               '<img src=\"' + rtn.files[0].url + '\"></img>');
                            },
                            'relative_urls' : false
                        });
               
           } 
        }],
      buttons: [{
            text: 'Save',
             handler: function(){
                  helpWindowFormPanel_<?php echo $_POST['id']; ?>.getForm().submit({
                        url: 'webhelp/_ajaxManipulators/helpDataManipulator.php',
                        method : 'post',
                        params:{ id: '<?php echo $_POST['id']?>', action: '<?php echo $_POST['action']?>', table: '<?php echo $_POST['table']?>' },
                        success: function(f,a){
                            
                            Ext.getCmp('<?php echo $_POST['grid'];?>').getStore().reload();
                            //Store<?php echo $_POST['rndID'];?>.reload();
                            
                            //console.log('<?php echo $_POST["id"]; ?>');  
                            Ext.getCmp('HelpMenuAdmin').getLoader().load(Ext.getCmp('HelpMenuAdmin').getNodeById('<?php echo $_POST['wholeId']; ?>').parentNode, 
                            function()
                            { 
                                var path = Ext.getCmp('HelpMenuAdmin').getNodeById('<?php echo $_POST['wholeId']; ?>').getPath(); 
                                Ext.getCmp('HelpMenuAdmin').expandPath(path); 
                            });
                            //helpWindowFormPanel_<?php echo $_POST['id']; ?>.close();
                            Ext.getCmp('<?php echo $_POST['tabPanelId']; ?>').remove(helpWindowFormPanel_<?php echo $_POST['id']; ?>);
                            /*helpWindow.hide();
                            helpWindow.destroy();*/
                            
                        }
                       
                    });
                
            }
            
        }]
});

Ext.getCmp('<?php echo $_POST['tabPanelId']; ?>').add(helpWindowFormPanel_<?php echo $_POST['id']; ?>).show();