function getCookie (_name)
{
    var cookies = document.cookie.split (';');
    for (i = 0 ; i < cookies.length; i++)
    {
        var cookie = cookies[i].split ('=');
        if (cookie[0].replace (/^\s+|\s+$/g, '') == _name)
        {
            return unescape (cookie[1].replace (/^\s+|\s+$/g, ''));
        }
    }
}

function commentCheck ()
{
    var name = document.getElementById ('name').value;
    var mail = document.getElementById ('mail').value;
    var site = document.getElementById ('site').value;
    var comment = document.getElementById ('comment').value;

    if (comment.length <= 0)
    {
        alert ('Merci de saisir un commentaire');
        return false;
    }
    if (name.length <= 0)
    {
        alert ('Merci de saisir un nom valide');
        return false;
    }
    var regmail = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/;
    if (regmail.exec (mail) == null)
    {
        alert ('Adresse mail invalide');
        return false;
    }
    var regurl = /^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i;
    if (site.length > 0 && regurl.exec (site) == null)
    {
        alert ('URL invalide');
        return false;
    }
    return true;
}

function enableComments ()
{
    if (getCookie ('comment_id') == '6c4e5ImUGM8D169h')
    {
        document.getElementById ('commentForm').action = '/add-comment.php';
        document.getElementById ('key').value = '$1$OAeQLMrc$yf0pK1r7q4kfl7dPfx7MZ.';
        displayProperty (document.getElementById ('commentBlock').style, 'block');
        displayProperty (document.getElementById ('nocommentBlock').style, 'none');;
    }
}

enableComments ();

