/*

BillText
Search & replace certain words w/ hyperlinked versions

ToDo's:
	- Support for multi-word terms
	- Ignore words within HTML tags
*/

// This array will probably need to be generated server-side:
var keywords=[
	'powerboat',
	'salmon',
	'steelhead',
	'vulnerability',
	'vulnerabilities',
	'security',
	'xss',
]

// The keyword will get appended to the end of this URL:
var url='http://somewhere.com/app?keyword='

// If you wanna style the link, or add in any extra attributes to the "A" tag
var link_attributes='style="color:green" target=top';


var body=document.body.innerHTML;

// Search & Replace
function parseHTML() {	
	for(var i=0;i<keywords.length;i++) {
		var b=keywords[i];	
		var re = new RegExp("(\\b"+ b +"\\b)", "ig");
		body = body.replace(re, '<A HREF='+url+b+' '+link_attributes+'>'+"$1"+'</a>');
	}
}


parseHTML();

// Replace the HTML of the page with the re-written version
document.body.innerHTML=body;
