
/* matthias - pour les commentaires associés aux articles */
var inputNom      = false;
var inputLocation = false;
var inputEmail    = false;
var inputCom      = false;

function activate(champ) {
    if(champ == "nom")         inputNom      = true;
    if(champ == "location")    inputLocation = true;
    if(champ == "email")       inputEmail    = true;
	if(champ == "commentaire") inputCom      = true;
}

function sendCom() {
    var nom      = document.getElementById("nom").value;
	var location = document.getElementById("location").value;
    var email    = document.getElementById("email").value;
    var commentaire = document.getElementById("commentaire").value;
    
    if(nom == "" || nom == "nom"){ 
        alert("Votre nom , Merci");
        document.getElementById("nom").focus();
        return false;
    }
	if(document.getElementById('location').value=='')
    {
		alert('Votre location , Merci');
		document.getElementById('location').focus();
		return false;
    }
    if(email.match(/^[a-zA-Z0-9][a-zA-Z0-9._-]*@([a-zA-Z][a-zA-Z0-9_\-]*\.)*[a-z0-9]+[a-z0-9\-]+\.[a-z]{2,6}$/) == null)
    {
        alert("Veuillez v\351rifier votre email, merci");
        document.getElementById("email").focus();
        return false;
    }
    if(commentaire == ""  || commentaire == "Votre commentaire ici")
    {
        alert("Que voulez vous dire ?");
        document.getElementById("commentaire").focus();
        return false;
    }
    
    // vérification des activates
    if(inputNom == true && inputEmail == true && inputCom == true){
        $.post("guestbook_add.php", {action: "ajaxPost",nom: nom,email: email,location: location,commentaire: commentaire},
        function(data){
            document.getElementById("nom").value = '';
            document.getElementById("email").value = '';
			document.getElementById("location").value = '';
            document.getElementById("commentaire").value = '';
            $("#txtGuestbook").fadeIn("slow").delay(5000).fadeOut("slow");
        });
    }
}

