﻿(function($) {
    ApplyClickableLinkToClass = function(selectedElements) {

        // Go through each of the passed in selections and try to apply a link to them
        $.each(selectedElements, function() {
            var linkElement = $("a:first", $(this));
            var link = linkElement.attr("href");

            if (!IsNullEmptyOrUndefined(link)) {

                $(this).click(function(firstLink) {
                    var link = firstLink;
                    return function() {
                        $(this).unbind('click');

                        if (link.triggerHandler('click') === undefined) {
                            if (link.attr("target") != "_blank") {
                                window.location = link.attr('href');
                            }
                        }
                    };
                } (linkElement));
            }
        });
    }

    // This method will check whether a string is null or empty
    function IsNullEmptyOrUndefined(stringToCheck) {
        if (stringToCheck === null || stringToCheck === undefined || stringToCheck.length === 0) {
            return true;
        }

        return false;
    }
})(jQuery);

