Ext.namespace("Optima");
Optima.Contact = function() {
    var pane = null;
    var msgBox = null;
      var init = function() {
         pane = new Ext.form.FormPanel({
            renderTo : "contact",
            labelWidth:150,
            border : false,
            items : [
               {
                  xtype:"textfield",
                  name : "nom",
                  fieldLabel : "Nom, Prénom *",
                  allowBlank : false
               },
               {
                  xtype:"textfield",
                  fieldLabel : "Email (pour répondre)*",
                  vtype : "email",
                  vtypeText : "Email invalide",
                  allowBlank : false,
                  name : "mail"
               },
               {
                  xtype:"textfield",
                  fieldLabel : "Objet *",
                  allowBlank : false,
                  name : "objet"
               },
               {
                  xtype:"textarea",
                  fieldLabel : "Message *",
                  allowBlank : false,
                  width : 400,
                  height : 200,
                  name : "message"
               }
            ],
            buttons : [
               {text : 'valider',handler : function() {
                     if (!pane.getForm().isValid()){
                        Ext.Msg.alert("Information","Il manque des informations");
                        return;
                     }
                     Ext.MessageBox.wait("Envoi de vos données","Envoi en cours");  
                     pane.getForm().submit({
                        url : './service/contact.php',
                        method : 'POST',
                        success : function() {
                           Ext.Msg.alert("Information","Envoi des données réussit!");
                           pane.getForm().reset();
                        },
                        failure : function(form,action) {
                           Ext.Msg.alert("Information","Erreur lors de l'envoi du mail");
                           
                        }
                     });
                  },scope : this},
               {text:'annuler',handler : function() {
                     pane.getForm().reset();
                  },scope : this
               }
            ]
         });
    
    }
    
    return {
        init : init
    }
}();
Ext.onReady(function(){
	//Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
        
	Optima.Contact.init();

});