Ext.printwizard = Ext.extend(Ext.Window, {
  width: 600,
  height: 500,
  title: 'Print',
  layout: 'fit',
  closeAction: 'hide',
  modal: true,
  plain: true,
  values: [],
  constructor: function(config){
        Ext.printwizard.superclass.constructor.apply(this, arguments);
        this.accordion.border = false;
        this.accordion.anchor = '100% -60';
        this.add(
          {
            xtype:'panel',
            layout: 'anchor', 
            border: false, 
            bodyStyle: 'background-color: #f8f8f8',
            items: [
              {xtype: 'panel',
              listeners: {
                    render : function(panel) {
                      tpl = new Ext.XTemplate(
                        '<tpl for=".">',
                            '<div class="printwizardTop">',
                              '<img src="images/satin_icons/printer.png"/>',
                              '<div id="printwizardTopInner">',
                                '<h3>{title}</h3>',
                                '<p>{info}</p>',
                              '</div>',
                            '</div>',
                        '</tpl>'
                      );
                      headerData = {title: config.headerText, info: config.info};
                      //console.log(panel.getEl());
                      tpl.overwrite(panel.body, headerData);  
                    }
              }
              }, 
              this.accordion
            ]
          }
        ); 
  },
  checkAssumptions: function(){
    errors = [];
     for (item in this.assumptions){
      if (typeof(this.assumptions[item]) != 'function') {
        if (this.assumptions[item][1] != undefined && this.assumptions[item][1] != ''){
          this.values[this.assumptions[item][0]] = this.assumptions[item][1];
        } else {
          errors.push(this.assumptions[item][0] + ' is not set');
        }
      }
    }
    if (errors.length > 0){
     errorString = errors.join('<br/>');
     Ext.Msg.alert('Error', errorString);
     this.values=[];
    }
    return (errors.length < 1);
    
  },    
  buttons: [
      {
        //disabled: true,
        text: 'Print',
        handler: function(){
          formValues = this.ownerCt.ownerCt.items.items[0].items.items[1].layout.activeItem.items.items[0].getForm().getValues();
          console.log(formValues);
          console.log(this.ownerCt.ownerCt.items.items[0].items.items[1].layout.activeItem.reportType);
        }
      },
    {
      text: 'Close',
      handler: function(){
        this.ownerCt.ownerCt.hide();
      }
    }
  ],
  listeners: {
    beforeShow : function(){
     if (!this.checkAssumptions()){
        return false;
     }    
    }
  }  
});

Ext.ComponentMgr.registerType('printwizard', Ext.printwizard);