var profanityArray = null;

function makeArray() { 
	if(profanityArray == null){		
		var wordString = window.parent.getProfanityWordList();
		var words = wordString.split(",");
		profanityArray = words;
	}
	return profanityArray;
}

function isProfanity(term){
	var list = makeArray();	 
	var flag = false;
	term = term.toUpperCase();
	for (var i = 0; i < list.length; i++){ 
		var pos = term.indexOf(list[i].toUpperCase());
		if (pos != -1) {
			var profanityPotential = false;
			if(pos == 0){
				profanityPotential = true;
			}
			else{
				var ch = term.charAt(pos - 1);
				if(ch == ' ' || ch == '_' || ch == '\n' || ch == '\r' || ch == ','){
					profanityPotential = true;
				}
			}
			
			if(profanityPotential){
				if(pos + list[i].length == term.length){
					profanityPotential = true;
				}
				else if(pos + list[i].length < term.length){
					var ch = term.charAt(pos + list[i].length);
					if(ch == ' ' || ch == '_' || ch == '\n' || ch == '\r' || ch == ',' || ch == '!'){
						profanityPotential = true;
					}
					else{
						profanityPotential = false;
					}
				}
			}
			if(profanityPotential){
				// if they're the same, then break out of the for loop
				flag = true;
				break;
			}
		} 
	} 
	return flag;
} 
