Ext.onReady(function() {
	Ext.QuickTips.init();
	Ext.QuickTips.enable();
	Ext.BLANK_IMAGE_URL = 'scripts/ext/resources/images/default/s.gif';
	// turn on validation errors beside the field globally
	Ext.form.Field.prototype.msgTarget = 'side';
	var cp = new Ext.state.CookieProvider();
	Ext.state.Manager.setProvider(cp);
	var form_rdv;
	var cook = Ext.state.Manager.getProvider();
	var objInstantStep = {
			nom : "",
			prenom : "",
			mail : ""
	};
	objInstantStep.nom = cook.get('nom');
	objInstantStep.prenom = cook.get('prenom'); 
	objInstantStep.mail = cook.get('mail');
	function sub_dem() {
		document.location.hash='#topform'
		form_rdv.getForm().submit({
			success : function(form, action) {
				Ext.get("form_rdv").update("<p>Merci pour votre demande. Nous reprenons contact avec vous dans les plus brefs délais.</p>");
				if (location.pathname == "/contact.jsp") {
					_gaq.push(['_trackPageview', '/analytics/Contact/confirmation']);
				} else {
					_gaq.push(['_trackPageview', '/analytics/DemandeRDV/confirmation']);
				}
			},
			failure : function(form, action) {
				switch (action.failureType) {
					case Ext.form.Action.CLIENT_INVALID :
						// Ext.Msg.alert("Failure",
						// "Form fields may not be submitted with invalid
						// values");
						break;
					case Ext.form.Action.CONNECT_FAILURE :
						Ext.Msg.alert("Failure", "Ajax communication failed");
						break;
					case Ext.form.Action.SERVER_INVALID :
						Ext.Msg.alert("Failure", action.result.msg);
				}
			}
		});
	}
	form_rdv = new Ext.FormPanel({
		url : 'servlet/ProcessRdv',
		bodyStyle:'padding:10px 0 0 10px; border:none;',	
		defaults : {
			blankText : "Champ obligatoire",
			validationEvent : false
		},
		items : [{
			xtype : 'textfield',
			name : 'frmCont_nom',
			fieldLabel : 'Nom*',
			labelStyle : 'width:160px',
			width : '200px',
			allowBlank : false,
			validateOnBlur : false,
			value : objInstantStep.nom
		}, {
			xtype : 'textfield',
			name : 'frmCont_prenom',
			fieldLabel : 'Prénom*',
			labelStyle : 'width:160px',
			width : '200px',
			allowBlank : false,
			validateOnBlur : false,
			value : objInstantStep.prenom
		}, {
			xtype : 'textfield',
			name : 'frmCont_email',
			vtype : 'email',
			fieldLabel : 'Adresse e-mail*',
			labelStyle : 'width:160px',
			width : '200px',
			allowBlank : false,
			validateOnBlur : false,
			value : objInstantStep.mail
		}, {
			xtype : 'label',
			html : "<h1><br />Etes-vous déjà client chez Partenamut ?</h1>"
		}, {
			xtype : "radio",
			boxLabel : "oui",
			name : "rb_client",
			inputValue : "1",
			hideLabel : true,
			checked : true
		}, {
			xtype : "radio",
			boxLabel : "non",
			name : "rb_client",
			inputValue : "0",
			hideLabel : true
		}, {
			xtype : "radio",
			boxLabel : "Pas encore, j'arrive de l'étranger",
			name : "rb_client",
			inputValue : "2",
			hideLabel : true
		}, {
			xtype : 'label',
			html : "<br />"
		}, {
			xtype : 'panel',
			layout : 'column',
			bodyBorder : false,
			border : false,
			hideBorders : true,
			items : [{
				xtype : 'label',
				html : 'N° GSM où l\'on peut vous contacter facilement (obligatoire)*&nbsp;',
			labelStyle : 'width:160px',
			width : '200px'
			}, {
				xtype : 'label',
				html : '+&nbsp;'
			}, {
				xtype : 'numberfield',
				name : 'frmCont_prefixe',
				width : '25px',
				allowDecimals : false,
				allowNegative : false,
				validateOnBlur : false,
				selectOnFocus : true ,
				value : '32',
				fieldLabel : 'préfixe international'
			}, {
				xtype : 'label',
				html : '&nbsp;&nbsp;/&nbsp;&nbsp;'
			}, {
				xtype : 'textfield',
				name : 'frmCont_tel',
				labelStyle : 'width:160px',
				width : '200px',
				selectOnFocus : true ,
				allowBlank : false,
				validateOnBlur : false
			}]
		}, {
			xtype : 'textfield',
			name : 'frmCont_rue',
			labelStyle : 'width:160px',
			width : '200px',
			validateOnBlur : false,
			fieldLabel : 'Rue'
		}, {
			xtype : 'textfield',
			name : 'frmCont_num',
			labelStyle : 'width:160px',
			width : '200px',
			validateOnBlur : false,
			fieldLabel : 'N°'
		}, {
			xtype : 'textfield',
			name : 'frmCont_bp',
			labelStyle : 'width:160px',
			width : '200px',
			fieldLabel : 'Boite'
		}, {
			xtype : 'textfield',
			name : 'frmCont_cp',
			labelStyle : 'width:160px',
			width : '200px',
			allowBlank : false,
			validateOnBlur : false,
			fieldLabel : 'Code Postal*'
		}, {
			xtype : 'textfield',
			name : 'frmCont_ville',
			labelStyle : 'width:160px',
			width : '200px',
			validateOnBlur : false,
			fieldLabel : 'Localité'
		}, {
			xtype : 'label',
			html : "<h1><br/>Moment où vous souhaitez être contacté</h1>"
		}, {
			xtype : "radio",
			boxLabel : "Journée",
			name : "rb_time",
			inputValue : "1",
			hideLabel : true
		}, {
			xtype : "radio",
			boxLabel : "Soirée",
			name : "rb_time",
			inputValue : "2",
			hideLabel : true
		}, {
			xtype : "radio",
			boxLabel : "Peu importe",
			name : "rb_time",
			inputValue : "3",
			hideLabel : true,
			checked : true
		},{
			xtype : 'label',
			html : "<br />"
		}, {
			xtype : 'textarea',
			name : 'frmCont_com',
			labelStyle : 'width:160px',
			width : '200px',
			maxLength: 500,
			fieldLabel : 'Commentaire'
		}, {
			xtype : 'button',
			name: 'bt_sub_dem',
			text: 'Envoyer',
			handler : sub_dem
		}]
	});
	form_rdv.render(Ext.get("form_rdv"));
	Ext.get("form_rdv").insertHtml("beforeEnd","<div id='mandat_field'><br/>&nbsp;*champs obligatoires</div>");
});
