App.Profile = function() {
	var User;
		
	return {
		init: function() {
			
		}
		
		, onActionFailed: function(form, action) {
			var m = (action.response) ? Ext.decode(action.response.responseText).errorMessage : 'Erforderliche Felder sind nicht oder unkorrekt ausgefüllt';
			if (typeof m == 'object') {
				var n = '';
				for (var line in m) n += '<div>' + m[line] + '</div>';
				m = n;
			}
			App.info.msg('Warnung', 'Es sind Fehler aufgetreten:<p style="margin-top:.5em;"><code>' + m + '</code></p>', 3);
		}
		
		, register: function() {
			if (App.User.getIsAuthenticated()) {
				App.info.msg('Hinweis', 'Sie sind bereits eingeloggt. Wenn Sie sich mit anderen Benutzerdaten neu anmelden möchten, müssen Sie sich vorher ausloggen.');
				return;
			}
			this.registerPanel = this.registerPanel || this._createRegisterPanel();
			
			Ext.get('register-form-foot').update('');
			Ext.get('register-form-foot').setDisplayed('none');
			// Ext.get('register-form-body').slideIn();
			App.getLayout().getRegion('center').showPanel(this.registerPanel);
		}
		
		, onRegisterComplete: function(form, action) {
			if (action.type != 'submit') return;
			var tpl = '<div class="x-form">' +
				'<div class="x-form-ct">' +
				'<fieldset>' +
				'	<legend>Diese Daten wurden gespeichert:</legend>' +
				'	<div class="x-form-ct x-form-column" style="width: 290px;">' +
				'		<div class="x-form-item"><label style="width:80px;">Login:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Login}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Kennwort:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">********</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Firma:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Company}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Kostenstelle:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{DepartmentNo}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">E-Mail:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Email}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Newsletter:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Newsletter:deBoolean}</div></div><div class="x-form-clear-left"></div>' +
				'	</div>' +
				'	<div class="x-form-ct x-form-column" style="width: 290px;">' +
				'		<div class="x-form-item"><label style="width:80px;">Anrede:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Salutation}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Name:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Firstname} {Lastname}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Anschrift:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Address:nl2br}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">PLZ/Ort:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Zip}&#160;{City}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Telefon:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Phone}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Fax:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Fax}</div></div><div class="x-form-clear-left"></div><div class="x-form-clear-left"></div>' +
				'	</div>' +
				'</fieldset>' +
				'</div></div>';
			tpl = new Ext.Template(tpl).apply(Ext.decode(action.response.responseText).data);
			Ext.get('register-form-foot').update(tpl);
			Ext.get('register-form-body').slideOut('t', { useDisplay: true, callback: function() { Ext.get('register-form-foot').slideIn(); } });
			App.User.login.defer(5000, App.User, [form, action]);
		}
		
		, edit: function() {
			if (! App.User.getIsAuthenticated()) return;
			this.editPanel = this.editPanel || this._createEditPanel();
						
			if (typeof App.nextStep == 'function') {
				this.editPanel.form.buttons[0].setText('<b>Fortfahren</b>');
			} else {
				this.editPanel.form.buttons[0].setText('Speichern');
			};
			
			this.editPanel.form.reset();
			Ext.get('profile-edit-form-body').setDisplayed(true);
			
			this.editPanel.form.load({method: 'POST', url: 'shop.php', params: { realm: 'user', action: 'getIdentity' } });			
			Ext.get('profile-edit-form-foot').update('');
			Ext.get('profile-edit-form-foot').setDisplayed('none');
			
			App.getLayout().getRegion('center').showPanel(this.editPanel);
		}
		
		, onEditComplete: function(form, action) {
			if (action.type != 'submit') return;
			// catch possible errors
			var r = Ext.decode(action.response.responseText);
			if (! r.success){
				if(r.errorMessage){
					var m = r.errorMessage;
					if (typeof m == 'object') {
						var n = '';
						for (var line in m) n += '<div>' + m[line] + '</div>';
						m = n;
					}
					App.info.msg('Warnung', 'Es sind Fehler aufgetreten:<p style="margin-top:.5em;"><code>' + m + '</code></p>', 3);			
				}
				App.info.msg('Warnung', 'Ein nicht näher bezeichneter Fehler ist aufgetreten');
				return;
			}
			
			if (typeof App.nextStep == 'function') {
				var fn = App.nextStep;
				App.nextStep = null;
				fn.call();
				return;
			}
							
			var tpl = '<div class="x-form">' +
				'<div class="x-form-ct">' +
				'<fieldset>' +
				'	<legend>Diese Daten wurden gespeichert:</legend>' +
				'	<div class="x-form-ct x-form-column" style="width: 290px;">' +
				'		<div class="x-form-item"><label style="width:80px;">Login:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Login}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Kennwort:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">********</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Firma:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Company}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Kostenstelle:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{DepartmentNo}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">E-Mail:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Email}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Newsletter:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Newsletter:deBoolean}</div></div><div class="x-form-clear-left"></div>' +
				'	</div>' +
				'	<div class="x-form-ct x-form-column" style="width: 290px;">' +
				'		<div class="x-form-item"><label style="width:80px;">Anrede:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Salutation}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Name:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Firstname} {Lastname}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Anschrift:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Address:nl2br}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">PLZ/Ort:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Zip}&#160;{City}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Telefon:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Phone}</div></div><div class="x-form-clear-left"></div>' +
				'		<div class="x-form-item"><label style="width:80px;">Fax:</label><div class="x-form-element" style="padding-left: 85px; padding-top:3px;">{Fax}</div></div><div class="x-form-clear-left"></div><div class="x-form-clear-left"></div>' +
				'	</div>' +
				'</fieldset>' +
				'</div></div>';
			tpl = new Ext.Template(tpl).apply(Ext.decode(action.response.responseText).data);
			// Ext.get('profile-edit-form-body').setDisplayed('none');
			Ext.get('profile-edit-form-body').setDisplayed('none');
			Ext.get('profile-edit-form-foot').update(tpl);
			Ext.get('profile-edit-form-foot').show();
			// Ext.get('profile-edit-form-body').slideOut('t', { useDisplay: true, callback: function() { Ext.get('profile-edit-form-foot').slideIn() } });

		}
		
		, changePassword: function() {
			if (! App.User.getIsAuthenticated()) return;
			this.changePasswordPanel = this.changePasswordPanel || this._createChangePasswordPanel();
			this.changePasswordPanel.form.reset();
			App.getLayout().getRegion('center').showPanel(this.changePasswordPanel);
			// Ext.get('change-password-form-body').slideIn();
		}
		
		, onChangePasswordComplete: function(form, action) {
			if (! action.type == 'submit') return;
			App.info.msg('Nachricht', 'Das Kennwort wurde geändert.', 3);
			App.home();
		}
		
		, requestPassword: function() {
			if (App.User.getIsAuthenticated()) return;
			this.requestPasswordPanel = this.requestPasswordPanel || this._createRequestPasswordPanel();
			App.getLayout().getRegion('center').showPanel(this.requestPasswordPanel);
			// Ext.get('request-password-form-body').slideIn();
		}

		, onRequestPasswordComplete: function(form, action) {
			App.info.msg('Nachricht', 'Das Kennwort wurde an die bei uns gespeicherte Mailadresse verschickt.', 5);
			App.home();
		}

		, subscribe: function() {	
			this.subscriptionPanel = this.subscriptionPanel || this._createSubscriptionPanel();
			this.subscriptionPanel.form.reset();
			App.getLayout().getRegion('center').showPanel(this.subscriptionPanel);
			// Ext.get('subscription-form-body').slideIn();
		}
		
		, onSubscriptionComplete: function() {
			App.info.msg('Info','Sie wurden für den Erhalt des Newsletters registriert', 5);
			App.home();
		}
		
		, unsubscribe: function() {
			this.unsubscriptionPanel = this.unsubscriptionPanel || this._createUnsubscriptionPanel();
			this.unsubscriptionPanel.form.reset();
			App.getLayout().getRegion('center').showPanel(this.unsubscriptionPanel);
		}
		
		, unsubscribeInfo: function() {
			this.unsubscriptionPanel = this.unsubscriptionPanel || this._createUnsubscriptionPanel();
			this.unsubscriptionPanel.form.reset();
			App.getLayout().getRegion('center').showPanel(this.unsubscriptionPanel);
		}
		
		, onUnsubscriptionComplete: function() {
			App.info.msg('Info', 'Der Versand an Ihre Adresse wurde deaktiviert', 5);
			App.home();
		}
		
		, feedback: function() {
			this.feedbackPanel = this.feedbackPanel || this._createFeedbackPanel();
			App.getLayout().getRegion('center').showPanel(this.feedbackPanel);
			// Ext.get('feedback-form-body').slideIn();
		}
		
		, onFeedbackComplete: function(form, action) {
			App.info.msg('Nachricht', 'Ihre Mitteilung wurde zugestellt.', 5);
			App.home();
		}
		
		, orderHistory: function() {
			
		}
		
		, articlesHistory: function() {
			
		}

		// private
		, _createRegisterPanel: function() {
			if (this.registerPanel) return this.registerPanel;
			
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
			this.registerPanel = c.add(
				new Ext.ContentPanel('register-panel'
					, { autoCreate: true, preservePanel: true }
					, App.templates.getFormTemplate().apply({ formTitle: 'Mein Benutzerkonto'
						, formHeadId: 'register-form-head'
						, formBodyId: 'register-form-body'
						, formFootId: 'register-form-foot'
					})
				)
			);
			l.showPanel(this.changePasswordPanel);
			l.endUpdate();
			var form = new Ext.form.Form({ url: 'shop.php', labelWidth: 80, baseParams: { realm: 'user', action: 'create' } });
			form.waitMsgTarget = true;
			var pw1, pw2;
			form.container();
				form.column({ width: 300 });
					form.fieldset({ legend: 'Identität' });
						form.add(
							new Ext.form.TextFieldRemoteVal({
								fieldLabel: 'Login'
								, name: 'Login'
								, width: 188
								, allowBlank: false
								, remoteValidation: 'onBlur'
								, urlRemoteVal: 'shop.php' // Url for remote validation
								, paramsRemoteVal: { realm: 'user', action: 'lookupLogin' }
								, method: 'POST'
								, timeout: 30
								, badServerRespText: 'My text'
								, badComText: 'My text'
							})  
							, pw1 = new Ext.form.TextField({ fieldLabel: 'Kennwort', name: 'Password', width: 188, allowBlank: false, inputType: 'password' })
							, pw2 = new Ext.form.TextField({ fieldLabel: 'Wiederholung', name: 'Password2', width: 188, allowBlank: false, validator: function(value) { return (value == pw1.getValue()); }, inputType: 'password' })
						);
					form.end(); // fieldset
					form.fieldset({ legend: 'Adresse' });
						form.add(
							new Ext.form.ComboBox({
								fieldLabel: 'Anrede'
								, hiddenName: 'Salutation'
								, store: new Ext.data.SimpleStore({
									fields: ['Salutation']
									, data : [
										['Herr'], ['Frau'], ['Firma']
									]
								})
								, displayField: 'Salutation'
								, mode: 'local'
								, triggeraction: 'all'
								, emptyText: 'Bitte Anrede wählen'
								, selectOnFocus: true
								, width:188
								, allowBlank: false
								, forceSelection: false
							})
							, new Ext.form.TextField({ fieldLabel: 'Vorname', name: 'Firstname', width: 188, allowBlank: false })
							, new Ext.form.TextField({ fieldLabel: 'Nachname', name: 'Lastname', width: 188, allowBlank: false })
							, new Ext.form.TextArea({ fieldLabel: 'Anschrift', name: 'Address', width: 190, growMin: 36, height: 36, allowBlank: false, grow: true })
						);
						form.container();
							form.column({ width: 135 },
								new Ext.form.TextField({ fieldLabel: 'PLZ/Ort', name: 'Zip', width: 44, allowBlank: false })
							);
							form.column({ width: 142, hideLabels: true },
								new Ext.form.TextField({ name: 'City', width: 138, allowBlank: false })
							);
						form.end(); // container
					form.end(); // fieldset
				form.end(); // column
				form.column({ width: 300, style: 'margin-left:10px;' });
					form.fieldset({ legend: 'Kontakt' });
						form.add(
							new Ext.form.TextFieldRemoteVal({
								fieldLabel: 'Mail-Adresse'
								, name: 'Email'
								, width: 188
								, allowBlank: false
								, remoteValidation: 'onBlur'
								, urlRemoteVal: 'shop.php' // Url for remote validation
								, paramsRemoteVal: { realm: 'user', action: 'lookupEmail' }
								, method: 'POST'
								, timeout: 30
								, badServerRespText: 'My text'
								, badComText: 'My text'
								, vtype: 'email'
							})  
							, new Ext.form.TextField({ fieldLabel: 'Telefon', name: 'Phone', width: 188, allowBlank: false })
							, new Ext.form.TextField({ fieldLabel: 'Fax', name: 'Fax', width: 188 })
						);
					form.end(); // fieldset
					form.fieldset({ legend: 'Firma (falls zutreffend)' });
						form.add(
							new Ext.form.TextField({ fieldLabel: 'Firmenname', name: 'Company', width: 188 })
							, new Ext.form.TextField({ fieldLabel: 'Kostenstelle', name: 'DepartmentNo', width: 188 })
						);
					form.end(); // fieldset
				form.end(); // column
			form.end(); // container
			form.fieldset({ legend: 'Newsletter', hideLabels: true });
				form.add(
					new Ext.form.Checkbox({ checked: true, name: 'Newsletter', inputValue: 1, boxLabel: 'Ja, ich möchte den wöchentlichen Newsletter mit den aktuellen BSI-Sonderangeboten erhalten.' })
					, new Ext.form.Checkbox({ checked: true, name: 'Infomail', inputValue: 1, boxLabel: 'Ich möchte auch weitere Informationsmails zu Sonderaktionen und ähnliches erhalten.' })
				);
				form.add(
					new Ext.form.Layout({ autoCreate: {
							tag: 'p',
							style: 'margin-left:20px;',
							html: 'Hinweis: Wenn Sie ein Häkchen deaktivieren, wird die entsprechende Mailaussendung abbestellt.<br/>Wenn Sie unsere Informationen nicht abbestellen möchten, lassen Sie die Häkchen bitte gesetzt.<br/>Es erfolgt prinzipiell keine mehrfache Zustellung der gleichen Inhalte an die gleiche Mailadresse.'
						}
					})
				);
			form.end(); // fieldset
			form.addButton({
				text: '<b>Speichern</b>'
				, handler: function() {
					form.submit({ waitMsg: 'Daten werden übertragen ...' });
				}
			});
			form.addButton('Abbrechen').on('click', function(elForm) { this.reset(); App.home(); }, form);
			form.on('actionfailed', this.onActionFailed, this);
			form.on('actioncomplete', this.onRegisterComplete, this);
			form.render('register-form-body');
			this.registerPanel.form = form;
			return this.registerPanel;
		}
		
		// private
		, _createChangePasswordPanel: function() {
			if (this.changePasswordPanel) return this.changePasswordPanel;
			this.changePasswordPanel = new Ext.ContentPanel('change-password-panel'
				, { autoCreate: true, preservePanel: true }
				, App.templates.getFormTemplate().apply({ formTitle: 'Kennworterinnerung'
					, formHeadId: 'change-password-form-head'
					, formBodyId: 'change-password-form-body'
					, formFootId: 'change-password-form-foot'
				})
			);
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
				c.add(this.changePasswordPanel);
			l.endUpdate();
			l.showPanel(this.changePasswordPanel);
			var pw, pw1, pw2;
			Ext.get('form-heading').update('Kontosicherheit');
			var form = new Ext.form.Form({ url: 'shop.php', labelWidth: 220, labelAlign: 'right', baseParams: { realm: 'user', action: 'changePassword' } });
			form.waitMsgTarget = true;
			form.fieldset({ legend: 'Kennwort ändern' });
				form.add(
					pw = new Ext.form.TextField({ fieldLabel: 'Altes Kennwort', name: 'oldPassword', width: 188, allowBlank: false, inputType: 'password' })
					, pw1 = new Ext.form.TextField({ fieldLabel: 'Neues Kennwort', name: 'Password', width: 188, allowBlank: false, inputType: 'password' })
					, pw2 = new Ext.form.TextField({ fieldLabel: 'Wiederholung', name: 'Password2', width: 188, allowBlank: false, validator: function(value) { return (value == pw1.getValue()); }, inputType: 'password' })
				);
			form.end();
			form.addButton({
				text: '<b>Speichern</b>'
				, handler: function() {
					form.submit({ waitMsg: 'Daten werden übertragen ...' });
				}
			});
			form.addButton('Abbrechen').on('click', App.home, App);
			form.on('actioncomplete', this.onChangePasswordComplete, this);
			form.on('actionfailed', this.onActionFailed, this);
			form.render('change-password-form-body');
		}

		// private
		, _createRequestPasswordPanel: function() {
			if (this.requestPasswordPanel) return this.requestPasswordPanel;
			this.requestPasswordPanel = new Ext.ContentPanel('request-password-panel'
				, { autoCreate: true, preservePanel: true }
				, App.templates.getFormTemplate().apply({ formTitle: 'Kennworterinnerung'
					, formHeadId: 'request-password-form-head'
					, formBodyId: 'request-password-form-body'
					, formFootId: 'request-password-form-foot'
				})
			);
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
				c.add(this.requestPasswordPanel);
			l.endUpdate();
			l.showPanel(this.requestPasswordPanel);
			var form = new Ext.form.Form({ url: 'shop.php', labelWidth: 250, labelAlign: 'right', baseParams: { realm: 'User',action: 'requestPassword' } });
			form.waitMsgTarget = true;
			form.fieldset({ legend: 'Fordern Sie die Zusendung Ihres Kennworts per Mail an' });
				form.add(
					new Ext.form.TextField({
						fieldLabel: 'Login, Mailadresse oder Kunden-Nr.'
						, name: 'Login'
						, width: 188
						, allowBlank: false
					})  
				);
			form.end();
			form.addButton({
				text: '<b>Erinnerungsmail anfordern</b>'
				, handler: function() {
					form.submit({ waitMsg: 'Daten werden übertragen ...' });
				}
			});
			form.addButton('Abbrechen').on('click', App.home, App);
			form.on('actionfailed', this.onActionFailed, this);
			form.on('actioncomplete', this.onRequestPasswordComplete, this);
			form.render('request-password-form-body');
			this.requestPasswordPanel.form = form;
			return this.requestPasswordPanel;
		}

		// private
		, _createEditPanel: function() {
			if (this.editPanel) return this.editPanel;
			
			this.editPanel = new Ext.ContentPanel('profile-edit-panel'
				, { autoCreate: true, preservePanel: true }
				, App.templates.getFormTemplate().apply({ formTitle: 'Mein Benutzerkonto'
					, formHeadId: 'profile-edit-form-head'
					, formBodyId: 'profile-edit-form-body'
					, formFootId: 'profile-edit-form-foot'
				})
			);
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
				c.add(this.editPanel);
			l.endUpdate();
			var form = new Ext.form.Form({ url: 'shop.php', labelWidth: 80, baseParams: { realm: 'User', action: 'update' } });
			form.waitMsgTarget = true;
			form.container();
				form.column({ width:300 });
					form.fieldset({ legend: 'Identität' });
						form.add(
							new Ext.form.TextFieldRemoteVal({
								fieldLabel: 'Login'
								, name: 'Login'
								, width: 188
								, allowBlank: false
								, remoteValidation: 'onBlur'
								, urlRemoteVal: 'shop.php' // Url for remote validation
								, paramsRemoteVal: { realm: 'user', action: 'lookupLogin' }
								, method: 'POST'
								, timeout: 30
								, badServerRespText: 'My text'
								, badComText: 'My text'
							})
							, new Ext.form.Layout({ id: 'pw-text' })
						);
					form.end(); // fieldset
					form.fieldset({ legend: 'Adresse' });
						form.add(
							new Ext.form.ComboBox({
								fieldLabel: 'Anrede'
								, hiddenName: 'Salutation'
								, store: new Ext.data.SimpleStore({
									fields: ['Salutation']
									, data : [
										['Herr'], ['Frau'], ['Firma']
									]
								})
								, displayField: 'Salutation'
								, mode: 'local'
								, triggerAction: 'all'
								, emptyText: 'Bitte Anrede wählen'
								, selectOnFocus:true
								, width:188
								, allowBlank: false
								, forceSelection: true
							})
							, new Ext.form.TextField({ fieldLabel: 'Vorname', name: 'Firstname', width: 188, allowBlank: false })
							, new Ext.form.TextField({ fieldLabel: 'Nachname', name: 'Lastname', width: 188, allowBlank: false })
							, new Ext.form.TextArea({ fieldLabel: 'Anschrift', name: 'Address', width: 188, growMin: 36, height: 36, allowBlank: false, grow: true })
						);
						form.container();
							form.column({ width: 135 },
								new Ext.form.TextField({ fieldLabel: 'PLZ/Ort', name: 'Zip', width: 44, allowBlank: false })
							);
							form.column({ width: 142, hideLabels: true },
								new Ext.form.TextField({ name: 'City', width: 138, allowBlank: false })
							);
						form.end(); // container
					form.end(); // fieldset
				form.end(); // column
				form.column({ width: 290, style: 'margin-left:10px;', clear: true });
					form.fieldset({ legend: 'Firmendaten' });
						form.add(
							new Ext.form.TextField({ fieldLabel: 'Firmenname', name: 'Company', width: 178 })
							, new Ext.form.TextField({ fieldLabel: 'Kostenstelle', name: 'DepartmentNo', width: 178 })
						);
					form.end(); // fieldset
					form.fieldset({ legend: 'Kontakt' });
						form.add(
							new Ext.form.TextFieldRemoteVal({
								fieldLabel: 'Mail-Adresse'
								, name: 'Email'
								, width: 178
								, allowBlank: false
								, remoteValidation: 'onBlur'
								, urlRemoteVal: 'shop.php' // Url for remote validation
								, paramsRemoteVal: { realm: 'user', action: 'lookupEmail' }
								, method: 'POST'
								, timeout: 30
								, badServerRespText: 'My text'
								, badComText: 'My text'
								, vtype: 'email'
							})  
							,new Ext.form.TextField({ fieldLabel: 'Telefon', name: 'Phone', width: 178, allowBlank: false })
							,new Ext.form.TextField({ fieldLabel: 'Fax', name: 'Fax', width: 178 })
						);
					form.end(); // fieldset
				form.end(); // column
			form.end(); // container
			form.fieldset({ legend: 'Newsletter', hideLabels: true });
				form.add(
					new Ext.form.Checkbox({ name: 'Newsletter', inputValue: 1, boxLabel: 'Ja, ich möchte den wöchentlichen Newsletter mit den aktuellen BSI-Sonderangeboten erhalten.' })
					, new Ext.form.Checkbox({ name: 'Infomail', inputValue: 1, boxLabel: 'Ich möchte auch weitere Informationsmails zu Sonderaktionen und ähnliches erhalten.' })
				);
			form.end(); // fieldset
			form.addButton({
				id: 'profile-edit-btn-submit'
				, text: '<b>Speichern</b>'
				, handler: function() {
					form.submit(/*{ waitMsg: 'Daten werden übertragen ...' }*/);
				}
			});
			form.addButton('Abbrechen').on('click', App.home, App);
			form.render('profile-edit-form-body');
			form.on('actionfailed', this.onActionFailed, this);
			form.on('actioncomplete', this.onEditComplete, this);
			Ext.get('pw-text').update('<div class="x-form-item"><label style="width:80px;">Kennwort:</label><div class="x-form-element" style="padding-left:85px; padding-top:3px; height: 18px;">****** <a href="javascript:;" id="pw-change" class="x-btn" ext:qtip="Hier klicken, um das Passwort zu ändern">Ändern</a></div></div><div class="x-form-clear-left"></div>');
			Ext.get('pw-change').on('click', this.changePassword, this);
			this.editPanel.form = form;
			return this.editPanel;
		}

		// private
		, _createChangePasswordPanel : function() {
			if (this.changePasswordPanel) return this.changePasswordPanel;
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
			this.changePasswordPanel = c.add(
				new Ext.ContentPanel('change-password-panel'
					, { autoCreate: true, preservePanel: true }
					, App.templates.getFormTemplate().apply({
						formTitle: 'Kontosicherheit'
						, formHeadId: 'change-password-form-head'
						, formBodyId: 'change-password-form-body'
						, formFootId: 'change-password-form-foot'
					})
				)
			);
			l.endUpdate();
			l.showPanel(this.changePasswordPanel);
			var pw, pw1, pw2;
			var form = new Ext.form.Form({ url: 'shop.php', labelWidth: 220, labelAlign: 'right', baseParams: { realm: 'user', action: 'changePassword' } });
			form.waitMsgTarget = true;
			form.fieldset({ legend: 'Kennwort ändern' });
				form.add(
					pw = new Ext.form.TextField({ fieldLabel: 'Altes Kennwort', name: 'oldPassword', width: 188, allowBlank: false, inputType: 'password' })
					, pw1 = new Ext.form.TextField({ fieldLabel: 'Neues Kennwort', name: 'Password', width: 188, allowBlank: false, inputType: 'password' })
					, pw2 = new Ext.form.TextField({ fieldLabel: 'Wiederholung', name: 'Password2', width: 188, allowBlank: false, validator: function(value) { return (value == pw1.getValue()); }, inputType: 'password' })
				);
			form.end();
			form.addButton({
				text: '<b>Speichern</b>'
				, handler: function() {
					form.submit({ waitMsg: 'Daten werden übertragen ...' });
				}
			});
			form.addButton('Abbrechen').on('click', App.home, App);
			form.on('actioncomplete', this.onChangePasswordComplete, this);
			form.on('actionfailed', this.onActionFailed, this);
			form.render('change-password-form-body');
			this.changePasswordPanel.form = form;
			return this.changePasswordPanel;
		}

		// private
		, _createSubscriptionPanel: function() {
			if (this.subscriptionPanel) return this.subscriptionPanel;
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
			this.subscriptionPanel = c.add(
				new Ext.ContentPanel('subscription-panel'
					, { autoCreate: true, preservePanel: true }
					, App.templates.getFormTemplate().apply({
						formTitle: 'Newsletter abonnieren'
						, formHeadId: 'subscription-form-head'
						, formBodyId: 'subscription-form-body'
						, formFootId: 'subscription-form-foot'
					})
				)
			);
			l.endUpdate();
			l.showPanel(this.subscriptionPanel);
			var form = new Ext.form.Form({ url: 'shop.php', labelAlign: 'right', baseParams: { realm: 'newsletter', action: 'subscribe' } });
			form.waitMsgTarget = true;
			form.fieldset({ labelWidth: 190, legend: 'Erforderliche Daten' });
				form.add(
					new Ext.form.TextField({ fieldLabel: 'E-Mail-Adresse', name: 'Email', width: 240, allowBlank: false, vtype: 'email' })  
					, new Ext.form.ComboBox({
						fieldLabel: 'Anrede'
						, hiddenName: 'Salutation'
						, store: new Ext.data.SimpleStore({
							fields: ['Salutation']
							, data : [
								['Herr'], ['Frau'], ['Firma']
							]
						})
						, displayField: 'Salutation'
						, mode: 'local'
						, triggerAction: 'all'
						, emptyText: 'Bitte Anrede wählen'
						, selectOnFocus:true
						, width:240
						, allowBlank: false
					})
					, new Ext.form.TextField({ fieldLabel: 'Vorname', name: 'Firstname', width: 240 })
					, new Ext.form.TextField({ fieldLabel: 'Nachname', name: 'Lastname', width: 240, allowBlank: false })
				);
			form.end();
			form.fieldset({ labelWidth: 80, legend: 'Optionale Daten' });
				form.column({ width: 290 });
					form.add(
						new Ext.form.TextField({ fieldLabel: 'Firmenname', name: 'Company', width: 188 })
						, new Ext.form.TextField({ fieldLabel: 'Kostenstelle', name: 'DepartmentNo', width: 188 })
						, new Ext.form.TextField({ fieldLabel: 'Telefon', name: 'Phone', width: 188 })
						, new Ext.form.TextField({ fieldLabel: 'Fax', name: 'Fax', width: 188 })
					);
				form.end(); // column
				form.column({ width: 290, style: 'margin-left:10px;', clear: true });
					form.add(
						new Ext.form.TextArea({ fieldLabel: 'Anschrift', name: 'Address', width: 194, growMin: 36, height: 36, grow: true })
					);
					form.container();
						form.column({ width: 135 },
							new Ext.form.TextField({ fieldLabel: 'PLZ/Ort', name: 'Zip', width: 44 })
						);
						form.column({ width: 142, hideLabels: true },
							new Ext.form.TextField({ name: 'City', width: 138 })
						);
					form.end(); // container
				form.end(); // column
			form.end();
			form.container({ hideLabels: true });
				form.add(
					new Ext.form.Checkbox({ checked: true, name: 'Newsletter', inputValue: 1, boxLabel: 'Ja, ich möchte den wöchentlichen Newsletter mit den aktuellen BSI-Sonderangeboten erhalten.' })
					, new Ext.form.Checkbox({ checked: true, name: 'Infomail', inputValue: 1, boxLabel: 'Ich möchte auch weitere Informationsmails zu Sonderaktionen und ähnliches erhalten.' })
				);
			form.end(); // container
			form.addButton({
				text: '<b>Abonnieren</b>'
				, handler: function() {
					form.submit({ waitMsg: 'Daten werden übertragen ...' });
				}
			});
			form.addButton('Abbrechen').on('click', App.home, App);
			form.on('actionfailed', this.onActionFailed, this);
			form.on('actioncomplete', this.onSubscriptionComplete, this);
			form.render('subscription-form-body');
			this.subscriptionPanel.form = form;
			return this.subscriptionPanel;
		}
		
		// private
		, _createUnsubscriptionPanel: function() {
			if (this.unsubscriptionPanel) return this.unsubscriptionPanel;
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
			this.unsubscriptionPanel = c.add(
				new Ext.ContentPanel('unsubscription-panel'
					, { autoCreate: true, preservePanel: true }
					, App.templates.getFormTemplate().apply({
						formTitle: 'Newsletter abbestellen'
						, formHeadId: 'unsubscription-form-head'
						, formBodyId: 'unsubscription-form-body'
						, formFootId: 'unsubscription-form-foot'
					})
				)
			);
			l.endUpdate();
			l.showPanel(this.unsubscriptionPanel);
			var form = new Ext.form.Form({ url: 'shop.php', labelWidth: 190, labelAlign: 'right', baseParams: { realm: 'Newsletter', action: 'unsubscribe' } });
			form.waitMsgTarget = true;
			form.fieldset({ legend: 'Erforderliche Daten' });
				form.add(
					new Ext.form.TextField({ fieldLabel: 'Mail-Adresse', name: 'Email', width: 240, allowBlank: false, vtype: 'email' })
				);  
				form.container({ hideLabels: true, style: 'margin-left:120px' });
					form.add(
						new Ext.form.Checkbox({ checked: false, name: 'Newsletter', inputValue: 1, boxLabel: 'Ich möchte den wöchentlichen Newsletter nicht länger erhalten' })
						, new Ext.form.Checkbox({ checked: false, name: 'Infomail', inputValue: 1, boxLabel: 'Ich möchte keine weiteren Informationsmails erhalten.' })
					);
				form.end(); // container
			form.end();
			form.fieldset({ legend: 'Optionale Daten' });
				form.add(
					new Ext.form.TextArea({ fieldLabel: 'Bemerkung', name: 'Comment', width: 246 })
				);
			form.end();
			form.container({ hideLabels: true });
				form.add(
					new Ext.form.Checkbox({ checked: false, name: 'deleteData', inputValue: 1, boxLabel: 'Ich wünsche, dass alle zu meiner Person gespeicherten Daten gelöscht werden.', qtip: 'Datenschutzhinweis: Falls zu Ihrer Person eventuelle Daten aus früheren Geschäftsprozessen gespeichert sind, werden diese nicht mit gelöscht.' })
				);
			form.end(); // container
			form.addButton({
				text: '<b>Abbestellen</b>'
				, handler: function() {
					form.submit({ waitMsg: 'Daten werden übertragen ...' });
				}
			});
			form.addButton('Abbrechen').on('click', App.home, App);
			form.on('actionfailed', this.onActionFailed, this);
			form.on('actioncomplete', this.onUnsubscriptionComplete, this);
			form.render('unsubscription-form-body');
			this.unsubscriptionPanel.form = form;
			return this.unsubscriptionPanel;
		}

		// private
		, _createFeedbackPanel: function() {
			if (this.feedbackPanel) return this.feedbackPanel;
			var l = App.getLayout(), c = l.getRegion('center');
			l.beginUpdate();
			this.feedbackPanel = c.add(
				new Ext.ContentPanel('feedback-panel'
					, { autoCreate: true, preservePanel: true }
					, App.templates.getFormTemplate().apply({
						formTitle: 'Ihre Mitteilung an uns'
						, formHeadId: 'feedback-form-head'
						, formBodyId: 'feedback-form-body'
						, formFootId: 'feedback-form-foot'
					})
				)
			);
			l.endUpdate();
			l.showPanel(this.feedbackPanel);
			var form = new Ext.form.Form({ url: 'shop.php', labelWidth: 190, labelAlign: 'right', baseParams: { realm: 'user', action: 'feedback' } });
			form.waitMsgTarget = true;
			var email;
			form.fieldset({ legend: 'Erforderliche Daten' });
				form.add(
					email = new Ext.form.TextField({ disabled: App.User.getIsAuthenticated(), value: App.User.getIsAuthenticated() ? App.User.getData().Email : '', fieldLabel: 'Mail-Adresse', name: 'Email', width: 240, allowBlank: false, vtype: 'email' })  
					, new Ext.form.TextField({ fieldLabel: 'Betreff', name: 'Subject', width: 240, allowBlank: false })  
					, new Ext.form.TextArea({ fieldLabel: 'Bemerkung', name: 'Comment', width: 240, allowBlank: false })
				);
			form.end();
			form.container({ hideLabels: true });
				form.add(
					new Ext.form.Checkbox({ checked: true, name: 'AnswerBack', inputValue: 1, boxLabel: 'Ich wünsche Rückmeldung zu meiner Nachricht.' })
				);
			form.end(); // container
			form.addButton({
				text: '<b>Absenden</b>'
				, handler: function() {
					form.submit({ waitMsg: 'Daten werden übertragen ...' });
				}
			});
			form.addButton('Abbrechen').on('click', App.home, App);
			form.on('actionfailed', this.onActionFailed, this);
			form.on('actioncomplete', this.onFeedbackComplete, this);
			form.render('feedback-form-body');
			this.feedbackPanel.form = form;
			App.User.on('login', function() { email.disable(); email.setValue(App.User.getData().Email); }, this);
			App.User.on('logout', function() { email.enable(); email.reset(); }, this);
			return this.feedbackPanel;
		}
	};
}();
