Ext.onReady(function(){

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

    Ext.each(Ext.select('.contact-form-link', true), function(el) {

        el.on('click',function() {
      
            if(Ext.getCmp('contact-form-window'))
                Ext.getCmp('contact-form-window').destroy();
           
            var contact_form = new Ext.form.FormPanel({
                id:'contact-form-panel'
                ,formId:'contact-form'
                ,frame: true
                ,defaults: { width: 280, xtype:'textfield', labelSeparator:'' }
                ,items:[ 
                     { id:'email', fieldLabel:'email*', name:'email' }
                    ,{ id:'title',fieldLabel:'title', name:'title' }
                    ,{ id:'firstname',fieldLabel:'first name*', name:'firstname' }
                    ,{ id:'lastname',fieldLabel:'last name*', name:'lastname' }
                    ,{ id:'phone', fieldLabel:'phone', name:'phone' }
                    ,{ xtype:'panel',hideLabel:true, style:'padding: 10px 10px 0px 0px;font-size: 12px;',width:400,html:'message*'}
                    ,{ id:'message',name:'message',xtype:'textarea',hideLabel:true,width:384 }

                ]
                ,buttons: [
                    {
                     text: 'Send'
                    ,style:'margin-right:60px'
                    ,handler:function(){
                        form = Ext.getCmp('contact-form-panel').getForm();
                        form.submit({
                            url: '/contact/send'
                            ,method:'POST'
                            ,success:function(form,action) {  
                                Ext.getCmp('contact-form-window').hide();
                                Ext.Msg.show({title: 'Email Sent', msg: action.result.reason, width:400, height:340,buttons:Ext.Msg.OK});
                             }
                            ,failure:function(form,action) {  

                            }
                            ,waitMsg:'Processing ...'
                        });
            
                    }
               }]
            });
           
            var contact_form_win = new Ext.Window({
                    id          : 'contact-form-window'
                    ,layout      : 'fit'
                    ,width       : 480
                    ,height      : 300
                    ,closeAction :'hide'
                    ,plain       : true
                    ,title: ' &nbsp;&nbsp; CONTACT '
                    ,items       : [contact_form]
           
            });
           
            contact_form_win.show();
      

            Ext.getCmp('email').focus();
       });

    });

});

