// Wordchecker JS

var words_2_check = ["arse","ars3","assbanger","assclown","assface","assfuck","asshole","asslicker","assmunch","asswipe","bastard","beaner","bitch","blowjob","boner","bullshit","bullsh1t","buttplug","butt-pirate","buttfucka","buttfucker","cameltoe","chinc","chink","chode","clit","cl1t","cock","cigarette","c1garette","c0ck","cockmuncher","cocksucker","cum","cumming","cunnilingus","cunt","damn","dick","dickhead","dickhole","dicks","dickwod","dildo","d1ldo","dild0","d1ld0","dipshit","dookie","douche","douchebag","dumass","dumbass","dumbass","dumbfuck","dumbshit","dyke","fag","faggit","faggot","fagtard","fatass","fellatio","fuck","fuckass","fucked","fucker","fuckface","fuckhole","fuckin","fucking","fucktard","fuckwad","fuckwit","gay","gaywad","goddamn","goddamnit","gooch","gook","gringo","hardon","homo","honkey","jackass","jerkoff","junglebunny","kike","kooch","kootch","kyke","lezzie","lezbian","motherfucker","motherfucking","negro","nigga","nigger","niglet","nutsack","panooch","pecker","peckerhead","piss","pissed","pissedoff","poonany","porchmonkey","prick","punta","pussy","puto","queef","queer","queerbait","renob","rimjob","sandnigger","scrote","shit","sh1t","shitface","shitfaced","shithead","shitter","shittiest","shitting","shitty","skank","slut","slutbag","testicle","thundercunt","titfuck","tits","twat","twats","va-j-j","vjayjay","wank","wanker","wank3r","whore","sex","stiffy","hard-on","wang","vagina","vag1na","g-spot","gspot","fingering","porn","p0rn","hardcore","underage","virgin","v1rgin","v1rg1n","virg1n","beastiality","pusc","slut","breast","steriods","st3roids","ster0ids","st3ro1ds","st3r01ds","viagra","v1agra","incest","1ncest","1nc3st","lolita","l0lita","l0l1ta","lol1ta","heroin","h3rion","h3r1on","h3r10n","her10n","heri0n","prozac","pr0zac"]; 

var symbols_2_check = [["\"","&quot;"],["'","&acute;"],["$","s"],["@","a"]];

var http_2_check = ["www","http","http://","<script","<style","<a","<b","<i","<hr","<img"];

function check_words(text_obj, text_name) {
    var return_value = false;
    
    var text_object = getObj(text_obj); 
    var text_2_read = text_object.value.toLowerCase();    
    var phase_1_start = "We are unable to send this message as it contains some bad words in the "+text_name+" field.\n";
    var phase_2_start = "We are unable to send this message as it contains some html words in the "+text_name+" field.\n";
    var error_text_p1 = 0;
    var error_text_p2 = 0;
    if (text_object.value) {
        var text_temp = replace_symbols(text_2_read);
        // check phase 1
        for (var w=0;w<words_2_check.length;w++) {
            var temp_word = words_2_check[w].toLowerCase();
            for (var s=0;s<symbols_2_check.length;s++) {
                if (text_2_read.indexOf(symbols_2_check[s][1]+temp_word+symbols_2_check[s][1]) != -1) {
                  error_text_p1++;
                } else if (text_2_read.indexOf(" "+temp_word+symbols_2_check[s][1]) != -1) {
                  error_text_p1++;
                } else if (text_2_read.indexOf(symbols_2_check[s][1]+temp_word+" ") != -1) {
                  error_text_p1++;
                }
            }
            if (text_2_read.indexOf(temp_word) != -1) {
                  error_text_p1++;
            }
        }

        // check phase 2
        for (var h=0;h<http_2_check.length;h++) {
            var temp_word = http_2_check[h].toLowerCase();
            for (var s=0;s<symbols_2_check.length;s++) {
                if (text_2_read.indexOf(symbols_2_check[s][1]+temp_word+symbols_2_check[s][1]) != -1) {
                    error_text_p2++;
                } else if (text_2_read.indexOf(" "+temp_word+symbols_2_check[s][1]) != -1) {
                    error_text_p2++;
                } else if (text_2_read.indexOf(symbols_2_check[s][1]+temp_word+" ") != -1) {
                    error_text_p2++;
                } 
            }
            if (text_2_read.indexOf(temp_word) != -1) {
                error_text_p2++;
            }
        }
        
        var text_2_alert = "";
        if (error_text_p1 > 0 || error_text_p2 > 0) {
            if (error_text_p1 > 0)
              text_2_alert += phase_1_start;
            if (error_text_p1 > 0 && error_text_p2 > 0) 
//              text_2_alert += "\n";
            if (error_text_p2 > 0)
              text_2_alert += phase_2_start;
        }

        if (text_2_alert.length > 0) {
            alert(text_2_alert);
        } else {
            return_value = true;
        }
        
        return return_value;
    }
}

function replace_symbols(text) {
    var text_2_return = text;
    for (var t=0;t<symbols_2_check.length;t++) {
        while(text_2_return.indexOf(symbols_2_check[t][0]) > -1) {
          text_2_return = text_2_return.replace(symbols_2_check[t][0],symbols_2_check[t][1]);
        }
    }
    return text_2_return;
}
