﻿(function($) {

    jQuery.fn.DecodeEmail = function() {

        function rot13Decode(encodedEmail) {
            return encodedEmail.replace(/[a-zA-Z]/g,
            function(c) {
                return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
            });
        }

        return this.each(function() {

            var text = $(this).text();
            var addr = $(this).attr('href').replace('znvygb:', '');

            if (text == addr) {
                text = rot13Decode(text);
            }

            addr = rot13Decode(addr);

            $(this).attr('href', 'mailto:' + addr);
            $(this).text(text);

        });
    }

})(jQuery);

$(document).ready(function() {
    $('a[href^=znvygb:]').DecodeEmail();
});
