ns('Carib.Order.Widgets');

/**
 * Common info window
 * 
 * @version $Id: common_info_win.js 544 2009-09-09 15:33:39Z  $
 */
Carib.Order.Widgets.CommonInfoWin = function(config) {
  config = $.extend({
    window_config: {
      autoOpen: false,
      title: 'Общая информация о путешествии',
      modal: true,
      closeOnEscape: false,
      dialogClass: 'order_wizard',
      resizable: false,
      position: ['right', 'top'],
      buttons: {
        'Отмена': this.onCancel.createDelegate(this),
        'OK': this.onOk.createDelegate(this)
      }
    },
    form: null // required      
  }, config);
  
  var form_size = config.form.getSize();
  config.window_config.width = form_size.width + 30;
  config.window_config.height = form_size.height + 230;
  
  this.addEvents({
    ok: true,
    cancel: true
  });
  
  Carib.Order.Widgets.CommonInfoWin.superclass.constructor.call(this, config);
}

utils.extend(Carib.Order.Widgets.CommonInfoWin, Carib.Order.Widgets.Window, {
  getForm: function() {
    return this.form;
  },
  
  onShow: function() {
    Carib.Order.Widgets.CommonInfoWin.superclass.onShow.call(this);
    
    this.form.updateFields();
  },
  
  onOk: function() {
    if(!this.form.validate())
      return;
      
    this.hide();
    this.form.updateRecord();
    this.fireEvent('ok', [this]);
  },
  
  onCancel: function() {
    this.hide();
    this.fireEvent('cancel', [this]);
  }
});

