// Copyright Andy Lavery, 2009.  All rights reserved.
// Toggle the options to show/hide terms and conditions.
function processSongSubmit() {
    // Check if the user has included a name of between 5 and 50 characters.
    var validationPassed = true;

    // Step 1:  Validation the song name
    var enteredSongName =  document.forms['projectForm'].submissionName.value;
    if (enteredSongName.length < 5 || enteredSongName.length > 50) {
        validationPassed = false;
        document.getElementById('warnIconName').className = 'visibleConfig';
        document.getElementById('idOfSubmissionNameTitle').className = 'SubmissionInputTitleWarning';
    } else { 
        document.getElementById('warnIconName').className = 'hiddenConfig';
        document.getElementById('idOfSubmissionNameTitle').className = 'SubmissionInputTitle';
    }

    // Step 2:  Validation the path of the mp3 file
    var validationMP3 = true;
    var enteredMP3Path =  document.forms['projectForm'].submissionMP3Recording.value;
    var regex = /.+\.(mp3)$/i; // Match any string that ends in ".mp3", ignoring case
    if (enteredMP3Path.length < 1) {
        validationPassed = validationMP3 = false;
    } else if (!regex.test(enteredMP3Path)) {
        validationPassed = validationMP3 = false;
    }
    if (validationMP3) {
        // Validation of mp3 path passes
        document.getElementById('warnIconMP3').className = 'hiddenConfig';
        document.getElementById('idOfSubmissionMP3Title').className = 'SubmissionInputTitle';
    } else { 
        document.getElementById('warnIconMP3').className = 'visibleConfig';
        document.getElementById('idOfSubmissionMP3Title').className = 'SubmissionInputTitleWarning';
    }

    // Step 3:  Validation the path of the .gif/.jpg/.jpeg file
    var validationThumbnail = true;
    var enteredThumbnailPath =  document.forms['projectForm'].submissionImage.value;
    var regex = /.+\.(jpg|gif|jpeg)$/i; // Match any string that ends in ".gif" or ".jpg", ignoring case
    if (enteredThumbnailPath.length < 1) {
        validationPassed = validationThumbnail = false;
    } else if (!regex.test(enteredThumbnailPath)) {
        validationPassed = validationThumbnail = false;
    }
    if (validationThumbnail) {
        // Validation of thumbnail path passes
        document.getElementById('warnIconThumbnail').className = 'hiddenConfig';
        document.getElementById('idOfSubmissionThumbnailTitle').className = 'SubmissionInputTitle';
    } else { 
        document.getElementById('warnIconThumbnail').className = 'visibleConfig';
        document.getElementById('idOfSubmissionThumbnailTitle').className = 'SubmissionInputTitleWarning';
    }

    // Step 4:  Validation that the terms and conditions have been accepted.
    var termsConditionsChecked =  document.forms['projectForm'].agreeToTerms.checked;
    if (termsConditionsChecked) {
        document.getElementById('warnIconCheckbox').className = 'hiddenConfig';
        document.getElementById('idOfSubmissionCheckboxTitle').className = 'SubmissionCheckboxLabel';
    } else {
        validationPassed = false;
        document.getElementById('warnIconCheckbox').className = 'visibleConfig';
        document.getElementById('idOfSubmissionCheckboxTitle').className = 'SubmissionCheckboxLabelWarning';
    }

    // Step 5:  Determine if we need to display general warning message, or if validation
    // passed and we can proceed to submit the form.
    if (validationPassed) {
        document.getElementById('possibleWarningForInputs').className = 'hiddenConfig';
        document.forms['projectForm'].action.value='submit2';
        document.forms['projectForm'].SUBMIT_BUTTON.value='true';
        document.forms['projectForm'].submit();
    } else {
        document.getElementById('possibleWarningForInputs').className = 'indentMessage';
    }
}
