IceCap.RowSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
  //if you want single cell selection or multiple
  singleSelect : true,

  //if when a cell is selected with control or shift if the entire row should be selected
  rowSelection: true,

  // private
  initEvents : function(){
    if (Ext.isIE) {
      this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
        "up" : function(e) {
          IceCap.moveCursorUp();
        }
        ,"down" : function(e) {
          IceCap.moveCursorDown();
        },
        scope: this
      });
    }
  }
});

IceCap.Window=Ext.extend(Ext.Window,{
  // defaults - can be changed from outside
  header:false
  ,closable:false
  ,plain:true
  ,modal:false
  ,autoScroll:true
  ,initComponent: function() {
    var tools = IceCap.buildPanelToolbar(IceCap.activeSession.scn);
    if (tools.length > 0) {
      this.tools = tools;
    }

    IceCap.Window.superclass.initComponent.apply(this,arguments);



  }
}); // eo extend
// register xtype
Ext.reg('iceCapWindow', IceCap.Window);

IceCap.SimplePanel=Ext.extend(Ext.Panel,{
  // defaults - can be changed from outside
  buttonAlign:'left'
  ,border:false
  ,bodyBorder:false
  ,layout:'absolute'
  ,autoScroll:true
  ,bodyStyle:'padding:5;'
  ,defaultType:'textfield'
  ,initComponent: function() {
    this.scn = saved.Scn;
    this.id = 'iceSmp' + saved.SessionNumber;
    this.windowNumber = saved.SessionNumber;
    this.emulator = saved.Scn.emulator;
    this.sessionNumber = saved.SessionNumber;

    var fields = IceCap.buildFormSimpleFields(saved.IceCapObj, saved.Scn);
    this.items = fields.items;

    IceCap.SimplePanel.superclass.initComponent.apply(this,arguments);
  }
}); // eo extend
// register xtype
Ext.reg('iceCapSimplePanel', IceCap.SimplePanel);

IceCap.Form = Ext.extend(Ext.Panel,{
  // defaults - can be changed from outside
  buttonAlign: 'left'
  ,border: false
  ,bodyBorder: false
  ,hidden: true
  ,initComponent: function () {
    this.id = 'icePnl' + IceCap.activeSession.windowNumber;
    this.windowNumber = IceCap.activeSession.windowNumber
    this.sessionNumber = IceCap.activeSession.sessionNumber
    this.emulator = IceCap.activeSession.scn.emulator

    var tools = IceCap.buildPanelToolbar(IceCap.activeSession.scn);
    if (tools.length > 0) {
      this.tools = tools;
    }

    IceCap.buildForm(this, IceCap.activeSession.scn);

    IceCap.Form.superclass.initComponent.apply(this,arguments);

  }
}); // eo extend
// register xtype
Ext.reg('iceCapForm', IceCap.Form);


IceCap.Menu = Ext.extend(IceCap.Panel, {
  initComponent:function() {
    IceCap.activeSession.isMenu = true;
    IceCap.activeSession.menu = {};
    IceCap.activeSession.menu.layout = this.layout;
    IceCap.activeSession.menu.clickEvent = this.clickEvent;
    IceCap.activeSession.menu.inputFieldNumber = this.inpFldNbr;
    IceCap.activeSession.menu.selectedElm = {};
    IceCap.activeSession.scn.buttonAlign = 'right';

    Ext.apply(this, {
      border:(this.border) ? this.border : false
      ,menuEndLine:(this.endLine) ? this.endLine : 0
      ,numberOfMenus:(this.menus) ? this.menus.length : 0
      ,menuCommandLine:(this.commandLine) ? this.commandLine.line : 0
      ,bodyStyle:{height:'100%'}
      ,html:this.buildMenu()
    });

    IceCap.Menu.superclass.initComponent.call(this);
  }
  ,buildMenu:function() {
    if (typeof(this.menus) == 'undefined') return;

    IceCap.activeSession.isMenu = false;

    this.adjustLine = (this.adjust) ? this.adjust + 1 : (this.adjustLine) ? this.adjustLine + 1 : 0;
    this.adjustColumn = (this.adjustColumn) ? this.adjustColumn + 1 : 0;

    this.warning4options = (typeof(this.warning4options) == 'undefined') ? [] : this.warning4options;
    var warning = [];
    for (var index in this.warning4options) {
      if (typeof(this.warning4options[index].option) != 'undefined') warning.push(this.warning4options[index].option);
    }

    var x=(this.menus[0].col - this.adjustColumn) * IceCap.xScale;
    var y=(this.menus[0].lin - this.adjustLine) * (IceCap.yScale - yScaleCorrection) + 5;
    var html = '';
    html += '<div class="icecap-menu-body" style="width:95%; height:94%; position:absolute;top:'+y+'px;left:'+x+'px;">';
    html += '<div class="icecap-menu-bwarp" style="width:85%;">';

    var first = 'x-grid3-row-first';
    var last  = '';

    this.colCnt = (this.colCnt) ? this.colCnt : 1;

    for (var c = 1; c <= this.colCnt; c++) {
      if (Ext.isIE) {
        html += '<div style="width:' + (95 / this.colCnt) + '%;display:inline-block;float:left;">';
      } else {
        html += '<div style="width:' + (95 / this.colCnt) + '%;display:inline-block;">';
      }
      this.menuFirstLine = 99;
      for (var i = 0; i < this.menus.length; i++) {
        var m = this.menus[i];
        m.colNbr = (m.colNbr) ? m.colNbr : 1;
        if (m.colNbr != c) continue;
        if (m.lin < this.menuFirstLine) this.menuFirstLine = m.lin;
        if (m.mnu.length == 0) {
          first = 'x-grid3-row-first';
          html += '<div style="width:100%;" class="icecap-menu-header">';
          html += '  <table cellspacing="0" cellpadding="0" border="0">';
          html += '    <tbody>';
          html += '      <tr>';
          html += '        <td class="iceCap-output-20 icecap-menu-text">'+m.txt+'</td>';
          html += '      </tr>';
          html += '    </tbody>';
          html += '  </table>';
          html += '</div>';
        } else {
          if (i == this.menus.length-1) {
            last  = 'x-grid3-row-last';
          } else if (i < this.menus.length-2 && this.menus[i+1].mnu.length == 0) {
            last  = 'x-grid3-row-last';
          } else {
            last  = '';
          }
          var wrn = false;
          if (warning.indexOf(m.mnu) != -1) {
            wrn = true;
          }

          var icon = '/system/snapOnIcon.aspx.png?keyword=' + m.txt + '&default=folder.png&insertRoot=true';
          html += '<div style="width:100%;" class="icecap-menu x-grid3-row ' + first + last + ' " onmouseover="IceCap.addClass(this, \'x-grid3-row-over\')" onmouseout="IceCap.removeClass(this, \'x-grid3-row-over\')"  onclick="IceCap.menuClicked(this, \''+m.mnu+'\', \''+m.txt+'\', '+wrn+')">';
          html += '  <table cellspacing="0" cellpadding="0" border="0">';
          html += '    <tbody>';
          html += '      <tr>';
          html += '        <td class="icecap-menu-icon"><img unselectable="on" src="'+icon+'" /></td>';
          html += '        <td class="iceCap-output-20 icecap-menu-id">'+m.mnu+'.</td>';
          html += '        <td class="iceCap-output-20 icecap-menu-text">'+m.txt+'</td>';
          html += '      </tr>';
          html += '    </tbody>';
          html += '  </table>';
          html += '</div>';
          first = '';
        }
      }
      html += '</div>';
    }
    html += '</div>';

    if (this.commandLine) {
      this.commandLine.id = 'cmd'+IceCap.activeSession.scn.sesNo+IceCap.activeSession.scn.window.level;
      html += '<div id='+this.commandLine.id+'></div>';
    }

    html += '</div>';

    delete this.menus;

    return html;
  }
  ,afterRender:function(panel) {
    IceCap.Menu.superclass.afterRender.call(this);

    if (this.commandLine) {
      new Ext.Panel({
        renderTo:this.commandLine.id
        ,width:"100%"
        ,height:this.commandLine.items.height + 20
        ,border:false
        ,items:this.commandLine.items
      });
    }
  }
});
Ext.reg('IceCap.Menu', IceCap.Menu);
