﻿function ValidateInput() {
    var showError = false;

    $(".ControlValidator span").each(function() {
        if ($(this).css("visibility") != "hidden") {
            showError = true;
        };
    });

    if (showError) {
        $("#" + ServerControl.MandatoryErrorLabel).show();
    }
    else {
        $("#" + ServerControl.MandatoryErrorLabel).hide();
    }

    /* In case of Course file upload check for Flash file */
    var courseFileUpload = $("#" + ServerControl.CourseFileUpload);
    if (courseFileUpload != null) {
        if (courseFileUpload.val() != null) {
            var courseFileName = new String(courseFileUpload.val());
            if ((courseFileName.length > 0) && (courseFileName.lastIndexOf(".swf") == -1) && (courseFileName.lastIndexOf(".zip") == -1)) {
                $("#" + ServerControl.FileUploadError).show();
                return false;
            }
            else {
                $("#" + ServerControl.FileUploadError).hide();
            }
        }
    }   
    
    return true;
};

$(document).ready(function() {
    $("#" + ServerControl.SubmitButton).click(function() {
        $("#" + ServerControl.ErrorRow).hide();
        $("#" + ServerControl.SuccessRow).hide();

        return ValidateInput();
    });

    $("#" + ServerControl.UploadButton).click(function() {
        $("#" + ServerControl.ErrorRow).hide();
        $("#" + ServerControl.SuccessRow).hide();

        return ValidateInput();
    });

    $("#" + ServerControl.MandatoryErrorLabel).hide();

    var fileUploadError = $("#" + ServerControl.FileUploadError);
    if (fileUploadError != null) {
        fileUploadError.hide();
    }
});
