
Ext.onReady(function(){

    var cwin ;

    var form = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelAlign: 'right',
        url: '/contact/submit',
        defaults: {
            xtype: 'textfield',
            labelSeparator:'',
            labelAlign: 'right',

            anchor: '95%'
        },

        items: [ 
{
            fieldLabel: 'First Name*', name: 'firstname', allowBlank:false
        },{ 
            fieldLabel: 'Last Name*', name: 'lastname', allowBlank:false
        },{ 
            fieldLabel: 'Company', name: 'company'
        },{ 
            fieldLabel: 'Address', name: 'address'
        },{ 
            fieldLabel: 'City', name: 'city'
        },{ 
            fieldLabel: 'State', name: 'state' 
        },{
            fieldLabel: 'Zip/PostalCode', name: 'zip'
        },{
            fieldLabel: 'Email*', name: 'email', vtype:'email', allowBlank:false
        },{ 
            fieldLabel: 'Phone', name: 'phone'
        },{ 
            xtype: 'label', html:'How did you find us'
        },{ 
            hideLabel:true, fieldLabel: 'How did you find us', name: 'how', xtype:'combo',
            mode: 'local',
            triggerAction: 'all',
            store: new Ext.data.ArrayStore({
                fields: [  'how' ],
                data: [ ['friend'], ['web search'], ['radio'], ['magazine'], ['trade show'], ['other'] ]
            }),
            valueField: 'how',
            displayField: 'how'

        },{ 
            fieldLabel: ' ', hideLabel: true, width: 405, height:200, name: 'message', xtype:'textarea'
        }




        ]
    });


      Ext.each(Ext.select('.contact-link',true), function(item){
          // create the window on the first click and reuse on subsequent clicks
     
          item.on('click',function(){
    
            if( Ext.get('home-flash') ){ 
                Ext.get('home-flash').update('<img id="home-bling" style="visibility:visible" alt="" src="/assets/flash/home/images/1.jpg" />');
            }
               if(!cwin){
                   cwin = new Ext.Window({
                       layout:'fit',
                       width:550,
                       autoHeight: true,
                       height:'auto',
                       clmseAction:'hide',
                       plain: true,
                       items: form,
        
                       buttons: [{
                           text:'send',
                           handler: function(){
                            form.getForm().submit({
                                url:'/contact/submit',
                                success:function(action,result){
                                    cwin.hide();
                                    Ext.Msg.alert('Success', 'Your message has been sent.');                     

                                }, failure:function(action,result){
                                    if(action.failureType=='clientValidation')
                                        Ext.Msg.alert('Failure', 'Please complete all required fields');                     
                                    else 
                                        Ext.Msg.alert('Failure', 'errors on form');

                                }


                            });

                           }
                       },{
                           text: 'close',
                           handler: function(){
                               cwin.hide();
                           }
                       }]
                   });
     
     
     
               }
                cwin.show(this);
     
          });
     
      });


});






