	var filterArray;
	var numFilterInputElements;
	var profaneFlag = false;

	function filterFunction(filterTagNames, category, locale)
    {
		var params = "";
    	filterArray = filterTagNames.split(",");
    	numFilterInputElements = filterArray.length;
        for(i=0; i<numFilterInputElements; i++)
        {
            var rawContent = document.getElementById(filterArray[i]).value;
            if(rawContent == "")
            {
                rawContent = "#";
            }
            rawContent = escape(rawContent);
            rawContent = rawContent.replace(/%3E/g, " temp_greater_than ");
            rawContent = rawContent.replace(/%3C/g, " temp_lesser_than ");
            rawContent = rawContent.replace(/%u2122/g, " temp_trademark ");
            rawContent = rawContent.replace(/%AE/g, " temp_registered_trademark ");
            rawContent = rawContent.replace(/%25/g, " temp_percent ");
			rawContent = rawContent.replace(/%u2019/g, " temp_special_quote ");
            rawContent = encodeURIComponent(rawContent);
            var wordContent = rawContent;
            params += ("word=" + wordContent + "&");
        }
        params = params.substr(0, (params.length-1));
        
       	params += ("&category=" + category); 
        params += ("&locale=" + locale);
        
        if(((location.href).indexOf("http://")) >= 0)
        {
            var url = "http://" + location.hostname + ":" + location.port + "/bin/filter.json";
        }
		else
		{
            var url = "https://" + location.hostname + ":" + location.port + "/bin/filter.json";
        }
			   
        $.ajax(
        {
        	async: false,
        	type: "POST",
            global: false,
            cache: false,
            dataType: "jsonp",
            url: url,    
            data: params,
            success: function(data)
            {
            	return profaneFlag;
            }
        });  
    }
    
    function parseJSONP(responseJsonObject)
    {
    	profaneFlag = false;
    	if(responseJsonObject.response == "invalidResponseFromWebservice")
    	{
    		alert("The Profanity-Filtering Service is not available at the moment. Please contact the administrator, and please try again later.");
    		profaneFlag = true;
    		return false;
    	}
       	for(i=0; i<numFilterInputElements; i++)
   	    {
       		if(responseJsonObject.response[i].filter.matched == true)
   	        {
       			profaneFlag = 1;
       			index = i;
   	        }
   	        replacementText = responseJsonObject.response[i].filter.replacement;
   	        if(replacementText == "#")
   	        {
   	        	replacementText = "";
   	        }
   	        if(replacementText.match("##") != null)
   	        {
   	        	profaneFlag = true;
   	            index = i;
   	        }
   	        replacementText = decodeURIComponent(replacementText);
   	        replacementText = replacementText.replace(/ temp_percent /g, "%25");
   	        replacementText = replacementText.replace(/ temp_registered_trademark /g, "%AE");
   	        replacementText = replacementText.replace(/ temp_trademark /g, "%u2122");
   	        replacementText = replacementText.replace(/ temp_lesser_than /g, "%3C");
   	        replacementText = replacementText.replace(/ temp_greater_than /g, "%3E");
			replacementText = replacementText.replace(/ temp_special_quote /g, "##");
   	        replacementText = unescape(replacementText);
   	        document.getElementById(filterArray[i]).value = replacementText;                    
   	    }
   	    if(profaneFlag == true)
   	    {
   	    	alert("Some information may be incorrect or inappropriate. Please try again");
   	        document.getElementById(filterArray[index]).focus();
   	    }
    }
    
    function check(filterTagNames)
    {
    	filterFunction(filterTagNames, "Slang", "en");
    	if(profaneFlag == true)
    	{
    		return false;
    	}
    	else
    	{
    		return true;
    	}    	
    }
    
    function checkVersion2(filterTagNames, category, locale)
    {
    	filterFunction(filterTagNames, category, locale);
    	if(profaneFlag == true)
    	{
    		return false;
    	}
    	else
    	{
    		return true;
    	}
    }
