App.Telefonliste.Sms = function(){
    
    var _SmsAdress;
    var _UserId;
    var _AnzahlZeichen = false;
    
    return{
        
        wakeup: function(id){
            App.setTrace('App.Telefonliste.Sms.wakeup');
            
            
            _UserId = id;
            
            if(!this.WindowContent){
                this.buildWindow.add(this.buildForm);
                this.WindowContent = true;
            }
            
            Ext.Ajax.request({
                url: 'frontend/controler/app.php',
                method: 'post',
                params: {
                    modul: 'telefonliste_sms',
                    aktion: 'holen',
                    id: id
                },
                success: function(result,request){
                    
                    var wert = Ext.util.JSON.decode(result.responseText);
                    
                    if(!wert.data.handy1){
                        Ext.getCmp('Telefonliste_Sms').hide();
                        App.information('Keine Handynummer vorhanden');
                        
                    }
                    else{
                        _SmsAdress = wert.data.handy1;
                        
                        Ext.getCmp('Telefonliste_SmsForm').getForm().findField('kennung').setValue(wert.data.kennung);
                    }

                    return;
                }
                
                
                
            });
            
            
            this.buildWindow.show();
            
            
            return;
        },
        
        WindowContent: false,
        
        buildForm: {
            "xtype": "form",
            "labelWidth": 100,
            "labelAlign": "left",
            "layout": "form",
            "width": 650,
            "autoHeight": true,
            "padding": 10,
            "buttonAlign": "center",
            id: 'Telefonliste_SmsForm',
            "items": [{
                    "xtype": "displayfield",
                    "name": "kennung",
                    "width": 400,
                    cls: 'viewDisplayfield'
                },{
                    "xtype": "displayfield",
                    "name": "platz",
                    "width": 200,
                    cls: 'viewDisplayfield',
                    id: 'Telefonliste_SmsInformation'
                },{
                    xtype: 'textfield',
                    fieldLabel: 'Betreff',
                    width: 400,
                    name: 'betreff',
                    allowBlank: false,
                    helpText: 'Der Inhalt der Betreffzeile wird nicht &uuml;bermittelt'
                },{
                    "xtype": "textarea",
                    "fieldLabel": "Information",
                    "width": 400,
                    name: 'information',
                    allowBlank: false,
                    helpText: 'Information eingeben',
                    "height": 200,
                    enableKeyEvents: true,
                    listeners: {
                        keyup: function(field){
                            
                            var value = field.getValue();
                            
                            var anzahl = 160 - value.length;
                            
                            if(anzahl >= 0){
                                var info = 'noch ' + anzahl + ' Zeichen m&ouml;glich';
                                _AnzahlZeichen = false;
                            }
                            else{
                                var info = "zu viele Zeichen";
                                _AnzahlZeichen = true;
                            }
                                
                            
                            Ext.getCmp('Telefonliste_SmsInformation').setValue(info);
                            
                        }   
                    }
                }],
            fbar: {
                "xtype": "toolbar",
                "items": [{
                        "xtype": "tbseparator"
                    },{
                        "xtype": "button",
                        "text": "versenden",
                        cls: 'x-btn-text-icon',
                        icon: 'library/icons/button_ok.png',
                        handler: function(){
                            App.Telefonliste.Sms.sendSms();
                        }
                    },{
                        "xtype": "tbseparator"
                    }]
            }
        },
        
        sendSms: function(){
            App.setTrace('App.Telefonliste.Mail.sendSms');
            
            if(_AnzahlZeichen)
                return;
            
            var FormPanel = Ext.getCmp('Telefonliste_SmsForm');            
            
            FormPanel.getForm().submit({
                url: 'frontend/controler/app.php',
                method: 'Post',
                params: {
                    modul: 'telefonliste_sms',
                    aktion: 'senden',
                    sms: _SmsAdress,
                    user: _UserId
                },
                success: function(form,action){
                    FormPanel.getForm().reset();
                    App.information('SMS wurde versandt');
                    Ext.getCmp('Telefonliste_Sms').hide();
                    
                }
            });
            
            return;
        },
        
        buildWindow: new Ext.Window({
            title: 'SMS versenden',
            width: 655,
            x: 120,
            y: 85,
            iconCls: 'icon-telefonliste_sms',
            modal: true,
            id: 'Telefonliste_Sms',
            draggable: true,
            closeAction: 'hide',
            resizable: false,
            autoHeight: true,
            // height: 400,
            closeAction: 'hide',
            shadow: false
        })
        
        
    }

}();
