﻿
    function removeLabel(t){
        var element = Ext.get(t);
        if(element) element.removeClass('label');
        return true;
    }
    Ext.onReady(function (){
    Ext.ns('TMOSS.Login');
    Ext.ns('Master','Browser','Content');

Content.Init = function(){}

    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    

    var input = Ext.get('username');
    if(input) if(input.getValue().length==0) input.addClass('label');
    input = Ext.get('password');
    if(input) if(input.getValue().length==0) input.addClass('label');
    input = Ext.get('la_premise');
    if(input) if(input.getValue().length==0) input.addClass('label');
    input = Ext.get('la_postcode');
    if(input) if(input.getValue().length==0) input.addClass('label');

    TMOSS.Login.LoginPanel = new Ext.Panel({
        cls: 'loginPanel',
        renderTo: 'login',
        border: false,
        height: 35,
        items: [
            {
                id: 'usernamePanel',
                width: 140,
                cls: 'loginbox',
                items: [{
                    xtype: 'textfield',
                    id: 'username',
                    name: 'username',
                    stateful: true,
                    stateEvents: ['valid', 'blur'],
                    emptyText: ' ',
                    emptyClass: 'usernameTextbox',
                    getState: function () {
                        return { value: this.getValue() };
                    },
                    width: 140,
                    enableKeyEvents: true,
                    listeners: {
                        keydown: function (tf, e) {
                            if (e.keyCode == 13) Ext.getCmp('buttonOk').fireEvent('click', null);
                        }
                    }
                }]
            },
            {
                id: 'passwordPanel',
                width: 170,
                cls: 'loginbox',
                items: [{
                    xtype: 'textfield',
                    id: 'password',
                    name: 'password',
                    inputType: 'password',
                    emptyText: ' ',
                    emptyClass: 'passwordTextbox',
                    width: 170,
                    enableKeyEvents: true,
                    listeners: {
                        keydown: function (tf, e) {
                            if (e.keyCode == 13) Ext.getCmp('buttonOk').fireEvent('click', null);
                        }
                    }
                }]
            },
            {
                id: 'okPanel',
                cls: 'loginbutton',
                width: 25,
                items: [
                    {
                        xtype: 'button',
                        id: 'buttonOk',
                        buttonId: 'buttonOkHTML',
                        iconCls: 'loginbuttonOk',
                        width: 22,
                        listeners: {
                            click: function(){
                                Ext.get('hdnusername').dom.value = Ext.getCmp('username').getValue();
                                Ext.get('hdnpassword').dom.value = Ext.getCmp('password').getValue(); 
                                Ext.get('loginContainer').dom.submit();
                            }
                        }
                    }
                ]
            },
            {
                id: 'cancelPanel',
                cls: 'loginbutton',
                width: 25,
                hidden: false,
                disabled: false,
                items: [
                    {
                        xtype: 'button',
                        id: 'buttonCancel',
                        iconCls: 'loginbuttonCancel',
                        listeners: {
                            click: function(){
                                Ext.getCmp('password').setValue('');
                            }
                        }
                    }
                ]
            }
        ]
    });

    Ext.getCmp('username').getValue()==''?Ext.getCmp('username').focus():Ext.getCmp('password').focus(); 
});
