function configCompte()
{
	function validateFileExtension(fileName) {
		var exp = /^.*.(jpg|JPG)$/;
		return exp.test(fileName);
	}
	var pictUploadForm = new Ext.FormPanel({
	   columnWidth:.5,
	   labelWidth:130,
	   bodyStyle: 'paddingLeft:5px',
	   height:'100%',
	   url: 'admin/php/config-comptes.php',
	   method: 'POST',
	   fileUpload: true,
	   items: [{xtype:'fieldset', title:'Votre logo',height:289,items:[{xtype:'label',text:'Le logo apparaîtra en en-tête des pages de votre site EVimmo3d. Format idéal : 200pixels x 120pixels'},{layout:'form',style:'paddingTop:5px',items:[{
		  xtype: 'textfield',
		  fieldLabel: '1- Fichier au format JPG',
		  labelSeparator: '',
		  name: 'newPic',
		  id:'newPic',
		  inputType: 'file',
		  allowBlank: false
		  },{ 
			xtype: 'box',
			autoEl: { tag: 'div',
			style: 'padding-bottom:5px',
			html: '<img id="pic" src="' + Ext.BLANK_IMAGE_URL + '" height="120"/>'
			}
		},
		  {
		  labelSeparator:"&nbsp:",
		  xtype:'button',
		  fieldLabel:'2- Charger logo',
		  text:'Charger',
		  width:100,
		  handler:function() {
			 var theForm = pictUploadForm.getForm();
			 if (!theForm.isValid()) {
				Ext.MessageBox.alert('Chargement du logo',
				  'Sélectionnez une image svp');
				return;
			 }
			 if (!validateFileExtension(Ext.getDom('newPic').value)) {
				Ext.MessageBox.alert('Chargement du logo',
				  'Format JPG uniquement.');
				return;
			 }
			 theForm.submit({
				params: { action: 'setLogo'},
				waitMsg: 'Chargement du logo'
			 });
			 }
			
	   }]}]}]
	});
	pictUploadForm.on({
	   actioncomplete: function(form, action) {
		  if (action.type == 'submit') {
			 var pic = action.result.data.path;
			 var search="?"+(new Date()).getTime();
			 Ext.getDom('pic').src = pic+search;
			 Ext.getDom('newPic').value = '';
		  }
	   }
	});
	var societePanel=new Ext.Panel({
		frame:true,
		title:"Ma société",
		items:[
			{layout:'column',anchor: '95%',items:[{ columnWidth: .5, id:'societeForm',layout:'form',xtype:'form',items:[
				{title:'Adresse du siège social',anchor: '95%',xtype:'fieldset',labelSeparator:"&nbsp:",defaultType: 'textfield',items:[
				{fieldLabel: 'Société', name: 'nom', anchor: '95%',allowBlank:false},
				{fieldLabel: 'Adresse', name: 'adresse1', anchor: '95%',allowBlank:false},
				{fieldLabel: 'Adresse', name: 'adresse2', anchor: '95%'},
				{fieldLabel: 'Code postal', name: 'cp', anchor: '95%',allowBlank:false},
				{fieldLabel: 'Ville', name: 'ville', anchor: '95%',allowBlank:false},
				{fieldLabel: 'Téléphone', name: 'tel1', anchor: '95%',allowBlank:false},
				{fieldLabel: 'Email contact', name: 'email', anchor: '95%',allowBlank:false,vtype:'email'},
				{fieldLabel: 'Site Web', name: 'web', anchor: '95%',type:'textfield'}]},{
				title:'Choisissez les couleurs de votre site EVimmo3d',xtype:'fieldset',labelSeparator:"&nbsp:",items:[
				new Ext.form.ComboBox({
					store: new Ext.data.JsonStore({
						id:'nom',
						root:'skins',
						totalProperty:'total',
						fields:[
							{name:'nom',type:"string"},
							{name:'thumb_path',type:'string'}
						],
						url:'admin/php/config-comptes.php',
						baseParams:{
							action:'getSkins'
						},
						autoLoad: true
						}),
					name:'skin',
					fieldLabel:'Couleurs',
					allowBlank:false,
					editable:false,
					displayField:'nom',
					typeAhead: false,
					loadingText: 'Recherche...',
					anchor: '95%',
					triggerAction:'all',
					tpl: new Ext.XTemplate(
						'<tpl for="."><div class="search-item">',
							'<h3>{nom}</h3>',
							'<img src="{thumb_path}" width="250" height="45"/>',
						'</div></tpl>'
					),
					itemSelector: 'div.search-item',
					plugins: [ new Ext.ux.FieldHelp('Choisissez la bannière de votre espace de vente') ]
				})],
				listeners:{render:societeLoad}
				}]},pictUploadForm]
			},{
				xtype:'fieldset', items:{xtype: 'box',
					autoEl: { tag: 'div',
					cls:'infos',
					html: '<img src="admin/images/info_icon.png"/>Ces informations permettront de personnaliser votre espace de vente <b>EVimmo3d</b> aux couleurs de votre société. <a href="javascript:video_help(\'personnalisation\')" style="float:right">Plus d\'aide ici</a>'
					}
				}
			}
				
		],
		tbar:[					
			'->',
			{
			iconCls : "bin_icon",
			text:"Annuler",
			handler:societeLoad
			},{
			iconCls : "save_icon",
			text:'Sauver',
			handler:societeSave
			}
		]
	});

	var contactForm=new Ext.FormPanel({
		frame:true,
		title:"Mon compte utilisateur",
		defaultType: 'textfield',
		labelWidth:150,
		items:[
			{title:'Informations personnelles',xtype:'fieldset',labelSeparator:"&nbsp:",defaultType: 'textfield',anchor: '95%',items:[
			{fieldLabel: 'Nom', name: 'nom', anchor: '95%',allowBlank:false},
			{fieldLabel: 'Prénom', name: 'prenom', anchor: '95%'},
			{fieldLabel: 'Email', name: 'email', anchor: '95%',allowBlank:false,plugins: [ new Ext.ux.FieldHelp('Adresse de destination des alertes de vente mails automatiques Evimmo') ]},
			{fieldLabel: 'Téléphone', name: 'tel1', anchor: '95%'}
			]},
			{title:'Informations de connexion',xtype:'fieldset',labelSeparator:"&nbsp:",defaultType: 'textfield',items:[
			{fieldLabel: 'Nom d\'utilisateur', name: 'login', anchor: '95%',allowBlank:false,allowBlank:false,plugins: [ new Ext.ux.FieldHelp('Nom d\'utilisateur requis pour la connexion à Evimmo') ]},
			{fieldLabel: 'Mot de passe', name: 'mdp', anchor: '95%',allowBlank:false,validateOnBlur:true,plugins: [ new Ext.ux.FieldHelp('Mot de passe requis pour la connexion à Evimmo') ]}
			]},
			{
				xtype:'fieldset', items:{
					xtype: 'box',
					autoEl: { tag: 'div',
					cls:'infos',
					html: '<img src="admin/images/info_icon.png"/>Choisissez vos informations de connexion et l\'adresse à laquelle vous souhaitez recevoir les alertes de vente <b>EVimmo3d</b>. <a href="javascript:video_help(\'utilisateur\')" style="float:right">Plus d\'aide ici</a>'
					}
				}
			}
		],
		listeners:{render:contactLoad},
		tbar:[					
			'->',
			{
			iconCls : "bin_icon",
			text:"Annuler",
			handler:contactLoad
			},{
			iconCls : "save_icon",
			text:'Sauver',
			handler:contactSave
			}
		]
		
	});

var domaineForm=new Ext.FormPanel({
	frame:true,
	title:"Adresse web",   
	url: 'admin/php/config-comptes.php',
	method: 'POST',
	trackResetOnLoad:true,
	items:[{
				xtype:'fieldset', style:'backgroundColor:orange',items:{xtype: 'box',
					autoEl: { tag: 'div',
					cls:'infos',
					html: '<img src="admin/images/info_icon.png"/>Votre espace <b>EVimmo3d</b> sera accessible à partir de cette adresse.'
					}
				}
			},
		{xtype:'fieldset',title:'Adresse Internet souhaitée pour votre espace de vente',defaultType: 'textfield',allowBlank:false,items:[
				{xtype:'hidden',name:'host',id:'host'},
				{fieldLabel: 'Adresse ', name: 'domain', id:"domain" ,width:100,maskRe:/[0-9a-zA-Z\-_]/i,plugins: [ new Ext.ux.FieldHelp('ne doit comporter que des lettres et des chiffres') ]}
		]}
		],
	tbar:[					
			'->',
			{
			iconCls : "bin_icon",
			text:"Annuler",
			handler:domainLoad
			},{
			iconCls : "save_icon",
			text:'Sauver',
			handler:domainSave
			}
		],
	listeners:{
		render:domainLoad,
		actionComplete:function(form,action){
			if(action.type=='load'){
				var el=Ext.getCmp('domain').getEl();
				var host=' .'+Ext.decode(action.response.responseText).data.host;
				//el.update('<span id="host_label">'+host+'</span>');
				if(null==Ext.get('host_label'))
				Ext.DomHelper.insertAfter(el,{tag:'span',id:'host_label',html:host});
			}
		}
	}
});
var accueilPanel=new Ext.Panel({
	frame:true,
	title:"Accueil",
	items:[{ 
		xtype: 'box',
		autoEl: { tag: 'div',
			style: 'padding-bottom:5px',
			id: 'accueil-panel',
			html: '<h1>Bienvenue</h1><p>Cet assistant va vous accompagner dans la personnalisation de votre EVimmo3d en <b>3 étapes</b>.</p><p>Cliquez <b>Suivant</b> pour continuer.</p><a href="http://www.ev3d.fr" target="_blank">Cliquez ici pour en savoir + sur EVimmo3d</a>'}
		}],
	tbar:['->',
		{
		iconCls : "next_icon",
		text:'Suivant',
		handler:function(){
			contactForm.enable();
			configTabs.setActiveTab(1);
			}
		}]
});

var endPanel=new Ext.Panel({
	frame:true,
	title:"Terminer",
	disabled:true,
	height:200,
	items:[{ 
		xtype: 'box',
		autoEl: { tag: 'div',
			style: 'padding-bottom:5px',
			id: 'accueil-panel',
			html: '<h1>Félicitations</h1><p>Vous avez configuré votre <b>EVimmo3d</b> avec succès.</p><p>Cliquez sur <b>Activer</b> pour terminer la procédure et découvrir votre nouvel espace.</p>'}
		}],
	tbar:['->',
		{
		iconCls : "end_icon",
		text:'Activer',
		handler:function(){
				var domain=Ext.getCmp('domain').getValue();
				Ext.Ajax.request({
						url : 'admin/php/config-comptes.php' , 
						params : { action : 'activate' },
						method: 'POST',
						success:function(){ 
							Ext.Msg.alert('Activation','Vous venez d\' activer votre Evimmo3d. <br>Rendez-vous sur '+domain+'.ev3d.fr.',function(btn, text){window.open('http://'+domain+'.ev3d.fr',"_self");});}
						});
			}
		}]
});

function domainLoad()
{
	domaineForm.getForm().load({		
		params:{action:'getDomain'},
		waitMsg: 'Chargement'
	});
}
function domainSave()
{	
	var form=domaineForm.getForm();
	form.submit({		
		params:{action:'setDomain'},
		waitMsg: 'Chargement',
		success:function(form, action) {
			if(page=='activation')
			{
				endPanel.enable();
				configTabs.setActiveTab(4);
			}
		},
		failure:function(form,action) {
			Ext.Msg.alert('Changement de domaine', 'le domaine '+Ext.getCmp('domain').getValue()+' n\'est pas disponible.');
		}
	});
}


	var configTabs=new Ext.TabPanel({
		style:{margin:'auto'},
		width:750,
		height:440,
		renderTo:'content',
		autoDestroy: false,
		items:[
			contactForm,
			societePanel,
			domaineForm
		],
		listeners:{
			beforetabchange:function(t,n,c){
				if(c==societePanel)
					return societeSave();
				else if(c==contactForm)
					return contactSave();
				else if(c==domaineForm)
					return domainSave();
			}
		}
	});

	Ext.getCmp('societeForm').getForm().on({
	   actioncomplete: function(form, action){
		  if(action.type == 'load'){
			 var societe = action.result.data;
			 Ext.getDom('pic').src = societe.logo;
		  }
	   }
	});
	
if(page=='activation')
{
	societePanel.on('afterrender',function(){
		var tb=societePanel.getTopToolbar();
		tb.remove(tb.items.items[2]);
		tb.remove(tb.items.items[1]);
		tb.add({
			iconCls : "next_icon",
			text:'Suivant',
			handler:function(){
				domaineForm.enable();
				configTabs.setActiveTab(3);
				}
			});
	});
	
	contactForm.on('afterrender',function(){
		var tb=contactForm.getTopToolbar();
		tb.remove(tb.items.items[2]);
		tb.remove(tb.items.items[1]);
		tb.add({
			iconCls : "next_icon",
			text:'Suivant',
			handler:function(){
				societePanel.enable();
				configTabs.setActiveTab(2);
				}
			});
	});
	
	domaineForm.on('afterrender',function(){
		var tb=domaineForm.getTopToolbar();
		tb.remove(tb.items.items[2]);
		tb.remove(tb.items.items[1]);
		tb.add({
			iconCls : "next_icon",
			text:'Suivant',
			handler:function(){
				domainSave();
				endPanel.enable();
				configTabs.setActiveTab(4);
				}
			});
		/*tb.add({
			iconCls : "activate_icon",
			text:'Activer maintenant',
			handler:function(){
				var domain=Ext.getCmp('domain').getValue();
				Ext.Msg.confirm('Activation','Vous allez maintenant activer votre Evimmo3d. Il sera disponible sur '+domain+'.',function(btn, text){
				if (btn == 'yes'){
					Ext.Ajax.request({
						url : 'admin/php/config-comptes.php' , 
						params : { action : 'activate' },
						method: 'POST',
						success:function(){ window.open(domain,"_self");}
						});
				}});
			}});*/
	});
	configTabs.insert(0,accueilPanel);
	configTabs.add(endPanel);
	societePanel.disable();
	contactForm.disable();
	domaineForm.disable();
}
configTabs.setActiveTab(0);
function societeLoad()
{	
		Ext.getCmp('societeForm').getForm().load({ 
		url: 'admin/php/config-comptes.php',
		params:{action:'read',table:'societe'},
		waitMsg: 'Chargement'
	});
}	
function societeSave()
{
	var form=Ext.getCmp('societeForm').getForm();
	if(form.isValid())
	form.submit({ 
		url: 'admin/php/config-comptes.php',
		params:{action:'save',table:'societe'},
		waitMsg: 'Sauvegarde'
	});
	else return false;
}
function contactLoad()
{	
	contactForm.getForm().load({ 
		url: 'admin/php/config-comptes.php',
		params:{action:'read',table:'utilisateur'},
		waitMsg: 'Chargement'
	});
}	
function contactSave()
{
	var form=contactForm.getForm();
	if(form.isValid())
	form.submit({ 
		url: 'admin/php/config-comptes.php',
		params:{action:'save',table:'utilisateur'},
		waitMsg: 'Sauvegarde'
	});
	else return false;
}


}
