Tp.ui.view.userCredential.forgotPassword = Class.create( {

	/*
	 * Default Constructor
	 */
	initialize : function(passwordConfig, handlers) {
		this.config = passwordConfig;
		this.handlers = handlers;
		Ext.QuickTips.init();
		this.initView();
	},
	initView : function() {

		var localObject = this;
		this.Panel = new Ext.FormPanel( {
			padding :'10px 10px 0 10px',
			cls :'userCredential',
			items : [ this.createEmail('Enter your email-Id/user-Id', 250, 25,
					"email", false, 'Email/User Name is required') ]
		});

		this.mainWindow = new Ext.Window( {
			layout :'anchor',
			width :410,
			height :120,
			modal :true,
			loadMask :true,
			maximizable :false,
			draggable :false,
			resizable :false,
			id :'forgotPassword',
			cls :'forgotPassword',
			title :'Forgot password',
			plain :true,

			items : [ this.Panel ],
			buttons : [ {
				text :'Cancel',
				handler : function() {
					localObject.mainWindow.destroy();
				}

			}, {
				text :'Submit',
				handler : function() {
					localObject.onDataEntered();

				}
			} ]

		});
		this.mainWindow.show();
		localObject.onDataCleared();
	},

	onDataCleared : function() {
		this.Panel.getForm().reset();
	},

	onDataEntered : function() {
		if (!this.Panel.getForm().isValid()) {

			return;
		}
		var localObject = this;
		
		var forgotPasswordObj = {

			userName :this.Panel.getForm().findField("email").getValue()
		};

		Tp.service.user.UserService.forgotPassword( {
			forgotPasswordObj :forgotPasswordObj
		}, {

			onBusinessFailure : function() {
				// this.mainWindow.destroy();
			Ext.MessageBox.show( {
				title :'Registration',
				msg :"E-mail Id does not exist",
				buttons :Ext.MessageBox.OK,
				animEl :'mb9',
				icon :Ext.MessageBox.INFO
			});
		},
		onSuccess : function() {
			localObject.closeView();
			Ext.MessageBox.show( {
				title :'Registration',
				msg :"Your user credential has been sent to your provided email id",
				buttons :Ext.MessageBox.OK,
				animEl :'mb9',
				icon :Ext.MessageBox.INFO
			});

		}
		});
	},

	closeView : function() {

		this.mainWindow.destroy();
	},

	createEmail : function(label, labelWidth, labelHeight, id, allowBlank,
			blankText) {
		var fieldLabel = label;
		if (!allowBlank) {
			fieldLabel = '<span class="mandatory">*</span>' + label;
		}

		return textVar = new Ext.form.TextField( {
			id :id,
			vtype :'email',
			allowBlank :allowBlank,
			maxLength :50,
			blankText :blankText,
			msgTarget :'side',
			fieldLabel :fieldLabel,
			labelSeparator :':',
			width :labelWidth,
			height :labelHeight
		});

	}
});
