Ext.onReady(function(){
	Ext.BLANK_IMAGE_URL = 'http://www.xavierboubert.fr/s.gif';

	Ext.QuickTips.init();
	
	Ext.form.Field.prototype.msgTarget = 'side';

	var connexionForm = new Ext.FormPanel({
        labelWidth: 100,
		id: 'connexionform',
        url: 'ajax.php',
        frame: true,
        title: 'Espace Clients - Connexion',
		style: 'margin: 0 auto; text-align: left;',
        bodyStyle: 'padding: 5px 5px 0;',
        width: 375,
        defaults: {width: 230},
        defaultType: 'textfield',

        items: [{
				xtype: 'label',
				html: '<div style="margin-bottom: 15px; border: 1px dashed #00b6e8; padding: 5px;">Vous n\'&ecirc;tes pas encore un de mes clients ? N\'h&eacute;sitez pas &agrave; <a href="http://www.xavierboubert.fr/contact">prendre contact avec moi</a> pour le devenir.</div>'
			}, {
                fieldLabel: 'Identifiant ',
                name: 'ident',
                allowBlank: false
            }, {
                fieldLabel: 'Mot de passe ',
                name: 'password',
				inputType: 'password',
                allowBlank: false
            }
        ],

        buttons: [{
            text: 'Connexion',
			handler: function () {
				if(connexionForm.getForm().isValid()) {
					connexionForm.getForm().submit({
						method: 'POST',
						waitTitle: 'Espace Clients - Connexion',
						waitMsg: 'Connexion en cours...',
						success: function(form, action) {
							var connexionform = Ext.get('connexionform') ;
							connexionform.fadeOut({
								duration:.5,
								remove: true,
								callback : function(){
									window.location.href = 'panel.php' ;
								}
							});
						},
						failure: function(form, action) {
							if(action.failureType == 'server') {
								var obj = Ext.util.JSON.decode(action.response.responseText) ;
								Ext.Msg.alert('Espace Clients', '<br /><span style="color:#970000;">'+obj.errors.reason+'</span><br />');
							}
							else {
								Ext.Msg.alert('Espace Clients', '<br /><span style="color:#970000;">'+ action.response.responseText+'</span><br />');
							}
						},
						params: { action: 'login' }
					});
				}
			}
        }]
    });

    connexionForm.render('connection');
}) ;
