﻿/// <reference path="fotoblur-1.0.3.js" />

// do stuff when dom is ready
$(document).ready(function () {
    $("#themeSelect").change(function () {
        $("#themeId").val($(this).val());
    });
});

function validateForm(requiresFile, btn, postBackFunc) {
    var message = "";
    var file = $.trim($("#File").val());
    var title = $.trim($("#txtImageTitle").val());
    var theme = $("#themeSelect").val();
    var artistBio = $.trim($("#txtArtistBio").val());
    var copyright = $("#ckbxCopyright").attr("checked");
    var fileLoc = $('#inputFile').val();

    // lock button
    $(btn).attr("disabled", "disabled");
    $("#txtSavingMsg").html("Saving. . .  Please wait.");

    if (requiresFile == undefined)
        requiresFile = true;

    if (requiresFile && $.trim(fileLoc).length < 1) {
        message += "Please provide a JPG file with your submission.\n";
    }
    if (title.length < 1) {
        message += "Please include an image title with your submission.\n";
    }
    if (theme.length < 1) {
        message += "Please select a theme for your submission.\n";
    }
//    if (artistBio.length < 1) {
//        message += "Please include a photographer bio with your submission.\n";
//    }
    if (artistBio.length > 1000) {
        message += "Your description is too long.  Please shorten your bio by " + (artistBio.length - 1000) + " character(s).\n";
    }
    if (copyright == false) {
        message += "Please click the proof of copyright statement before submitting your image if you qualify.";
    }

    if (message.length > 0) {
        alert(message);
        $(btn).removeAttr("disabled");
        $("#txtSavingMsg").html("");
        return false;
    }

    // validation succeeded
    eval(postBackFunc);
    return true;
}
