/*
 * Ext JS Library 2.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/* Make sure you run qstoarr.js */
/* Define the strView to be used by Ektron ID */
var strView = "govt_iib_ei";
if (qsParm['id'] == '5132') {
	strView = "govt_iib_ei";
} else if (qsParm['id'] == '5146') {
	strView = "subs_iib_ei";
} else if (qsParm['id'] == '5150') {
	strView = "corp_iib_ei";
} else if (qsParm['id'] == '5168') {
	strView = "debt_iib_ei";
}
 
Ext.onReady(function(){
	
	Ext.BLANK_IMAGE_URL = '/ext/resources/images/default/s.gif';
	Ext.util.CSS.createStyleSheet('.x-grid3-cell-inner {margin-right: 2px}', '.x-grid3-cell-inner');
	
	var eireader1 = new Ext.data.JsonReader({
            root: 'data',
            totalProperty: 'recordcount',
            idProperty: 'intid',
            fields: ['strcurrentvaluetext', 'strforecastvaluetext', 'strname', 'strpreviousvaluetext', 'intid']
        });
		
	function renderIndicator(value, p, record){
        return String.format('<a href="#" onClick="win=window.open(\'/Pages/Help.aspx?id={1}\', \'popup\', \'width=680, height=420, scrollbars=yes, resizable=yes\');win.focus();">{0}</a>', value, record.data.intid);
    }
	
	var homecolumns1 = new Ext.grid.ColumnModel([{
           id: 'name', 
           header: "Indicator",
           dataIndex: 'strname',
		   renderer: renderIndicator,
		   width: 165
        },{
           header: "Current Value",
           dataIndex: 'strcurrentvaluetext',
           align: 'right',
		   width: 100
        },{
           header: "Previous Value",
           dataIndex: 'strpreviousvaluetext',
           align: 'right',
		   width: 90
        },{
           header: "Forecast Value",
           dataIndex: 'strforecastvaluetext',
           align: 'right',
		   width: 128
        }]);
		
	homecolumns1.defaultSortable = false;
	
	var eiviewconfig = {forceFit:false, enableRowBody:true, showPreview: false};
	
	//BEGIN home_iib_ei
	var proxy1 = new Ext.data.ScriptTagProxy({
		url: 'http://data.investinginbondseurope.org/iibeu-site/actGetEIAsJSON.cfm',
		method: 'GET'
	});
	
	proxy1.on('beforeload', function(p, params) {
		params.strView = strView;
	});
	
	var store1 = new Ext.data.Store({
		proxy: proxy1,
        reader: eireader1
    });
	
	var grid1 = new Ext.grid.GridPanel({
		el: 'economic_indicators',
		autoWidth: true,
		autoHeight: true,
		store: store1,
		cm: homecolumns1,
		loadMask: true,
		viewConfig: eiviewconfig
	});
	
	// render it
	grid1.render();
	
	// trigger the data store load
	store1.load();
	//END home_iib_ei
	
	//BEGIN benchmark_rates
	var eireader6 = new Ext.data.JsonReader({
		root: 'data',
        totalProperty: 'recordcount',
        idProperty: 'intid',
		fields: ['strdateloc', 'strname', 'strvalue', 'intid']
	});
		
	var homecolumns6 = new Ext.grid.ColumnModel([{
           id: 'name', 
           header: "Rate",
           dataIndex: 'strname',
		   renderer: renderIndicator,
		   width: 165
        },{
           header: "Current Value",
           dataIndex: 'strvalue',
           align: 'right',
		   width: 128
        },{
           header: "Date",
           dataIndex: 'strdateloc',
           align: 'right',
		   width: 190
        }]);
		
	homecolumns6.defaultSortable = false;
		
    var store6 = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
            url: 'http://data.investinginbondseurope.org/iibeu-site/actGetBRAsJSON.cfm',
			method: 'GET'
        }),
        reader: eireader6
    });
    
    var grid6 = new Ext.grid.GridPanel({
        el: 'benchmark_rates',
        autoWidth: true,
		autoHeight: true,
        store: store6,
        cm: homecolumns6,
        loadMask: true,
        viewConfig: eiviewconfig
    });

    // render it
    grid6.render();

    // trigger the data store load
    store6.load();
	//END benchmark_rates
	
});
