txt = [];

Ext.onReady(function(){

	Ext.Ajax.request({
		url: 'register.php5?mode=template',
		callback: function(options,success,response){
			txt = eval("("+response.responseText+")");
			register("lu");
		}
	});
});

function register(brand){
//	alert(txt['tx_group_product']);
	Ext.QuickTips.init();

	var storeProd = new Ext.data.JsonStore({
		url: 'register.php5?mode=fetchProducts&brand='+brand, 			
		autoLoad: true,
		root: 'data',
		fields: [{name: 'produkte'},{name: 'id'}]
	});

	var storeCountry = new Ext.data.JsonStore({
		url: 'register.php5?mode=fetchCountryList', 			
		autoLoad: true,
		root: 'data',
		fields: [{name: 'Name'},{name: 'ISO-3'}]
	});
	
	var storeCurrency = new Ext.data.JsonStore({
		url: 'register.php5?mode=fetchCurrencies', 			
		autoLoad: true,
		root: 'data',
		fields: [{name: 'Currency'}]
	});


	var registerForm = new Ext.FormPanel({
		url: 'index.php5?page=contact_request',
		id: 'contactForm',
		renderTo: 'wizard_main',
		scrollable: true,
		autoScroll: true,
		border: false,
		frame: false,
		style: 'position:absolute;margin-top: 20px;background-color:transparent;',
		bodyStyle: 'color:#fff;background-color:transparent;',
		defaults: {
			allowBlank: false,
			msgTarget: 'under',
			invalidText: txt['tx_invalid_entry'],
			blankText: txt['tx_no_blanktext']
		},

		items:[{
			layout: 'form',
			id: 'step1',
			border: false,
			buttonAlign: 'center',
			frame:false,
			bodyStyle: 'padding-top:10px;background-color:#000;',
			labelWidth: 160,
			defaults: {
				allowBlank: false,
				msgTarget: 'under',
				invalidText: txt['tx_invalid_entry'],
				blankText: txt['tx_no_blanktext']
			},
			items: [{
				xtype: 'combo',
				name: 'product',
				id: 'id_product',
				hiddenName: 'product_id',
				mode: 'local',
				width: 170,
				fieldLabel: txt['tx_produkt']+'*',
				displayField: 'produkte',
				valueField: 'id',
				store: storeProd,
		   		triggerAction: 'all',
				selectOnFocus: true,
				forceSelection: true,
				allowBlank: false

			},{
				xtype: 'numberfield',
				maxLength: 9,
				name: 'r_serial_sub',
				id: 'id_serial_sub',
				width: 100,
				allowBlank: false,
				fieldLabel: txt['tx_serial']+"(Sub)*"
			},{
				xtype: 'numberfield',
				maxLength: 9,
				name: 'r_serial_top1',
				id: 'id_serial_top1',
				width: 100,
				allowBlank: false,
				fieldLabel: txt['tx_serial']+"(Top 1)*"
			},{
				xtype: 'numberfield',
				maxLength: 9,
				name: 'r_serial_top2',
				id: 'id_serial_top2',
				width: 100,
				allowBlank: false,
				fieldLabel: txt['tx_serial']+"(Top 2)*"
			},{
				xtype: 'datefield',
				format: 'd.m.Y',
				name: 'r_kaufdatum',
				id: 'id_kaufdatum',
				allowBlank: false,
				fieldLabel: txt['tx_date_of_purchase']+'*'
			},{
				layout: 'column',
				bodyStyle: 'background-color:#000;',
		//		width: 650,
				border: false,
				frame: false,
				items:[{
					layout: 'form',
					bodyStyle: 'background-color:#000;',
					border: false,
					frame: false,
					width: 230,
					defaults: {
						allowBlank: false,
						msgTarget: 'title',
						invalidText: txt['tx_invalid_entry'],
						blankText: txt['tx_no_blanktext']
					},

					items:[{
						xtype: 'textfield',
						width: 60,
						name: 'r_kaufpreis',
						id: 'id_kaufpreis',
						allowBlank: false,
						fieldLabel: txt['tx_kaufpreis']+'*'
					}]
				},{
					layout: 'form',
					border: false,
					bodyStyle: 'background-color:#000;',
					frame: false,
					defaults: {
						allowBlank: false,
						msgTarget: 'title',
						invalidText: txt['tx_invalid_entry'],
						blankText: txt['tx_no_blanktext']
					},

					items:[{
						xtype: 'combo',
						width: 80,
						labelWidth: 0,
						name: 'r_currency',
						id: 'id_currency',
						hideLabel: true,
						mode: 'local',
						displayField: 'Currency',
						store: storeCurrency,
						typeAhead: true,
			   			triggerAction: 'all',
						selectOnFocus: true,
						forceSelection: true
					}]
				}]
			}],

			buttons: [{
				text: txt['tx_weiter'],
				id: 'id_goto_step2',
				handler: function(){
					if(validate('step1') && Ext.getCmp('id_kaufpreis').isValid() && Ext.getCmp('id_currency').isValid()){
						var dt = new Date(Ext.getCmp('id_kaufdatum').getValue());
						product = {
							id_product: Ext.getCmp('id_product').getValue(),
							r_serial_sub: Ext.getCmp('id_serial_sub').getValue(),
							r_serial_top1: Ext.getCmp('id_serial_top1').getValue(),
							r_serial_top2: Ext.getCmp('id_serial_top2').getValue(),
							r_kaufdatum: dt.format("Y-m-d"),
							r_kaufpreis: Ext.getCmp('id_kaufpreis').getValue()
						};

						Ext.Ajax.request({
							url: 'register.php5?mode=validateProduct',
							params: {
								product: Ext.util.JSON.encode(product)
							},
							method: 'POST',
							callback: function(options,success,response){
								data = eval("("+response.responseText+")");
								if(data['success']){
									Ext.getCmp('step1').hide();
									Ext.getCmp('step2').show();
									Ext.get('winfo').update("Step 2/5: "+txt['tx_group_dealer']);
								}else{
									alert(data['msg']);
								}
							}
						});
					}
				}
			}]
		},{	
			layout: 'form',
			id: 'step2',
			border: false,
			bodyStyle: 'margin-top: 10px;background-color:#000',
			buttonAlign: 'center',
			frame:false,
			hidden: true,
			defaults: {
				allowBlank: false,
				msgTarget: 'under'
			},
			items:[{
				xtype: 'textfield',
				id: 'r_h_firma',
			//allowBlank: false,
				fieldLabel: txt['tx_firma']+'*'
			},{
				xtype: 'textfield',
				id: 'r_h_verkaeufer',
				allowBlank: true,
				fieldLabel: txt['tx_kontaktperson']
			},{
				xtype: 'textfield',
				id: 'r_h_telefon',
				allowBlank: true,
				fieldLabel: txt['tx_telefon']
			},{
				xtype: 'textfield',
				id: 'r_h_strasse',
				fieldLabel: txt['tx_strasse']+'*'
			},{
				layout: 'column',
				border: false,
				bodyStyle: 'background-color:#000',
				frame: false,
				width: 500,
				items:[{
					layout: 'form',
					border: false,
					bodyStyle: 'background-color:#000',
					width: 200,
					frame: false,
					items:[{
						xtype: 'textfield',
						id: 'r_h_plz',
						fieldLabel: txt['tx_plz']+'*',
						allowBlank: false,
						width: 80,
						style: 'margin-right:10px;'
					}]
				},{
					layout: 'form',
					bodyStyle: 'background-color:#000',
					border: false,
					frame: false,
					labelWidth: 40,
					items:[{
						xtype: 'textfield',
						id: 'r_h_ort',
						width: 150,
						allowBlank: false,
						fieldLabel: txt['tx_ort']+'*'
					}]
				}]
			},{
				xtype: 'combo',
				name: 'h_land',
				id: 'h_land',
				hiddenName: 'r_h_land',
				mode: 'local',
				width: 230,
				fieldLabel: txt['tx_land']+'*',
				displayField: 'Name',
				valueField: 'ISO-3',
				store: storeCountry,
				typeAhead: true,
		   		triggerAction: 'all',
				selectOnFocus: true,
				forceSelection: true,
				listWidth:'240'//,
				//allowBlank: false
			}],

			buttons: [{
				text: txt['tx_weiter'],
				handler: function(){
					if(validate('step2')){
						Ext.getCmp('step2').hide();
						Ext.getCmp('step3').show();
						Ext.get('winfo').update("Step 3/5: "+txt['tx_group_customer']);
					}

				}
			}]
			
	},{
			layout: 'form',
			id: 'step3',
			border: false,
			bodyStyle: 'margin-top: 10px;background-color:#000',
			buttonAlign: 'center',
			frame:false,
			hidden: true,
			defaults: {
				allowBlank: false,
				msgTarget: 'under'
			},
			items:[{
				xtype: 'textfield',
				id: 'r_k_name',
				fieldLabel: txt['tx_name']+'*'
			},{
				xtype: 'textfield',
				id: 'r_k_vorname',
				fieldLabel: txt['tx_vorname']+'*'//,
				//allowBlank: false
			},{
				xtype: 'textfield',
				id: 'r_k_telefon',
				fieldLabel: txt['tx_telefon'],
				allowBlank: true
			},{
				xtype: 'textfield',
				id: 'r_k_strasse',
				fieldLabel: txt['tx_strasse']+'*'
			},{
				layout: 'column',
				border: false,
				bodyStyle: 'background-color:#000',
				frame: false,
				width: 500,
				items:[{
					layout: 'form',
					bodyStyle: 'background-color:#000',
					border: false,
					frame: false,
					width: 200,
					items:[{
						xtype: 'textfield',
						id: 'r_k_plz',
						fieldLabel: txt['tx_plz']+'*',
						width: 80,
						style: 'margin-right:10px;',
						allowBlank: false
					}]
				},{
					layout: 'form',
					bodyStyle: 'background-color:#000',
					border: false,
					frame: false,
					labelWidth: 40,
					items:[{
						xtype: 'textfield',
						id: 'r_k_ort',
						width: 150,
						fieldLabel: txt['tx_ort']+'*',
						allowBlank: false
					}]
				}]
			},{
				xtype: 'combo',
				name: 'k_land',
				id: 'k_land',
				hiddenName: 'r_k_land',
				mode: 'local',
				width: 230,
				fieldLabel: txt['tx_land']+'*',
				displayField: 'Name',
				valueField: 'ISO-3',
				store: storeCountry,
				typeAhead: true,
		   		triggerAction: 'all',
				selectOnFocus: true,
				forceSelection: true,
				listWidth:'240',
				allowBlank: false
			},{
				xtype: 'textfield',
				id: 'r_k_fax',
				fieldLabel: 'Fax',
				allowBlank: true
			},{
				xtype: 'textfield',
				id: 'r_k_email',
				fieldLabel: 'E-Mail*',
				vtype: 'email'
			}],

			buttons: [{
				text: txt['tx_weiter'],
				handler: function(){
					if(validate('step3')){
						Ext.getCmp('step3').hide();
						Ext.getCmp('step4').show();
						Ext.get('lucas').hide();
						Ext.get('winfo').update("Step 4/5: "+txt['tx_group_questions']);
					}
				}
			}]
			
		},{
			layout: 'form',
			id: 'step4',
			border: false,
			bodyStyle: 'margin-top: 10px;background-color:#000;',
			style: 'background-color:#000;',
			height: 430,
			autoScroll: true,
			buttonAlign: 'center',
			frame:false,
			hidden: true,
			defaults: {
				labelStyle: 'width:250px;*margin-top:20px;background-color:#000'
			},
			items:[{
				xtype: 'radiogroup',
				fieldLabel: txt['how_old_are_you'],
				labelStyle: '*margin-top:0px;width:250px;background-color:#000',
				columns: [80, 80, 80],
				vertical: true,
				name: 'idAge',

				items:[{
					xtype: 'radio',
					name: 'q_alter',
					inputValue: '< 17',
					boxLabel: '< 17'
				},{
					xtype: 'radio',
					name: 'q_alter',
					inputValue: '18-25',
					boxLabel: '18-25'
				},{
					xtype: 'radio',
					name: 'q_alter',
					inputValue: '26-35',
					boxLabel: '26-35'
				},{
					xtype: 'radio',
					name: 'q_alter',
					inputValue: '36-45',
					boxLabel: '36-45'
				},{
					xtype: 'radio',
					name: 'q_alter',
					inputValue: '46-55',
					boxLabel: '46-55'
				},{
					xtype: 'radio',
					name: 'q_alter',
					inputValue: '> 46',
					boxLabel: '> 46'
				}]
			},{
				xtype: 'checkboxgroup',
				fieldLabel: txt['how_do_you_use'],
				bodyStyle: 'background-color: #000',
				style: 'margin-top: 20px',
				columns: [140, 270],
				vertical: true,
				name: 'idUse',
				defaults: {
					labelStyle: 'width:250px;*margin-top:20px;background-color:#000'
				},
				items:[{
					xtype: 'checkbox',
					name: 'q_hobby',
					inputValue: 'yes',
					boxLabel: txt['tx_hobby']
				},{
					xtype: 'checkbox',
					name: 'q_semi_pro',
					inputValue: 'yes',
					boxLabel: txt['tx_semi_pro']
				},{
					xtype: 'checkbox',
					name: 'q_pro',
					inputValue: 'yes',
					boxLabel: txt['tx_pro']
				},{
					xtype: 'checkbox',
					name: 'q_verleih',
					inputValue: 'yes',
					boxLabel: txt['tx_verleih']
				},{
					xtype: 'checkbox',
					name: 'q_solo',
					inputValue: 'yes',
					boxLabel: txt['tx_entertainer']
				},{
					xtype: 'checkbox',
					name: 'q_band',
					inputValue: 'yes',
					boxLabel: txt['tx_band']
				},{
					xtype: 'checkbox',
					name: 'q_multimedia',
					inputValue: 'yes',
					boxLabel: txt['tx_multimedia']
				},{
					xtype: 'checkbox',
					name: 'q_studio',
					inputValue: 'yes',
					boxLabel: txt['tx_tonstudio']
				},{
					xtype: 'checkbox',
					name: 'q_dj',
					inputValue: 'yes',
					boxLabel: 'DJ'
				},{
					xtype: 'checkbox',
					name: 'q_festinstall',
					inputValue: 'yes',
					boxLabel: txt['tx_festinstallation']
				}/*,{
					xtype: 'textfield',
					name: 'q_sonst',
					fieldLabel: txt['tx_other']
				}*/]
			},{
				xtype: 'radiogroup',
				fieldLabel: txt['how_long'],
				style: 'margin-top: 20px',
				columns: [80, 80, 80],
				vertical: true,
				name: 'idExperience',
				items:[{
					xtype: 'radio',
					name: 'q_taetigkeit',
					inputValue: '< 1',
					boxLabel: '< 1'
				},{
					xtype: 'radio',
					name: 'q_taetigkeit',
					inputValue: '1-2',
					boxLabel: '1-2'
				},{
					xtype: 'radio',
					name: 'q_taetigkeit',
					inputValue: '3-5',
					boxLabel: '3-5'
				},{
					xtype: 'radio',
					name: 'q_taetigkeit',
					inputValue: '5-10',
					boxLabel: '5-10'
				},{
					xtype: 'radio',
					name: 'q_taetigkeit',
					inputValue: '> 10',
					boxLabel: '> 10'
				}]
			},{
				xtype: 'checkboxgroup',
				fieldLabel: txt['how_did_you_find_out'],
				style: 'margin-top: 20px',
				columns: 1,
				vertical: true,
				name: 'idFindOut',
				items:[{
					xtype: 'checkbox',
					name: 'q_haendlergespraech',
					inputValue: 'yes',
					boxLabel: txt['tx_dealer_info']
				},{
					xtype: 'checkbox',
					name: 'q_freunde',
					inputValue: 'yes',
					boxLabel: txt['tx_friends_info']
				},{
					xtype: 'checkbox',
					name: 'q_konzert',
					inputValue: 'yes',
					boxLabel: txt['tx_concert_info']
				},{
					xtype: 'checkbox',
					name: 'q_prospekt',
					inputValue: 'yes',
					boxLabel: txt['tx_prospekt_info']
				},{
					xtype: 'checkbox',
					name: 'q_internet',
					inputValue: 'yes',
					boxLabel: txt['tx_internet_info']
				},{
					xtype: 'checkbox',
					name: 'q_messe',
					inputValue: 'yes',
					boxLabel: txt['tx_messe_info']
				},{
					xtype: 'checkbox',
					name: 'q_fachzeitschrift',
					inputValue: 'yes',
					boxLabel: txt['tx_journal_info']
				},{
					xtype: 'textfield',
					name: 'q_zeitschriften',
					fieldLabel: txt['tx_which']
				}]
			},{
				xtype: 'checkboxgroup',
				fieldLabel: txt['why_did_you_buy'],
				style: 'margin-top: 20px',
				columns: 1,
				vertical: true,
				name: 'idFindOut',
				items:[{
					xtype: 'checkbox',
					name: 'q_markenname',
					inputValue: 'yes',
					boxLabel: txt['tx_marke']
				},{
					xtype: 'checkbox',
					name: 'q_garantie',
					inputValue: 'yes',
					boxLabel: txt['tx_garantie']
				},{
					xtype: 'checkbox',
					name: 'q_preis',
					inputValue: 'yes',
					boxLabel: txt['tx_preis']
				},{
					xtype: 'checkbox',
					name: 'q_features',
					inputValue: 'yes',
					boxLabel: txt['tx_ausstattung']
				},{
					xtype: 'checkbox',
					name: 'q_qualitaet',
					inputValue: 'yes',
					boxLabel: txt['tx_quality']
				},{
					xtype: 'checkbox',
					name: 'q_design',
					inputValue: 'yes',
					boxLabel: txt['tx_design']
				},{
					xtype: 'checkbox',
					name: 'q_handling',
					inputValue: 'yes',
					boxLabel: txt['tx_handling']
				},{
					xtype: 'checkbox',
					name: 'q_test',
					inputValue: 'yes',
					boxLabel: txt['tx_testbericht']
				},{
					xtype: 'checkbox',
					name: 'q_sound',
					inputValue: 'yes',
					boxLabel: txt['tx_sound']
				},{
					xtype: 'textfield',
					fieldLabel: txt['tx_other'],
					name: 'q_kauf_sonstiges'
				}]
			}],

			buttons: [{
				text: txt['tx_weiter'],
				handler: function(){
					Ext.getCmp('step4').hide();
					Ext.getCmp('step5').show();
					Ext.get('winfo').update("Step 5/5: "+txt['tx_group_final']);
					Ext.get('lucas').show();
				}
			}]

		},{
			layout: 'form',
			id: 'step5',
			border: false,
			bodyStyle: 'margin-top: 10px;background-color:#000;color:#fff;overflow:hidden',
			height: 150,
			autoScroll: true,
			buttonAlign: 'center',
			frame:false,
			hidden: true,
			defaults: {
				labelStyle: 'width:250px;*margin-top:20px;'
			},

			items:[{
				xtype: 'checkbox',
				hideLabel: true,
				checked: false,
				name: 'garantie_accept',
				inputValue: 'yes',
				boxLabel: txt['tx_garantie_accept']
			}],

			buttons:[{
				text: txt['tx_senden'],
				handler: function(){
					var warrantyAccepted=registerForm.getForm().findField("garantie_accept").getValue();
					if(warrantyAccepted){
						registerForm.getForm().submit({
							url: 'register.php5?mode=register',
							success: function(){
								alert(txt['tx_reg_final']);
								location.href="register.php5";
							}
						});
					}else{
						alert(txt['tx_warranty_not_accepted']);
					}

				}
			}]
		}]
	});





/*					Ext.getCmp('step1').hide();
					Ext.getCmp('step5').show(); 
*/			
					/*
					Ext.get('winfo').update("Step 4/4: "+txt['tx_group_questions']);
					Ext.get('contactForm').setStyle("padding-top", "30px");
					Ext.get('contactForm').setStyle("overflow", "auto");*/

	Ext.get('winfo').update("Step 1/5: "+txt['tx_group_product']);

}

function validate(what){
	valid=true;
	Ext.getCmp(what).items.each(function(item,index,length){
		if(!item.isXType('panel')){
			if(!item.isValid()){
				valid=false;
			}
		}
	});

	return valid;
}

