﻿function toggleComments(span, commentType)
{
    var comments = document.getElementById(commentType + 'Comments');
    var header = document.getElementById(commentType + 'Header');
    var wrapper = document.getElementById(commentType + 'Wrapper');
    wrapper.style.display = 'block';
    var divOpen = new fx.Height(comments,{duration:250});
    
    if(span.innerHTML == 'View')
    {
        span.innerHTML = 'Hide';
	    divOpen.custom(comments.offsetHeight,header.offsetHeight + wrapper.offsetHeight);
	}
	else
    {
        span.innerHTML = 'View';
	    divOpen.custom(comments.offsetHeight,header.offsetHeight);
	}
}

function ValidateForm()
{
    document.getElementById('emailError').style.display = 'none';
    document.getElementById('nameError').style.display = 'none';
    document.getElementById('noCommentError').style.display = 'none';
    
    var isValid = true;
    var optional = !(document.getElementById('Notify').checked);
    var comment = document.getElementById('comment').value;
    
    var emailValid = ValidateEmail(document.getElementById('commentEmail').value, optional);
    if(!emailValid)
    {
        if(optional)
        {
            document.getElementById('emailError').innerHTML = 'Invalid email address';
        }
        else
        {
            document.getElementById('emailError').innerHTML = 'Valid email address required for notifications';
        }
        document.getElementById('emailError').style.display = 'block';
        isValid = false;
    }
    if(document.getElementById('commentName').value.length > 50)
    {
        document.getElementById('nameError').style.display = 'block';
        isValid = false;
    }
    if(!comment || comment.length == 0)
    {
        document.getElementById('noCommentError').style.display = 'block';
        isValid = false;
    }
    
    return isValid;
}
