// Add the additional 'advanced' VTypes
Ext.apply(Ext.form.VTypes, {
    password : function(val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },

    passwordText : 'Passwords do not match'
});




Ext.onReady(function() {
 Ext.QuickTips.init();
}); // eo function onReady
   
  function showPassReset(initOptions){
        var _self = this;
        var _settings = {};
        _settings.editorPassID = 0;
        
        Ext.apply(_settings, initOptions);

	function saveForm(){
		return PassPanel.getForm().submit({
			clientValidation: true,            
			url:'/ajax/staff/resetPass.cfm', 
			waitMsg:'Saving New Password...',
			params: {
			  pass_id: _settings.editorPassID
			},
			errorReader : new Ext.data.JsonReader({
				root:'errors',
				successProperty:'success'
			  }, ['id']),
			success: function(form, action) {
			  Ext.getCmp('pass_editor_'+_settings.editorPassID).close();
			  if(action.result.pass_id)
				_settings.editorPassID = action.result.pass_id;
			  return true;
			},
			failure: function(form, action) {
			  switch (action.failureType) {
				case Ext.form.Action.CLIENT_INVALID:
				  Ext.Msg.alert('Failure', 'Please verify all form fields are correct.');
				  break;
				case Ext.form.Action.CONNECT_FAILURE:
				  Ext.Msg.alert('Failure', 'Ajax communication failed');
				  break;
				case Ext.form.Action.SERVER_INVALID:
				default:
				  Ext.Msg.alert('Failure', action.result.msg);
			  }
			  return false;
			}
		});
	}
	
	
	 // application main entry point
	 
	 // create form panel with anchored fields
	   var PassPanel = new Ext.form.FormPanel({
		 id:'formanchor-form',
		 labelWidth:70,
		 bodyStyle:'padding:15px',
		 border:false,
		 frame:true,
		 defaults: {
			anchor: '90%',
			msgTarget: 'side',
      inputType: 'password'
		 },
     defaultType: 'textfield',
		 items:[{
					xtype:'textfield',
					fieldLabel: 'Password',
					name:'passtitle',
					id: 'pass_editor_title_'+_settings.editorPassID,
					allowBlank:false,
					maxLength: 70, 
					maxLengthText: 'Maximum keyword length is 70 characters'
				 },{
         fieldLabel: 'Confirm Password',
        name: 'pass-cfrm',
        vtype: 'password',
        initialPassField: 'pass_editor_title_'+_settings.editorPassID
         }],
         
		 buttons:[{
					text:'Save',
					handler: function(){ saveForm(); }
				  },{
					text:'Cancel',
					handler: function(){ win.close() }
			      }]
	   });
	  
	 // create and show window
	 var win = new Ext.Window({
	 id:'pass_editor_'+_settings.editorPassID
	 ,width:325
	 ,minWidth:325
	 ,height:160
	 ,minHeight:160
	 ,maxHeight:160
	 ,plain:true
	 ,title:'Password Reset'
	 ,layout:'fit'
	 ,border:false
	 ,closable:false
	 ,items:PassPanel
	 });
	 win.show();
	  
  }