﻿// Based on http://www.mikezilla.com/exp0035.html
function wordhighlight(words){
    // Get col2 / col2HP
    var col2 = (document.getElementById("col2") || document.getElementById("col2HP"));
    // If it exists...
    if(col2)
    {
        // Regular Expression to match html tags
        regexp = /<[^<>]*>/ig;
        // Build the list of matches
        matchHtml = col2.innerHTML.match(regexp);
        // Strip out the html tags from the text
        stripHtml = col2.innerHTML.replace(regexp, "$!$");
        // Regular expression to match the words
        regexp = new RegExp("\\b(" + words + ")\\b", "gi");
        // Create the highlights
        tmp = stripHtml.replace(regexp, "<span class=\"highlight\">$1</span>");
        // Go through the placeholders and one-by-one...
        for(i=0 ; tmp.indexOf("$!$") > -1; i++)
        {
            // ... put the HTML tags back
	        tmp = tmp.replace("$!$", matchHtml[i]);
        }
        // Reset the contents of col2
        col2.innerHTML = tmp;
    }
}
