Ext.SSL_SECURE_URL="../../../resources/images/default/s.gif"; 
Ext.BLANK_IMAGE_URL="../../../resources/images/default/s.gif";
var LoginLabels = null ;
var BrowserLangage = null ;
Ext.onReady(function() {
    BrowserLangage = $get('BrowserLangage').innerHTML ;
       
    if (BrowserLangage == '' )
    {
        Ext.Ajax.request({
           url: location.href,
           params:{'BrowserLangage': ( navigator.appName == 'Microsoft Internet Explorer' ? navigator.browserLanguage:  navigator.language)},
           success: function (response)
            {
                location.href = location.href ;		                            
            },
           failure: function (response){}
        });
     }
     else
     {
        WSLogin.GetLoginLabels( BrowserLangage ,ShowLoginFormSucces,ShowLoginFormFailure);	
     } 
     
});

function ShowLoginFormFailure(response){
}
function ShowLoginFormSucces(response){	
    LoginLabels = response ;
	var logoPanel = new Ext.Panel({
		baseCls: 'x-plain',
		id: 'login-logo',
        region: 'north',
        height:100
	});
    function OnSubmit(){
        if( formPanel.getForm().isValid())
        {
            fp.getEl().mask(LoginLabels.Lbl_Verification_Login);// Checking of your Login and Password in progress ...
            formPanel.getForm().submit({
                reset: false,
	            params: {
    	            
	            },
                success : function(f, a){
                    if(a && a.result){
                        window.location = a.result.url;
                    }
                },
                failure : function(f, a){
                    fp.getEl().unmask();
                    Ext.Msg.alert(response.Lbl_Erreur,response.Lbl_Erreur_Connexion);
                    formPanel.getForm().reset();

                }
		    });
		}
	} ;
	var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        baseParams: {module: 'login'},
        defaults: {width: 200},
        defaultType: 'textfield',
        frame: false,
        height: 100,
        id: 'login-form',
        labelWidth: 115,
        region: 'center',
        url:location.href,
        items: [
            {
                xtype :'label',
                text:'',//LoginLabels.Lbl_SessionTimeOut,
                cls:'_SessionTimeOut'
            },{
                fieldLabel: LoginLabels.Lbl_Utilisateur,
                name: 'login',
                id:'login',
               //emptyText : LoginLabels.Lbl_Utilisateur,
                allowBlank: false
            },{
                fieldLabel: LoginLabels.Lbl_Mot_Passe,
                inputType: 'password',
                name: 'password',
                //emptyText : LoginLabels.Lbl_Mot_Passe,
                allowBlank: false
            }
        ]
	});
		
    var fp = new Ext.Panel({
        frame: true,
        labelWidth: 150,
        width: 401,
		height: 257,
		plain: true,
		title: LoginLabels.Lbl_Authentification, 
        keys: {
        	key: [13], 
	        scope:this,
	        handler: function(){
               OnSubmit();
		   }
        },
        renderTo:'_login_window',
        layout: 'border',        
        items: [
        	logoPanel,
        	formPanel,
        	{
        	    region: 'south',
                bbar: new Ext.Toolbar({
                    items:[
                    new Ext.Toolbar.Button(
			            {
				            tooltip:LoginLabels.Lbl_French ,
				            minWidth: 16,
				            iconCls:'iFR',
				            handler: function(){
                              Ext.Ajax.request({
                                   url: location.href,
                                   params:{'BrowserLangage':'FR'},
                                   success: function (response)
		                            {
		                                location.href = location.href;		                            
		                            },
                                   failure: function (response){}
                               });
				            }
			            }
		            ),
		            new Ext.Toolbar.Button(
			            {
				            tooltip:LoginLabels.Lbl_English ,
				            minWidth: 16,
				            iconCls:'iEN',
				            handler: function(){
                               Ext.Ajax.request({
                                   url: location.href,
                                   params:{'BrowserLangage':'EN'},
                                   success: function (response)
		                            {
		                                location.href = location.href;		                            
		                            },
                                   failure: function (response){}
                               });
				            }
			            }
		            ),
                    '->',
		            new Ext.Toolbar.Button(
			            {
				            text:'Login',
				            minWidth: 100,
				            iconCls:'ilogin',
				            handler: function(){
                               OnSubmit();
				            }
			            }
		            ),
		            '-',
		            new Ext.Toolbar.Button(
			            {
				            text:LoginLabels.Lbl_Mot_Passe_Oublie,
				            minWidth: 100,
				            iconCls:'ipassword',
				            handler: function(){
				               ForgetYourPassword();
				            }
			            }
		            )
		            ]
                })
        	}
        ]
    });
};

function ForgetYourPassword(){	
        if (Ext.getCmp('login').getValue() != "" )
        {
            Ext.getCmp('login-form').getEl().mask(LoginLabels.Msg_Recovering_Pass);
            Ext.Ajax.request({
               url: location.href,
               params:{'uswe_username':Ext.getCmp('login').getValue()},
               success: function (response)
                {
                    var responseText = eval(response.responseText)[0] ;
                    if(responseText.success == 'true')
                        Ext.Msg.alert('Info',LoginLabels.Msg_Recover_Pass_Success);
                    else if(responseText.errors =='NotFound')
                        Ext.Msg.alert('Info',LoginLabels.Lbl_Login_Incorrecte);
                    else
                        Ext.Msg.alert('Info', LoginLabels.Msg_Recover_Pass_Failure );
                    Ext.getCmp('login-form').getEl().unmask();
                },
               failure: function (response){
                    Ext.Msg.alert(LoginLabels.Lbl_Erreur,LoginLabels.Msg_Recover_Pass_Failure);
                    Ext.getCmp('login-form').getEl().unmask();
               }
            });
            
        }
        else{
            Ext.Msg.alert(LoginLabels.Lbl_Erreur,LoginLabels.Msg_Recover_Pass_Failure);
        }
}

function ShowTermeOfUse(){
    
   var win = new Ext.Window({
     width: 500
     ,height:600
     ,minWidth: 300
     ,minHeight: 200
     ,autoScroll:true
     ,plain:true
     ,frame : true
     ,bodyStyle:'padding:5px;'
     ,autoLoad:{
        url: 'TermeOfUse-Fr.aspx'
     }
     ,iconCls:'privacy-policy'
     ,title: LoginLabels.Lbl_TermesOfUse
     ,listeners:{
        show:function() {
             this.loadMask = new Ext.LoadMask(this.body, {
                msg:'Loading. Please wait...'
            });
        }
    }
 });
 win.show();
 
}
function ShowPrivacyPolicy(){
      
}
