function genNewLeadWin(){
	_newLeadWin = new Ext.Window({
		title:_lang.new_lead
		,id:'_newLeadWin'
		,width:580
		,height:500
		,closable:false
		,autoScroll:true
		,frame:true
		,region:'center'
		,modal:true
		,layout:'fit'
		,items:[
			new Ext.form.FormPanel({
				frame:true
				,id:'newLeadForm'
				,autoScroll:true
				,defaultType: 'textfield'
				,items:[
					new Ext.form.Hidden({
						id:'addr[assign2user]',
						name:'addr[assign2user]',
						value:_loggedInuserId
					}),
					new Ext.form.Hidden({
						id:'id_leadtype',
						name:'id_leadtype',
						value:'2'
					}),
					new Ext.form.Hidden({
						id:'res',
						name:'res',
						value:'1'
					}),
					new Ext.form.Hidden({
						id:'user_id',
						name:'user_id',
						value:_loggedInuserId
					}),
					{
			            xtype:'fieldset',
			            title: _lang.verwaltung,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaults: {width: 210},
			            defaultType: 'textfield',
			            items :[
			            	new Ext.form.ComboBox({
				               allowBlank: false,
				               stateful : true,
				             	fieldLabel:_lang.lead_owner + '*',
			            		id:'addr[name_durch]',
			            		name:'addr[name_durch]',
				                store:leadGetOwner,
				                hiddenName:'addr[id_durch]',
				                hiddenField:'user_id',
				               	valueField:'user_id',
								displayField:'name',
								typeAhead: true,
								mode: 'remote',
								triggerAction: 'all',
								selectOnFocus:true,
								forceSelection:true,
								editable: false,
								listeners: {
        							'render' : function(){
        								Ext.getCmp('addr[name_durch]').setValue(_loggedInuserId);
        								Ext.getCmp('addr[name_durch]').setRawValue(_loggedInFirstName + ' ' + _loggedInLastName);
        								//Ext.getCmp('addr[name_durch]').setRawValue(_loggedInuserId);
        							}
        						}
				           })
			            ]
			        },
			        {
			            xtype:'fieldset',
			            title: _lang.lead_customer_data,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaults: {width: 210},
			            defaultType: 'textfield',
			            items :[{
			                    fieldLabel: _lang.lead_company,
			                    name: 'addr[company]',
			                    id:'addr[company]'
			                }
			            ]
			        },
			        {
			            xtype:'fieldset',
			            title: _lang.lead_ansprechpartner,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaults: {width: 210},
			            defaultType: 'textfield',
			            items :[
			                    new Ext.form.ComboBox({
					                fieldLabel: _lang.lead_sal,
									emptyText: _lang.sel_sal,
									store: new Ext.data.SimpleStore({
								        fields: ['sal_name','sal_id'], 
								        data: [
								        	['keine','0']
								        	,['Herr','1']
								        	,['Frau','2']
								        ]
							        }),
							        allowBlank: true,
					                stateful : true,
					                hiddenName:'addr[salutation_id]',
					                hiddenField:'sal_id',
					                valueField:'sal_id',
        							editable: false,
									displayField:'sal_name',
									typeAhead: true,
									mode: 'local',
									id:'addr[salutation_name]',
									name:'addr[salutation_name]',
									triggerAction: 'all',
									selectOnFocus:true,
									forceSelection:true
								})
			                ,
			                {
			                    fieldLabel: _lang.lead_first_name,
			                    name: 'addr[first_name]',
			                    id:'addr[first_name]'
			                },
			                {
			                    fieldLabel: _lang.lead_last_name,
			                    name: 'addr[last_name]',
			                    id:'addr[last_name]'
			                }
			            ]
			        },
			        {
			            xtype:'fieldset',
			            title: _lang.lead_anschrift,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaults: {width: 210},
			            defaultType: 'textfield',
			            items :[
			            	{
								fieldLabel: _lang.lead_street_nr + '*',
								name: 'addr[street]',
								id: 'addr[street]',
								allowBlank: false,
								plugins: [Ext.ux.plugins.InlineItems],
								inlineItemLabel: _lang.lead_street,
								inlineItems: [ 
								{
									xtype: 'textfield',
									name: 'LegalLastName',
									inlineItemLabel: _lang.lead_nr,
									name: 'addr[street_no]',
									id: 'addr[street_no]',
									allowBlank: false
								}]
							},
							{
								fieldLabel: _lang.lead_zip_city + '*',
								name: 'addr[zip]',
								id:'addr[zip]',
								allowBlank: false,
								plugins: [Ext.ux.plugins.InlineItems],
								inlineItemLabel: _lang.lead_zip,
								width:100,
								inlineItems: [ 
								{
									xtype: 'textfield',
									name: 'addr[city]',
									id: 'addr[city]',
									width:236,
									inlineItemLabel: _lang.lead_city,
									allowBlank: false
								}]
							},
							new Ext.form.ComboBox({
			            		fieldLabel: _lang.lead_land + '*',
			            		store:getCountries,
			            		allowBlank: false,
				                stateful : true,
				                triggerAction:true,
				                hiddenName:'addr[country]',
				                hiddenField:'country_id',
				                valueField:'country_id',
								displayField:'country_name',
								typeAhead: true,
								mode: 'remote',
								id:'addr[country_name]',
								name:'addr[country_name]',
								triggerAction: 'all',
								selectOnFocus:true,
								forceSelection:true,
        						editable: false,
        						listeners: {
        							'render' : function(){
        								Ext.getCmp('addr[country_name]').setValue(82);
        								Ext.getCmp('addr[country_name]').setRawValue('Deutschland');
        							}
        						}
			            	})
			            ]
			            
			        },
			        {
			            xtype:'fieldset',
			            title: _lang.lead_general_data,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaultType: 'textfield',
			            items :[
			            	{
								fieldLabel: _lang.lead_vorw_ruf,
								name: 'addr[phone][c_presel]',
								id: 'addr[phone][c_presel]',
								value:'049',
								allowBlank: false,
								plugins: [Ext.ux.plugins.InlineItems],
								inlineItemLabel: _lang.lead_vorw_tel,
								inlineItems: [ 
									{
										xtype: 'textfield',
										name: 'addr[phone][prefix]',
										id: 'addr[phone][prefix]',
										allowBlank: true
									},
									{
										xtype: 'textfield',
										name: 'addr[phone][no]',
										id: 'addr[phone][no]',
										allowBlank: true
									}
								]
							},
							{
								fieldLabel: _lang.lead_vorw_fax,
								name: 'addr[fax][c_presel]',
								id: 'addr[fax][c_presel]',
								value:'049',
								allowBlank: false,
								plugins: [Ext.ux.plugins.InlineItems],
								inlineItemLabel: _lang.lead_vorw_f,
								inlineItems: [ 
									{
										xtype: 'textfield',
										name: 'addr[fax][prefix]',
										id: 'addr[fax][prefix]',
										allowBlank: true
									},
									{
										xtype: 'textfield',
										name: 'addr[fax][no]',
										id: 'addr[fax][no]',
										allowBlank: true
									}
								]
							},
							{
			                    fieldLabel: _lang.lead_mail,
			                    name: 'addr[email]',
			                    id:'addr[email]',
			                    width:210
			                }
							
			            ]
			        },
		            {
			            xtype:'fieldset',
			            title: _lang.lead_inform_res,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaultType: 'textfield',
			            defaults: {width: 210},
			            items :[
			            	{
			                    fieldLabel: _lang.lead_beginn + '*',
			                    name: 'addr[reserve][res_start]',
			                    id:'addr[reserve][res_start]',
			                    readOnly:true,
			                    value: new Date().format('d') + '.' + new Date().format('m.Y')
			                },
			                {
			                    fieldLabel: _lang.lead_end + '*',
			                    name: 'addr[reserve][res_until]',
			                    readOnly:true,
			                    id:'addr[reserve][res_until]',
			                    value: makeMyDate(3, 'd.m.Y')
			                }
			            ]
		            },
		            {
			            xtype:'fieldset',
			            title: _lang.lead_notice,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaults: {width: 210},
			            items :[
			            	new Ext.form.TextArea({
			            		id:'other[cmt]'
			            		,name:'other[cmt]'
			            		,fieldLabel:'Text'
			            	})
			            ]
		            }
				
				],
				buttons: [
						{
							text:_lang.close
							,handler: function(){
								_newLeadWin.destroy();
							}
						},
						{
		            		text: _lang.save_and_close,
		            		handler: function(){
								Ext.getCmp('newLeadForm').getForm().submit({
									url:ServerUrl + '' + modul_leads + '/saveLead.php', 
									waitMsg: _lang.lead_check_save,
		            			clientValidation: true,
									success:function(form, action){
										obj = Ext.util.JSON.decode(action.response.responseText);
										//GetValues(obj);
										if(obj.ok == 0){
											Ext.example.msg(_lang.failure,_lang.lead_save_fail);
										}
										if(obj.ok == 1){
											Ext.example.msg(_lang.success,_lang.lead_save_success);
											_newLeadWin.destroy();
											lead_list_grid_store.reload();
										}
										//Ext.example.msg('Erfolg','Die ge&uuml;nschte Aktion wurde erfolgreich durchgefu&uuml;hrt!');
										//_newLeadWin.destroy();
									},
									failure:function(form, action){
										Ext.example.msg(_lang.failure,_lang.failure);
									}
								});
							},
							scope:this
			        	}
			        ]
			})
		]
	});
}

function generate_lead_edit_window(){
	_lead_edit_window = new Ext.Window({
		title:_lang.lead_edit_details + ' ' + _act_lead_name
		,id:'_lead_edit_window'
		,width:850
		,height:450
		,closable:false
		,autoScroll:true
		,frame:true
		,region:'center'
		,modal:true
		,layout:'fit'
		,items:[
			new Ext.TabPanel({
				layoutOnTabChange: true,
				activeTab: 0,
				id:'lead_edit_TabPanel'
			})
		]
		,buttons:[
			{
				text:'Schliessen'
				,handler: function(){
					_lead_edit_window.destroy();
				}
			}
		]
	});
	Ext.getCmp('lead_edit_TabPanel').add({
		title: _lang.lead_gen_dat,
		id: 'general_Lead_Data',
		items:[
			new Ext.form.FormPanel({
				frame:true
				,id:'lead_edit_general'
				,autoScroll:true
				//,url:ServerUrl + '' + modul_leads + 'updater.php?lead_id=' + _act_lead_id + '&todo=getGeneralData'
				,url:ServerUrl + '' + modul_leads + '/updater.php?&person_id=' + _act_pers_id + '&lead_id=' + _actt_lead_id + '&addr_id=' + _act_addr_id + '&todo=getGeneralData'
//				,defaultType: 'textfield'
				,items:[
					new Ext.form.Hidden({
						name:'address_id'
						,id:'address_id'
						,value:_act_addr_id
					}),
					new Ext.form.Hidden({
						name:'user_id'
						,id:'user_id'
						,value:_loggedInuserId
					}),
					new Ext.form.Hidden({
						name:'lid'
						,id:'lid'
						,value:_actt_lead_id
					}),
					new Ext.form.Hidden({
						name:'id_leadtype'
						,id:'id_leadtype'
						,value:'2'
					}),
					new Ext.form.Hidden({
						name:'person_id'
						,id:'person_id'
					}),
					new Ext.form.Hidden({
						name:'company_person_id'
						,id:'company_person_id'
						,value:_act_comp_pers_id
					}),
					new Ext.form.Hidden({
						name:'[addr][reserve][res_start]'
						,id:'[addr][reserve][res_start]'
						,value:_act_res_start
					}),
					new Ext.form.Hidden({
						name:'[addr][reserve][res_until]'
						,id:'[addr][reserve][res_until]'
						,value:_act_res_until
					}),
					new Ext.form.Hidden({
						name:'addr[fax][phone_id]'
						,id:'addr[fax][phone_id]'
					}),
					new Ext.form.Hidden({
						name:'addr[phone][phone_id]'
						,id:'addr[phone][phone_id]'
					}),
					{
			            xtype:'fieldset',
			            title: _lang.verwaltung,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaults: {width: 210},
			            defaultType: 'textfield',
			            items :[
			            	new Ext.form.ComboBox({
				               allowBlank: false,
				               stateful : true,
				             	fieldLabel:_lang.lead_owner + '*',
			            		id:'addr[name_durch]',
			            		name:'addr[name_durch]',
				                store:leadGetOwner,
				                hiddenName:'addr[id_durch]',
				                hiddenField:'user_id',
				               	valueField:'user_id',
								displayField:'name',
								typeAhead: true,
								mode: 'remote',
								triggerAction: 'all',
								selectOnFocus:true,
								forceSelection:true,
								editable: false,
								listeners: {
									'render' : function(){
										Ext.getCmp('addr[name_durch]').setValue(_loggedInuserId);
										Ext.getCmp('addr[name_durch]').setRawValue(_loggedInFirstName + ' ' + _loggedInLastName);
										//Ext.getCmp('addr[name_durch]').setRawValue(_loggedInuserId);
									}
								}
				           })
			            ]
			        },
					{
			            xtype:'fieldset',
			            title: _lang.lead_customer_data,
			            collapsible: true,
			            autoHeight:true,
			            width:'95%',
			            defaults: {width: 210},
			            defaultType: 'textfield',
			            items :[{
			                    fieldLabel: _lang.lead_company,
			                    name: 'addr[company]',
			                    id:'addr[company]'
			                }
			            ]
			        },
					{
			            layout:'column',
			            border:false,
			            items:[{
			                columnWidth:.5,
			                layout: 'form',
			                border:false,
							
			                items: [{
									xtype: 'fieldset',
									title: _lang.lead_ansprechpartner,
									collapsible: true,
									autoHeight: true,
									anchor:'95%',
									defaults: {
										width: 210
									},
									items: [new Ext.form.ComboBox({
										fieldLabel: _lang.lead_sal,
										emptyText: _lang.sel_sal,
										store: new Ext.data.SimpleStore({
											fields: ['sal_name', 'sal_id'],
											data: [['keine', '0'], ['Herr', '1'], ['Frau', '2']]
										}),
										allowBlank: true,
										stateful: true,
										hiddenName: 'addr[salutation_id]',
										hiddenField: 'sal_id',
										valueField: 'sal_id',
										editable: false,
										displayField: 'sal_name',
										typeAhead: true,
										mode: 'local',
										id: 'addr[salutation_name]',
										name: 'addr[salutation_name]',
										triggerAction: 'all',
										selectOnFocus: true,
										forceSelection: true
									}), {
										fieldLabel: _lang.lead_first_name,
										xtype: 'textfield',
										name: 'addr[first_name]',
										id: 'addr[first_name]'
									}, {
										fieldLabel: _lang.lead_last_name,
										xtype: 'textfield',
										name: 'addr[last_name]',
										id: 'addr[last_name]'
									}]
								}]
			            },{
			                columnWidth:.5,
			                layout: 'form',
			                border:false,
			                items: [{
									xtype: 'fieldset',
									title: _lang.lead_ansprechpartner,
									collapsible: true,
									autoHeight: true,
									anchor:'95%',
									defaults: {
										width: 210
									},
									items: [
										{
											fieldLabel: _lang.lead_vorw_ruf,
											xtype:'textfield',
											name: 'addr[phone][c_presel]',
											id: 'addr[phone][c_presel]',
											value:'049',
											width:30,
											allowBlank: false,
											plugins: [Ext.ux.plugins.InlineItems],
											inlineItems: [ 
												{
													xtype: 'textfield',
													name: 'addr[phone][prefix]',
													id: 'addr[phone][prefix]',
													allowBlank: true,
													width:100
												},
												{
													xtype: 'textfield',
													name: 'addr[phone][no]',
													id: 'addr[phone][no]',
													allowBlank: true,
													width:100
												}
											]
										},
										{
											fieldLabel: _lang.lead_vorw_fax,
											xtype:'textfield',
											name: 'addr[fax][c_presel]',
											id: 'addr[fax][c_presel]',
											value:'049',
											width:30,
											allowBlank: false,
											plugins: [Ext.ux.plugins.InlineItems],
											inlineItems: [ 
												{
													xtype: 'textfield',
													name: 'addr[fax][prefix]',
													id: 'addr[fax][prefix]',
													allowBlank: true,
													width:100
												},
												{
													xtype: 'textfield',
													name: 'addr[fax][no]',
													id: 'addr[fax][no]',
													allowBlank: true,
													width:100
												}
											]
										},
										{
											xtype:'textfield',
						                    fieldLabel: _lang.lead_mail,
						                    name: 'addr[email]',
						                    id:'addr[email]',
						                    width:235
						                }
									]
								}]
			            }]
			        }
						
		       ],
		       buttons:[
			       	{
	            		text: _lang.save,
	            		handler: function(){
							Ext.getCmp('lead_edit_general').getForm().submit({
								url:ServerUrl + '' + modul_leads + '/updater.php?todo=updateGeneral', 
								waitMsg: _lang.lead_check_save,
	            			clientValidation: true,
								success:function(form, action){
									obj = Ext.util.JSON.decode(action.response.responseText);
									//GetValues(obj);
									if(obj.ok == 0){
										//Ext.example.msg('Fehler','Dieser Kunde wurde bereits geschützt, der Kundenschutzt kann nur auf einen Mitarbeiter je Kunde angelegt werden! Bitte wenden Sie sich an Ihren Ansprechpartner!');
									}
									if(obj.ok == 1){
										//Ext.example.msg('Erfolg','Ihr Kunde wurde für Sie erfolgreich geschützt!');
										lead_list_grid_store.reload();
									}
									Ext.example.msg(_lang.success,_lang.success);
								},
								failure:function(form, action){
									Ext.example.msg(_lang.failure,_lang.failure);
								}
							});
						},
						scope:this
		        	}
		       ],
		       listeners:{
		       		'render' : function(){
		       			this.load({
							url:this.url
							,waitMsg: _lang.load_data
						});
		       		}
		       }
			})
			
		],
		frame:false,
		layout:'fit',
		region:'center'
	});
	Ext.getCmp('lead_edit_TabPanel').add({
		title: _lang.lead_anschrift_ed,
		id: 'lead_anschrift',
		items:[
		new Ext.form.FormPanel({
			frame:true
			,id:'lead_edit_anschrift'
			,autoScroll:true
			,url:ServerUrl + '' + modul_leads + '/updater.php?company_person_id=' + _act_comp_pers_id + '&person_id=' + _act_pers_id + '&lead_id=' + _actt_lead_id + '&addr_id=' + _act_addr_id + '&todo=getaddress'
			,defaultType: 'textfield'
			,items:[new Ext.form.Hidden({
						name:'address_id'
						,id:'address_id'
						,value:_act_addr_id
					}),
					new Ext.form.Hidden({
						name:'user_id'
						,id:'user_id'
						,value:_loggedInuserId
					}),
					new Ext.form.Hidden({
						name:'lid'
						,id:'lid'
						,value:_actt_lead_id
					}),
					new Ext.form.Hidden({
						name:'id_leadtype'
						,id:'id_leadtype'
						,value:'2'
					}),
					new Ext.form.Hidden({
						name:'person_id'
						,id:'person_id'
					}),
					new Ext.form.Hidden({
						name:'company_person_id'
						,id:'company_person_id'
						,value:_act_comp_pers_id
					}),
					new Ext.form.Hidden({
						name:'[addr][reserve][res_start]'
						,id:'[addr][reserve][res_start]'
						,value:_act_res_start
					}),
					new Ext.form.Hidden({
						name:'[addr][reserve][res_until]'
						,id:'[addr][reserve][res_until]'
						,value:_act_res_until
					}),
						{
				            xtype:'fieldset',
				            title: _lang.lead_anschrift,
				            collapsible: true,
				            autoHeight:true,
				            width:'95%',
				            defaults: {width: 210},
				            defaultType: 'textfield',
				            items :[
				            	{
									fieldLabel: _lang.lead_street_nr + '*',
									name: 'addr[street]',
									id: 'addr[street]',
									allowBlank: false,
									plugins: [Ext.ux.plugins.InlineItems],
									inlineItemLabel: _lang.lead_street,
									inlineItems: [ 
									{
										xtype: 'textfield',
										name: 'LegalLastName',
										inlineItemLabel: _lang.lead_nr,
										name: 'addr[street_no]',
										id: 'addr[street_no]',
										allowBlank: false
									}]
								},
								{
									fieldLabel: _lang.lead_zip_city + '*',
									name: 'addr[zip]',
									id:'addr[zip]',
									allowBlank: false,
									plugins: [Ext.ux.plugins.InlineItems],
									inlineItemLabel: _lang.lead_zip,
									width:100,
									inlineItems: [ 
									{
										xtype: 'textfield',
										name: 'addr[city]',
										id: 'addr[city]',
										width:236,
										inlineItemLabel: _lang.lead_city,
										allowBlank: false
									}]
								},
								new Ext.form.ComboBox({
				            		fieldLabel: _lang.lead_land + '*',
				            		store:getCountries,
				            		allowBlank: false,
					                stateful : true,
					                triggerAction:true,
					                hiddenName:'addr[country]',
					                hiddenField:'country_id',
					                valueField:'country_id',
									displayField:'country_name',
									typeAhead: true,
									mode: 'remote',
									id:'addr[country_name]',
									name:'addr[country_name]',
									triggerAction: 'all',
									selectOnFocus:true,
									forceSelection:true,
									editable: false,
									listeners: {
										'render' : function(){
											Ext.getCmp('addr[country_name]').setValue(82);
											Ext.getCmp('addr[country_name]').setRawValue('Deutschland');
										}
									}
				            	})
				            ]
				            
				        },
						{
				            xtype:'fieldset',
				            title: _lang.lead_notice,
				            collapsible: true,
				            autoHeight:true,
				            width:'95%',
				            items :[
				            	new Ext.form.HtmlEditor({
				            		id:'other[cmt]'
				            		,name:'other[cmt]'
				            		,fieldLabel:'Text'
				            		,width:600
				            		,height:100
				            	})
				            ]
			            }
				 ],
				  buttons:[
			       	{
	            		text: _lang.save,
	            		handler: function(){
							Ext.getCmp('lead_edit_anschrift').getForm().submit({
								url:ServerUrl + '' + modul_leads + '/updater.php?todo=lead_edit_anschrift', 
								waitMsg: _lang.lead_check_save,
	            			clientValidation: true,
								success:function(form, action){
									obj = Ext.util.JSON.decode(action.response.responseText);
									//GetValues(obj);
									if(obj.ok == 0){
										//Ext.example.msg('Fehler','Dieser Kunde wurde bereits geschützt, der Kundenschutzt kann nur auf einen Mitarbeiter je Kunde angelegt werden! Bitte wenden Sie sich an Ihren Ansprechpartner!');
									}
									if(obj.ok == 1){
										//Ext.example.msg('Erfolg','Ihr Kunde wurde für Sie erfolgreich geschützt!');
										
									}
									lead_list_grid_store.reload();
									Ext.example.msg(_lang.success,_lang.success);
								},
								failure:function(form, action){
									Ext.example.msg(_lang.failure,_lang.failure);
								}
							});
						},
						scope:this
		        	}
		       ],
				 listeners:{
		       		'render' : function(){
		       			getCountries.load();
		       			this.load({
							url:this.url
							,waitMsg: _lang.load_data
						});
		       		}
		       }
			})
		],
		frame:false,
		layout:'fit',
		region:'center'
	});
	
}