/*
 *  $Id: form.validation.js 8 2010-04-15 19:24:02Z stuart $
 *  
 *  dev.stuconnolly.com
 *  Open Source Software Development
 *
 *  Copyright (c) 2010 Stuart Connolly. All rights reserved.
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
/**
 * Validates the feedback form's input elements.
 */
function validateFeedbackForm()
{
    var errorMessage = '';
    var form = document.forms['feedbackform'];
    
    
    if (trim(form.title.value).length == 0) {
        errorMessage = "- The title field is blank\n";
    }
    
    if (form.cc.checked) {
        if (trim(form.email.value).length == 0) {
            errorMessage += "- The email field is blank\n";
        }
        else {
            if (validateEmailAddress(trim(form.email.value)) == false) {
                errorMessage += "- The email address '" + trim(form.email.value) + "' is not valid.\n";
            }
        }
    }
    
    if (trim(form.description.value).length == 0) {
        errorMessage += "- The description field is blank\n";
    }
    
    if (trim(form.year.value).length == 0) {
        errorMessage += "- The current year field is blank\n";
    }
    else {
        if (isNaN(trim(form.year.value))) {
            errorMessage += "- The current year field is not numeric\n";
        }
        else {
            var date = new Date();
                        
            if (trim(form.year.value) != date.getUTCFullYear()) {
                errorMessage += '- Anti-spam measure failed.';
            }
        }
    }
    
    if (errorMessage.length > 0) {
        alert("Form validation failed. Please take note of the following:\n\n" + errorMessage);
        
        return false;
    }
}
