var ValidateUploadForm = function()
{
    this.$form = $('form[name=upload-form]');
    this.errors = [];

    this.isValid = function()
    {
        this.data = {
            videoFilename:      this.$form.find('input[name=video_file]').val(),
            videoTitle:         this.$form.find('input[name=video_title]').val(),
            authorName:         this.$form.find('input[name=author_name]').val(),
            authorEmail:        this.$form.find('input[name=author_email]').val(),
            videoRights:        this.$form.find('input[name=video_rights]').filter(':checked').val(),
            schoolId:           this.$form.find('input[name=school_id]').val(),
            customSchoolName:   this.$form.find('input[name=custom_school_name]').val(),
            customSchoolZipCode:this.$form.find('input[name=custom_school_zipcode]').val(),
            customSchoolCity:   this.$form.find('input[name=custom_school_city]').val(),
            ownerName:          this.$form.find('input[name=video_owner_name]').val(),
            ownerEmail:         this.$form.find('input[name=video_owner_email]').val(),
            hasPermission:      this.$form.find('input[name=have_video_permissions]').is(':checked'),
            giveOwnPermission:  this.$form.find('input[name=give_own_permission]').is(':checked')
        };
        
        if (isEmpty(this.data.videoFilename))
        {
            this.errors.push(errorMessages.upload_video.file_empty);
        }

        if (isEmpty(this.data.videoTitle))
        {
            this.errors.push(errorMessages.upload_video.video_title_empty);
        }
        else if (!isStringLengthBetween(this.data.videoTitle, 1, 40))
        {
            this.errors.push(errorMessages.upload_video.video_title_length);
        }


        if (isEmpty(this.data.authorName))
        {
            this.errors.push(errorMessages.upload_video.author_name_empty);
        }

        if (isEmpty(this.data.authorEmail))
        {
            this.errors.push(errorMessages.upload_video.author_email_empty);
        }
        else if (!isEmail(this.data.authorEmail))
        {
            this.errors.push(errorMessages.upload_video.author_email_invalid);
        }

        if (isEmpty(this.data.schoolId))
        {
            this.errors.push(errorMessages.upload_video.school_empty);
        }
        else if (this.data.schoolId == 'custom')
        {
            if (isEmpty(this.data.customSchoolName))
            {
                this.errors.push(errorMessages.upload_video.custom_school_name_empty);
            }
            if (isEmpty(this.data.customSchoolCity))
            {
                this.errors.push(errorMessages.upload_video.custom_school_city_empty);
            }
        }

        if (this.data.videoRights != 'myself')
        {
            if (isEmpty(this.data.ownerName))
            {
                this.errors.push(errorMessages.upload_video.owner_name_empty);
            }

            if (isEmpty(this.data.ownerEmail))
            {
                this.errors.push(errorMessages.upload_video.owner_email_empty);
            }

            if (!this.data.hasPermission)
            {
                this.errors.push(errorMessages.upload_video.upload_permission);
            }
        }
        else
        {
            if (!this.data.giveOwnPermission)
            {
                this.errors.push(errorMessages.upload_video.own_upload_permission);
            }
        }

        return (this.errors.length < 1);
    }
}
