//----------------------------------------------------------------------
// Function to validate the contents of our form before it is submitted
//----------------------------------------------------------------------
function ValidateContactForm( form )
{
    var errors = new Array();
    //------------------------------------------------------------------
    // require a name
    //------------------------------------------------------------------
    var name = document.getElementById('name');
    if ( name.value == "" || (/^.{1,200}$/.test(name.value) == false) )
    {
        // not valid, so add an error message to our array and change
        // the background colour accordingly
        errors.push('You must specify your name');
        name.style.backgroundColor = '#FFCCCC';
    }
    else
    {
        // valid, so change the background colour accordingly
        name.style.backgroundColor = '#CCFFCC';
    }
    //------------------------------------------------------------------
    // require either a phone number or email address
    //------------------------------------------------------------------
    var email = document.getElementById('email');
    var phone = document.getElementById('telephone');
    if ( (email.value == "") && (phone.value == "") )
    {
        // The email or phone does not comply to the required format so add
        // an error message to our array and change the background
        // colour accordingly
        errors.push('You must specify either a phone number or email address');
        email.style.backgroundColor = '#FFCCCC';
        phone.style.backgroundColor = '#FFCCCC';
    }
    else if ( email.value != "" && (/^[^@]+@[^@]+$/.test(email.value) == false) )
    {
        errors.push('You must specify a valid email address');
        email.style.backgroundColor = '#FFCCCC';
    }
    else if ( phone.value != "" && (/^.{5,50}$/.test(phone.value) == false) )
    {
        errors.push('You must specify a valid phone number');
        phone.style.backgroundColor = '#FFCCCC';
    }
    else
    {
        // valid, so change the background colour accordingly
        email.style.backgroundColor = '#CCFFCC';
        phone.style.backgroundColor = '#CCFFCC';
    }
    //------------------------------------------------------------------
    // require an enquiry
    //------------------------------------------------------------------
    var message = document.getElementById('enquiry');
    if ( message.value == "" )
    {
        // The enquiry does not comply to the required format so add
        // an error message to our array and change the background
        // colour accordingly
        errors.push('You must specify your enquiry');
        message.style.backgroundColor = '#FFCCCC';
     }
    else
    {
        // valid, so change the background colour accordingly
        message.style.backgroundColor = '#CCFFCC';
    }
    //------------------------------------------------------------------
    // Only if all the checks above are ok do we return true
    //------------------------------------------------------------------
    if ( errors.length > 0 )
    {
        var error_message = 'The following errors were found with your submission:' + "\n";
        // Update our message if there is only one error
        if (errors.length == 1)
        {
            error_message = 'The following error was found with your submission:' + "\n";
        }
        // Append the error message(s)
        for ( var i in errors)
        {
            error_message = error_message + '- ' + errors[i] + "\n";
        }
        alert(error_message);
        return false;
    }
    else
    {
        // Let the user know that the form will now be submitted
        // ( Good practice because the data then disappears from the form!)
        //alert('Thank you for your enquiry!');
        return true;
    }
}
//----------------------------------------------------------------------
// Function to validate the contents of our form before it is submitted
//----------------------------------------------------------------------
function ValidateNewsletterForm( form )
{
    var errors = new Array();
    //------------------------------------------------------------------
    // require either a phone number or email address
    //------------------------------------------------------------------
    var email = document.getElementById('email_to_subscribe');
    if ( email.value != "" && (/^[^@]+@[^@]+$/.test(email.value) == false) )
    {
        errors.push('You must specify a valid email address');
        email.style.backgroundColor = '#FFCCCC';
    }
    else
    {
        // valid, so change the background colour accordingly
        email.style.backgroundColor = '#CCFFCC';
    }
    //------------------------------------------------------------------
    // Only if all the checks above are ok do we return true
    //------------------------------------------------------------------
    if ( errors.length > 0 )
    {
        var error_message = 'The following errors were found with your submission:' + "\n";
        // Update our message if there is only one error
        if (errors.length == 1)
        {
            error_message = 'The following error was found with your submission:' + "\n";
        }
        // Append the error message(s)
        for ( var i in errors)
        {
            error_message = error_message + '- ' + errors[i] + "\n";
        }
        alert(error_message);
        return false;
    }
    else
    {
        // Let the user know that the form will now be submitted
        // ( Good practice because the data then disappears from the form!)
        //alert('Thank you for your enquiry!');
        return true;
    }
}
function ValidateSupportForm( form )
{
    var errors = new Array();
    //------------------------------------------------------------------
    // require a contact name
    //------------------------------------------------------------------
    var input_to_test = document.getElementById('1_contact_name');
    if ( input_to_test.value == "" )
    {
        errors.push('You must specify a contact name');
        input_to_test.style.backgroundColor = '#FFCCCC';
    }
    else
    {
        input_to_test.style.backgroundColor = '#CCFFCC';
    }
    //------------------------------------------------------------------
    // require an organisation name
    //------------------------------------------------------------------
    var input_to_test = document.getElementById('3_organisation_name');
    if ( input_to_test.value == "" )
    {
        errors.push('You must specify an organisation name');
        input_to_test.style.backgroundColor = '#FFCCCC';
    }
    else
    {
        input_to_test.style.backgroundColor = '#CCFFCC';
    }
    //------------------------------------------------------------------
    // require an address
    //------------------------------------------------------------------
    var input_to_test = document.getElementById('4_address');
    if ( input_to_test.value == "" )
    {
        errors.push('You must specify a contact address and postcode');
        input_to_test.style.backgroundColor = '#FFCCCC';
    }
    else
    {
        input_to_test.style.backgroundColor = '#CCFFCC';
    }
    //------------------------------------------------------------------
    // require either a phone number or email address
    //------------------------------------------------------------------
    var email = document.getElementById('7_email');
    var phone = document.getElementById('5_telephone');
    if ( (email.value == "") && (phone.value == "") )
    {
        // The email or phone does not comply to the required format so add
        // an error message to our array and change the background
        // colour accordingly
        errors.push('You must specify either a phone number or email address');
        email.style.backgroundColor = '#FFCCCC';
        phone.style.backgroundColor = '#FFCCCC';
    }
    else if ( email.value != "" && (/^[^@]+@[^@]+$/.test(email.value) == false) )
    {
        errors.push('You must specify a valid email address');
        email.style.backgroundColor = '#FFCCCC';
    }
    else if ( phone.value != "" && (/^.{5,50}$/.test(phone.value) == false) )
    {
        errors.push('You must specify a valid phone number');
        phone.style.backgroundColor = '#FFCCCC';
    }
    else
    {
        // valid, so change the background colour accordingly
        email.style.backgroundColor = '#CCFFCC';
        phone.style.backgroundColor = '#CCFFCC';
    }




    
    //------------------------------------------------------------------
    // Only if all the checks above are ok do we return true
    //------------------------------------------------------------------
    if ( errors.length > 0 )
    {
        var error_message = 'The following errors were found with your submission:' + "\n";
        // Update our message if there is only one error
        if (errors.length == 1)
        {
            error_message = 'The following error was found with your submission:' + "\n";
        }
        // Append the error message(s)
        for ( var i in errors)
        {
            error_message = error_message + '- ' + errors[i] + "\n";
        }
        alert(error_message);
        return false;
    }
    else
    {
        // Let the user know that the form will now be submitted
        // ( Good practice because the data then disappears from the form!)
        //alert('Thank you for your enquiry!');
        return true;
    }
}

