function PopulateConfigWindow() {
    FeedWindow.CreateWindow();
}

Ext.onReady(function(){
    var feedstore = new Ext.data.JsonStore({
            id: "feedstore",
            root: 'items',
            totalProperty: 'totalcount',
            idProperty: 'url',
            remoteSort: true,
            baseParams: {
            filter: "",
            customerid: "0"
        },
        fields: [
                'url','text'
        ],
        // load using script tags for cross domain, if the data in on the same domain as
        // this page, an HttpProxy would be better
        proxy: new Ext.data.HttpProxy({
                url: 'index.php?fuse=home&action=DoDashboardPluginAction&plugin=rssreader&pluginAction=getFeeds'
        })
    });
    var feedUrl = new Ext.form.ComboBox({
        id: 'feed-url',
        fieldLabel: 'Enter the URL of the feed to show',
        emptyText: 'http://example.com/blog/feed',
        width: 400,
        validationEvent: false,
        validateOnBlur: false,
        msgTarget: 'under',
        triggerAction: 'all',
        displayField: 'url',
        mode: 'local',
        tpl: new Ext.XTemplate(
                '<tpl for="."><div class="x-combo-list-item" qtip="{url}">',
                '<strong>{text}</strong>',
                '<div class="x-clear"></div>',
                '</div></tpl>'),
        store: feedstore
    });
    feedstore.load();

    var pluginconfigwindow = new Ext.FormPanel({
        labelAlign:'top',
        border: false,
        height: 90,
        items:[
                {
                    border: false,
                    layout:'column',
                    style:'padding-top:10px;',
                    items:[
                        {
                            border: false,
                            columnWidth:.90,
                            layout: 'form',
                            items: [feedUrl]
                        },
                        {
                            border: false,
                            columnWidth:.10,
                            layout: 'form',
                            items: [{
                                style:'padding-left:6px;',
                                border: false,
                                xtype:'numberfield',
                                hideLabel : false,
                                fieldLabel: lang('Items'),
                                name: 'rssitems',
                                value: '2',
                                emptyText: '2',
                                maxLength: 1,
                                id:'rssitems',
                                width:25
                            }]
                        }
                    ]
                }
        ],
        bodyStyle:'background:transparent;padding-top:10px;padding-left:10px;'
    });

    function FeedWindowConfig(update){
        if(this instanceof FeedWindowConfig){
            this.update = update;
            this.CreateWindow = createWindow;
            this.LoadFields = loadFields;
        }else{
            return new FeedWindowConfig();
        }
    }
    FeedWindow = new FeedWindowConfig();

    function loadFields(){

    }

    function createWindow(){

        win = new Ext.Window({
            title:"RSS Viewer",
            width:480,
            shadow:false,
            autoHeight:true,
            modal:true,
            closeAction:'destroy',
            plain: true,
            items: [pluginconfigwindow],
            buttons: [
                {
                    text: 'Update',
                    handler: function(){
                        additionalPostBody = "";
                        if(feedUrl.selectedIndex==-1){
                            additionalPostBody = "&newfeed=1";
                            rssItemsURL = feedUrl.getValue();
                            rssItemsName = "Rss Feed";
                        }else{
                            rssItemsURL = feedUrl.getStore().data.items[feedUrl.selectedIndex].data.url;
                            rssItemsName = feedUrl.getStore().data.items[feedUrl.selectedIndex].data.text;
                        }
                        rssItemsCount = Ext.get('rssitems').getValue();

                        Ext.Ajax.request({
                            url: 'index.php?fuse=home&action=DoDashboardPluginAction',
                            params: { plugin: "rssreader", pluginAction : "editRssURL", count:rssItemsCount, url: rssItemsURL, name: rssItemsName+additionalPostBody},
                            success: RSSUpdated
                        });

                        win.destroy();
                    }
                },
                    {
                    text: 'Close',
                    handler: function(){
                        win.destroy();
                    }
                }]
        });
        pluginconfigwindow.getForm().reset();
        win.show(this);
    }

    function RSSUpdated(t){
         document.getElementById('rssfeed').innerHTML = "";
         rssstore.setBaseParam('feed',rssItemsURL);
         rssstore.load();
    }



});
