var xmlhttp;
function loadXMLDoc(url){
	// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=state_Change
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
	}else if (window.ActiveXObject){ // code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp){
			xmlhttp.onreadystatechange=state_Change
			xmlhttp.open("GET",url,true)
			xmlhttp.send()
		}
	}
}
function state_Change(){
	if (xmlhttp.readyState==4){
		if (xmlhttp.status==200){
			document.getElementById('contenu-franchise').innerHTML=xmlhttp.responseText
		}else{
			alert("Problème pour retrouver les données :" + xmlhttp.statusText)
		}
	}
}
function popTemoins(page){
	window.open(page,"displayWindow","scrollbars=yes,status=no,height=600,width=550");
}
function showOther(arg){
	if(arg == 'autres'){
		document.getElementById('precise_connu').style.visibility = 'visible';
	}else{
		document.getElementById('precise_connu').style.visibility = 'hidden';
	}
}
function doQueryForm1(){
	var cfcObj = new Object();
	cfcObj.civilite = document.form1.civilite.options[document.form1.civilite.selectedIndex].value;
	cfcObj.nom = document.form1.nom.value;
	cfcObj.prenom = document.form1.prenom.value;
	cfcObj.adresse = document.form1.adresse.value;
	cfcObj.cp = document.form1.cp.value;
	cfcObj.ville = document.form1.ville.value;
	cfcObj.pays = document.form1.pays.value;
	cfcObj.tel = document.form1.tel.value;
	cfcObj.email = document.form1.email.value;
	cfcObj.situation = document.form1.situation.value;
	if(trim(cfcObj.nom) == ""){
		alert("vous devez saisir votre nom");
	}else if(trim(cfcObj.prenom) == ""){
		alert("vous devez saisir votre prénom");
	}else if(trim(cfcObj.tel) == ""){
		alert("vous devez saisir votre numéro de téléphone");
	}else if(trim(cfcObj.email) == "" || !emailCheck(cfcObj.email)){
		alert("Vous devez saisir votre email");
	}else{
		// ok, on envoie l'objet au cfc
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'step1', cfcObj, doQueryFirstResults);
	}
}
function doQueryFirstResults(r){
	var id_dde = r.id_dde[0];
	var str = "";
	var d = new Date();
	str = str + "<h1 align='center'>Rejoindre le r&eacute;seau AGENDA Expertises</h1>";
	str = str + "<h2>Merci de préciser votre projet. L'ensemble des informations collect&eacute;es reste strictement confidentiel.</h2>";
	str = str + "<form name='form2' onsubmit='return false'>";
	str = str + "<input type='hidden' name='id_dde' value='" + r.id_dde[0] + "' />";
	str = str + "<fieldset>";
	str = str + "<legend>Votre projet</legend>";
	str = str + "<label for='implantation' style='width:275px'><strong>Dans quel d&eacute;partement ou r&eacute;gion &nbsp;<br /> souhaitez-vous vous implanter ? &nbsp;</strong></label>";
	str = str + "<input name='implantation' style='width:100px'><br /><br />";
	str = str + "<label for='date_demarrage' style='width:275px'>A quelle date pensez-vous d&eacute;marrer ? &nbsp;</label>";
	str = str + "<input name='date_demarrage' value='jj/mm/aaaa' style='width:100px' onfocus=\"this.value='';\"><br /><br />";
	str = str + "<label for='budget' style='width:275px'><strong>Quel budget souhaitez-vous investir, &nbsp;<br />y compris emprunts bancaires ? &nbsp;</strong></label>";
	str = str + "<input name='budget' style='width:100px'><br /><br />";
	str = str + "<label for='commentaires' style='width:120px'>Commentaires : </label>";
	str = str + "<textarea name='commentaires' style='width:255px;height:60px;'></textarea><br /><br />";
	str = str + "<label for='connu_comment' style='width:155px'>Comment avez-vous &nbsp;<br />connu AGENDA ? &nbsp;</label>";
	str = str + "<select name='connu_comment' style='width:220px' onChange='showOther(this.options[selectedIndex].value);'>";
	str = str + "<option value='magazine franchise'>Magazine de franchise</option>";
	str = str + "<option value='autres revues'>Autres revues</option>";
	str = str + "<option value='bouche a oreille'>Bouche &agrave; oreille</option>";
	str = str + "<option value='publicite radio'>Publicit&eacute; radio</option>";
	str = str + "<option value='site internet'>Site Internet</option>";
	str = str + "<option value='autres'>Autres</option>";
	str = str + "</select><br /><br />";
	str = str + "<div id='precise_connu' style='visibility:hidden'>";
	str = str + "<label for='connu_comment_autres' style='width:120px'>Précisez : </label>";
	str = str +	"<input name='connu_comment_autres' style='width:255px;'><br />";
	str = str + "</div>";
	str = str +	"<div align='right'>";
	str = str + "<input name='submit2' type='submit' class='btnSubmit' style='width:80px;' value='ENVOYER' onclick='doQueryForm2();' />";
	str = str + "</div>";
	str = str + "</fieldset>";
	str = str + "</form>";
	$('bloc-central').innerHTML = str;
	var str2 = "<img src='images/recrutement/formation-reseau-agenda.jpg' alt='Rejoindre le r&eacute;seau de diagnostiqueurs AGENDA' title='Rejoindre le r&eacute;seau de diagnostiqueurs AGENDA' width='214' height='168' hspace='10' vspace='10' />";
	$('img-tableau').innerHTML = str2;
}

function doQueryForm2(){
	var cfcObj = new Object();
	cfcObj.id_dde = document.form2.id_dde.value;
	cfcObj.implantation = document.form2.implantation.value;
	cfcObj.date_demarrage = document.form2.date_demarrage.value;
	cfcObj.budget = document.form2.budget.value;
	cfcObj.commentaires = document.form2.commentaires.value;
	cfcObj.connu_comment = document.form2.connu_comment.options[document.form2.connu_comment.selectedIndex].value;
	if(document.form2.connu_comment_autres != null){
		cfcObj.connu_comment_autres = document.form2.connu_comment_autres.value;
	}else{
		cfcObj.connu_comment_autres = '';
	}
	if(trim(cfcObj.implantation) == ""){
		alert("vous devez saisir votre région ou département souhaité");
	}else if(!isDate(cfcObj.date_demarrage)){
		alert("vous devez saisir une date valide");
	}else if(trim(cfcObj.budget) == ""){
		alert("vous devez saisir votre budget");
	}else{
		// ok, on envoie l'objet au cfc
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'step2', cfcObj, doQueryEndResults);
	}
}
function doQueryEndResults(r){
	var str = "";
	str = str + "<h1 align='center'>Rejoindre le r&eacute;seau AGENDA Expertises</h1>";
	str = str + "<h2>Merci " + r.civilite[0] + " " + r.prenom[0] + " " + r.nom[0] + "<br /><br />";
	str = str + "Votre demande a bien &eacute;t&eacute; enregistr&eacute;e et nous vous en remercions.<br />";
	str = str + "Notre service d&eacute;veloppement vous contactera prochainement.<br /><br /><br />";
	str = str + "Pour en savoir plus :<br />";
	str = str + "Denis RUIZ<br />";
	str = str + "AGENDA France<br />";
	str = str + "Immeuble Le Gamma<br />";
	str = str + "95 Avenue des Logissons<br />";
	str = str + "13770 VENELLES<br />";
	str = str + "T&eacute;l. : 04 42 54 43 29<br />";
	str = str + "Fax : 04 42 54 31 15<br />";
	str = str + "<a href='mailto:denis.ruiz@agendafrance.fr?subject=Demande Informations Franchise'>denis.ruiz@agendafrance.fr</a>";
	$('bloc-central').innerHTML = str;
}
