Ext.onReady(function () {
 if (!ww.q) ww.q={}
  Ext.apply(ww.q,  {
    pf: {
      manipulate: function () {
        ww.q.frmPart.width = 590;
//        ww.q.pForm = ww.q.pf.getUpdatePartForm('frmParticulars');
        ww.q.pForm.getForm().findField('FREmail').disable();
        ww.q.pf.mountFieldsValue();
      },
      mountFieldsValue: function () {
        oForm = ww.q.pForm.getForm();
        var objs = ww.ps||{}
        for (var f in objs) {
          var o = oForm.findField(f);
          if (o) {
            if (o.mountTextValue) o.mountTextValue(objs[f]);
              else o.setValue(objs[f]);
          }
        }
      },
      getUpdatePartForm: function (div) {
        var oReturn = new Ext.FormPanel({
          renderTo: div,
          width: 590, buttonAlign: 'left', 
          border: false, frame: false,
          defaultType: 'textfield',
          items: ww.q.frmPart,
          buttons: [{text: 'Save',
            handler: function () {
              var oForm = ww.q.pForm.getForm();
              if(oForm.isValidElseAlert()) {
                oForm.submit({
                  url: '/questionnaire/q_action.asp', params: {type: 'savepart', key: ww.key}, 
                  waitMsg: 'Saving...',
                  success: function(frm, oAction) {
                    if (oAction.result) {
                      var res = oAction.result||{};
                      ww.msg = res.msg;
                      if (res.msgCode=='saved') {
                        ww.msgbox.info('Done! Your particulars has been updated.', {
                          fn: function (btn) { window.location=ww.msg; }
                        });
                      } else {
                        ww.msgbox.err('Server busy: Please try again later!');
                      }
                    } else {
                      ww.msgbox.err('Unexpected error: Please try again later!');
                    }
                  }
                });
              }
            }
          },{text: 'Reset',
            handler: function () {
              ww.q.pf.mountFieldsValue();
            }
          }]
        }); 
        return oReturn;
      }
    },
    frmPart: new Ext.form.FieldSet({
      title: 'Personal Particulars and Show listings', autoHeight:true, defaults: {width: 575, border: false }, 
      items: [{
        layout: 'column', defaults: {layout: 'form', border: false, labelWidth: 90, 
          defaults: {allowBlank: false, style: 'margin-bottom: 1px;', xtype: 'textfield', itemCls: 'x-question-item'}
        }, 
        items: [{
          columnWidth:.45, items: { fieldLabel: 'First Name', name: 'FRFirstName', maxLength: 50 }
        },{
          columnWidth:.55, items: { fieldLabel: 'Family Name', name: 'FRLastName', maxLength: 50 }
        }]
      }, { 
        layout: 'form', border: false, labelWidth: 90, defaultType: 'textfield', 
        defaults: {allowBlank: false, itemCls: 'x-question-item'}, 
        items: [{
          fieldLabel: 'NRIC/FIN No.', name: 'FRNric', vtype: 'nricformat', width: 300, style: 'margin-bottom: 1px;'
        }]
      }, { 
        layout: 'form', border: false, labelWidth: 90, defaultType: 'textfield', 
        defaults: {allowBlank: false, itemCls: 'x-question-item'}, 
        items: [{
          fieldLabel: 'Email Address', name: 'FREmail', vtype: 'email', width: 300, style: 'margin-bottom: 1px;'
        }]
      }, {
        xtype: 'datecombofield', fieldLabel: 'Date of Birth', name: 'FRDOB', 
        minYear: new Date().format('Y') - 90, maxYear: new Date().format('Y') - 6, 
        itemDefaults: { itemCls: 'x-question-item' }
      }, { 
        layout: 'form', border: false, labelWidth: 90, defaultType: 'textfield', 
        defaults: {allowBlank: false, itemCls: 'x-question-item'}, 
        items: [{
          name: 'FRAddress', fieldLabel: 'Address', maxLength: 255, width: 400, style: 'margin-bottom: 1px;'
        }/*,{
          name: 'FROccupation', fieldLabel: 'Occupation', maxLength: 100, width: 300, style: 'margin-bottom: 1px;'
        }*/,{
          name: 'FROccupation', xtype: 'combo', fieldLabel: 'Designation', width: 300, style: 'margin-bottom: 1px;',editable: false, 
          emptyText:'Please select...', triggerAction: 'all', width: 210, store: [
            'Management', 'Executive', 'Support', 'Unemployed','Retiree','Home-maker','Full-time National Serviceman','Student'
          ]
        }
        ,{
          name: 'PRCPerformanceIDText', xtype: 'combo', fieldLabel: 'Show', editable: false,
          emptyText:'Please select...', triggerAction: 'all', width: 400, store: ww.perf[0]
        },{
          xtype: 'label', html: '<div style="padding-top: 5px;">Your information will be kept confidential and we may send you information about the scheme from time to time.</div>'
        }]
      }]
    })
  });
});
