﻿function validateCommentSubmit()
{
    var msg = '';
    var rxEmail = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    var rxUnsafe = /[<>]/;
    
    if (document.getElementById("UserName").value == "")
        msg += 'Your name is required.\n';
    else if (document.getElementById("UserName").value.match(rxUnsafe))
        msg += 'Name contains potentially unsafe characters - please do not use < >\n';
        
    if (document.getElementById("Email").value == "")
        msg += 'Email address is required.\n';
    else if (!document.getElementById("Email").value.match(rxEmail))
        msg += 'Email address is invalid.\n';
        
    var comment = document.getElementById("CommentText").value;
    if (comment == "")
        msg += 'Comment text is required.\n';
    else 
    { 
        if (comment.length > 2000)
            msg += 'Comment must be 2000 characters or less (currently ' + comment.length + ')\n';
        if (comment.match(rxUnsafe))
            msg += 'Comment contains potentially unsafe characters - please do not use < >\n';
    }
        
    if (msg == '')
        return true;
    else
    {
        alert(msg);
        return false;
    } 
}

