/*  
Client entered a bunch of content and then needed to wrap all 
copyright and trademark symbols in <sup> tags.

This function can be called multiple times over a page because
some templates load content dynamically.
*/  
$(document).ready(function(){
    super_marks();
});
function super_marks() {
    var tags = ["a", "h1", "h2", "p", "div"];

    var reg = "<div>&reg;</div>";
    var trade = "<div>&trade;</div>";
    for (var i=0; i < tags.length; i++) {
        $(tags[i] + ":contains("+$(reg).html()+")").each(function(){
            var has_super = ($("sup", $(this)).size() > 0);
            if (has_super) { return true; }

            $(this).html(
                $(this).html().replace(
                    // /$(reg).html()/g,
                    /\u00ae/g,
                    "<sup>"+$(reg).html()+"</sup>"
                )
            );
        });

        $(tags[i] + ":contains("+$(trade).html()+")").each(function(){
            var has_super = ($("sup", $(this)).size() > 0);
            if (has_super) { return true; }

            $(this).html(
                $(this).html().replace(
                    // /$(trade).html()/g,
                    /\u2122/g,
                    "<sup>"+$(trade).html()+"</sup>"
                )
            );
        });
    }
}

