/**
@Site référent : www.massage-alsace.com
@Créateur : Mr BERTHORELLY Frédéric.
@Date : 01/03/2009
@Pour : Mlle BORTMANN Bernadette.
*/

/** Déclaration de l'expression régulière 
permettant le contrôle de l'adresse email 
insérer par l'utilisateur */
	PatternMail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

/** 
Création d'un objet XMLHttpRequest.
Cet objet est utilisé dans la fonction 
d'envoi d'un mail. 
*/
var xhr = false;

if (window.XMLHttpRequest) 
	{
		xhr = new XMLHttpRequest();
} 
else if (window.ActiveXObject)
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
}	
/** 
Fonction appelée à l'ouverture de la page. 
Elle affiche la page d'accueil du site et règle 
l'opacité du bouton accueil à 100% ainsi que 
l'opacité des deux autres boutons à 50% 
pour IE et Navigateur moteur Gecko
*/
	function Loading()
		{
			document.getElementById('imgAccueil').style.filter = "alpha(opacity='100')";
			document.getElementById('imgAccueil').style.opacity = "1.0";
			
			document.getElementById('corps1').style.display = "block";
					
			document.getElementById('imgTar').style.filter = "alpha(opacity='50')";
			document.getElementById('imgTar').style.opacity = "0.5";
					
			document.getElementById('imgCon').style.filter = "alpha(opacity='50')";
			document.getElementById('imgCon').style.opacity = "0.5";
	}		
	
/** 
Fonction d'affichage d'une div selon le choix de 
l'utilisateur sur le menu 
*/
	function setVisible(division)
		{
			var affichage = document.getElementById(division);
				var image = document.getElementById('droite');
		
			affichage.style.display = "block";
		
			if(division == "corps1")
				{
					image.style.backgroundImage = "url('style/images/bambou.gif')";
			}
			if(division == "corps2")
				{
					image.style.backgroundImage = "url('style/images/sable.gif')";
			}
			if(division == "corps3")
				{
					image.style.backgroundImage = "url('style/images/bulles.gif')";
			}
	}
	
/** 
Fonction servant à cacher toutes les div 
du corps de l'application 
*/
	function setHidden()
		{
			for(var i = 1; i < 4; i++)
				{
					document.getElementById('corps'+i).style.display = "none";
			}
	}

/** 
Fonction d'opacité au survol 
d'un bouton. 
*/
	function Opacite(element)
		{
			document.getElementById(element).style.filter = "alpha(opacity='100')";
			document.getElementById(element).style.opacity = "1.0";
	}

/** 
Fonction d'opacité à la sortie du survol 
d'un bouton.
*/	
	function OpaciteOut(element)
		{
			document.getElementById(element).style.filter = "alpha(opacity='50')";
			document.getElementById(element).style.opacity = "0.5";
			
			if(document.getElementById('corps1').style.display == "block")
				{
					document.getElementById('imgAccueil').style.filter = "alpha(opacity='100')";
					document.getElementById('imgAccueil').style.opacity = "100";
					
					document.getElementById('imgTar').style.filter = "alpha(opacity='50')";
					document.getElementById('imgTar').style.opacity = "0.5";
					
					document.getElementById('imgCon').style.filter = "alpha(opacity='50')";
					document.getElementById('imgCon').style.opacity = "0.5";
			}
			if(document.getElementById('corps2').style.display == "block")
				{
					document.getElementById('imgAccueil').style.filter = "alpha(opacity='50')";
					document.getElementById('imgAccueil').style.opacity = "0.5";
					
					document.getElementById('imgTar').style.filter = "alpha(opacity='100')";
					document.getElementById('imgTar').style.opacity = "100";
					
					document.getElementById('imgCon').style.filter = "alpha(opacity='50')";
					document.getElementById('imgCon').style.opacity = "0.5";
			}
			if(document.getElementById('corps3').style.display == "block")
				{
					document.getElementById('imgAccueil').style.filter = "alpha(opacity='50')";
					document.getElementById('imgAccueil').style.opacity = "0.5";
					
					document.getElementById('imgTar').style.filter = "alpha(opacity='50')";
					document.getElementById('imgTar').style.opacity = "0.5";
					
					document.getElementById('imgCon').style.filter = "alpha(opacity='100')";
					document.getElementById('imgCon').style.opacity = "100";
			}
	}
	
/**
Fonction d'initialisation du formulaire. 
*/
	function setInit()
		{
			document.getElementById('adresse').value = "";
			document.getElementById('corps').value = "";
			document.getElementById('nom').value = "";
			document.getElementById('adresse').style.background = "#FFFFFF";
			document.getElementById('sujet').style.background = "#FFFFFF";
			document.getElementById('corps').style.background = "#FFFFFF";
			document.getElementById('nom').style.background = "#FFFFFF";
	}
/**
Fonction d'affichage du popup des contre indications.
*/
	function Contre_indic(e, page) { 
		var posx = 0;
		var posy = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
			}
		else if (e.clientX || e.clientY){
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}
		window.open(page,"popup",'height=335px,width=420px,top='+posx+'px,left='+posy+'px,resizable=no, toolbar=no,menubar=no, status=yes');
	}
	
function replaceAll(str, search, repl) {
 while (str.indexOf(search) != -1)
  str = str.replace(search, repl);
 return str;
}
	
/** 
Fonction d'envoi d'un email. 
*/
	function EnvoyerMail()
		{
		
			var ads = document.getElementById('adresse').value;
			var suj = document.getElementById('sujet').value;
			var cor = document.getElementById('corps').value.replace(/\n/g,'<br />');
			var nom = document.getElementById('nom').value;
			
			/**/
			 var norm = new Array('À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
			'Ì','Í','Î','Ï', 'Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý',
			'Þ','ß', 'à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î',
			'ï','ð','ñ', 'ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','ý','þ','ÿ');
			var spec = new Array('A','A','A','A','A','A','A','C','E','E','E','E',
			'I','I','I','I', 'D','N','O','O','O','0','O','O','U','U','U','U','Y',
			'b','s', 'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i',
			'i','d','n', 'o','o','o','o','o','o','u','u','u','u','y','y','b','y');

			for (var i = 0; i < spec.length; i++)
				{
					cor = replaceAll(cor, norm[i], spec[i]);
				}
			for (var z = 0; z < spec.length; z++)
				{
					nom = replaceAll(nom, norm[z], spec[z]);
				}
					
			/**/
			
			
			if(PatternMail.test(ads) && cor != "" && nom != "")
				{
					/**on appelle le fichier contenant le script php (email.php)*/
					
					xhr.open("GET", "./scripts/email.php?qui="+ads+"&sujet="+suj+"&cors="+cor+"&nom="+nom);
		
					alert("Votre email est en cours d'envoi");
    
					xhr.send(null);
					
					setInit();
					
					setHidden();
					
					Loading();
			}
			else
				{
			
					if(PatternMail.test(ads) == false){
						document.getElementById('adresse').style.background = "#fc4c7e";}
						else{
							document.getElementById('adresse').style.background = "#a4fb86";}
					if(suj == "-"){
						document.getElementById('sujet').style.background = "#fc4c7e";}
						else{
							document.getElementById('sujet').style.background = "#a4fb86";}
					if(cor == ""){
						document.getElementById('corps').style.background = "#fc4c7e";}
						else{
						document.getElementById('corps').style.background = "#a4fb86";}
					if(nom == ""){
						document.getElementById('nom').style.background = "#fc4c7e";}
						else{
						document.getElementById('nom').style.background = "#a4fb86";}	
			}		
	}
