	
Ext.form.VTypes = function(){
	
	var alpha = /^[a-zA-Z_]+$/;
	var alphanum = /^[a-zA-Z0-9_]+$/;
  // var email = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
 //  var email = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
   var email = /^([a-zA-Z0-9_\.-]+)@([\da-zA-Z\.-]+)\.([a-zA-Z\.]{2,6})$/;
	//var email = /^([\w]+)(\.[\w]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/;
	var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;

	
	return {
		
		'email' : function(v){
			return email.test(v);
		},
		
		'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
		
		'emailMask' : /[a-z0-9_\.\-@]/i,

		
		'url' : function(v){
			return url.test(v);
		},
		
		'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
		
		
		'alpha' : function(v){
			return alpha.test(v);
		},
		
		'alphaText' : 'This field should only contain letters and _',
		
		'alphaMask' : /[a-z_]/i,

		
		'alphanum' : function(v){
			return alphanum.test(v);
		},
		
		'alphanumText' : 'This field should only contain letters, numbers and _',
		
		'alphanumMask' : /[a-z0-9_]/i
	};
}();

	
	



function sessionOver(el,success,response,options){
							if (!success){
							 Ext.Msg.show({
								 title: 'Fehler',
								 msg: 'Ihre Sitzung ist abgelaufen, bitte melden Sie sich erneut an.',
								 buttons: Ext.Msg.OK,
								 fn: function (){
									 window.location.href=window.location.href;
								 },
								 icon: Ext.MessageBox.ERROR
								 
							 });
							}   
}    // turn on validation errors beside the field globally
	Ext.form.Field.prototype.msgTarget = 'side';
	// The action
	var action = new Ext.Action({
		text: 'Password ändern',
		handler: function(){
			passwdWin.show();
			//Ext.MessageBox.alert('Click','You clicked on "Password ?ndern".');
		},
		iconCls: 'silk_lockedit'
	});
	
   var lvStore = new Ext.data.JsonStore({
	   auotLoad: true,
		url: 'user_profile_ajax.php',
		root: 'countries',
		baseParams: {
			action: 'getCountries'
			},
		fields: ['cn'],
		idProperty: 'cn'
	});
	
var cardNav = function(incr){
	var l = Ext.getCmp('aboWizardWindow').getLayout();
	var i = l.activeItem.id.split('card-')[1];
	var next = parseInt(i,10) + incr;
	var lo=0;
	var hi=3;
	if (next>=lo && next<=hi){
	l.setActiveItem(next);
	}
		if (next==4){
			Ext.getCmp('aboBestellForm').getForm().setValues({
				pdfAbo : Ext.get('cbPDF').dom.checked,
				druckAbo : Ext.get('cbDruck').dom.checked,
				versandLand : VL,
				zahlWeise : ZW
				
				
			});
			
					  Ext.getCmp('aboBestellForm').getForm().submit({
						url:'user_profile_ajax.php', 
						params: {action:'saveAboOrder'},             
						success: function(form, action) {
						//userProfileForm.getForm().setValues(userProfileForm.getForm().getValues());
						Ext.Msg.alert("Info", "Ihre Bestellung wurde gespeichert.");
							Ext.getCmp('aboWizardWindow').isSubmitted=true;   
						   Ext.getCmp('aboWizardWindow').close();
						},
						failure: function(form, action) {

							switch (action.failureType) {
							case Ext.form.Action.CLIENT_INVALID:
								//Ext.Msg.alert("Failure", "Fehler im Formular. Bitte &Uuml;berpr7uuml;fen Sie Ihre Angaben");
								break;
							case Ext.form.Action.CONNECT_FAILURE:
								Ext.Msg.alert("Failure", "Kommunikation mit dem Server nicht möglich");
								break;
							case Ext.form.Action.SERVER_INVALID:
								Ext.Msg.alert("Failure", action.result.msg);
							}
						}, waitMsg:'Speichere Bestellung...'
			});
		}
};

function heartbeat(){
Ext.Ajax.request({
   url: 'user_profile_ajax.php',
   success: someFn,
   failure: otherFn,
   params: { action: 'heartbeat' }
});
	return true;
}




	var aboWizardWindow;
		displayAboWizardWindow= function(){
			aboWizardWindow = new Ext.Window({

				//el:'aboWizardWindow-el',
				id: 'aboWizardWindow',
				//layout:'fit',
				modal:true,
				width:500,
				height:400,
				closeAction:'close',
				plain: true,
 layout:'card',
	activeItem: 0,
	bodyStyle: 'padding:5px',
	defaults: {border:false},
			listeners:{
					'beforerender': function (me){
						if (heartbeat()){
							
						}   else{
							 Ext.Msg.alert('Fehler', 'Ihre Sitzung ist abgelaufen, bitte melden Sie sich erneut an.');
							return false;
							
							
						}                 
					
					
					
					
					},
					'beforeclose': function (me){
					if(me.isSubmitted===false){
							Ext.Msg.show({
							   title:'Frage',
							   msg: "Sie haben die Bestellung noch nicht abgeschlossen. Möchten Sie wirklich die Bestellung abbrechen? (Sie können jederzeit in Ihrem Benutzerprofil unter 'Abonnement' den Bestellvorgang erneut starten.)",
							   buttons: Ext.Msg.YESNO,
							   fn: function (buttonId,text,opt){
								if (buttonId=='yes'){
									Ext.getCmp('aboWizardWindow').isSubmitted=true;   
									Ext.getCmp('aboWizardWindow').close();
									//window.location.href='http://www.griechenland.net';                 
									}else {
									return false;
									}
							   },
							   animEl: 'elId',
							   scope: action,
							   icon: Ext.MessageBox.QUESTION
							});                          
					}else{
					return true;
					}
				
				},
		id: 'card-0',
		tbar: [
		   {xtype: 'tbtext', text: '<b>Willkommen</b>'}
		],
		bbar: [
		   {xtype: 'tbtext', text: 'Schritt 1 von 4'}
		],                        autoLoad: {
						url:'user_profile_ajax.php', 
						params: {action:'loadAboWizardPage', page:'0'},
						scripts: true,
						callback: sessionOver                        
				}, unstyled:true,
					bodyCfg: {tag: 'p',
	   
		cls: 'aboAuswahl'},
		listeners: {'show': function (that){
		Ext.getCmp('aboWizardWindow').isSubmitted=false;
			Ext.getCmp('nextButton').setText('weiter');
		 Ext.getCmp('backButton').disable();
		 Ext.getCmp('nextButton').enable();
		}}
		
	},    
	items: [
{
		id: 'card-1',
		layout: 'fit',
		tbar: [
		   {xtype: 'tbtext', text: '<b>Abo - Auswahl</b>'}
		],
		bbar: [
		   {xtype: 'tbtext', text: 'Schritt 2 von 4'}
		],
		//layout: 'fit',
				
				autoLoad: {
						url:'user_profile_ajax.php', 
						params: {action:'loadAboWizardPage', page:1},
						scripts: true                    
				},
				 
				unstyled:true,
					bodyCfg: {tag: 'p',
	   
		cls: 'aboAuswahl'},
		listeners: {'show': function (that){
			Ext.getCmp('nextButton').setText('weiter');
		  Ext.getCmp('card-1').syncSize();
		 // Ext.getCmp('aboAuswahlForm').syncSize();
		// createAboAuswahlForm(Ext.getCmp('card-1').body);
			setPdfAboBetrag(true);        
		}}
				
				
	},{
		id: 'card-2',
		tbar: [
		   {xtype: 'tbtext', text: '<b>Abo - Gebühren</b>'}
		],
		bbar: [
		   {xtype: 'tbtext', text: 'Schritt 3 von 4'}
		],
						autoLoad: {
						url:'user_profile_ajax.php', 
						params: {action:'loadAboWizardPage', page:2},
						scripts: true                    
				}, unstyled:true,
					bodyCfg: {tag: 'p',
	   
		cls: 'aboAuswahl'
	},listeners: {'show': function (that){
		Ext.getCmp('nextButton').setText('weiter');
			setformularSatz();
		}}
		},{
		id: 'card-3',
		tbar: [
		   {xtype: 'tbtext', text: '<b>Abo - Bestellung abschicken</b>'}
		],
		bbar: [
		   {xtype: 'tbtext', text: 'Schritt 4 von 4'}
		],
						autoLoad: {
						url:'user_profile_ajax.php', 
						params: {action:'loadAboWizardPage', page:3},
						scripts: true                    
				}, unstyled:true,
					bodyCfg: {tag: 'p',
	   
		cls: 'aboAuswahl'
	},
		listeners: {'show': function (me){
			Ext.getCmp('nextButton').setText('abschicken');
			if (!Ext.getCmp('aboBestellForm')){
			createAboBestellForm(Ext.getCmp('card-3').body);           
			}
		}
		}
	}],


				buttons: [{
					text:'zurück',
					id: 'backButton',
					disabled:true,
					handler: cardNav.createDelegate(this, [-1])
				},{
					text: 'weiter',
					id: 'nextButton',
					handler: cardNav.createDelegate(this, [1])
					
				}]
			});
		aboWizardWindow.show();
	};







	


Ext.onReady(function(){    

	Ext.QuickTips.init();
	lvStore.load();
	 var userProfileForm = new Ext.FormPanel({
		listeners: {
		// Called every time a validation poll happens 
			'clientvalidation': function(that){

							if(that.form.isDirty()){
								if (Ext.getCmp('passwd1').getValue().length>=Ext.getCmp('passwd1').initialConfig.minLength & Ext.getCmp('passwd1').getValue()==Ext.getCmp('passwd2').getValue()){
									  Ext.getCmp('userProfileSaveButton').enable();  
																		}else{
									  Ext.getCmp('userProfileSaveButton').disable();  
									}
								
								
							}else{
								Ext.getCmp('userProfileSaveButton').disable();
							}            
			

			},
				'afterrender': function (that){
						Ext.get('loading-mask').remove();
						Ext.get('loading').remove();
				}            
		},
		id: 'userProfileForm',
		labelAlign: 'top',
		title: 'Griechenland Zeitung => User Anmeldung',
		iconCls: 'user',
		trackResetOnLoad: true,
		monitorValid: true,

		//bodyStyle:'padding:5px',
		renderTo: 'extform',
		frame:true,
		width: 600,
		items: [{
			title:'<font style="color: red;">Ich möchte...</font>',            
			xtype:'fieldset',
				layout: 'form',
				labelAlign: 'left',
				border:true,
				items:[{
				xtype: 'radiogroup',
				columns:1,
				allowBlank: false,
				anchor: '95%',
				labelAlign: 'left',
		  defaults: {
			labelWidth: 0
		},              
					height: 160,
				items: [{

					xtype:'radio',
					boxLabel: '...ein <b>Jahres-Abo</b> der GZ (Online-Version bzw. PDF und/oder Druckausgabe).<br>',
					name: 'aboSelect',
					inputValue: 'jahr',
					anchor:'100%',
					height: 90
				},{
					
					xtype:'radio',
					boxLabel: '...die GZ 2 Wochen lang <B>kostenlos testen</b> (nur PDF)<BR><BR>Falls Sie ein Druck-Probe-Abo möchten, schicken Sie uns bitte eine <a href="mailto:info@hellasproducts.com">E-Mail</a>.',
					name: 'aboSelect',
					inputValue: 'probe',
					anchor:'100%',
					height: 50
				}]
				}]
		
		},{
			title:'Person',            
			xtype:'fieldset',
			layout:'column',
			//border:false,
			items:[{
				columnWidth:.5,
				layout: 'form',
				border:false,
				items: [{
					xtype:'textfield',
					fieldLabel: 'Vorname',
					name: 'firstname',
					anchor:'92%',
					allowBlank:false,
					labelStyle: 'color: red;'
				},{
					xtype:'textfield',
					fieldLabel: 'Nachname',
					name: 'lastname',
					anchor:'92%',
					allowBlank:false,
					labelStyle: 'color: red;'
				}]
			},{
				columnWidth:.5,
				layout: 'form',
				border:false,
				items: [ {
					xtype:'textfield',
					fieldLabel: 'Institution',
					name: 'institution',
					anchor:'92%'
				},{
					xtype:'textfield',
					fieldLabel: 'Firma',
					name: 'company',
					anchor:'92%'
				}, {
					xtype:'textfield',
					fieldLabel: 'Beruf',
					name: 'occupation',
					anchor:'92%'
				}]
			}]
		},{
			
			xtype:'fieldset',
			id:'userProfileTabPanel',
			plain:true,
			title:'Addressdaten',
			layout:'column',
			items:[{
				columnWidth:.5,
				layout: 'form',
				defaultType: 'textfield',                
					items: [{
						fieldLabel: 'Straße & Nummer',
						name: 'street',
						allowBlank:false,
						anchor:'92%',
					labelStyle: 'color: red;'
					},{
						fieldLabel: 'PLZ',
						name: 'postcode',
						allowBlank:false,
						anchor:'92%',
					labelStyle: 'color: red;'
					},{
						fieldLabel: 'Stadt',
						name: 'city',
						allowBlank:false,
						anchor:'92%',
					labelStyle: 'color: red;'
					},{
						autoCreate: true,
						autoShow: true,
						xtype: 'combo',
						lazyRender: true,
						lazyInit: false,
						typeAhead: false,
						editable: false,
						triggerAction: 'all',
						fieldLabel: 'Land',
						mode: 'local',
						store: lvStore,
						valueField: 'cn',
						displayField: 'cn',
						hiddenName: 'country',
						emptyText: 'Bitte Land wählen...',
						selectOnFocus:true,                
						listWidth: 260,
						allowBlank:false,
						anchor:'92%',
					labelStyle: 'color: red;'
						}]    
				}]
			},{
				xtype:'fieldset',
				title:'Kommunikation',
				layout:'column',
				items:[{
					columnWidth:.5,
					layout: 'form',
					defaultType: 'textfield',                
						items: [{
						xtype:'textfield',
						fieldLabel: 'eMail Adresse',
						name: 'email',
						vtype:'email',
						anchor:'92%',
					labelStyle: 'color: red;'
					},{
						fieldLabel: 'Telefon',
						name: 'telephone',
						allowBlank:false,
						anchor:'92%',
					labelStyle: 'color: red;'
					},{
						fieldLabel: 'Fax',
						name: 'fax',
						anchor:'92%'
					}]
				}]
				},{
			title:'Userdaten',            
			xtype:'fieldset',
			layout:'column',
			items:[{
				columnWidth:.5,
				layout: 'form',
				border:false,
				items: [{
					xtype:'textfield',
					fieldLabel: 'Username',
					name: 'username',
					anchor:'92%',
					allowBlank:false,
					labelStyle: 'color: red;'
				}]
			},{
				columnWidth:.5,
				layout: 'form',
				border:false,
				items: [ 
						{
						xtype:'textfield',
						fieldLabel: 'Passwort (min. 6 Zeichen)',
						id: 'passwd1',
						name: 'passwd1',
						allowBlank:false,
						anchor:'92%',
						minLength: 6,
					labelStyle: 'color: red;'
						},{
						xtype:'textfield',
						fieldLabel: 'Passwort (Überprüfung)',
						id: 'passwd2',
						name: 'passwd2',
						allowBlank:false,
						anchor:'92%',
						minLength: 6,
					labelStyle: 'color: red;'
						}                
				]
			}]
		},{
				xtype:'fieldset',
				layout:'column',
				title:'Falls Sie Ihr Passwort vergessen...',
				items:[{
				columnWidth:.5,                   
				layout:'form',
				defaults: {width: 230},
				defaultType: 'textfield',

				items: [{
						fieldLabel: 'Geheime Frage',
						id: 'passwdQuestion',
						name: 'passwdQuestion',
						allowBlank:false,
						minLength: 1,
						anchor:'92%',
					labelStyle: 'color: red;'
						}]},{
				columnWidth:.5,                   
				layout:'form',
				defaults: {width: 230},
				defaultType: 'textfield',

				items: [{                            
						fieldLabel: 'Ihre Antwort',
						id: 'passwdAnswer',
						name: 'passwdAnswer',
						allowBlank:false,
						minLength: 1,
						anchor:'92%',
					labelStyle: 'color: red;'
						}]
				
						}]
				},
{
			title:'Ich möchte außerdem...',            
			xtype:'fieldset',
				layout: 'form',
				labelAlign: 'left',
				border:true,
				items:[{
				xtype: 'checkboxgroup',
				columns:1,
				allowBlank: true,
				anchor: '98%',
				labelAlign: 'left',
				
				items: [{
					checked: true,
					height: 50,
					xtype:'checkbox',
					boxLabel: '... den wöchentlich erscheinenden, kostenlosen Newsletter der GΖ abonnieren.',
					name: 'newsletter',
					inputValue: 'true',
					anchor:'92%'
				}]
				}]
		
		}                ],
			


			
		

		buttons: [{
			id: 'userProfileSaveButton',
			text: 'weiter',
			disabled:true,
		handler: function(){
			userProfileForm.getForm().submit({
						url:'user_profile_ajax.php', 
						params: {action:'createUserData'},             
						success: function(form, action) {
							Ext.Msg.show({
							   title:'Wichtige Information',
							   msg: action.result.msg,
							   buttons: Ext.Msg.OK,
							   fn: function (){
								   userProfileForm.destroy();
						   },
							   animEl: 'elId',
							   scope: action,
							   icon: Ext.MessageBox.QUESTION
							});                            
							//Ext.Msg.alert("Wichtige Information", action.result.msg);

						},
						failure: function(form, action) {
							switch (action.failureType) {
							case Ext.form.Action.CLIENT_INVALID:
								Ext.Msg.alert("Fehler", "Fehler im Formular. Bitte überprüfen Sie Ihre Angaben");
								break;
							case Ext.form.Action.CONNECT_FAILURE:
								Ext.Msg.alert("Fehler", "Kommunikation mit dem Server nicht möglich");
								break;
							case Ext.form.Action.SERVER_INVALID:
								Ext.Msg.alert("Fehler", action.result.msg);
								break;
							default:
								Ext.Msg.alert("Fehler", action.result.msg);
							}
						}, waitMsg:'Speichere Daten...'
			});
		}
		}]
	});

	});
