// state
  Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

// quicktips
  Ext.QuickTips.init();

// some defaults
  Ext.AppSrvUrl = 'appsrv';
  Ext.BLANK_IMAGE_URL = (function() {
    if (Ext.isIE8 || Ext.isGecko || Ext.isOpera) {
      return "data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
    } else {
      return "media/appsrv/images/blank.png";
    }
  })();
    
// app controller
  Ext.app.App = function(cfg){
    Ext.apply(this, cfg);
    this.addEvents({
      'ready' : true,
      'beforeunload' : true,
      'sessionexpire': true
    });
    Ext.onReady(this.init, this);
  };
  
  Ext.extend(Ext.app.App, Ext.util.Observable, {
    isReady: false,
    
    initApp : function(){
      this.desktop  = new Ext.Desktop();
      Ext.EventManager.on(window, 'beforeunload', this.onUnload, this);
      this.fireEvent('ready', this);
      this.isReady = true;
    },
    
    getModules : Ext.emptyFn,
    init : Ext.emptyFn,
    
    initModules : function(ms){
    },
    
    onReady : function(fn, scope){
      if(!this.isReady){
        this.on('ready', fn, scope);
      }else{
        fn.call(scope, this);
      }
    },
    
    getDesktop : function(){
      return this.desktop;
    },
    
    onUnload : function(e){
      if(this.fireEvent('beforeunload', this) === false){
        e.stopEvent();
      }
    }
  });

// module controller
  Ext.app.Module = function(config){
    Ext.apply(this, config);
    Ext.app.Module.superclass.constructor.call(this);
    this.init();
  }
  Ext.extend(Ext.app.Module, Ext.util.Observable, {
    init : function(){
      this.app = App;
    },
    getDesktop : function(){
      return this.desktop;
    },
    onUnload : function(e){
      if(this.fireEvent('beforeunload', this) === false){
        e.stopEvent();
      }
    }
  });
  Ext.Modules = {};

// create app controller
  App = new Ext.app.App({
  
    init: function() {
      this.desktop  = new Ext.Desktop();
    },
    
    getModules: function(){
      //
    },
    
    loadUrl: function(url) {
      document.location.href = url;
    },
    
    reloadWindow: function() {
      document.location.reload();
    },
    
    openWin: function(name, url) {
      window.open(url, name, "width=800,height=600,left=100,top=200");
    },
    
    plugin: function(remoteUrl){
      return new Ext.ux.Plugin.RemoteComponent({
        url : remoteUrl
      });
    },
    
    // load js file and exec
    load: function(url, params, callback) {
      Ext.getBody().mask('Lade Daten...');
      Ext.Ajax.request({
        url: url,
        success: function(response) {
          eval(response.responseText);
          Ext.getBody().unmask();
        },
        callback: callback,
        params: params
      });
      Ext.Ajax.on('requestcomplete', function() {
        
      }, this);
    },
    
    // make ajax request
    request: function(config) {
      Ext.Ajax.request(config);
    }
    
  });
