function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){
					return true;
		}
	}else{
		return false;
	}
}
function checkFields(i) {
	var stopForm = false;
	var styleClass = "#ffffff";
	var styleClassError = "#de0406";
	if (i=='comment') {
		document.getElementById('avisoComment').style.visibility = 'hidden';	
		document.getElementById('namecomment').style.backgroundColor = styleClass;
		document.getElementById('emailcomment').style.backgroundColor = styleClass;
		document.getElementById('messagecomment').style.backgroundColor = styleClass;
		document.getElementById('codeForm').style.backgroundColor = styleClass;
		if (document.getElementById('namecomment').value =='') {
			document.getElementById('namecomment').style.backgroundColor = styleClassError;
			stopForm = true;
		}
		if (document.getElementById('codeForm').value =='') {
			document.getElementById('codeForm').style.backgroundColor = styleClassError;
			stopForm = true;
		}
		if (document.getElementById('messagecomment').value =='') {
			document.getElementById('messagecomment').style.backgroundColor = styleClassError;
			stopForm = true;
		}
		var emailField = document.getElementById('emailcomment');
		if (!checkMail(emailField)) {
			document.getElementById('emailcomment').style.backgroundColor = styleClassError;
			stopForm = true;
		}
		if (stopForm == true) {
			document.getElementById('avisoComment').innerHTML = 'Erreur, SVP vérifiez les champs soulignés';
			document.getElementById('avisoComment').style.visibility = 'visible';
			return false;
		}
	} else if (i=='friend') {
		document.getElementById('avisoFriend').style.visibility = 'hidden';
		document.getElementById('emailfriend').style.backgroundColor = styleClass;
		document.getElementById('emailsender').style.backgroundColor = styleClass;
		var emailField = document.getElementById('emailfriend');
		if (!checkMail(emailField)) {
			document.getElementById('emailfriend').style.backgroundColor = styleClassError;
			stopForm = true;
		}
		var emailField = document.getElementById('emailsender');
		if (!checkMail(emailField)) {
			document.getElementById('emailsender').style.backgroundColor = styleClassError;
			stopForm = true;
		}
		if (stopForm == true) {
			document.getElementById('avisoFriend').innerHTML = 'Erreur, SVP vérifiez les champs soulignés!';
			document.getElementById('avisoFriend').style.visibility = 'visible';
			return false;
		}
	}
}
	