/******************************************************AJAX****************************************************/
function FuncAJAX(div, page, data, flag)
{
	var data = data.replace(/ /g, "_")
	var data = data.replace(/'/g, "\''")
	var data = data.replace(/é/g, "e")
	var data = data.replace(/è/g, "e")
	var data = data.replace(/à/g, "a")
	var data = data.replace(/ù/g, "u")
	//alert(div);
	var content = document.getElementById(div);
	if(document.all)
	{
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		var XhrObj = new XMLHttpRequest();		
		content.innerHTML = content.innerHTML;
	}
	

	if (flag == 1)
	{
		if (document.getElementById(div).style.display == "none")
		{
			document.getElementById(div).style.display = "block"
			XhrObj.open("POST", page);
			XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			XhrObj.send(data);
			XhrObj.onreadystatechange = function() 
			{				
				if (XhrObj.readyState == 4 && XhrObj.status == 200) 
				{
					content.innerHTML = XhrObj.responseText;
				}
			}
		}
		else
			document.getElementById(div).style.display = "none"
	}
	else
	{
		XhrObj.open("POST", page);
		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(data);
		XhrObj.onreadystatechange = function() 
		{				
			if (XhrObj.readyState == 4 && XhrObj.status == 200) 
			{
				content.innerHTML = XhrObj.responseText;
			}
		}
	}
		
	
}
/*****************************************************************************************************************/

function envoyer_mail_ami() {
	if (document.getElementById('nom_exp').value == "") {
		alert("Veuillez indiquer un nom");
		document.getElementById('nom_exp').focus();
		return false;
	}
	if ((document.getElementById('mail_exp').value == "") || (!chk(document.getElementById('mail_exp').value))) {
		alert("Votre email est invalide");
		document.getElementById('mail_exp').focus();
		return false;
	}
	if ((document.getElementById('mail_ami').value == "") || (!chk(document.getElementById('mail_ami').value))) {
		alert("L'email de votre ami est invalide");
		document.getElementById('mail_ami').focus();
		return false;
	}
	FuncAJAX("vide","/pages/envoyer_ami.php","infos="+document.getElementById('page').value+"#"+document.getElementById('nom_exp').value+"#"+document.getElementById('mail_exp').value+"#"+document.getElementById('mail_ami').value);
	alert('La page a bien été envoyée à '+document.getElementById('mail_ami').value);
	fermer_mail_ami();
}

function afficher_mail_ami() {
	document.getElementById('nom_exp').value="";
	document.getElementById('mail_exp').value="";
	document.getElementById('mail_ami').value="";
	document.getElementById('envoyer_ami').style.display = 'block';
	document.getElementById('nom_exp').focus();
}

function fermer_mail_ami() {
	document.getElementById('envoyer_ami').style.display = 'none';
}

function verif_champ(nom,champ) {
	if (nom.value == "") { alert("Veuillez saisir "+champ); nom.focus(); return false; }
	return true;
}
	
function verif_select(nom,champ) {
	if (nom.selectedIndex == 0) { alert("Veuillez sélectionner "+champ); nom.focus(); return false; }
	return true;
}

function verif_int(nom,champ) {
	var chkZ = 1;
	for(i=0;i<nom.value.length;++i)
	if(nom.value.charAt(i) < "0" || nom.value.charAt(i) > "9")
		chkZ = -1;
	if(chkZ == -1) { alert(champ+" n'est pas valide"); nom.value =""; nom.focus(); return false; }
	return true;
}

function verif_mail(nom) {
	if (!chk(nom.value)) { alert("l'email est incorrect"); nom.focus(); return false; }
	return true;
}