﻿

//----------------------------------------------------------------//
function Comments_HookUp() {
    window.Comments_Form        = document.getElementById("Comments_Form");
    window.Comments_Name        = document.getElementById("Comments_Name");
    window.Comments_Email       = document.getElementById("Comments_Email");
    window.Comments_PrivMsg     = document.getElementById("Comments_PrivMsg");
    window.Comments_Subscribe   = document.getElementById("Comments_Subscribe");
    window.Comments_Body        = document.getElementById("Comments_Body");
    window.Comments_NoComments  = document.getElementById("Comments_NoComments");
    window.Comments_Post        = document.getElementById("Comments_Post");
}


//----------------------------------------------------------------//
function Comments_Subscribe_OnClick() {
    Comments_HookUp();
    
    if (!Comments_Subscribe.checked) {
        if (Comments_NoComments.checked) {
            Comments_NoComments.checked = false;
            Comments_NoComments_OnClick();
        }
    }
    
}


//----------------------------------------------------------------//
function Comments_NoComments_OnClick() {
    Comments_HookUp();
    if (Comments_NoComments.checked) {
        
        Comments_Body.value = "";
        Comments_Body.onfocus = function() {this.blur(); }
        Comments_Body.style.backgroundColor = "#EEEEEE";
        
        Comments_Subscribe.checked = true;
        
    } else {
        Comments_Body.onfocus = null;
        Comments_Body.style.backgroundColor = "";
    }
}


//----------------------------------------------------------------//
function Comments_Form_OnSubmit() {
    Comments_HookUp();
    
    if (Comments_PrivMsg.checked && Comments_Email.value == "") {
        setTimeout("alert('You want to allow private messages.  I need your email address to send them to you.')", 0);
        return false;
    }
    
    if (Comments_Subscribe.checked && Comments_Email.value == "") {
        setTimeout("alert('You want to subscribe to comments.  I need your email address to send them to you.')", 0);
        return false;
    }
    
    if (Comments_Email.value != "") {
        if (!Comments_Email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$/)) {
            setTimeout("alert('Not a valid email address.')", 0);
            return false;
        }
    }
    
    if (Comments_Body.value == "" && !Comments_NoComments.checked) {
        setTimeout("alert('Please type some comments or check \"Nothing to say\".')", 0);
        return false;
    }
    
    return true;
}


