function ReplaceKeyWords() {
    var URL = window.location.pathname;
    var PageName = URL.substring(URL.lastIndexOf('/') + 1);
    PageName = PageName.toUpperCase();

    if (PageName != 'MANAGET1T2.ASPX' && PageName != 'ACCUMULATOR.ASPX') { 
		/***** Script for preventing words from breaking into separate lines  */

        setTimeout(function(){$("body :not(option)").replaceText(/Full Throttle Blue Demon/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Full Throttle Sugar Free/gi, fortmatText);}, 10);       
        setTimeout(function(){$("body :not(option)").replaceText(/Minute Maid Light/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Simply Grapefruit/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Diet cherry Coke/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/diet Sprite Zero/gi, fortmatText);}, 10);
		setTimeout(function(){$("body :not(option)").replaceText(/Coca-Cola light/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Simply Lemonade/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Design Machine/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/BACARDI Mixers/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Coca-Cola zero/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Diet Coke Plus/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Diet Dr Pepper/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Dr Pepper Zero/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Simply Limeade/gi, fortmatText);}, 10);		
        setTimeout(function(){$("body :not(option)").replaceText(/Cokesolutions/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Full Throttle/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/POWERADE Zero/gi, fortmatText);}, 10);       
        setTimeout(function(){$("body :not(option)").replaceText(/Sprite light /gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Tum-E-Yummies/gi, fortmatText);}, 10);
		setTimeout(function(){$("body :not(option)").replaceText(/caffeine-free/gi, fortmatText);}, 10);      
        setTimeout(function(){$("body :not(option)").replaceText(/Coke Catalog/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Simply Apple/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/LOS Planner/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/DASANI Plus/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Juan Valdez/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Mello Yello/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Minute Maid/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Sprite zero/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Sprite Zero/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/diet Sprite/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Honest Tea/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Coca-Cola/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Coke zero/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Diet Coke/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Dr Pepper/gi, fortmatText);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/Gold Peak/gi, fortmatText);}, 10);

        setTimeout(function(){$("body :not(option)").replaceText(/glac\u00E9au vitaminwater zero/gi, formatVitaminZero);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/glac\u00E9au vitaminwater/gi, formatVitamin);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/glac\u00E9au smartwater/gi, formatSmartwater);}, 10);
        setTimeout(function(){$("body :not(option)").replaceText(/CokeChannel/gi, formatCokeChannel);}, 10);
		setTimeout(function(){$("body :not(option)").replaceText(/Simply Orange/gi, fortmatOrg);}, 10);
    };
};

function fortmatText(str) {
    return "<span style=\"white-space: nowrap;\">" + str + "<\/span>";
};

function formatCokeChannel(str) {
    return "<span style=\"white-space: nowrap;\">Coke<b>Channel<\/b><\/span>";
};

function formatSmartwater(str) {
    return "<span style=\"white-space: nowrap;\">glac&eacute;au&nbsp;<b>smart<\/b>water<\/span>";
};

function formatVitamin(str) {
    return "<span style=\"white-space: nowrap;\">glac&eacute;au&nbsp;<b>vitamin<\/b>water<\/span>";
};

function formatVitaminZero(str) {
    return "<span style=\"white-space: nowrap;\">glac&eacute;au&nbsp;<b>vitamin<\/b>water&nbsp;zero<\/span>";
};

function fortmatOrg(str) {
    return "<div style=\"white-space: nowrap;\">" + str + "<\/div>";
};

$.fn.replaceText = function (search, replace, text_only) {
    return this.each(function () {
        var node = this.firstChild,
            val, new_val, remove = [];
        if (node) {
            do {
                if (node.nodeType === 3) {
                    val = node.nodeValue;
                    new_val = val.replace(search, replace);
                    if (new_val !== val) {
                        if (!text_only && /</.test(new_val)) {
                            $(node).before(new_val);
                            remove.push(node);
                        } else {
                            node.nodeValue = new_val;
                        }
                    }
                }
            } while (node = node.nextSibling);
        }
        remove.length && $(remove).remove();
    });
};

jQuery.fn.removeHighlight = function () {
    return this.find("span.highlight").each(function () {
        with(this.parentNode) {
            replaceChild(this.firstChild, this);
        }
    }).end();
};

function highLight() {
    searchTerm = searchInput.val();
    searchRegex = new RegExp(searchTerm, 'g');
    $("#container *").replaceText(searchRegex, '<span class="highlight">' + searchTerm + '</span>');
}

var searchInput = $("#keyword"),
    searchTerm, searchRegex;
$("#apply-highlight").click(function () {
    highLight();
});
//$("form").submit(function(){highLight();});
$("#remove-highlight").bind("click", function () {
    $("#container").removeHighlight();
}); 
