// JavaScript Document


/*DEV*/

function SwitchProduct(ki){
	document.location.href = "?MonProduit="+ki.value;
}

/*FIN DEV*/

function ShowAvertissement(ki){
	ki.className = "avertissementOn";
}


function UpdateProduitOld(ki){
	if(ki.id=="dejasuivi1"){
		document.getElementById("dejasuivi2").checked = false;
		document.getElementById("dejasuivi3").checked = false;
		document.getElementById("dejasuivi4").checked = false;
		document.getElementById("dejasuivi5").checked = false;
		document.getElementById("dejasuivi6").checked = false;
	}else{
		document.getElementById("dejasuivi1").checked = false;
	
	}
	
//	alert(document.getElementById("dejasuivi").value);
}


function CheckIdentifiants(){
	if(document.getElementById("ctx_email").value!="" && verifmail(document.getElementById("ctx_email").value) && document.getElementById("ctx_passe").value!=""){
		document.connexion.submit();
	}else{
		
		if(document.getElementById("ctx_email").value=="" || !verifmail(document.getElementById("ctx_email").value)){
			document.getElementById("ctx_email").style.borderColor = "#8c0000";
		}else{
			document.getElementById("ctx_email").style.borderColor = "#ffffff";
		}

		if(document.getElementById("ctx_passe").value==""){
			document.getElementById("ctx_passe").style.borderColor = "#8c0000";
		}else{
			document.getElementById("ctx_passe").style.borderColor = "#ffffff";
		}
		
	}
}

function CheckInscription2(){
	erreur = 0;
	
	if(document.form.b_date){
		with(b_date = document.form.b_date){
			if(b_date.value==""){ AlertChamp(b_date); erreur++; }else{ AutoriseChamp(b_date); }
		} //debut cure
	}
	
	with(mych = document.form.degre_cellulite){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //cellulite
	with(mych = document.form.minceur){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //minceur
	with(mych = document.form.fermete_peau){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //fermete
	with(mych = document.form.alimentation){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //alimentation
	with(mych = document.form.sport){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //sport
	
	if(erreur==0){ document.form.submit(); }

}


/*
function ValideFormFin(){
	erreur = 0;

	with(mych = document.satisfaction.satisfait){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //satisfait
	with(mych = document.satisfaction.note){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //note
	with(mych = document.satisfaction.efficacite){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //efficacite
	with(mych = document.satisfaction.fermete){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //fermete
	with(mych = document.satisfaction.parfum){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //parfum
	with(mych = document.satisfaction.rapport){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //rapport
	with(mych = document.satisfaction.action){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //action
	//deplu
	with(mych = document.satisfaction.avenir){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //avenir
	with(mych = document.satisfaction.attentes){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //attentes
	//attentewhy
	
	if(erreur==0){ document.satisfaction.submit(); }else{
		alert("Attention, les champs en rouge sont erronés ou incomplets");	
	}

}
*/
function ValideFormFin(){
	erreur = 0;

	with(mych = document.satisfaction.note){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //note
	with(mych = document.satisfaction.avenir){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //avenir
	with(mych = document.satisfaction.attentes){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } } //programme
 
	if(erreur==0){ document.satisfaction.submit(); }else{
		alert("Attention, les champs en rouge sont erronés ou incomplets");	
	}

}


function CheckForm(){
	erreur = 0;
	
	//civilite
	with(mych = document.form.civilite){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }

	//nom
	with(mych = document.form.nom){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }
	
	//prenom
	with(mych = document.form.prenom){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }

	//date naissance
	with(jour = document.form.b_jour,mois = document.form.b_mois,annee = document.form.b_annee){ if(jour.value=="" || mois.value=="" || annee.value==""){ AlertChamp(jour); AlertChamp(mois); AlertChamp(annee); erreur++; }else{ AutoriseChamp(jour); AutoriseChamp(mois); AutoriseChamp(annee); } }
	
	//Email + Confirmation
	with(mych = document.form.mail,mychconfirm = document.form.mailconfirm){
		if(mych.value=="" || mychconfirm.value==""){
			AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
		}else{
			if(mych.value==mychconfirm.value && verifmail(mych.value)){
				AutoriseChamp(mych); AutoriseChamp(mychconfirm);
			}else{
				AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
			}
		}
	}
	
	//Mot de passe + Confirmation
	with(mych = document.form.pass,mychconfirm = document.form.passconfirm){
		if(mych.value=="" || mychconfirm.value==""){
			AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
		}else{
			if(mych.value==mychconfirm.value){
				AutoriseChamp(mych); AutoriseChamp(mychconfirm);
			}else{
				AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
			}
		}
	}
	
	//Avez-vous déjà suivi un traitement Somatoline Cosmetic ?
	if(document.getElementById("dejasuivi1").checked || document.getElementById("dejasuivi2").checked || document.getElementById("dejasuivi3").checked || document.getElementById("dejasuivi4").checked || document.getElementById("dejasuivi5").checked || document.getElementById("dejasuivi6").checked || document.getElementById("dejasuivi7").checked){
		for(ct=1;ct<=7;ct++){ AutoriseChamp(document.getElementById("dejasuivi"+ct)); }
	}else{
		for(ct=1;ct<=7;ct++){ AlertChamp(document.getElementById("dejasuivi"+ct)); }
		erreur++;
	}
	
	//Êtes vous en possession d’un traitement Somatoline Cosmetic ?
	with(mych = document.form.traitementencours){
		if(mych.value==""){
			AlertChamp(mych);
			erreur++;
		}else{
			AutoriseChamp(mych);
			//Si oui, quel traitement suivez-vous ?
			if(mych.value=="1" || mych.value=="2"){ with(mychsuite = document.form.traitementencourswhat){ if(mychsuite.value==""){ AlertChamp(mychsuite); erreur++; }else{ AutoriseChamp(mychsuite); } } }
		}
	}

		
	if(document.form.recevoirinfos[0].checked==false && document.form.recevoirinfos[1].checked==false){
		AlertChamp(document.form.recevoirinfos[0]);
		AlertChamp(document.form.recevoirinfos[1]);
		erreur++;
	}else{
		AutoriseChamp(document.form.recevoirinfos[0]);
		AutoriseChamp(document.form.recevoirinfos[1]);
	}

	

	if(erreur==0){
		document.form.submit();
	}else{
		alert("Attention, les champs en rouge sont erronés ou incomplets");	
	}
	
}

function SelectNoNewsletter(){
	alert("Attention, en sélectionnant « non » vous décidez de ne pas bénéficier du programme de suivi Somatoline Cosmetic.");
}

function CheckMesDonnees(){
	erreur = 0;
	
	//civilite
	with(mych = document.form.civilite){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }

	//nom
	with(mych = document.form.nom){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }
	
	//prenom
	with(mych = document.form.prenom){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }

	//date naissance
	with(jour = document.form.b_jour,mois = document.form.b_mois,annee = document.form.b_annee){ if(jour.value=="" || mois.value=="" || annee.value==""){ AlertChamp(jour); AlertChamp(mois); AlertChamp(annee); erreur++; }else{ AutoriseChamp(jour); AutoriseChamp(mois); AutoriseChamp(annee); } }
	
	//Email + Confirmation
	with(mych = document.form.mail,mychconfirm = document.form.mailconfirm){
		if(mych.value=="" || mychconfirm.value==""){
			AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
		}else{
			if(mych.value==mychconfirm.value && verifmail(mych.value)){
				AutoriseChamp(mych); AutoriseChamp(mychconfirm);
			}else{
				AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
			}
		}
	}
	
	//Mot de passe + Confirmation
	with(mych = document.form.pass,mychconfirm = document.form.passconfirm){
		if(mych.value=="" || mychconfirm.value==""){
			AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
		}else{
			if(mych.value==mychconfirm.value){
				AutoriseChamp(mych); AutoriseChamp(mychconfirm);
			}else{
				AlertChamp(mych); AlertChamp(mychconfirm); erreur++;
			}
		}
	}
	
	if(erreur==0){ document.form.submit(); }
	
}




function CheckConfirmMesDonnees(){
	erreur = 0;
	
	//civilite
	with(mych = document.form.civilite){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }

	//nom
	with(mych = document.form.nom){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }
	
	//prenom
	with(mych = document.form.prenom){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }

	//date naissance
	with(jour = document.form.b_jour,mois = document.form.b_mois,annee = document.form.b_annee){ if(jour.value=="" || mois.value=="" || annee.value==""){ AlertChamp(jour); AlertChamp(mois); AlertChamp(annee); erreur++; }else{ AutoriseChamp(jour); AutoriseChamp(mois); AutoriseChamp(annee); } }
	
	with(mych = document.form.traitementwait){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }
	
	if(erreur==0){ document.form.submit(); }
	
}





function CheckDiagnostic(){
	erreur = 0;

	//choix problematique
	with(mych = document.form.problematique){ if(mych.value==""){ AlertChamp(mych); erreur++; }else{ AutoriseChamp(mych); } }
	
	if(erreur==0){ document.form.submit(); }else{
		alert("Attention, les champs en rouge sont erronés ou incomplets");	
	}
}


function UpdatePossessionTraitement(ki){
	if(ki.value=="0"){
		document.form.traitementencourswhat.disabled = true;
		document.form.traitementencourswhat.selectedIndex = 0;
		AutoriseChamp(document.form.traitementencourswhat);
	}else{
		document.form.traitementencourswhat.disabled = false;
	}
}




function show_flash(adresse,largeur,hauteur){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+largeur+'" height="'+hauteur+'" title="">');
	document.write('<param name="movie" value="'+adresse+'">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="quality" value="high">');
	document.write('<embed src="'+adresse+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largeur+'" height="'+hauteur+'" wmode="transparent"></embed>');
	document.write('</object>');
}





function GetId(id){
	return document.getElementById(id);
}
function move(e) {
	if(i) {  // Si la bulle est visible, on calcul en temps reel sa position ideale
		if (navigator.appName!="Microsoft Internet Explorer") {
		GetId("curseur").style.left=e.pageX + 5+"px";
		GetId("curseur").style.top=e.pageY + 10+"px";
		}else{
		GetId("curseur").style.left=20+event.x+document.body.scrollLeft+"px";
		GetId("curseur").style.top=10+event.y+document.body.scrollTop+"px";
		}
	}
}
 
function ShowBulle(e) {
	if(i==false){
		Legendes = new Array("",
			"Sur une échelle de <b>1 à 10</b>, veuillez évaluer<br>le niveau de fermeté de votre peau<br>(10 représentant une peau très ferme)",
			"<b>Stade 0 :</b> pas  de cellulite.<br /><b>Stade 1 :</b> le  pincement seul induit l\'aspect « peau  d\'orange » de la peau.<br /><b>Stade 2 :</b> la  peau prend un aspect « peau  d\'orange » en position  debout mais reste lisse en position couchée.<br /><b>Stade 3 :</b> l\'aspect « peau  d\'orange » est présent quelle que soit la position.",
			"Sur une échelle de <b>1 à 10</b>, veuillez évaluer<br>la perception de votre silhouette<br>(10 étant votre silhouette idéale).",
			"Nombre d'applications par jour",
			"Nombre de jours d'application",
			"<b>1</b> Alimentation déséquilibrée (très riche en graisses, en sel et en sucre)<br /><b>2</b> Alimentation peu saine (quelques excès en graisses, en sel et en sucre)<br /><b>3</b> Alimentation saine (très peu d'excès, alimentation générale équilibrée)<br /><b>4</b> Alimentation très saine (aucun excès, alimentation très équilibrée)",
			"<b>1</b> Aucune  pratique du sport<br /><b>2</b> Pratique du  sport faible et irrégulière<br /><b>3</b> Pratique du  sport moyenne et régulière<br /><b>4</b> Pratique intensive du sport"
		);
		GetId("curseur").innerHTML = Legendes[e]; // on copie notre texte dans l'élément html
		GetId("curseur").style.visibility="visible"; // Si il est cacher (la verif n'est qu'une securité) on le rend visible.
		i=true;
	}
}

function HideBulle() {
	if(i==true){
		GetId("curseur").style.visibility="hidden"; // Si la bulle est visible on la cache
		i=false;
		GetId("curseur").style.left="0px";
		GetId("curseur").style.top="0px";
	}
}

function AlertChamp(ki){
	//ki.style.border = "1px solid #8c0000";
	ki.style.backgroundColor = "#FFD5D6";
	//if(ki.type=="checkbox"){ ki.style.border = "2px solid #FFD5D6"; }
	
}

function AutoriseChamp(ki){
	//ki.style.border = "1px solid #0cb1b4";
	ki.style.backgroundColor = "";
	//if(ki.type=="checkbox"){ ki.style.border = "none"; }
}


function verifmail(adrr){
	 var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	 if(reg.test(adrr)==true) return true;
	 else return false;  
}


function protectmail(origine,lien){
	
	learo="benjaminsisko";
	lepoint="jonathanarcher";
	origine=origine.split(learo);
	origine = origine[0]+"@"+origine[1];
	if(lien){
		return '<a href="mailto:'+origine+'">'+lien+'</a>';
	}else{
		return '<a href="mailto:'+origine+'">'+origine+'</a>';
	}
}

//AJAX ===============================================================================
function getXMLHTTPRequest(){
var req = false;
try
  {
   req = new XMLHttpRequest(); /* e.g. Firefox */
  }
catch(err1)
  {
  try
    {
     req = new ActiveXObject("Msxml2.XMLHTTP");
  /* some versions IE */
    }
  catch(err2)
    {
    try
      {
       req = new ActiveXObject("Microsoft.XMLHTTP");
  /* some versions IE */
      }
      catch(err3)
        {
         req = false;
        }
    }
  }
return req;
}

var myRequest = getXMLHTTPRequest();

function myRandom(){
	return new Date().getTime();
}

function UpdateCureStep(ki,el,phase,src,cure){
	
		url = "inc.update.cure.step.php";
		//document.getElementById(src).innerHTML = "envoi en cours";
		ki.disabled=true;
		ki.style.backgroundImage="url(imgs/interface/loading.gif)";

		myRequest.open("GET", url+"?rand="+myRandom()+"&element="+el+"&valeur="+ki.value+"&phase="+phase+"&cure="+cure, true); //ask our XMLHTTPRequest object to open a server connection
		myRequest.onreadystatechange = function(){
			if(myRequest.readyState == 4) { // we are only interested in readyState of 4, i.e. "loaded"
				if(myRequest.status == 200) { // if server HTTP response is "OK"
					//document.getElementById(src).innerHTML = myRequest.responseText;
					ki.disabled=false;
					ki.style.backgroundImage="none";
				} else {
					alert("An error has occurred: " + myRequest.statusText); // issue an error message for any other HTTP response
				}
			}
		}
		myRequest.send(null);// and finally send the request

}


function SendPassword(){
		ki = "emailoubli";
		zemail = document.getElementById(ki).value;
		if(zemail!="" && verifmail(zemail)){
			AutoriseChamp(document.getElementById(ki));
			document.oubli.submit();
		}else{
			AlertChamp(document.getElementById(ki));
		}
	
}
