function unObfuscateEmails() {
  var anchors = document.links;
  for (var n = 0; n < anchors.length; n++) {   
    if (anchors[n].href.toLowerCase().indexOf("mailto:") > -1) {   
      if (anchors[n].href.toLowerCase().indexOf("javascript:") == -1) { // DotNetNuke hasn't already obfuscated the email using its own mechanisms.
        anchors[n].href = unObfuscateEmail(anchors[n].href); // Unobfuscate the email link.
      }
      anchors[n].innerHTML = unObfuscateEmail(anchors[n].innerHTML); // Unobfuscate the displayed email address.

    }
  };  

}

function unObfuscateEmail(email) {
	// Unencrypts an email address.
	email = email.replace(/\!/g, '');
	email = email.replace(/\`/g, '');
	email = email.replace(/\#/g, '');
	email = email.replace(/\$/g, '');
	email = email.replace(/\%/g, '');
	email = email.replace(/\~/g, '');
	email = email.replace(/\;/g, '');
	email = email.replace(/\?/g, '');
	
	email = email.replace(/\|/g, '@'); // Pipe is always converted back to @ symbol.
	return email;
}

// This sets up the themed combo boxes.
(function($) {
    $.fn.extend({

        customStyle: function(options) {
            if (!$.browser.msie || ($.browser.msie && $.browser.version > 6)) {
                return this.each(function() {

                    var currentSelected = $(this).find(':selected');
                    $(this).after('<span class="themedSelect"><span class="themedSelectInner">' + currentSelected.text() + '</span></span>').css({ position: 'absolute', opacity: 0, fontSize: $(this).next().css('font-size') });
                    var selectBoxSpan = $(this).next();
                    var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) - parseInt(selectBoxSpan.css('padding-right'));
                    var selectBoxSpanInner = selectBoxSpan.find(':first-child');
                    selectBoxSpan.css({ display: 'inline-block' });
                    selectBoxSpanInner.css({ width: selectBoxWidth, display: 'inline-block' });
                    var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
                    $(this).height(selectBoxHeight).change(function() {
                        selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
                    });

                });
            }
        }
    });
})(jQuery);
