// JavaScript Document
var ok;
function focusin(input,init){
	if(input.value == init){
		input.value ="";
	}
}
function focusout(input,init){
	if(input.value == ""){
		input.value =init;
	}
}
function formulaire(){
	ok= true;
	inputset(validecourriel(document.getElementsByName('Infolettre').item(0).value),document.getElementsByName('Infolettre').item(0));	
	if(ok){
		sendForm(document.getElementsByName('Infolettre').item(0).value)
	}
	return false;
}
function sendForm(courriel)
{
	 $.getJSON("/includes/envoiCourriel.php",
	  {
		courriel: courriel
	  },
	  function(data) {
	   	merci( data.rep);
	  });
}
function merci(msg){

	document.getElementsByName('Infolettre').item(0).value = msg;
	document.getElementsByName('Infolettre').item(0).style.border='3px solid none';
}

function validecourriel(courriel){
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]­{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	return reg.test(courriel);
}

function inputset(valide,input){
	if(!valide)
	{	
		ok=false;
		input.style.border='3px solid #F00';
	}
    else
    {
        input.style.border='3px solid none';
    }
}
