jQuery(document).ready(function($) {
	$('a').not('[href*="mailto:"]').each(function() {
		var re = new RegExp('^https?\:\/\/' + window.location.host),
			re2 = new RegExp('noopener'),
			re3 = new RegExp('noreferrer'),
			href = this.href,
			rel = $(this).attr('rel') || '';
		
		// if the address starts with http (or also https), but does not link to the current domain
		if ( href.search(/^http/) != -1 && !re.test(href) ) {
			//$(this).attr('onClick', 'javascript:window.open("' + href + '"); return false;');
			//$(this).removeAttr('target');
			
			// Add noopener if it's not there
			rel = !re2.test(rel) ? rel + ' noopener' : rel;
			
			// Add noreferrer if it's not there
			rel = !re3.test(rel) ? rel + ' noreferrer' : rel;
			
			$(this).attr('rel', rel);
			$(this).attr('target', '_blank');
		};
	});
});