//validation vtype
var changePasswordUrl = siteUrl + 'changePassword';
Ext.apply(Ext.form.VTypes, {

passwordStrength : function(val) {
	
		if(val.length < 6){
			 return false;
		}else{
			return true;
		}
},

passwordStrengthText : 'Password must be longer than 6' 
});
Ext.apply(Ext.form.VTypes, {

password : function(val, field) {
	if (field.initialPassField) {
		var login = Ext.getCmp(field.initialPassField);
		return (val == login.getValue());
	}
	return true;
},

passwordText : 'Passwords do not match' 
});



function changePassword(){
    var co = Ext.get('mainGrid');
        if(co != null){
            co.remove();
        }
    Ext.QuickTips.init();

    var cp = new Ext.form.FormPanel({
        
				defaultType:'textfield',
				Frame: true,
        title:'Change User Password',
        labelAlign: 'right',
        labelWidth: 130,
        width:700,
        height:215,
        id : 'mainGrid',
        monitorValid:true,
				modal: true,
				bodyStyle: 'padding: 10px 10px 0 20px;',
				padding:200,
				url:changePasswordUrl,
        
        items:[
        {
            fieldLabel:'Old Password',
            name:'oldPassword',
            inputType: 'password',
            width:190,
            allowBlank:false
        },

        {
            fieldLabel:'New Password',
            name:'newPassword',
            inputType: 'password',
            vtype:'passwordStrength',
            width:190,
            id: 'pass',
            allowBlank:false
        },

        {
            fieldLabel:'Confirm New Password',
            name:'password1',
            inputType: 'password',
						width:190,
            vtype:'password',
            initialPassField: 'pass',
            allowBlank:false
        }
        ],

        buttons:[{
            text:'Submit',
            handler:function(){
                cp.getForm().submit({
                    method:'get',
                    waitTitle:'please wait.....',
                    waitMsg:'Send data...',

                    success:function(){
                        Ext.Msg.alert('Status', 'Change Password Succeeded!');
                        cp.getForm().reset();
                    },

                    failure:function(form, action){
                        if(action.failureType == 'server'){
                        	  obj = Ext.util.JSON.decode(action.response.responseText);
                            Ext.Msg.alert('Change Password  Failed!', obj.errors.reason);
                        } else {
                            Ext.Msg.alert('Change Password  Failed!', 'Passwords do not match or too short');
                        }
                        cp.getForm().reset();
                    }
                });
            }
        },

        {
            text: 'Reset',
            handler: function(){
                cp.getForm().reset();
            }
        }]
    });
    
    cp.render('gridCourses');

}