App = function(){
    
    // begin private
    
    var _Toolbar;
    
    // end private
    
    // begin public
    return{
        
        Debug: true,
        
        Bridge: 0,
        
        setBridge: function(bridge){
            App.setTrace('App.setBridge');
            
            this.Bridge = bridge;
            
            return;
        },
        
        getBridge: function(){
            App.setTrace('App.getBridge');
            
            return this.Bridge;
        },
        
        Navigation: Array(),
        
        start: function(){
            App.setTrace('App.start');
            
            this.buildToolbar();
            this.doLayoutToolbar();
        },
        
        buildToolbar: function(){
            App.setTrace('App.buildToolbar');
            
            
            _Toolbar = new Ext.Toolbar({
                id: 'toolbar',
                height: 30,
                renderTo: 'north',
                items: [{
                    xtype: 'tbspacer',
                    width: 50
                },{
                    text: "'Voicecity' 0.7.2"
                },{
                   xtype: 'tbseparator' 
                }]
              });
            
        },
        
        getToolbar: function(){
            App.setTrace('App.getToolbar');
            
            return _Toolbar;  
        },
        
        doLayoutToolbar: function(){
            App.setTrace('App.doLayoutToolbar');
            
            _Toolbar.doLayout();
            return;
        },
        
        setTrace: function(info){
            
            if(window.console && window.console.firebug && this.Debug){
                console.info(info);
                return;
            }
            else
                return;
        },
        
        checkNavigation: function(modul,id){
            App.setTrace('App.checkNavigation');
            
            App.setBridge(id);
            
            for(var i = 0; i < App.Navigation.length; i++){
                
                var name = App.Navigation[i];

                if(modul == name){
                    
                    var call = eval('App.' + name + '.wakeup();');
                }
                else{
                    Ext.getCmp(name).setVisible(false);
                }
                
            }
            
            return;
        },
        
        setNavigation: function(modul){
            App.setTrace('App.setNavigation');
            
            this.Navigation.push(modul);
            return;    
        },
        
        GridCellPhonebutton: function(val,cell,record){
            
            if(val){
                var id = record.data.id;
                return "&nbsp;&nbsp;&nbsp;" + val + "&nbsp;&nbsp;&nbsp; <a href='#'><img src='library/icons/telephone.png' border='0' onclick='App.makeCall(\"" + val + "\",\"" + id + "\");return false;'></a>";   
            }                
            else
                return ' ';
            
        },
        
        makeCall: function(val,id){
            App.setTrace('App.makeCall');
            
            
            Ext.Ajax.request({
               url: 'frontend/controler/app.php',
               method: 'Post',
               success: function(result, response){
                    
                    var info = Ext.util.JSON.decode(result.responseText);
                    App.information(info.info);
                    
                    // ruft Fenster des Protokoll auf
                    App.Telefonliste.viewProtokoll(id);
               },
               failure: function(result, response){
                    // Ext.MessageBox.alert('False');
                    App.information('keine Verbindung m&ouml;glich');
               },
               params: {
                   modul: 'telefonliste',
                   aktion: 'call',
                   callphone: val
               }
            });

        },
        
        msgCt: null,
        
        createBox: function(t, s) {  
            return ["<div class=\"msg\" style=\"width: 150px; z-index: 10;\">", "<div class=\"x-box-tl\"><div class=\"x-box-tr\"><div class=\"x-box-tc\"></div></div></div>", "<div class=\"x-box-ml\"><div class=\"x-box-mr\"><div class=\"x-box-mc\"><h3>", t, "</h3>", s, "</div></div></div>", "<div class=\"x-box-bl\"><div class=\"x-box-br\"><div class=\"x-box-bc\"></div></div></div>", "</div>"].join("");  
        },
        
        information: function(information){
            
            if (!this.msgCt) {  
                this.msgCt = Ext.DomHelper.insertAfter('north', {  
                    id: "msg-div"  
                }, true);  
            }
            
            this.msgCt.alignTo(document, "t");
              
            var m = Ext.DomHelper.append(this.msgCt, {  
                html: this.createBox(information)  
            }, true);
            
            m.slideIn("t").pause(3).ghost("t", {  
                remove: true  
            });
            
            return; 
    }
        
    }
    // end public

}();

Ext.onReady(App.start,App);
