function isCommentOkayToSubmit(email_field, url_field, comment_field, name_field) {
    var email = document.getElementById(email_field).value;
    var url = document.getElementById(url_field).value;
    var comment = document.getElementById(comment_field).value;
    var name = document.getElementById(name_field).value;
    if (checkEmail(email) && checkUrl(url) && checkName(name) && checkComment(comment)) {
        document.getElementById(url_field).value = '';
        alert("Your comment has been submitted and will be available for viewing shortly.");
        return true; 
    } else {
        alert("Unable to submit your comment.  Please make sure that all required fields are filled out and that any URL (if provided) is valid and starts with 'http://'");
    }
    return false;
}

function checkEmail(email) {
    // a very simple email validation checking. 
    // you can add more complex email checking if it helps 
    if(email.length <= 0) {
      return false;
    }
    var splitted = email.match("^(.+)@(.+)$");
    if (splitted == null) {
        return false;
    }
    if (splitted[1] != null ) {
        var regexp_user=/^\"?[\w-_\.]*\"?$/;
        if (splitted[1].match(regexp_user) == null) {
            return false;
        }
    }
    if(splitted[2] != null) {
        var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
        if (splitted[2].match(regexp_domain) == null) {
            var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
            if (splitted[2].match(regexp_ip) == null) {
                return false;
            }
        } // if
        return true;
    }
    return false;
}

function checkName(name) {
    if (name.length < 2) {
        return false;
    } else if (name == 'NAME') {
        alert(name.value);
        return false;
    } else {
        return true;
    }
}

function checkUrl(url) {
    if (url == 'URL (OPTIONAL)') {
        return true;
    } else if (url.length > 0) {
        var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
        return regexp.test(url);
    } else {
        return true;
    }
}

function checkComment(comment) {
    if (comment.length < 2) {
        return false;
    } else {
        return true;
    }    
}

function toggleBlogComments(id_fieldname) {
    if (document.getElementById(id_fieldname).style.display == "inline") {
        document.getElementById(id_fieldname).style.display='none';
        return true;
    } else {
        document.getElementById(id_fieldname).style.display='inline';
        return true;
    }
}