Ext.namespace('brodos.login'); 
brodos.login.repeat = function (service, hash, cookie, successCallback, failureCallback)
                            {
                                if (cookie == undefined || parseInt(cookie) != 1)
                                {
                                    cookie = 0;
                                }
                                
                                if (hash.length < 1)
                                {
                                    failureCallback();
                                }
                                else
                                {
                                    Ext.Ajax.request(
                                                     {
                                                       url:     service,
                                                       success: successCallback,
                                                       failure: failureCallback,
                                                       params:  { 
                                                                    Hash: hash,
                                                                    Mode: 'Relogin', 
                                                                    Cookie: cookie 
                                                                }
                                                     }
                                                    );
                                }
                            };

brodos.login.execute = function (service, identifer, password, cookie, successCallback, failureCallback)
                            {
                                if (cookie == undefined || parseInt(cookie) != 1)
                                {
                                    cookie = 0;
                                }
                                
                                if (identifer.length < 1 || password.lenth < 1)
                                {
                                    failureCallback();
                                }
                                else
                                {
                                    Ext.Ajax.request(
                                                     {
                                                       url:     service,
                                                       success: successCallback,
                                                       failure: failureCallback,
                                                       params:  { 
                                                                    Id: identifer, 
                                                                    Password: password, 
                                                                    Mode: 'Login', 
                                                                    Cookie: cookie 
                                                                }
                                                     }
                                                    );
                                }
                            };   

brodos.login.dialog = function (tdo, service, identifer, cookie, successCallback, failureCallback, beforeExecuteCallback)
                           {
                                var IdentiferField = new Ext.form.TextField(
                                                                       {    
                                                                          fieldLabel: tdo._IDF_USER,
                                                                          width:      150,
                                                                          xtype:      'textfield',
                                                                          id:         'idfSystemIdentifer',
                                                                          xtype:      'textfield',
                                                                          allowBlank: false,
                                                                          listeners:  { 
                                                                                         'specialkey': LoginExecuter_OnEnter
                                                                                      }                                              
                                                                        }
                                                                      );
                                                                      
                                                                      
                                var PasswordField = new Ext.form.TextField(
                                                                      {
                                                                        fieldLabel: tdo._IDF_PASSWORD,
                                                                        width:      150,
                                                                        xtype:      'textfield',
                                                                        inputType:  'password',
                                                                        id:         'idfSystemPassword',
                                                                        allowBlank: false,
                                                                        listeners:  { 
                                                                                        'specialkey': LoginExecuter_OnEnter 
                                                                                    }
                                                                       }
                                                                      );
                                                                      
                                                                      
                                 var LoginButton = new Ext.Button({
                                                                     text:      tdo._IDF_LOGIN_BUTTON,
                                                                     id:        'idfSystemLoginButton',
                                                                     autoShow:  true,
                                                                     listeners: { 
                                                                                    'click': LoginExecuter
                                                                                }
                                                                  });
                                                                  
                                 var CancelButton = new Ext.Button({
                                                                     text:      tdo._IDF_CANCEL_BUTTON,
                                                                     id:        'idfSystemCancelButton',
                                                                     autoShow:  true,
                                                                     listeners: { 
                                                                                    'click': function () 
                                                                                             {
                                                                                                idfLoginWindow.close();
                                                                                             }
                                                                                }
                                                                  });
                                                                  
                                function LoginExecuter_OnEnter(Sender, EventArgs)
                                {
                                    if (EventArgs.getCharCode() == EventArgs.ENTER)
                                    {
                                         LoginExecuter();
                                    }
                                }
                                                                  
                                function LoginExecuter(executeCallback)
                                {
                                    if (IdentiferField.isValid() && PasswordField.isValid())
                                    {
                                        if (typeof beforeExecuteCallback == 'function')
                                        {
                                            beforeExecuteCallback();
                                        }
                                        brodos.login.execute(service, IdentiferField.getValue(), PasswordField.getValue(), cookie, successCallback, failureCallback);
                                    }
                                }
                                                                      

                                 var idfSystemLoginPanel = new Ext.FormPanel(
                                                                            {
                                                                                labelWidth: 75, 
                                                                                frame:      true,
                                                                                region:     'center',
                                                                                bodyStyle:  'padding: 5px 5px 0',
                                                                                width:       270,
                                                                                items: [IdentiferField, PasswordField],
                                                                                buttons: [LoginButton, CancelButton]
                                                                            }
                                                                        );
                                                                        
                                if (identifer != undefined && identifer != null && identifer.length > 0)
                                {
                                    IdentiferField.setValue(identifer);
                                    IdentiferField.setDisabled(true);
                                }
                                
                                PasswordField.setValue('');
                                PasswordField.reset();

                                var idfLoginWindow = new Ext.Window(
                                                                    {    
                                                                        title:      tdo._IDF_LOGIN_TITLE,
                                                                        closable:   true,
                                                                        width:      270,
                                                                        height:     140,
                                                                        modal:      true,
                                                                        closable:   true,
                                                                        resizable:  false,
                                                                        draggable:  false,
                                                                        layout:     'fit',
                                                                        items:      [idfSystemLoginPanel]
                                                                    }
                                                                  ); 
                                return idfLoginWindow;
                            }