Kelda.Info.RSFAFGrid = Ext.extend(Ext.grid.GridPanel,{
	initComponent : function() {
	
		this.defaultRenderer = function(val) {
			if(isNaN(val))
				return '-';
			return Kelda.Info.NumberFormat(val,'0.000,00/i');
		};
	
		this.rsfafcolumns=[{
			id: 'type',
			header:keldan_lang_text("type") ,
			dataIndex: 'fullName',
			hidden:false,
			sortable:true,
			width: 40
		},{
            id: 'kg', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
        	header: 'KG',
        	dataIndex: 'volume',
        	align:'right',
        	width: 30,
        	renderer:this.defaultRenderer,
        	hidden:false,
        	sortable:true
        },{
            id: 'krkg', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            header: "KR/KG",
            dataIndex: 'last',
            align:'right',
            renderer:this.defaultRenderer,
            width: 30,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        },{
            id: 'total', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            header: keldan_lang_text("total"),
            dataIndex: 'turnover',
            align:'right',
            renderer:function(val) {
        	return Kelda.Info.NumberFormat(val,'0.000/i');
        	},
            width: 40,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        },{
            id: 'rsfdate', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            header: keldan_lang_text("dateshort"),
            align:'right',
            dataIndex: 'lastUpdated',
            renderer:Ext.util.Format.dateRenderer('d/m/y'),
            width: 30,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        }];
		
		this.rsfafstore = new Ext.data.JsonStore({
				root: 'response',
	        	id:'rsfaf',
	            fields: [ {name:'fullName',type:'string'},{name:'lastUpdated',type:'date',dateFormat:'timestamp'},
	            	{name:'volume',type:'float'},{name:'last',type: 'float'},{name:'turnover',type:'float'},
	            	{name:'category',type:'string'}
	            ],
	            proxy: new Ext.data.HttpProxy({
	            	//url: window.location.protocol+"//"+window.location.hostname+"/"+basePath+"feedconnect/getFeed"
	            	url: window.location.protocol+"//"+window.location.hostname+"/"+basePath+"connector/getRSFAF"
	            }),
	            sortInfo:{field:'category',direction:'ASC'}
            
        });
		this.rsfafview = new Ext.grid.GridView( {
			forceFit : true,
			autoFill:true,
            enableRowBody:true,
            scrollOffset:1,
            showPreview:false,
            getRowClass : function(record, rowIndex, p, store){
				if ((parseInt(rowIndex) % 2) == 0)
					return 'odd-row';
			}
		});
		Ext.apply(this,{
			id:'rsfgrid_'+Math.random()*103,
    		store : this.rsfafstore,
    	    columns:this.rsfafcolumns,
    	    view:this.rsfafview
    	});
		
    	
    	var s = this.rsfafstore;
    	var t = this.rsfafType;
    	this.rsfaftask = {
	        	run:function() {
    				//s.load({params:{feedName:'rsfaf',type:t}});
    				s.load({params:{type:t}});
				},
				interval: 3600000
		};
		this.rsfafstore.on('load',function(){
			if(Ext.Msg.isVisible()) {
				keldan_store_count--;
				Ext.Msg.updateProgress((keldan_fixed_stcount-keldan_store_count)/keldan_fixed_stcount
						,keldan_fixed_stcount-keldan_store_count+(keldan_lang=='is' ? ' af ' : ' of ')+keldan_fixed_stcount);
				if(keldan_store_count==0) {
					Ext.Msg.hide();
					keldan_store_count=-1;
				}
			}
		});
    	
    	this.on('render',function(comp) {
    		Ext.TaskMgr.start(this.rsfaftask);
    	});
    	this.on('destroy',function(){
    		Ext.TaskMgr.stop(this.rsfaftask);
    	});
    	Kelda.Info.RSFAFGrid.superclass.initComponent.apply(this,arguments);
	},
	 stopPoll : function() {
		Ext.TaskMgr.stop(this.rsfaftask);
	},
	startPoll : function() {
		Ext.TaskMgr.start(this.rsfaftask);
	}
});

Kelda.Info.FSGrid = Ext.extend(Ext.grid.GridPanel,{
	initComponent : function() {
	
		this.defaultRenderer = function(val) {
			if(isNaN(val))
				return '-';
			return Kelda.Info.NumberFormat(val,'0.000,00/i');
		};
	
		this.fscolumns=[{
			id: 'fullname',
			header:keldan_lang_text("type") ,
			dataIndex: 'fullName',
			hidden:false,
			sortable:true,
			width: 40
		},{
            id: 'fs_last', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
        	header: keldan_lang_text('midprice')+' kr.',
        	tooltip:keldan_lang_text('midprice_q'),
        	dataIndex: 'last',
        	align:'right',
        	width: 30,
        	renderer:function(val) {
				if(isNaN(val))
					return '-';
				return Kelda.Info.NumberFormat(val,'0.000,00/i');
			},
         	hidden:false,
        	sortable:true
        },{
            id: 'fs_bid', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            header: keldan_lang_text('minprice')+' kr.',
            tooltip:keldan_lang_text('minprice_q'),
            dataIndex: 'bid',
            align:'right',
            renderer:function(val) {
				if(isNaN(val))
					return '-';
				return Kelda.Info.NumberFormat(val,'0.000,00/i');
			},
            width: 30,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        },{
            id: 'fs_ask', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            dataIndex: 'ask',
            header:keldan_lang_text('maxprice')+' kr.',
            tooltip:keldan_lang_text('maxprice_q'),
            align:'right',
            renderer:function(val) {
				if(isNaN(val))
					return '-';
				return Kelda.Info.NumberFormat(val,'0.000,00/i');
			},
            width: 40,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        },{
            id: 'fs_turnover', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            dataIndex: 'turnover',
            header:keldan_lang_text('totalvalue'),
            tooltip:keldan_lang_text('totalvalue_q'),
            align:'right',
            renderer:function(val) {
        		return Kelda.Info.NumberFormat(val,'0.000/i');
        	},
            width: 30,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        },{
            id: 'fs_volume', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            header:keldan_lang_text('totalkg')+' kg.',
            tooltip:keldan_lang_text('totalkg_q'),
            dataIndex: 'volume',
            align:'right',
            renderer:function(val) {
        		return Kelda.Info.NumberFormat(val,'0.000/i');
        	},
            width: 30,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        },{
            id: 'fs_count', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            header: keldan_lang_text('totaltrades'),
            tooltip:keldan_lang_text('totaltrades_q'),
            dataIndex: 'daycount',
            align:'right',
            renderer:function(val) {
        		return Kelda.Info.NumberFormat(val,'0.000/i');
        	},
            width: 30,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        },{
            id: 'rsfdate', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
            header: keldan_lang_text("dateshort"),
            align:'right',
            dataIndex: 'lastUpdated',
            renderer:Ext.util.Format.dateRenderer('d/m/y'),
            width: 30,
            hidden:false,
            //renderer: this.renderTopic,
            sortable: true
        }];
		
		this.fstore = new Ext.data.JsonStore({
				root: 'response',
	        	id:'fs',
	            fields: [ {name:'fullName',type:'string'},{name:'lastUpdated',type:'date',dateFormat:'timestamp'},
	            	{name:'volume',type:'float'},{name:'last',type: 'float'},{name:'turnover',type:'float'},
	            	{name:'ask',type: 'float'},{name:'bid',type: 'float'},{name:'daycount',type:'int'}
	            	
	            ],
	            proxy: new Ext.data.HttpProxy({
	            	//url: window.location.protocol+"//"+window.location.hostname+"/"+basePath+"feedconnect/getFeed"
	            	url: window.location.protocol+"//"+window.location.hostname+"/"+basePath+"connector/getFS"
	            })
	            //sortInfo:{field:'category',direction:'ASC'}
            
        });
		this.fsview = new Ext.grid.GridView( {
			forceFit : true,
			autoFill:true,
            enableRowBody:true,
            scrollOffset:1,
            showPreview:false,
            getRowClass : function(record, rowIndex, p, store){
				if ((parseInt(rowIndex) % 2) == 0)
					return 'odd-row';
			}
		});
		Ext.apply(this,{
			id:'fsgrid_'+Math.random()*103,
    		store : this.fstore,
    	    columns:this.fscolumns,
    	    view:this.fsview
    	});
		
    	
    	var s = this.fstore;
    	
    	this.fstask = {
	        	run:function() {
    				//s.load({params:{feedName:'rsfaf',type:t}});
    				s.load();
				},
				interval: 3600000
		};
		this.fstore.on('load',function(){
			if(Ext.Msg.isVisible()) {
				keldan_store_count--;
				Ext.Msg.updateProgress((keldan_fixed_stcount-keldan_store_count)/keldan_fixed_stcount
						,keldan_fixed_stcount-keldan_store_count+(keldan_lang=='is' ? ' af ' : ' of ')+keldan_fixed_stcount);
				if(keldan_store_count==0) {
					Ext.Msg.hide();
					keldan_store_count=-1;
				}
			}
		});
    	
    	this.on('render',function(comp) {
    		Ext.TaskMgr.start(this.fstask);
    	});
    	this.on('destroy',function(){
    		Ext.TaskMgr.stop(this.fstask);
    	});
    	Kelda.Info.FSGrid.superclass.initComponent.apply(this,arguments);
	},
	 stopPoll : function() {
		Ext.TaskMgr.stop(this.rsfaftask);
	},
	startPoll : function() {
		Ext.TaskMgr.start(this.rsfaftask);
	}
});

Ext.reg('FSPortlet_Child',Kelda.Info.FSGrid);

Ext.reg('RSFAFPortlet_Child',Kelda.Info.RSFAFGrid);
Kelda.Info.RSFAFPortlet = Ext.extend(Ext.Panel,{
	title: '',
	layout:'fit',
	plugins: [Ext.ux.PortletPlugin],
    closeable: true,
    maximizable:false,
    settings: false,
    resizeable:true,
    collapsible:true,
    version:1.0001,
    nohelp:true,
    width:400,
    height:290
    
});
Ext.reg('RSFAFPortlet',Kelda.Info.RSFAFPortlet);
