var win;
var forgetPassWin;
function doLogin() {
  Ext.QuickTips.init();

    var getPassPanel = new Ext.FormPanel({
        id:'passform',
        frame: false,
        title:'Oubli du mot de passe',
        labelAlign: 'right',
        bodyStyle:"padding-top:20px",
        labelWidth: 120,
        waitMsgTarget: true,
        errorReader : new Ext.data.JsonReader(
        {
        root:"errors",
        successProperty:"success"
        },
        ['id', 'msg'])
        ,
              items: [new Ext.form.FieldSet({
                height:100,
                defaultType: 'textfield',
                border:false,
                items: [{
                        fieldLabel: 'Email',
                        name: 'email',
                        width:240
                    }
                    ]
                })]
                });

    var fs = new Ext.FormPanel({
        id:'loginform',
        frame: false,
        title:'Connection',
        labelAlign: 'right',
        bodyStyle:"padding-top:20px",
        labelWidth: 120,
reader : new Ext.data.JsonReader(
{
root:"bill",
totalProperty:"total",
successProperty:"success"
}),

errorReader : new Ext.data.JsonReader(
{
root:"errors",
successProperty:"success"
},
['id', 'msg'])
,
        waitMsgTarget: true,
              items: [new Ext.form.FieldSet({
                height:100,
                defaultType: 'textfield',
                border:false,
                items: [{
                        fieldLabel: 'Email ',
                        name: 'username',
                        width:240
                    },
                    {
                        fieldLabel: 'Mot de passe ',
                        name: 'password',
                        width:240,
                        inputType: 'password'
                    }
                    ]
                })]
                });
                if(!forgetPassWin){
            forgetPassWin = new Ext.Window({
                layout:'fit',
                width:500,
                height:220,
                closeAction:'hide',
                plain: true,
                modal:true,
                items: [getPassPanel]

,

                buttons: [

                {
                    text:'Envoyer mon mot de passe',
                    handler: function(){
                           getPassPanel.getForm().submit({url:'http://www.heig.org/login/ajaxsendpass', waitMsg:'Connection en cours...', success: function() {
                             Ext.MessageBox.alert('Information', 'Un email permettant de changer votre mot de passe vient de vous être envoyé.',function() {});
                             forgetPassWin.hide();
                             }});


                    }
                },{
                    text: 'Annuler',
                    handler: function(){
                        forgetPassWin.hide();

                    }
                }]
            });
        }
        getPassPanel.getForm().on({
	actioncomplete: function( form, action ) {

        forgetPassWin.hide();
	}
         });


        if(!win){
            win = new Ext.Window({
                layout:'fit',
                width:500,
                height:220,
                closeAction:'hide',
                plain: true,
                modal:true,
                items: [fs]

,

                buttons: [
                {
                   
                    text:'J\'ai perdu mon mot de passe',
                    handler: function(){
                        win.hide();
                        forgetPassWin.show();
                    }
                },
                {
                    text:'Connection',
                    handler: function(){
                          fs.getForm().submit({url:'http://www.heig.org/login/checklogin', waitMsg:'Connection en cours...', success: function() {
                                //Ext.get("languages").load("http://www.heig.org/login/ajaxloggedmenu");

                          }});


                    }
                },{
                    text: 'Annuler',
                    handler: function(){
                        win.hide();

                    }
                }]
            });
        }
        fs.getForm().on({
	actioncomplete: function( form, action ) {
	window.location.reload(true);

	}
         });

        win.show();
var nav = new Ext.KeyNav("loginform", {
    "enter" : function(e){
                          fs.getForm().submit({url:'http://www.heig.org/login/checklogin', waitMsg:'Connection en cours...', success: function() {
                                //Ext.get("languages").load("http://www.heig.org/login/ajaxloggedmenu");

                          }});
    },

    scope : this
});
}
