// JavaScript Document
// BY: Cameron McGregor
// CREATED: October 05, 2006
// ABSTRACT: Contains javascript functions used with the comment forms in EIS Platform

//Comment action being committed
var commentAction = "";

//Store comment locally for later use
var storeComment = "";

//comment ID acted upon for alerts, etc.
var actCommentID = -1;

//timer object for auto-switching menus
var tmr;

//Timer for showing logout messages if error posting
var tmrLogoutMsg;

//tcm uri for currently submitted request (comments)
var currentTcmUri = "";

//Whether or not the textarea for post comments has been focused
var focused = false;

//The strings representing various error types from the server
var ERR_NOT_LOGGED_IN = "notLoggedIn";
var ERR_COMMENT_MISSING = "commentMissing";
var ERR_COMMENT_EMPTY = "commentEmpty";
var ERR_UNKNOWN = "unknown"; 

//Comment with bad characters error message
var BAD_CHAR_ERROR_MSG = "The system is unable to post your comment.  Please ensure that your comment" +
						" only includes the following system characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabc" +
						"defghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=+'\":;<>,./?*\|~.  As well, do" + 
						" not cut and paste your comment from Microsoft Word.";

//Comment with unknown error message
var UNKNOWN_ERROR_MSG = "The system is unable to post your comment.   Please retry or contact us for assistance.";

//Object for holding error results
function objErrResult(msg, loggedIn)
{
	this.msg = msg;
	this.loggedIn = loggedIn;
}

//Update controls classes based on the base control set name.
//  Each form has a corresponding tab set (or span) that must be updated
function updateCtrlsClass(ctrlName, newClass)
{
	var ctrl = document.getElementById(ctrlName);
	if (ctrl)
	{
//		alert("ctrl found:" + ctrlName);
		ctrl.className = newClass;
	}
/*	//DEBUG
	else
		alert("ctrl NOT FOUND!!! " + ctrlName);
*/
}

//Show the "showForm" and hide all forms in the "hideForms" array
//  giving the appearance that the forms are overlayed
function showCommentForm(showForm, hideForms)
{
	//show the form
	updateCtrlsClass(showForm, "");

	//Set the selected tag (inactive)
	updateCtrlsClass(showForm + "_tab", "active");


	for (i = 0; i < hideForms.length; i++)
	{
		//Hide the form
		updateCtrlsClass(hideForms[i], "hidden");
		
		//Set the tabs as active
		updateCtrlsClass(hideForms[i] + "_tab", "");
		
	}
		
	return false;
}

//Show the existing comments form
function showExistingComments()
{
	clearTimeout(tmr);

	showCommentForm('view_comment', new Array('post_comment', 'alert_moderator'));

	//Hide the character counter message
	updateCtrlsClass("character_limit_tab", "hidden");

}

//Show the post comment form
function showPostComments()
{
	clearTimeout(tmr);

	updateCtrlsClass("comment_submit", "");
	updateCtrlsClass("comment_thanks", "hidden");
	updateCtrlsClass("comment_post_error", "hidden");
	
	showCommentForm('post_comment', new Array('view_comment', 'alert_moderator'));

	var el = document.getElementById('new_comment');
	if ((el)  && (el.value == ''))
	{
		focused = false;
		el.value = 'Enter comments...';
	}
	
	//Show the character counter message
	updateCtrlsClass("character_limit_tab", "");
}

//Show the confirm alert form
function showConfirmAlert()
{
	clearTimeout(tmr);
	
	updateCtrlsClass("alert_confirm", "");
	updateCtrlsClass("alert_thanks", "hidden");
	updateCtrlsClass("comment_alert_error", "hidden");
	
	showCommentForm('alert_moderator', new Array('view_comment', 'post_comment'));
	
	//Hide the character counter message
	updateCtrlsClass("character_limit_tab", "hidden");
}

//Get the comments string
function doCommentString(uri)
{
	var result = "";
	var count = Number(doGetCommentCount(uri));
	if (count > 0)
	{
		
		if (count == 1)
			result = "comment"
		else
			result = "comments"

		result = "(" + String(count) + "&nbsp;" + result + ")";
	}
	

	return result;
}

//Get more comments from the server
function doMoreComments(tcmuri)
{
	commentAction = "more";
	
	return xmlCommentPost("/Comment", false, tcmuri);
}

//Get comment count from the server
function doGetCommentCount(tcmuri)
{
	commentAction = "count";
	
	return xmlCommentPost("/Comment", false, tcmuri);
}

//Post a user's comment
function doPostComment(tcmuri)
{
	//Do webtrends capture of post comment event
	try
	{
		dcsMultiTrack("DCS.dcsuri","/Post A Comment.html","DCSext.activity","Post a Comment","DCSext.CommentedArticle",
			getArticleTitle(),"WT.ti","Post A Comment","WT.AJAX","1","DCSqry","","DCSext.articleAuthor","");

		DCS.dcsuri=DCS.dcsqry=WT.ti=WT.AJAX=DCSext.CommentedArticle=DCSext.activity="";
	}
	catch (err)
	{
	}
	//Still post the comment even if Webtrends fails
	commentAction = "post";
	
	xmlCommentPost("/Comment", true, tcmuri);
}

//Alert the moderator
function doAlertModerator(commentID)
{
	actCommentID = commentID;
	showConfirmAlert();
}

//Commit the moderator alert
function commitAlert(tcmuri)
{
	commentAction = "alert";
	xmlCommentPost("/Comment", true, tcmuri);
}

//Update the comment counter div contents
function updateCommentCounter(tcmuri)
{
	var countCtrl = document.getElementById("counter_" + tcmuri);
	if (countCtrl)
	{
		var newCount = document.getElementById("newcount_" + tcmuri);
		if (newCount)
			countCtrl.innerHTML = newCount.innerHTML;
	}
}

//Setup the Comment query to be sent to the server
function setupCommentQuery(tcmuri)
{
	//We will always have the action to be performed
	var result = "commentAction=" + commentAction + "&uri=" + tcmuri;
	
	if (commentAction == "post")
	{
		//Get the comment
		ctrl = document.getElementById("new_comment");
		if (ctrl)
		{
			storeComment = FilterExpletives(ctrl.value);
			result = result + "&comment=" + escape(storeComment);
			result = result + "&commentCheck=" + encodeURIComponent(storeComment);
			
		}
		
		//Get the title
		result = result + "&title=" + encodeURIComponent(document.title);

		//Get the summary
		ctrl = document.getElementById("commentSummary_" + tcmuri);
		if (ctrl)
			result = result + "&copy=" + encodeURIComponent(ctrl.innerHTML);

	}
	else if (commentAction == "alert")
	{
		result = result + "&commentID=" + actCommentID;
	}
	
	return result;
}

//Post an XML HTTP Request for AJAX
// This code was taken from common.js originally written by Will Price
function xmlCommentPost(strURL, doAsynchronous, tcmuri) 
{
    var xmlHttpReq = false;
    var query = setupCommentQuery(tcmuri);
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, doAsynchronous);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xmlHttpReq.setRequestHeader('encoding', 'UTF-8');

    //Do asynchronous request
    if (doAsynchronous)
    {
        xmlHttpReq.onreadystatechange = function() {
            if (xmlHttpReq.readyState == 4) 
			{
				//Everything was ok
				if (xmlHttpReq.status == 200)
					updatePage(xmlHttpReq.responseText);
				//A known error occurred
				else if (xmlHttpReq.status == 400)
					errorPage(xmlHttpReq.responseText);
				//An unknown error occurred
				else
					showCommentError(UNKNOWN_ERROR_MSG);
            }
        }

        //Set the current uri for setting comments when returned
        currentTcmUri = tcmuri;

        //Compose and send the request string
        xmlHttpReq.send(query);

    }
    //Return results on synchronous requests
    else
    {
        //Compose and send the request string
        xmlHttpReq.send(query);

        return xmlHttpReq.responseText;
    }	
    
}

//Update the page according to results returned from the AJAX request
// This code was taken from common.css originally written by Will Price
function updatePage(strResult)
{
	
	var comments = document.getElementById("existing_comments");

	if (comments)
		comments.innerHTML = strResult;
	
	//Update the comment counter
	updateCommentCounter(currentTcmUri);
	currentTcmUri = "";
	
	//Show appropriate success message depending on action
	if (commentAction == "post")
	{
		updateCtrlsClass("comment_submit", "hidden");
		showPostSuccess();
		tmr = setTimeout("showExistingComments();", 5000);
		ctrl = document.getElementById("new_comment");
	
		if (ctrl)
		{
			ctrl.value = "Enter comments...";
			focused = false;
		}
	}
	else if (commentAction == "alert")
	{
		updateCtrlsClass("alert_confirm", "hidden");
		showAlertSuccess();
		tmr = setTimeout("showExistingComments();", 5000);
	} 
}

//Update the page according to the error returned from the AJAX request
function errorPage(strResult)
{
	var err = eval('(' + strResult + ')');

	//Handle user not logged in
	if (err.type == ERR_NOT_LOGGED_IN)
		showCommentError(unescape(err.message));
	//The comment probably had bad characters
	else if (err.type == ERR_COMMENT_MISSING)
	{
		el = document.getElementById("new_comment");
	
		if (el)
			el.value = unescape(err.message);
		
		showCommentError(BAD_CHAR_ERROR_MSG);
	}
	//An unknown error occurred
	else if (err.type == ERR_UNKNOWN)
		showCommentError(UNKNOWN_ERROR_MSG);
		
//	checkLogout(err);
}

//Make an error div (if it is currently missing) and add the error message to it
function showCommentError(msg)
{
	var el = document.getElementById('comment_error_msg');
	
	//Create the error comment div if it does not exist
	if (!el)
	{
		parentEl = document.getElementById('comment_submit');
		el = document.createElement('div');
		el.setAttribute('id', 'comment_error_msg');
		parentEl.insertBefore(el, parentEl.firstChild);
	}
	else
		el.className = "";
	
	
	//Set the error message
	if (el)
		el.innerHTML = msg;
	
	new Effect.Highlight(el);
	
}

//Show post success/failure message
function showPostSuccess()
{
	updateCtrlsClass("comment_thanks", "");
	updateCtrlsClass("comment_post_error", "hidden");
	updateCtrlsClass("comment_error_msg", "hidden");
		
}

//Show alert success/failure message
function showAlertSuccess(hadErr)
{
	updateCtrlsClass("alert_thanks", "");
	updateCtrlsClass("comment_alert_error", "hidden");
	updateCtrlsClass("comment_error_msg", "hidden");
}

//Check if we must show the logged out messages now
function checkLogout(err)
{
	if (err.loggedIn == false)
		tmrLogoutMsg = setTimeout("updateCommentLogoutMessages();", 5000);
}

function updateCommentLogoutMessages()
{
	var ctrl = document.getElementById("post_comment");
	if (ctrl)
		ctrl.innerHTML = postCommentLoginTags();

	ctrl = document.getElementById("alert_moderator");
	if (ctrl)
		ctrl.innerHTML = alertModeratorLoginTags();
}

//Push the user to the login page before they can comment
function doCommentsLogin(url)
{
	location.assign(url + "?dest=" + location.pathname);
}

//Write the HTML comments form to the document
//The user must have Javascript for the commenting to work so this approach is safe
function writeOutCommentsForm(uri)
{
	var root = document.getElementById("rootCommentFormDiv_" + uri);
	var auth = false;
	if (document.getElementById("commentAuth_" + uri))
		auth = true;
		
	var xmlDoc;

	if (root)
	{
		//Opening div and comments form leader
		var text = '<div><div class="heading clearfix"><h1>User Comments</h1>' +
					'<ul class="total_comments"><li>Total comments: <div id="counter_' + 
					String(uri) + '">' + doGetCommentCount(uri) + '</div></li></ul></div>' +
					'<div class="content_container comments_form">' +
					'<div class="container clearfix"><div class="content clearfix">' +
					commentFormTabTags(auth) + '<div id="comments_form">' +
					displayCommentsFormTags(uri) + commentPostFormTags(auth, uri) +
					alertModeratorFormTags(auth, uri) + '</div></div></div></div></div>';
					
/* Problems importing the node from MSXML DOM to HTMLDOM in IE
For now use innerHTML, in future maybe use Sarissa (by: Manos Batsis)

		try //Internet Explorer
		{
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = "false";
			xmlDoc.loadXML(text);
		}
		catch(e)
		{
			try //Firefox, Mozilla, Opera, etc.
			{
				parser = new DOMParser();
				xmlDoc = parser.parseFromString(text,"text/xml");
			}
			catch(e) 
			{
				alert(e.message)
			}
		}
		*/
		root.innerHTML = text;
		
	}
}

//The HTML/XML tags for the comment form tabs
function commentFormTabTags(auth)
{
	var authText = "";
	
	if (auth)
		authText = '<li id="character_limit_tab"><span>(maximum 2000 characters: ' +
					'<span id="comment_char_counter">2000</span> remaining)</span></li>';
		
	return '<ul id="comments_nav" class="comments_nav clearfix">' +
			'	<li id="view_comment_tab" class="active">' +
			'		<a href="javascript:void(0)" onclick="javascript:showExistingComments();return false;">' +
			'			<span>Most Recent</span></a>' +
			'	</li><li id="post_comment_tab">' +
			'		<a href="javascript:void(0)" onclick="showPostComments();return false;">' +
			'			<span>Post Comment</span></a>' +
			'	</li>' + authText + '</ul>';
}

//The HTML/XML tags for the comment display form
function displayCommentsFormTags(uri)
{
	
	return '<div id="view_comment"><form action="">' +
			'<input name="uri" id="uri" value="' + uri + '" type="hidden"/>' +
			'	<div class="existing_comments" id="existing_comments" name="existing_comments">' +
			doMoreComments(uri) + 
			'</div></form></div>';
}

//The HTML/XML tags for the comment posting form
function commentPostFormTags(auth, uri)
{
	var authText = "";
	
	if (auth)
		authText = '<form action=""><div id="comment_submit">' +
					'	<textarea id="new_comment" name="new_comment" class="new_comment" ' +
					'		onfocus="doClear(\'new_comment\')" maxlength="2000" ' +
					'		onKeyUp="maxLengthDisplay(this, \'comment_char_counter\')" ' +
					'		onKeyDown="maxLengthDisplay(this, \'comment_char_counter\')">' +
					'		Enter comments...</textarea>' +
					'		<input name="submit" value="submit" onclick="doPostComment(\'' + uri + '\');"' +
					'		type="button" class="button"/></div>' +
					'	<div id="comment_thanks" class="hidden">' +
					'		Thank you for your comments. Your comment has been accepted.' +
					'	</div><div id="comment_post_error" class="hidden"></div></form>';
	else
		authText = postCommentLoginTags();
		
	return '<div id="post_comment" class="hidden">' + authText + '</div>';
}

//The HTML/XML tags for the alert moderator form
function alertModeratorFormTags(auth, uri)
{
	var authText = "";
	
						
					
	if (auth)
		authText = '<form><div id="alert_confirm"><p>Your user id will be tracked ' +
					'	with the alert for the moderator regarding this comment.' +
					'	Are you sure you wish to report this comment as offensive?'	+
					'	</p><p><input name="Yes" value="Yes" onclick="commitAlert(\'' +
					uri	+ '\');" type="button"/><input name="No" value="No" ' +
					'	onclick="showExistingComments();" type="button"/></p>' +
					'	</div><div id="alert_thanks" class="hidden">Thank you for your ' +
					'		submission. The comment has been flagged and the moderator notified.' +
					'	</div><div id="comment_alert_error" class="hidden"></div></form>';
	else
		authText = alertModeratorLoginTags();
		
	return '<div id="alert_moderator" class="hidden">' + authText + '</div>';
}

//The login post comment tags are separate for interface updating purposes
function postCommentLoginTags()
{
	return 'You must be <a href="javascript:doCommentsLogin(\'/profile/login.html\');">' +
			'logged in</a> to post a comment. <br/>Click ' +
			'<a href="javascript:doCommentsLogin(\'/profile/login.html\');">to login in.</a>';
}

//The login alert moderator tags are separate to update the interface
function alertModeratorLoginTags()
{
	return 'You must be <a href="javascript:doCommentsLogin(\'/profile/login.html\');">' +
			'logged in</a> to alert the moderator. <br/>Click ' +
			'<a href="javascript:doCommentsLogin(\'/profile/login.html\');">to login in.</a>';
}


//====================PROFANITY FILTER====================
// ==UserScript==
// @name          Profanity Filter
// @namespace     http://www.someurlthingherethatsprettyunique.com/blah/ProfanityFilter
// @description    Version 1.0: Filters profanity from website.  Edit the array profanity to control 
//                               which words are removed from pages and replaced with ***.
// @include         *
// ==/UserScript==

/*
Author: MCE

Significantly rewritten other replacement scripts to noticably improve performance and add pseudo-threading to gradually replace words on larger pages.

Version: 1.0
1.0 - First Release

Competing scripts and extensions:
* http://www.arantius.com/article/arantius/clean+language/

Improvements Needed:
* Filter HTML attributes (ALT, TITLE, TOOLTIP, etc)
* Add an interface to manage the words by turning this into an extension.
*/
// Licensed for unlimited modification and redistribution as long as
// this notice is kept intact.

//This Profanity script was borrowed and severly modified from
// Author: Cameron McGregor, EIS
// Version: 1.0, JULY-27-2007

//Add words/phrases to be filtered out to this list in reverse alphabetical order
var badwords=['wtf',
'wop',
'whore',
'whoar',
'wetback',
'wank',
'twaty',
'twat',
'titty',
'titties',
'tits',
'teets',
'spunk',
'spook',
'spic',
'son-of-a-bitch',
'sonofabitch',
'son of a bitch',
'sob',
'snatch',
'smut',
'sluts',
'slut',
'sleaze',
'slag',
'shiz',
'shitty',
'shittings',
'shitting',
'shitters',
'shitter',
'shitted',
'shits',
'shitings',
'shiting',
'shit-head',
'shithead',
'shitfull',
'shited',
'shit',
'shemale',
'sheister',
'shat',
'sh!t',
'scum-bum',
'scumbum',
'scum-bucket',
'scumbucket',
'scum-bag',
'scumbag',
'scum',
'screw',
'schlong',
'retard',
'qweef',
'quif',
'queer',
'queef',
'queeb',
'pussys',
'pussy',
'pussies',
'pusse',
'punk',
'pricks',
'prick',
'pr0n',
'pornos',
'porno',
'porn',
'piss-off',
'pissoff',
'pissing',
'pissin',
'pisses',
'pissers',
'pisser',
'pissed-off',
'pissed',
'piss',
'pimp',
'phuq',
'phuks',
'phukking',
'phukked',
'phuking',
'phuked',
'phuk',
'phuck',
'phone-sex',
'phonesex',
'pecker',
'orgasms',
'orgasm',
'orgasims',
'orgasim',
'niggers',
'nigger',
'niggas',
'nigga',
'nerd',
'muthafucks',
'muthafuckings',
'muthafucking',
'muthafuckin',
'muthafuckers',
'muthafucker',
'muthafucked',
'muthafuckaz',
'muthafuckas',
'muthafucka',
'muthafuck',
'mutha',
'muff',
'mound',
'motherfucks',
'motherfuckings',
'motherfucking',
'motherfuckin',
'motherfuckers',
'motherfucker',
'motherfucked',
'motherfuck',
'mothafucks',
'mothafuckings',
'mothafucking',
'mothafuckin',
'mothafuckers',
'mothafucker',
'mothafucked',
'mothafuckaz',
'mothafuckas',
'mothafucka',
'mothafuck',
'motha',
'mook',
'mick',
'merde',
'masturbate',
'lusting',
'lust',
'loser',
'lesbo',
'lesbian',
'kyke',
'kunilingus',
'kums',
'kumming',
'kummer',
'kum',
'kuksuger',
'kuk',
'kraut',
'kondums',
'kondum',
'kock',
'knob',
'kike',
'kawk',
'jizz',
'jizm',
'jiz',
'jism',
'jis',
'jew',
'jesus h christ',
'jesus fucking christ',
'jerk-off',
'jerk',
'jap',
'jack-off',
'jackoff',
'jacking off',
'jack-ass',
'jackass',
'jack off',
'hussy',
'hot-sex',
'hotsex',
'hot sex',
'horny',
'horniest',
'hore',
'hook-nose',
'hooknose',
'hooker',
'honkey',
'homo',
'hoer',
'hell',
'heebie',
'hardcoresex',
'hard on',
'h4x0r',
'h0r',
'guinne',
'gook',
'gonads',
'goddamn',
'gazongers',
'gay-sex',
'gaysex',
'gay-lord',
'gaylord',
'gay',
'gang-bangs',
'gangbangs',
'gang-banged',
'gangbanged',
'gang-bang',
'gangbang',
'fux0r',
'furburger',
'fuks',
'fukc',
'fuk',
'fuck-you',
'fuckyou',
'fuck-up',
'fuckup',
'fucks',
'fuckme',
'fuckings',
'fucking',
'fuckin',
'fuckers',
'fucker',
'fucked',
'fuck',
'fuck you',
'fuck me',
'fuc',
'fu',
'foreskin',
'fock',
'fist-fucks',
'fistfucks',
'fist-fuckings',
'fistfuckings',
'fist-fucking',
'fistfucking',
'fist-fuckers',
'fistfuckers',
'fist-fucker',
'fistfucker',
'fist-fucked',
'fistfucked',
'fist-fuck',
'fistfuck',
'finger-fucks',
'fingerfucks',
'finger-fucking',
'fingerfucking',
'finger-fuckers',
'fingerfuckers',
'finger-fucker',
'fingerfucker',
'finger-fucked',
'fingerfucked',
'finger-fuck',
'fingerfuck',
'fellatio',
'felatio',
'feg',
'fcuk',
'fatso',
'fat-ass',
'fatass',
'farty',
'farts',
'fartings',
'farting',
'farted',
'fart',
'fah-q',
'fags',
'fagots',
'fagot',
'faggs',
'faggot',
'faggit',
'fagging',
'fagget',
'fag',
'dyke',
'dumbass',
'douche bag',
'dong',
'dipshit',
'dinkus',
'dinks',
'dink',
'dildos',
'dildo',
'dike',
'dick-weed',
'dickweed',
'dick-lips',
'dicklips',
'dick',
'damn',
'cyberfucking',
'cyberfuckers',
'cyberfucker',
'cyberfucked',
'cyberfuck',
'cyberfuc',
'cunts',
'cuntlicking',
'cuntlicker',
'cuntlick',
'cunt',
'cunnilingus',
'cunillingus',
'cunilingus',
'cumshot',
'cums',
'cumming',
'cummer',
'cum',
'crap',
'cooter',
'cocksucks',
'cocksucking',
'cock-sucker',
'cocksucker',
'cocksucked',
'cocksuck',
'cocks',
'cock-moan',
'cockmoan',
'cock-brethe',
'cockbrethe',
'cock',
'cock moan',
'cobia',
'clits',
'clit',
'clam',
'circle jerk',
'chink',
'cawk',
'buttpicker',
'butthole',
'butthead',
'butt-fucker',
'buttfucker',
'butt-fuck',
'buttfuck',
'butt-face',
'buttface',
'butt',
'butt hair',
'butt fucker',
'butt breath',
'butch',
'bung hole',
'bum',
'bullshit',
'bull shit',
'bucket cunt',
'brown-town',
'browntown',
'brown-eye',
'browneye',
'brown eye',
'boobs',
'boobies',
'boob',
'boner',
'bone-head',
'bonehead',
'blow-jobs',
'blowjobs',
'blow-job',
'blowjob',
'bitching',
'bitchin',
'bitches',
'bitchers',
'bitcher',
'bitch',
'bestiality',
'bestial',
'belly whacker',
'beaver',
'beastility',
'beastiality',
'beastial',
'bazoombas',
'bastard',
'balls',
'ass-wipe',
'asswipe',
'ass-master',
'assmaster',
'ass-licker',
'asslicker',
'ass-kisser',
'asskisser',
'assholes',
'asshole',
'asses',
'ass wipe',
'ass master',
'ass licker',
'ass lick',
'ass kisser',
'ass'];

//Build the expletives array into a regular expression
var bw = "\\b(" + badwords.join("|") + ")\\b";
bw = new RegExp(bw, "gi");

//Default replacement text if not provided
var DEFAULT_REPLACE_TEXT = "***";

//Do a find replace on the passed string
function FilterExpletives(checkStr, replaceText)
{
	
	if (typeof(replaceText) == 'undefined')
		replaceText = DEFAULT_REPLACE_TEXT;
	
	return checkStr.replace(bw, replaceText);
}