/**
 * @class Ext.app.Portal
 * @extends Object
 * A sample portal layout application class.
 */
// TODO: Fill in the content panel -- no AccordionLayout at the moment
// TODO: Fix container drag/scroll support (waiting on Ext.lib.Anim)
// TODO: Fix Ext.Tool scope being set to the panel header
// TODO: Drag/drop does not cause a refresh of scroll overflow when needed
// TODO: Grid portlet throws errors on destroy (grid bug)
// TODO: Z-index issues during drag
//alert('test');
	//Ext.Loader.setConfig({enabled:true});
	Ext.Loader.setConfig({    enabled: true,
						 disableCaching: false,
    paths: {
        'Ext': 'ext/src'//,
        //'AppName': '/Assets/desktop/app'
    }
});
	

//Ext.get('loading').remove();
//Ext.get('loading-mask').fadeOut({remove:true});
setTimeout(function(){
Ext.get('loading').remove();
Ext.get('loading-mask').fadeOut({remove:true});
}, 450);	
	
//HEY
//Ext.Loader.setConfig({enabled:true});

Ext.Loader.disableCaching = false;
Ext.require('Ext.util.*');
Ext.require('Ext.form.*');
Ext.require('Ext.core.DomHelper');
Ext.require([
    'Ext.tree.*',
    'Ext.data.*',
    'Ext.window.MessageBox'
	
]);



			


Ext.define('BasicModel', {extend: 'Ext.data.Model', fields: ['rating_name', 'rating',
       'rating_name_precinct',
       'rating_precinct']});
var selmo =  Ext.create('Ext.selection.CheckboxModel',{
selModel : 'SINGLE',
singleSelect: true,
listenters:
{
	selectionchange: function () {},
	beforedeselect:function () {},
beforeselect:function () {},
deselect:function () {},
select:function () {}
},	
	checkOnly:true});
var selmo2 =
new Ext.selection.CheckboxModel({
  // override private method to allow toggling of selection on or off for multiple rows.
  handleMouseDown : function(g, rowIndex, e){
    var view = this.grid.getView();
    var isSelected = this.isSelected(rowIndex);
    if(isSelected) {
      this.deselectRow(rowIndex);
    } 
    else if(!isSelected || this.getCount() > 1) {
      this.selectRow(rowIndex, true);
      view.focusRow(rowIndex);
    }
  },
  singleSelect: true
});

//Ext.define('selmo', {extend: 'Ext.grid.CheckboxSelectionModel'});
Ext.define('FileModel', {extend: 'Ext.data.Model', fields: ['file']});
var dashdata =
   [
   ['INDEPENDENT','4404'], ['SWING','1163'], ['1-D','899'], ['2-D','424'], ['3-D','251'], ['4-D','198'], ['5-D','147'], ['6-D','84'], ['1-R','434'], ['2-R','179'], ['3-R','53'], ['4-R','28'], ['5-R','27'], ['6-R','25'], ['Else','0']
   ];
var filestore = Ext.create('Ext.data.ArrayStore', {
	//var filestore = Ext.create('Ext.data.JsonStore', {
    // store configs
    //,autoDestroy: true,
    //,storeId: 'dashstore'
    //reader: Array
 
    //,idIndex: 0
    //,data: dashdata
   model: FileModel
    ,autoLoad: true
     /*,fields: [
       'rating_name',
       {name: 'rating', type: 'string'},
       'rating_name_precinct',
       'rating_precinct'
       //{name: 'change', type: 'float'},
       //{name: 'pctChange', type: 'float'},
       //{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
    ]*/

	

/*    proxy: {
        type:'ajax',
        url :'load.php',
        reader:			{	type: 		'json', root: 'county_precinct' },
        extraParams:	{	action: 	'load_precincts', county:'2',EndDate: '' },
        listeners:		{	exception2: 	function () { alert("hey"); } }      
    },
 */  
    ,proxy: {
            reader:			{	type: 		'json', root: 'data' },
            type: 'ajax',
               model: FileModel,
            extraParams: {
            	'action': 'get_file_list'

            	},
            //actionMethods : 
//            url: 'check-nodes.json'
            //url: 'http://localhost/~beazley/voter/load.php?action=getopts2&county_code=2&precinct=1'
            //url: 'http://localhost/~beazley/voter/load.php'
            url: 'load.php'
        }
 
});
var dashstore = Ext.create('Ext.data.ArrayStore', {
    // store configs
    //,autoDestroy: true,
    //,storeId: 'dashstore'
    //reader: Array
 
    //,idIndex: 0
    //,data: dashdata
    model: BasicModel
    ,autoLoad: true
     /*,fields: [
       'rating_name',
       {name: 'rating', type: 'string'},
       'rating_name_precinct',
       'rating_precinct'
       //{name: 'change', type: 'float'},
       //{name: 'pctChange', type: 'float'},
       //{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
    ]*/

/*    proxy: {
        type:'ajax',
        url :'load.php',
        reader:			{	type: 		'json', root: 'county_precinct' },
        extraParams:	{	action: 	'load_precincts', county:'2',EndDate: '' },
        listeners:		{	exception2: 	function () { alert("hey"); } }      
    },
 */  
    ,proxy: {
            reader:			{	type: 		'json', root: 'data' },
            type: 'ajax',
            model: BasicModel,
            extraParams: {
            	'action': 'getdashboard',
            	'county_code':'002'

            	},
            //actionMethods : 
//            url: 'check-nodes.json'
            //url: 'http://localhost/~beazley/voter/load.php?action=getopts2&county_code=2&precinct=1'
            //url: 'http://localhost/~beazley/voter/load.php'
            url: 'load.php'
        }
 
});
 var tree_store2 = Ext.create('Ext.data.TreeStore', {
        proxy: {
            type: 'ajax',
            extraParams: {
            	'action': 'get_output_opts'
            	},
            //actionMethods : 
//            url: 'check-nodes.json'
            //url: 'http://localhost/~beazley/voter/load.php?action=getopts2&county_code=2&precinct=1'
            //url: 'http://localhost/~beazley/voter/load.php'
            url: 'load.php'
        },
        sortOnLoad : false
        /*,
        sorters: [{
            property: 'leaf',
            direction: 'ASC'
        }, {
            property: 'text',
            direction: 'ASC'
        }] */
    });
 var store = Ext.create('Ext.data.TreeStore', {
        proxy: {
            type: 'ajax',
            extraParams: {
            	'action': 'getopts2'
				//,
            	//'county_code':'002',
            	//'precinct':'1'
            	},
            //actionMethods : 
//            url: 'check-nodes.json'
            //url: 'http://localhost/~beazley/voter/load.php?action=getopts2&county_code=2&precinct=1'
            //url: 'http://localhost/~beazley/voter/load.php'
            url: 'load.php'
        },
        sortOnLoad : false
        /*,
        sorters: [{
            property: 'leaf',
            direction: 'ASC'
        }, {
            property: 'text',
            direction: 'ASC'
        }] */
    });
 
 
var tree3 = Ext.create('Ext.tree.Panel', {
        store: tree_store2,
        rootVisible: false,
        useArrows: true,

        //features: [groupingFeature],
        //features:Ext.create('Ext.grid.feature.Grouping',{
        //groupHeaderTpl: 'Cuisine: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'
    //}),
        //frame: true,
        //title: 'Check Tree',
        //renderTo: 'tree-div',
        width: 600,
        height: 650,
        dockedItems2: [{
            xtype: 'toolbar',
            items: [
            {
                text: 'Get',
                handler: function(){
                    var records = tree3.getView().getChecked(),
                        names = [];
                    
                    Ext.Array.each(records, function(rec){
                        names.push(rec.get('text'));
                    });
                    
                    Ext.MessageBox.show({
                        title: 'Selected Nodes Tree3',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    });
                }
            },
                {
                text: 'Select All',
                handler: function(){
                    var records = tree3.getView().getChecked(),
                        names = [];
                      tree3.getRootNode().cascadeBy(function(n) {
                      //if( node.data.checked ){}
					    //var ui = n.getUI();
					    n.attributes.checked = false;
    				//ui.toggleCheck(false);
					});
                    
                    /*
                    Ext.Array.each(records, function(rec){
                        names.push(rec.get('text'));
                    });
                    
                    Ext.MessageBox.show({
                        title: 'Selected Nodes',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    }); */
                    }
                }
				
            ]
            
        }]
    });


 var tree_precincts_store = Ext.create('Ext.data.TreeStore', {

    //root: {expanded: true, text: "", "data": []} // <- Inline root

        proxy: {
            type: 'ajax',
            extraParams: {'action': 'get_precincts_for_tree',
            	//params: { 'action': 'get_precincts_for_tree', 'county_code' :this.getRawValue() }
            	'county_code':'002'
				//,'precinct':'1'
            	},
            //actionMethods : 
//            url: 'check-nodes.json'
            //url: 'http://localhost/~beazley/voter/load.php?action=getopts2&county_code=2&precinct=1'
            //url: 'http://localhost/~beazley/voter/load.php'
            url: 'load.php'
        },
        sortOnLoad : false
        /*,
        sorters: [{
            property: 'leaf',
            direction: 'ASC'
        }, {
            property: 'text',
            direction: 'ASC'
        }] */
    });

var tree_precincts = Ext.create('Ext.tree.Panel', {
	scroll: false,
viewConfig: {
    autoScroll: true
},
        store: tree_precincts_store,
        rootVisible: false,
        useArrows: true,
title:'Campaign Selector',
autoHeight: true,
//scroll: 'both',
autoShow: true,
								autoScroll: true,
								border: false,
								iconCls: 'nav',
        //features: [groupingFeature],
        //features:Ext.create('Ext.grid.feature.Grouping',{
        //groupHeaderTpl: 'Cuisine: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'
    //}),
        //frame: true,
        //title: 'Check Tree',
        //renderTo: 'tree-div',
        width: 600,
        height: 650,
		listeners: {
			checkchange: function( node, checked, eOpts )			
			{
				//alert(node.checked = true);
				//alert(checked);
				node.cascadeBy(function(child){
				//alert(child.get('checked') = false)	;			
					 child.set('checked', checked);
					});
			   var records = tree2.getView().getChecked(),
                    names = [];
            
            Ext.Array.each(records, function(rec){
                names.push(rec.get('text'));
            });
	     var records2 = tree3.getView().getChecked(),
                        names2 = [], file_type = '',report_type = '';
			
                    
                    Ext.Array.each(records2, function(rec){
			if(rec.get("text") == 'PDF')
			file_type = '&file_type=pdf'
if(rec.get("text") == 'Consultant Summary')
report_type = '&report_type=summary'
                        names2.push(rec.get('text'));
                    });
					
			var records3 = tree_precincts.getView().getChecked(),
                        names3 = [];
                    
                    Ext.Array.each(records3, function(rec){
                        //names.push(rec.get('text'));
						names3.push(rec.get('id'));
                    });		
				dashstore.load({
					
       
 			params: {  'congo' :names3.join('+'), 'search':names.join('+')}, 			
 				proxy:{
 			 		extraParams:	{	 county:'10' }
 				}
 			});			
				
				
				
				/*
				if(node)
					{
					//var args=[isCheck];
					node.cascade(function(){
					c=args[0];
					this.ui.toggleCheck(c);
					this.attributes.checked=c;
					},null,args);
					}
				*/
				
			}
			
			
			},
        dockedItems: [{
            xtype: 'toolbar',
            items: [
            /*{
                text: 'Get',
                handler: function(){
                    var records = tree_precincts.getView().getChecked(),
                        names = [];
                    
                    Ext.Array.each(records, function(rec){
                        //names.push(rec.get('text'));
						names.push(rec.get('id'));
                    });
                    
                    Ext.MessageBox.show({
                        title: 'Selected Nodes Pre',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    });
                }
            },
                {
                text: 'Select All',
                handler: function(){
                    var records = tree2.getView().getChecked(),
                        names = [];
                      tree2.getRootNode().cascadeBy(function(n) {
                      //if( node.data.checked ){}
					    //var ui = n.getUI();
					    n.attributes.checked = false;
    				//ui.toggleCheck(false);
					});

                      
                   /* /*
                    Ext.Array.each(records, function(rec){
                        names.push(rec.get('text'));
                    });
                    
                    Ext.MessageBox.show({
                        title: 'Selected Nodes',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    }); */ /*
                    }
                }, */  {
						   text: 'Download',
						   //formBind: true, //only enabled once the form is valid
						  // disabled: true,
						   handler: function() {
							   var records = tree2.getView().getChecked(),
									   names = [];
							   
							   Ext.Array.each(records, function(rec){
								   names.push(rec.get('text'));
							   });
							var records2 = tree3.getView().getChecked(),
										   names2 = [], file_type = '',report_type = '',full_report = '';
							   
									   
							Ext.Array.each(records2, function(rec){
								if(rec.get("text") == 'PDF')
									file_type = '&file_type=pdf'

							   	if(rec.get("text") == 'Consultant Summary')
									report_type = '&report_type=summary'
								
								if(rec.get("text") == 'Full Report')
							report_type = '&full_report=true';

										   names2.push(rec.get('text'));
									   });
			
									   
							   var records3 = tree_precincts.getView().getChecked(),
										   names3 = [];
									   
									   Ext.Array.each(records3, function(rec){
										   //names.push(rec.get('text'));
										   names3.push(rec.get('id'));
									   });		
				   
					  /* 
					   Ext.MessageBox.show({
						   title: 'Selected Nodes',
						   msg: names3.join('<br />'),
						   icon: Ext.MessageBox.INFO
					   });
					  */  //alert('load.php?action=file_to_download&congo='+names3.join('+')+'&county_code='+Ext.getCmp('combo1').getValue()+'&precinct='+Ext.getCmp('combo2').getValue()+'&search='+ names.join('+') + file_type);
				   
						   Ext.core.DomHelper.append(document.body, {
								tag: 'iframe',
							   id:'downloadIframe',
								   frameBorder: 0,
									width: 0,
							   height: 0,
							   css: 'display:none;visibility:hidden;height:0px;',
							   //src: 'load.php?action=file_to_download&county_code='+Ext.getCmp('combo1').getValue()+'&precinct='+Ext.getCmp('combo2').getValue() 
							   src: 'load.php?action=file_to_download&congo='+names3.join('+')+'&county_code='+Ext.getCmp('combo1').getValue()+'&precinct='+Ext.getCmp('combo2').getValue()+'&search='+ names.join('+') + file_type + report_type
						   });
//						   var form = this.up('form').getForm();
						   /*var form = this.('form').getForm();
						   if (form.isValid()) {
							   form.submit({
								   success: function(form, action) {
									 // Ext.Msg.alert('Success', action.result.msg);
								   },
								   failure: function(form, action) {
									   Ext.Msg.alert('Failed', action.result.msg);
								   }
							   });
						   
							   
						   }*/
						    Ext.getCmp('portlet-3').update('<p><iframe style="overflow:auto;width:100%;height:100px;" frameborder="0" src="load.php?action=get_access_log"  ></iframe></p>');
							filestore.load();					   
					   }
					  
				   }
            ]
            
        }]
    });
    var tree2 = Ext.create('Ext.tree.Panel', {
        store: store,
        rootVisible: false,
        useArrows: true,

        width: 600,
        height: 650
		,
		listeners: {
			checkchange: function( node, checked, eOpts )			
			{
				//alert(node.checked = true);
				//alert(checked);
				node.cascadeBy(function(child){
				//alert(child.get('checked') = false)	;			
					 child.set('checked', checked);
					});
			   var records = tree2.getView().getChecked(),
                    names = [];
            
            Ext.Array.each(records, function(rec){
                names.push(rec.get('text'));
            });
	     var records2 = tree3.getView().getChecked(),
                        names2 = [], file_type = '',report_type = '';
			
                    
                    Ext.Array.each(records2, function(rec){
			if(rec.get("text") == 'PDF')
			file_type = '&file_type=pdf'
if(rec.get("text") == 'Consultant Summary')
report_type = '&report_type=summary'
                        names2.push(rec.get('text'));
                    });
					
			var records3 = tree_precincts.getView().getChecked(),
                        names3 = [];
                    
                    Ext.Array.each(records3, function(rec){
                        //names.push(rec.get('text'));
						names3.push(rec.get('id'));
                    });		
				dashstore.load({
					
       
 			params: {  'congo' :names3.join('+'), 'search':names.join('+')}, 			
 				proxy:{
 			 		extraParams:	{	 county:'10' }
 				}
 			});			
				
			}
			
			
			},
        dockedItems2: [{
            xtype: 'toolbar',
            items: [
            {
                text: 'Get',
                handler: function(){
                    var records = tree2.getView().getChecked(),
                        names = [];
                    
                    Ext.Array.each(records, function(rec){
                        names.push(rec.get('text'));
                    });
                    
                    Ext.MessageBox.show({
                        title: 'Selected Nodes',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    });
                }
            },
                {
                text: 'Select All',
                handler: function(){
                    var records = tree2.getView().getChecked(),
                        names = [];
                      tree2.getRootNode().cascadeBy(function(n) {
                      //if( node.data.checked ){}
					    //var ui = n.getUI();
					    n.attributes.checked = false;
    				//ui.toggleCheck(false);
					});

                      
                    /*
                    Ext.Array.each(records, function(rec){
                        names.push(rec.get('text'));
                    });
                    
                    Ext.MessageBox.show({
                        title: 'Selected Nodes',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    }); */
                    }
                }
            ]
            
        }]
    
		});

 

/*
    var tree = Ext.create('Ext.tree.Panel', {
        store: store,
        rootVisible: false,
        useArrows: true,
        
        frame: true,
        //title: 'Check Tree',
        //renderTo: 'tree-div',
        width: 600,
        height: 450,
        dockedItems: [{
            xtype: 'toolbar',
            items: {
                text: 'Get checked nodes',
                handler: function(){
                    var records = tree.getView().getChecked(),
                        names = [];
                    
                    Ext.Array.each(records, function(rec){
                        names.push(rec.get('text'));
                    });
                    
                    Ext.MessageBox.show({
                        title: 'Selected Nodes',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    });
                }
            }
        }]
    });
*/

// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
    fields: ['abbr', 'name'],
    data : [
        {"abbr":"AL", "name":"Alabama"},
        {"abbr":"AK", "name":"Alaska"},
        {"abbr":"AZ", "name":"Arizona"}
    
    ]
});

// Create the combo box, attached to the states data store

var cat = 1;
Ext.define('voter_data', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'vuid', type: 'int'} ,
        {name: 'rating', type: 'string'},
        {name: 'firstName', type: 'string'},
        {name: "county_code", type: 'string'},
        {name: "precinct", type: 'string'},
        {name: "last_name", type: 'string'}, 
        {name: "first_name", type: 'string'}, 
        {name: "middle_name", type: 'string'}, 
        {name: "former_last_name", type: 'string'}, 
        {name: "suffix", type: 'string'}, 
        {name: "gender", type: 'string'}, 
        {name: "dob", type: 'string'}, 
        {name: "perm_house_number", type: 'string'}, 
        {name: "perm_designator", type: 'string'}, 
        {name: "perm_directional_prefix", type: 'string'}, 
        {name: "perm_street_name", type: 'string'}, 
        {name: "perm_directional_suffix", type: 'string'}, 
        {name: "perm_unit_number", type: 'string'}, 
        {name: "perm_unity_type", type: 'string'}, 
        {name: "perm_city", type: 'string'}, 
        {name: "perm_zipcode", type: 'string'}, 
        {name: "mailing_address_1", type: 'string'}, 
        {name: "mailing_address_2", type: 'string'}, 
        {name: "mailing_city", type: 'string'}, 
        {name: "mailing_state", type: 'string'}, 
        {name: "mailing_zipcode", type: 'string'}, 
        {name: "edr", type: 'string'}, 
        {name: "suspense_status", type: 'string'}, 
        {name: "spanish_surname_flag", type: 'string'}, 
        {name: "po2000", type: 'string'}, 
        {name: "ru2000", type: 'string'}, 
        {name: "ge2000", type: 'string'}, 
        {name: "ge2001", type: 'string'}, 
        {name: "po2002", type: 'string'}, 
        {name: "ru2002", type: 'string'}, 
        {name: "ge2002", type: 'string'}, 
        {name: "ge2003", type: 'string'}, 
        {name: "po2004", type: 'string'}, 
        {name: "ru2004", type: 'string'}, 
        {name: "ge2004", type: 'string'}, 
        {name: "ge2005", type: 'string'}, 
        {name: "po2006", type: 'string'}, 
        {name: "ru2006", type: 'string'}, 
        {name: "ge2006", type: 'string'}, 
        {name: "lo2007", type: 'string'}, 
        {name: "ge2007", type: 'string'}, 
        {name: "po2008", type: 'string'}, 
        {name: "ru2008", type: 'string'}, 
        {name: "lo2008", type: 'string'}, 
        {name: "ge2008", type: 'string'}, 
        {name: "se2008", type: 'string'}, 
        {name: "phone", type: 'string'}, 
        {name: "source", type: 'string'}, 
        {name: "match_type", type: 'string'}        
    ]
});

Ext.define('county_precinct', {
    extend: 'Ext.data.Model',
    fields: [
//        {name: 'firstName', type: 'string'},
//        {name: 'lastName',  type: 'string'},
//        {name: 'age',       type: 'int'},
//        {name: 'eyeColor',  type: 'string'}

//        {name: 'firstName', type: 'string'},
//        {name: 'lastName',  type: 'string'},
//        {name: 'age',       type: 'int'},
//		  {name: 'county',  type: 'string'}
 		{name: 'precinct',  type: 'string'},      
        {name: 'county_code',  type: 'string'}
    ]
});
var store4 = Ext.create('Ext.data.Store', {
    //autoLoad: true,
    model: "voter_data",
    proxy: {
        type:'ajax',
        url :'load.php',
        reader:			{	type: 		'json', root: 'data' },
        extraParams:	{	action: 	'load_precincts', county:'2','EndDate': '' },
        listeners:		{	exception2: 	function () { alert("hey"); } }      
    },
    listeners: {	
    load: function() { 
        // alert("data loaded");
        //alert(this.getAt(0).get("county_code"));
    },
    beforeload: function() {
        //alert('before load');
    },
        beforeprefetch: function() {alert('before prefetch');}    
    }
});

var store3 = Ext.create('Ext.data.Store', {
    //autoLoad: true,
    model: "county_precinct",
    proxy: {
        type:'ajax',
        url :'load.php',
        reader:			{	type: 		'json', root: 'county_precinct' },
        extraParams:	{	action: 	'load_precincts', county:'2',EndDate: '' },
        listeners:		{	exception2: 	function () { alert("hey"); } }      
    },
    listeners: {	
    load: function() { 
        //alert("data loaded");
   		 //alert(this.getAt(0).get("county_code"));
    },
    beforeload: function() {
        //alert('before load');
    },
        beforeprefetch: function() {alert('before prefetch');}    
    }
});

var cat = 1;
Ext.define('counties', {
    extend: 'Ext.data.Model',
    fields: [
    // {name: 'firstName', type: 'string'},
    // {name: 'lastName',  type: 'string'},
    // {name: 'age',       type: 'int'},
    // {name: 'eyeColor',  type: 'string'}
    
    // {name: 'firstName', type: 'string'},
    // {name: 'lastName',  type: 'string'},
    // {name: 'age',       type: 'int'},
    {name: 'county',  type: 'string'},      
    {name: 'county_code',  type: 'string'}
    //{name: 'county_code',  type: 'string'}

    ]
});
var store2 = Ext.create('Ext.data.Store', {
    //autoLoad: true,
    model: "counties",
    proxy: {
        type:'ajax',
        url :'load.php',
        reader:			{	type: 		'json', root: 'county' },
        extraParams:	{	action: 	'load_counties', 'EndDate': '' },
        listeners:		{	exception2: 	function () { alert("hey"); } }      
    },
    listeners: {	
    load: function() { 
        //alert("data loaded");
   		//alert(this.getAt(0).get("county_code"));
    },
    beforeload: function() {
        //alert('before load');
    },
    beforeprefetch: function() {alert('before prefetch');}
    }
});
/*
Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
//        {name: 'firstName', type: 'string'},
//        {name: 'lastName',  type: 'string'},
//        {name: 'age',       type: 'int'},
//        {name: 'eyeColor',  type: 'string'}

        {name: 'firstName', type: 'string'},
        {name: 'lastName',  type: 'string'},
        {name: 'age',       type: 'int'},
        {name: 'eyeColor',  type: 'string'}

    ]
});
var store = Ext.create('Ext.data.Store', {
    autoLoad: true,
    model: "User",
    proxy: {
        type: 'ajax',
        url : 'load.php',
        reader: {
            type: 'json',
            root: 'data'
        }
        
    },
    listeners: {
    load: function() {
    //alert("data loaded");
    
    }
    }
});
*/
/*
Ext.define("Ext.app.ChartPortlet3",{
extend:"Ext.panel.Panel",
alias:"widget.chartportlet",
requires:["Ext.data.JsonStore","Ext.chart.theme.Base","Ext.chart.series.Series","Ext.chart.series.Line","Ext.chart.axis.Numeric"],
generateData:function(){
	var b=[{name:"x",djia:10000,sp500:1100}],a;for(a=1;a<50;a++){
		b.push({name:"x",sp500:b[a-1].sp500+((Math.floor(Math.random()*2)%2)?-1:1)*Math.floor(Math.random()*7),djia:b[a-1].djia+((Math.floor(Math.random()*2)%2)?-1:1)*Math.floor(Math.random()*7)})}return b},
initComponent:function(){
Ext.apply(this,{
	layout:"fit",
	width:600,
	height:300,
	items:{
		xtype:"chart",
		animate:false,
		shadow:false,
		store:Ext.create("Ext.data.JsonStore",{
			fields:["name","sp500","djia"],
			data:this.generateData()}),
		legend:{position:"bottom"},
		axes:[{type:"Numeric",position:"left",
			fields:["djia"],
			title:"Dow Jones Average",
			label:{font:"11px Arial"}},
			{
				type:"Numeric",
				position:"right",
				grid:false,
				fields:["sp500"],
				title:"S&P 500",
				label:{font:"11px Arial"}}],
		series:[{
			type:"line",
			lineWidth:1,
			showMarkers:false,
			fill:true,
			axis:"left",
			xField:"name",
			yField:"djia",
			style:{"stroke-width":1}},
			{type:"line",lineWidth:1,showMarkers:false,axis:"right",xField:"name",yField:"sp500",style:{"stroke-width":1}}]}});
this.callParent(arguments)}});

Ext.define("Ext.app.ChartPortlet2",{
        extend:"Ext.panel.Panel",
alias:"widget.chartportlet",
requires:["Ext.data.JsonStore","Ext.chart.theme.Base","Ext.chart.series.Series","Ext.chart.series.Line","Ext.chart.axis.Numeric"],
generateData:function(){
	var b=[{name:"x",djia:10000,sp500:1100}],a;for(a=1;a<50;a++){
		b.push({name:"x",sp500:b[a-1].sp500+((Math.floor(Math.random()*2)%2)?-1:1)*Math.floor(Math.random()*7),djia:b[a-1].djia+((Math.floor(Math.random()*2)%2)?-1:1)*Math.floor(Math.random()*7)})}return b},
initComponent:function(){
Ext.apply(this,{
	layout:"fit",
	width:600,
	height:300,
	items:{
		xtype:"chart",
		animate:false,
		shadow:false,
		store:Ext.create("Ext.data.JsonStore",{
			fields:["name","sp500","djia"],
			data:this.generateData()}),
		legend:{position:"bottom"},
		axes:[{type:"Numeric",position:"left",
			fields:["djia"],
			title:"Dow Jones Average",
			label:{font:"11px Arial"}},
			{
				type:"Numeric",
				position:"right",
				grid:false,
				fields:["sp500"],
				title:"S&P 500",
				label:{font:"11px Arial"}}],
		series:[{
			type:"line",
			lineWidth:1,
			showMarkers:false,
			fill:true,
			axis:"left",
			xField:"name",
			yField:"djia",
			style:{"stroke-width":1}},
			{type:"line",lineWidth:1,showMarkers:false,axis:"right",xField:"name",yField:"sp500",style:{"stroke-width":1}}]}});
this.callParent(arguments)}});
 */

Ext.define('Ext.app.Portal', {

    extend: 'Ext.container.Viewport',

    uses: ['Ext.app.PortalPanel', 'Ext.app.PortalColumn', 'Ext.app.GridPortlet'],//, 'Ext.app.ChartPortlet2', 'Ext.app.ChartPortlet3'],

    getTools: function(){
        return [{
            xtype: 'tool',
            type: 'gear',
            handler: function(e, target, panelHeader, tool){
                var portlet = panelHeader.ownerCt;
                portlet.setLoading('Working...');
                Ext.defer(function() {
                    portlet.setLoading(false);
                }, 2000);
            }
        }];
    },

    initComponent: function()
	{
        var content = '<div class="portlet-content">'+Ext.example.shortBogusMarkup+'</div>';


			var form1 = Ext.create('Ext.form.Panel', {
			//title: 'Voter Roll Selector',
			//bodyPadding: 5,
			width: 195,
			// The form will submit an AJAX request to this URL when submitted
			url: 'load.php',
			// Fields will be arranged vertically, stretched to full width
			//layout: 'anchor',
			//defaults: {
			//    anchor: '100%'
			//},
			// The fields
			defaultType: 'textfield',
			items: [    
					
					Ext.create('Ext.form.field.ComboBox', {
						hidden: true,
					//fieldLabel: 'C',
				//    store: states,
					id: 'combo1',
					width: 180,
					store: store2,
					queryMode: 'local',
					multiSelect: true,
					//queryMode: 'remote',
					//displayField: 'name',
					displayField: 'county',
					 //valueField: 'abbr'
					valueField: 'county_code',
					value: 1,
					listeners: {
						select: function() {
						
						//alert(this.getValue());
						//alert(Ext.getCmp('combo1').getValue());
						tree_precincts_store.load({
							params: { 'action': 'get_precincts_for_tree', 'county_code' :this.getRawValue() }, // this.getValue() }, 			
								proxy:{
									extraParams:	{	 county:'10' }
								}
							});
				
							dashstore.load({
							params: {  'county_code' :this.getValue() }, 			
								proxy:{
									extraParams:	{	 county:'10' }
								}
							});
							store3.load({
							params: {  county:this.getValue() }, 			
								proxy:{
									extraParams:	{	 county:'10' }
								}
							});
							//alert(this.getValue());
							//  alert(dashstore.getAt(0).get("rating"))
						}
					}	 
					/*,
					renderTo: Ext.getBody()*/
				})
					,
			
					Ext.create('Ext.form.field.ComboBox', {
					id: 'combo2',
					width: 180,
					hidden: true,
					//fieldLabel: 'C',
					store: store3,
					queryMode: 'local',
					displayField: 'precinct',
					//layout: 'absolute',
					listeners: {
						select: function() {
						dashstore.load({
							params: {  'county_code' : Ext.getCmp('combo1').getValue(), 'precinct':this.getValue() }, 			
								proxy:{
									extraParams:	{	 county:'10' }
								}
							});
						/*
						store.load({params: {
									action: 'getopts2', 
									'county_code': Ext.getCmp('combo1').getValue(),
									'precinct': Ext.getCmp('combo2').getValue() 
								}});
						*/
						
						
							//alert('select');
							Ext.Ajax.request({
								url: 'load.php',
								params: {
									action: 'getopts', 
									'county_code': Ext.getCmp('combo1').getValue(),
									'precinct': Ext.getCmp('combo2').getValue() 
								},
								success: function(response){
					
									var text = response.responseText;
												//alert('hey');
						
								jsonData= Ext.JSON.decode(text);
								Ext.getCmp('Hello').removeAll();
								for (var i = 0; i <jsonData.index.length; i++){
								Ext.getCmp('Hello').add(
									Ext.create('Ext.panel.Panel', {
										id: 'panel'+  jsonData.data[jsonData.index[i]].name,
										text:'hey',
										layout: 'absolute',
										//html: 'count: '+jsonData.data[jsonData.index[i]].name,
										height: 20
									}));
									
									//alert(jsonData.data[jsonData.index[i]].length);
									Ext.getCmp('panel'+  jsonData.data[jsonData.index[i]].name).add(
									Ext.create('Ext.form.Label', {
									xtype:'label',
									height: 20,
									width: 25,
									text: jsonData.data[jsonData.index[i]].name }));
									
								for (var j = 0; j < jsonData.data[jsonData.index[i]].length; j++){
									Ext.getCmp('panel'+  jsonData.data[jsonData.index[i]].name).add(
										[Ext.create('Ext.form.field.Checkbox',{
											id: 'panel'+  jsonData.data[jsonData.index[i]].name + 'id_' + j,
											x: (j * 70 + 75 ) ,
									//		y: (j * 20),
											height:15,
											width: 20,
											 applyTo: 'local-states'
											 }),
									Ext.create('Ext.form.Label', {
									xtype:'label'   ,
									x: (j * 70 + 45 ) ,
									//y: (j * 20),
									height: 25,
									width: 25,
									text: "" + jsonData.data[jsonData.index[i]][j].split('-').splice(0,1),
									name: 'lblLastLogin',
									style: 'font-weight:bold;'//,
									//anchor:'93%'
								 }) ]
											 
											 
									);
									Ext.getCmp('panel'+  jsonData.data[jsonData.index[i]].name).doLayout();
									}
								/*Ext.getCmp('Hello').removeAll();
								for (var i = 0; i <jsonData.index.length; i++){
									Ext.getCmp('Hello').add(
										Ext.create('Ext.panel.Panel', {
											id: 'panel'+  jsonData.data[jsonData.index[i]].name,
											text:'hey',
											html: 'count: '+jsonData.data[jsonData.index[i]].name,
											height: 20
									}));
								*/
								//Ext.getCmp('Hello').doLayout();
								//if (i > 5)
								//break;
									
								}
									//alert(jsonData.data[i].name);
									//Ext.getCmp('Hello').doLayout();
									//alert(jsonData.index.length);
									// process server response here
								}
							});
							
						}
					},
					
					valueField: 'precinct'
				})
				
				/*
				,
				
				
						Ext.create('Ext.form.Label', {
							xtype:'label'
							,
							height: 25,
							width: 25,
							text: "Available Options",
							name: 'lblLastLogin',
							style: 'font-weight:bold;'//,
							//anchor:'93%'
						 })
				, 
					Ext.create('Ext.form.field.Checkbox',{
					applyTo: 'local-states'
					
					})
					   
					   */

					   ],
				   
					   // Reset and Submit buttons
					   buttons2: [
					   /*
						   {
						   text: 'Reset',
						   handler: function() {
							   this.up('form').getForm().reset();
						   }
					   },*/ 
					   {
						   text: 'Preview',
						   //formBind: true, //only enabled once the form is valid
						   //disabled: true,
						   handler: function() {
							   var records = tree2.getView().getChecked(),
									   names = [];
				   
								   Ext.Array.each(records, function(rec){
									   names.push(rec.get('text'));
								   });
							 /*  Ext.MessageBox.show({
								   title: 'Selected Nodes',
								   msg: names.join('<br />'),
								   icon: Ext.MessageBox.INFO
							   });*/
				   
							   store4.load({
								   params: { 
									   action: 'getlist', 
									   'county_code': Ext.getCmp('combo1').getValue(),
									   'precinct': Ext.getCmp('combo2').getValue() ,
								   'search' : ''+ names.join('+')
								   } 				
							   });
				   
							   /*        
							   var form = this.up('form').getForm();
							   if (form.isValid()) {
							   alert(Ext.fly('combo1').getValue());
								   form.submit({
									   params: {action: 'getlist', 
									   'county_code': Ext.getCmp('combo1').getValue(),
									   'precinct': Ext.getCmp('combo2').getValue() },
									   success: function(form, action) {
										  Ext.Msg.alert('Success', action.result.msg);
									   },
									   failure: function(form, action) {
										   Ext.Msg.alert('Failed', action.result.msg);
									   }
								   });
							   }
							   */
						   }
					   }
					   , 
					   {
						   text: 'Download',
						   //formBind: true, //only enabled once the form is valid
						  // disabled: true,
						   handler: function() {
							   var records = tree2.getView().getChecked(),
									   names = [];
							   
							   Ext.Array.each(records, function(rec){
								   names.push(rec.get('text'));
							   });
							var records2 = tree3.getView().getChecked(),
										   names2 = [], file_type = '',report_type = '';
							   
									   
							Ext.Array.each(records2, function(rec){
								if(rec.get("text") == 'PDF')
									file_type = '&file_type=pdf'

							   	if(rec.get("text") == 'Consultant Summary')
									report_type = '&report_type=summary'

										   names2.push(rec.get('text'));
									   });
									   
							   var records3 = tree_precincts.getView().getChecked(),
										   names3 = [];
									   
									   Ext.Array.each(records3, function(rec){
										   //names.push(rec.get('text'));
										   names3.push(rec.get('id'));
									   });		
				   
					  /* 
					   Ext.MessageBox.show({
						   title: 'Selected Nodes',
						   msg: names3.join('<br />'),
						   icon: Ext.MessageBox.INFO
					   });
					  */  //alert('load.php?action=file_to_download&congo='+names3.join('+')+'&county_code='+Ext.getCmp('combo1').getValue()+'&precinct='+Ext.getCmp('combo2').getValue()+'&search='+ names.join('+') + file_type);
				   
						   Ext.core.DomHelper.append(document.body, {
								tag: 'iframe',
							   id:'downloadIframe',
								   frameBorder: 0,
									width: 0,
							   height: 0,
							   css: 'display:none;visibility:hidden;height:0px;',
							   //src: 'load.php?action=file_to_download&county_code='+Ext.getCmp('combo1').getValue()+'&precinct='+Ext.getCmp('combo2').getValue() 
							   src: 'load.php?action=file_to_download&congo='+names3.join('+')+'&county_code='+Ext.getCmp('combo1').getValue()+'&precinct='+Ext.getCmp('combo2').getValue()+'&search='+ names.join('+') + file_type + report_type
						   });
						   var form = this.up('form').getForm();
						   if (form.isValid()) {
							   form.submit({
								   success: function(form, action) {
									 // Ext.Msg.alert('Success', action.result.msg);
								   },
								   failure: function(form, action) {
									   Ext.Msg.alert('Failed', action.result.msg);
								   }
							   });
						   }
					   }
				   }
					   
					   
					   ]//,
					   //renderTo: Ext.getBody()
				   });
		
		function authPrompt(username) {
			var state = 0,dd;
			if ((dd =Ext.getCmp('pass')) != undefined)
				dd.hide();
		//Ext.getCmp('center-containter').show();
			Ext.Ajax.request({
				url: 'load.php',
				params: {
					action: 'isauth'
				},
				success: function(response) {
					
					var text = response.responseText;
					var jsonData= Ext.JSON.decode(text);

					if (jsonData.data == 'true'){
						
						Ext.getCmp('center-containter').show();
						
						store2.load();
						
						//store.load();
						tree_store2.load();
						tree_precincts_store.load();
						filestore.load();
						
						//var ee='ee';
						//alert('show');
					}
					else
					{
						if ((dd =Ext.getCmp('user')) != undefined)
								dd.show();
							else 
								Ext.MessageBox.add({
									xtype: 'textfield',
									id: 'user',
									name: 'name',
									//fieldLabel: 'Password',
									width: 200,		
									x: 10,
									//y: 0,
									//inputType: 'password',												
									//allowBlank: false  // requires a non-empty value
								});						
						
					//for (var passwordPrompt = true; passwordPrompt ==  true ;) {
					// Ext.MessageBox.prompt('', 'USERNAME:', function(btn,text) {
					Ext.Msg.show({
						//title:'Save Changes?',
						msg: 'USERNAME: ',
						buttons: Ext.Msg.OK,
						fn: function(btn){
							var text = Ext.getCmp('user').getValue();
							if(text == '')
								authPrompt('');
							else {
								//Ext.MessageBox.getTextField().el.dom.type = 'password';
								if ((dd =Ext.getCmp('user')) != undefined)
									dd.hide();
								if ((dd =Ext.getCmp('pass')) != undefined)
									dd.show();
								else 
									Ext.MessageBox.add({
										xtype: 'textfield',
										id: 'pass',
										name: 'name',
										//fieldLabel: 'Password',
										width: 200,		
										x: 10,
										//y: 0,
										inputType: 'password',												
										//allowBlank: false  // requires a non-empty value
									});
								Ext.Msg.show({
									//title:'Save Changes?',
									msg: 'Password for '+text,
									buttons: Ext.Msg.OK,
									tbar: [
											{ xtype: 'button', text: 'Button 1' }
										  ],
									fn: function(){
										
										var mypass = Ext.getCmp('pass').getValue();
												Ext.getCmp('pass').setValue('');
										Ext.Ajax.request({
											url: 'load.php',
											method: 'GET',
											params: {
												action: 'auth',
												user: Ext.getCmp('user').getValue(),
												pass: mypass
											},
											success: function(response) {
												//alert(mypass);
												var text = response.responseText;
												var jsonData= Ext.JSON.decode(text);
												if(jsonData.data == 'true')
												{
												  var ee = 'ee';
												  //alert('Success');
												  Ext.getCmp('center-containter').show();
												  store2.load();
												  store.load();
												  tree_store2.load();
												  tree_precincts_store.load();
												  
													var ee='ee';
													//alert('show2');
												}
												else{
													//alert('Success');
													//alert(jsonData.data);
													authPrompt('');
												}
											}
										});
										
										
										//authPrompt('');
										} ,
									animEl: 'elId'
								 });
							}
							//Ext.MessageBox.prompt('Password', 'Please enter your password:', function() {
							//});
						}});
					//}
					//for (var i = 0; i <jsonData.index.length; i++){
					//}
					}	
				}
			});								
		}

		 Ext.apply(this, {
					id: 'app-viewport',
					hidden: false,
					layout: {
						type: 'border',
						padding: '0 5 5 5' // pad the layout from the window edges
					},
					
					listeners: {
						render: function (){
							
								authPrompt('');
							
						}
									
							
						},
					//items:[],
					items: [{
						id: 'app-header',
						xtype: 'box',
						region: 'north',
						height: 40,
						html: 'Voter List Manager Beta'
					},{
						xtype: 'container',
						region: 'center',
						layout: 'border',
						id: 'center-containter',
						hidden: true,
						
						items: [{
							id: 'app-options',
							title: 'Options',
							region: 'west',
							animCollapse: true,
							width: 200,
							minWidth: 150,
							maxWidth: 400,
							split: true,
							collapsible: true,
							layout: 'accordion',
							layoutConfig:{
								animate: true
							},
							
							items: [
							tree_precincts,	
							/*{
								//html: form1,//content,
								title:'Campaign Selector',
								autoScroll: true,
								border: false,
								iconCls: 'nav'
								//,								items: [tree_precincts]
								//items2:[form1,tree_precincts]
							},*/
							{
								//html: form1,//content,
								title:'Voter Roll Selector',
								//width: 100,
								autoScroll: true,
								border: false,
								iconCls: 'nav',
								items:[tree2]
							}
							
							,{
								title:'Output Settings',
								html: content,
								border: false,
								autoScroll: true,
								iconCls: 'settings'
								,items: [tree3]
							}]
						},{
							id: 'app-portal',
							xtype: 'portalpanel',
							layout: 'absolute',
							region: 'center',
							items: [
							
							{
								id: 'col-0',
								items: [ 
								/*{
									id: 'portlet-2',
									title: 'Portlet 2',
									tools: this.getTools(),
									html: content,
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								}
								,*/
								 
								{
									id: 'portlet-112',
									title: 'Dash Board "Grid Portlet"',
									tools: this.getTools(),
										items:   Ext.create('Ext.panel.Panel', {
											id: 'panel++',
											text:'hey',
											layout: 'absolute',
											//html: 'count: '+jsonData.data[jsonData.index[i]].name,
											height: 360,
											items:
											Ext.create('Ext.grid.Panel', {
							//title: 'Simpsons',
							store:
							dashstore
							,columns: [      
								{ header: 'Demographic', width: 200, dataIndex: 'rating_name'/*,renderer: function (val) {  alert(val);   } */ },
								{ header: 'Count', dataIndex: 'rating' }
								/*,
								{ header: 'rating_precinct', dataIndex: 'rating_precinct' }*/
							],
							height: 360
							//,width: 600
											})
							/* new Ext.grid.GridPanel({
							 title: 'Approvals',
							 renderTo: Ext.getBody(),
							 height: 500,
							 width: 700,
							 store: new Ext.data.ArrayStore({
							   idIndex:0,
							   data: [ ['01/01/11','Held', 1], ['02/02/11','Approved', 2] ],
						 
							   fields: ['approved_date', 'approval_status',{name:'approval_id', type:'int'}] //specify other fields here
							 }),
							 
						   
							   columns:[{
							header:'Approval Date',
							dataIndex:'approved_date'
							   },{
							 header:'Approval Status',
							 dataIndex:'approval_status'
							   },{
							 header:'Approval ID',
							 dataIndex:'approval_id'
							   }]                    
						  
						 })*/
		
									}),
								   
								   //tree
										
									
		
									
									//[{}], 
									//Ext.create('Ext.app.GridPortlet'),
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								}
								/*,
								{
									id: 'portlet-1',
									title: 'Voter Roll Preview "Grid Portlet"',
									tools: this.getTools(),
									items:Ext.create('Ext.grid.Panel', {
									//title: 'Simpsons',
									store: store4,
									columns: [
										
										// { header: 'vuid' , dataIndex:  'vuid' },
										// { header: 'firstName',  dataIndex: 'firstName' },
										{ header:  "Rating", dataIndex:  "rating",width: 75 },
										{ header:  "County Code", dataIndex:  "county_code",width: 75 },
										{ header:  "Precinct", dataIndex:  "precinct" ,width: 47 },
										{ header: "Last Name", dataIndex: "last_name" ,width: 60 }, 
										{ header: "First Name",  dataIndex: "first_name" ,width: 60 }, 
										{ header:  "Middle Name",  dataIndex: "middle_name" ,width: 80 }, 
										//{ header:  "former_last_name",   dataIndex: "former_last_name"  }, 
										
										{ header:  "Suffix",  dataIndex: "suffix" ,width: 50}, 
										{ header: "Gender",  dataIndex:  "gender" ,width: 50}, 
										{ header:  "DOB",   dataIndex: "dob" ,width: 70}, 
										
										{ header:  "Perm House #",  dataIndex:  "perm_house_number" ,width: 70}, 
										{ header: "Perm Designator", dataIndex: "perm_designator" ,width: 95}, 
										
										{ header:  "Perm Dir. Prefix", dataIndex: "perm_directional_prefix" ,width: 90}
										//{ header: 'Name',  dataIndex: 'name' },
										//{ header: 'Email', dataIndex: 'email', flex: 1 },
										//{ header: 'Phone', dataIndex: 'phone' }
									],
									height: 265,
									width: 1600
									}),
		
									
									//[{}], 
									//Ext.create('Ext.app.GridPortlet'),
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								}  */ ]
							},
							{
								id: 'col-1',
								width: 300,
								//height: 100,
								items: [{
									id: 'portlet-3-2',
									title: 'Files',
									height: 160,
									tools: this.getTools(),
									html: '<br><BR><BR><BR><BR><BR>',
									items: Ext.create('Ext.grid.Panel', {
							//title: 'Simpsons',
							selModel: selmo,
							store:filestore
							,columns: [      
								//selmo,
								{ header: 'filename', width:200, dataIndex: 'file' }
							],
							height: 160
							//,width: 600
											})
									,
									listeners:
																		
									{		render: function() {
										//alert(filestore.getAt(0).get('file')
											
											//forfilestore.getAt(0).length
											  
//											  );
		 },
										'close': Ext.bind(this.onPortletClose, this)
									}
								},{
									id: 'portlet-3-1',
									title: 'News',
									tools: this.getTools(),
									html: '<p><iframe style="overflow:auto;width:100%;height:100px;" frameborder="0" src="news.html"  ></iframe></p>',
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								},
										{
									id: 'portlet-3',
									title: 'Activity Log',
									tools: this.getTools(),
									html: '<p><iframe style="overflow:auto;width:100%;height:100px;" frameborder="0" src="load.php?action=get_access_log"  ></iframe></p>',
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								}]
							}/*,{
								id: 'col-2',
								items2: [{
									id: 'portlet-3',
									title: 'Portlet 3',
									tools: this.getTools(),
									html: '<div class="portlet-content">'+Ext.example.bogusMarkup+'</div>',
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								}]
							} ,{
								id: 'col-3',
								items2: [{
									id: 'portlet-4',
									title: 'Stock Portlet2',
									tools: this.getTools(),
									items: Ext.create('Ext.app.ChartPortlet'),
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								},{
									id: 'portlet-5',
									title: 'Stock Portlet3',
									tools: this.getTools(),
									items: Ext.create('Ext.app.ChartPortlet3'),
									listeners: {
										'close': Ext.bind(this.onPortletClose, this)
									}
								}]
							} */
							
							]
						}]
					}]
				});
				this.callParent(arguments);
    },

    onPortletClose: function(portlet) {
        this.showMsg('"' + portlet.title + '" was removed');
    },

    showMsg: function(msg) {
        var el = Ext.get('app-msg'),
            msgId = Ext.id();

        this.msgId = msgId;
        el.update(msg).show();

        Ext.defer(this.clearMsg, 3000, this, [msgId]);
    },

    clearMsg: function(msgId) {
        if (msgId === this.msgId) {
            Ext.get('app-msg').hide();
        }
    }
});



