﻿// JScript File
// Utku Ozan ÇANKAYA
// 03.07.2007
//
// Perfoms regular expression check on an input strings and either
// warns the user with a message or
// replaces the rude word with alternative
// according to the rude word in text

// Example:
// NON-CATCHABLE:
// The ASSistant professor preferred to eat MUFFins with BUTTer while Mr. DICKinson
// preferred to but fast food with SODexho tickets
//
// CATCHABLE:
// The boy was so rude and yelling around fuck you son of a BITCH, you WHORE, pissed IDIOT

// These are the catchable rude words
var rudeWords = new Array(
        new Array('ass',            ''),
        new Array('asshole',        ''),
        new Array('arse',           ''),
        new Array('arsehole',       ''),
        new Array('bastard',        ''),
        new Array('bitch',          ''),
        new Array('bloody',         ''),
        new Array('bollocks',       ''),
        new Array('boob',           ''),
        new Array('bosom',          ''),
        new Array('breast',         ''),
        new Array('bugger',         ''),
        new Array('bullshit',       ''),
        new Array('butt',           ''),
        new Array('butthole',       ''),
        new Array('buttock',        ''),
        new Array('bum',            ''),
        new Array('clit',           ''),
        new Array('clitoris',       ''),
        new Array('cock',           ''),
        new Array('coon',           ''),
        new Array('crap',           ''),
        new Array('dick',           ''),
        new Array('dickhead',       ''),
        new Array('douch',          ''),
        new Array('douche',         ''),
        new Array('douch-bag',      ''),
        new Array('douchbag',       ''),
        new Array('douche-bag',     ''),
        new Array('douchebag',      ''),
        new Array('dyke',           ''),
        new Array('faggot',         ''),
        new Array('fanny',          ''),
        new Array('foreskin',       ''),
        new Array('homo',           ''),
        new Array('jerk',           ''),
        new Array('jizz',           ''),
        new Array('kike',           ''),
        new Array('knob',           ''),
        new Array('masturbate',     ''),
        new Array('masturbation',   ''),
        new Array('milf',           ''),
        new Array('muff',           ''),
        new Array('nipple',         ''),
        new Array('nob',            ''),
        new Array('oral',           ''),
        new Array('paki',           ''),
        new Array('penis',          ''),
        new Array('piss',           ''),
        new Array('pissflap',       ''),
        new Array('pissed',         ''),
        new Array('poo',            ''),
        new Array('poof',           ''),
        new Array('porn',           ''),
        new Array('porno',          ''),
        new Array('pornstar',       ''),
        new Array('prick',          ''),
        new Array('pussy',          ''),
        new Array('rectum',         ''),
        new Array('semen',          ''),
        new Array('sex',            ''),
        new Array('shag',           ''),
        new Array('shite',          ''),
        new Array('sod',            ''),
        new Array('sodding',        ''),
        new Array('spastic',        ''),
        new Array('spaz',           ''),
        new Array('sperm',          ''),
        new Array('spunk',          ''),
        new Array('tit',            ''),
        new Array('toss',           ''),
        new Array('tosser',         ''),
        new Array('turd',           ''),
        new Array('twat',           ''),
        new Array('vagina',         ''),
        new Array('whore',          ''),
        new Array('wop',            ''),
        new Array('yid',            ''),
        new Array('yiddo',          ''));

// These are ther replaceable rude words with alternatives
var rudeRepWords = new Array(
        new Array('ass', 'a**'),
        new Array('asshole', 'a**hole'),
        new Array('arse', 'a**e'),
        new Array('arsehole', 'a***hole'),
        new Array('bastard', 'b***ard'),
        new Array('bitch', 'b**ch'),
        new Array('bloody', 'b****y'),
        new Array('bollocks', 'b****cks'),
        new Array('boob', 'b**b'),
        new Array('bosom', 'b*som'),
        new Array('breast', 'b***st'),
        new Array('bugger', 'bu**er'),
        new Array('bullshit', 'bull***t'),
        new Array('butt', 'b*tt'),
        new Array('butthole', 'b*tthole'),
        new Array('buttock', 'b*ttock'),
        new Array('bum', 'b*m'),
        new Array('clit', 'cl*t'),
        new Array('clitoris', 'cl**oris'),
        new Array('cock', 'c**k'),
        new Array('coon', 'c**n'),
        new Array('crap', 'cr*p'),        
        new Array('cocksucker','c**ksucker'),
        new Array('cum', 'c*m'),
        new Array('cunt', 'c**t'),
        new Array('dick', 'd**k'),
        new Array('dickhead', 'd**khead'),
        new Array('douch', 'd***h'),
        new Array('douche', 'd***he'),
        new Array('douch-bag', 'd***h-bag'),
        new Array('douchbag', 'd***hbag'),
        new Array('douche-bag', 'd***h-bag'),
        new Array('douchebag', 'd***hbag'),
        new Array('dyke', 'd**e'),
        new Array('faggot', 'f***ot'),
        new Array('fanny', 'f***y'),
        new Array('fuck', 'f**k'),
        new Array('fucking', 'f***ing'),
        new Array('fucker', 'f***er'),
        new Array('foreskin', 'f***skin'),
        new Array('homo', 'h**0'),
        new Array('jerk', 'j*rk'),
        new Array('jizz', 'j**z'),
        new Array('kike', 'k**e'),
        new Array('knob', 'k**b'),
        new Array('masturbate', 'm*****bate'),
        new Array('masturbation', 'm******ation'),
        new Array('motherfucker',  'motherf**ker'),
        new Array('motherfucking', 'motherf**king'),
        new Array('milf', 'm**f'),
        new Array('muff', 'm**f'),
        new Array('nipple', 'n***le'),
        new Array('nigger', 'n**ger'),
        new Array('nob', 'n*b'),
        new Array('oral', 'o**l'),
        new Array('Paki', 'p***'),
        new Array('penis', 'p**is'),
        new Array('piss', 'pi**'),
        new Array('pissflap', 'pi**flap'),
        new Array('pissed', 'pi**ed'),
        new Array('poo', 'p**'),
        new Array('poof', 'p**f'),
        new Array('porn', 'p**n'),
        new Array('porno', 'p**no'),
        new Array('pornstar', 'p**nstar'),
        new Array('prick', 'p**ck'),
        new Array('pussy', 'p***y'),
        new Array('rectum', 'r***um'),
        new Array('semen', 's****n'),
        new Array('sex', 's*x'),
        new Array('shag', 's**g'),
        new Array('shit', 's**t'),
        new Array('shite', 's***e'),
        new Array('sod', 's*d'),
        new Array('sodding', 's***ing'),
        new Array('spastic', 's***tic'),
        new Array('spaz', 's**z'),
        new Array('sperm', 's***m'),
        new Array('spunk', 's***k'),
        new Array('tit', 't*t'),
        new Array('titties', 't****es'),
        new Array('titfuck', 'titf**ck'),
        new Array('toss', 't**s'),
        new Array('tosser', 't**ser'),
        new Array('turd', 't**d'),
        new Array('twat', 't**t'),
        new Array('vagina', 'v****a'),
        new Array('wank', 'w**k'),
        new Array('wanker', 'w**ker'),
        new Array('whore', 'w***e'),
        new Array('wop', 'w**'),
        new Array('yid', 'y**'),
		new Array('yiddo', 'y***o'),
        new Array('shitty', 'sh**ty'),
		new Array('wanky', 'w**ky'),
		new Array('tosspot', 't*sspot'),
		new Array('shithead', 's**thead'),
		new Array('dickhead', 'd**khead'),
		new Array('spaff', 'sp*ff')
		
 );

// This is the global warning message for catchable rude words
var rudeWarnMsg = 'The uptight monkeys that live inside our machines think your message may contain inappropriate language or be a bit too rude for a friendly site like Push.\n\n'+ 

'Please take another look at what you\'ve written and see if there are changes that might make the monkeys happy.\n\n'+ 

'If you don’t, we’ll asterisk the rude bits, the monkeys will tell us and, if we think they\'ve got a point, we may decide to remove your message and even cancel your membership. Don\'t say you haven\'t been warned.\n\n'+ 

'We’re sorry for this – we know it looks lame – but it’s to stop us getting blocked by school filters.\n';


var rudeWarnMsg1 = 'The uptight monkeys that live inside our machines think your message may contain inappropriate language or be a bit too rude for a friendly site like Push. \r\n'+
    'Please take another look at what you\'ve written and see if there are changes that might make the monkeys happy. \r\n'+
    'If you don\'t, the monkeys will tell us and, if we think they\'ve got a point, we may decide to remove your message and even cancel your membership. \r\n'+
    'Don\'t say you haven\'t been warned.';
 
function checkRudeWords(rudeMsg)
{
     
    // This is the main function that performs the operation
    var retValue=rudeMsg;
    if (checkOccurance(rudeMsg))    // Check if a rude word exists
    {
        alert(rudeWarnMsg);
       
      retValue= replaceOccurance(rudeMsg);  // Replace replaceable rude words
    }
    return retValue;    
} 
    
//function checkOccurance(objid)
function checkOccurance(inputStr)
{
//    var inputStr="";
//    if(objid)
//    {
//       inputStr=objid.value;
//       
//    }
    if(inputStr)
    {       
        for (var i=0; i < rudeWords.length; i++)    // For every item in rude words
        {
            var reg = new RegExp('\\b' + rudeWords[i][0].toString() + '\\b', ['gi']); // Compose regular expression
            if (reg.exec(inputStr)) // Make regular check
            {
                return true;
            }
            else
            {
                var reg2 = new RegExp('\\b' + rudeWords[i][0].toString() + 's' + '\\b', ['gi']); // Compose regular expression
                if (reg2.exec(inputStr)) // Make regular check
                {
                    return true;
                }
            }
        }
        for (var i=0; i < rudeRepWords.length; i++)    // For every item in rude words
        {
            var reg = new RegExp('\\b' + rudeRepWords[i][0].toString() + '\\b', ['gi']); // Compose regular expression
            if (reg.exec(inputStr)) // Make regular check
            {
                return true;
            }
            else
            {
                var reg2 = new RegExp('\\b' + rudeRepWords[i][0].toString() + 's' + '\\b', ['gi']); // Compose regular expression
                if (reg2.exec(inputStr)) // Make regular check
                {
                    return true;
                }
            }
        }
    }
    return false;
}

function replaceOccurance(inputStr)
{
    
   
    if(inputStr)
    {             
        for (var i=0; i < rudeRepWords.length; i++) // For every item in replaceable rude words
        {
            var reg = new RegExp('\\b' + rudeRepWords[i][0].toString() + '\\b', ['gi']);  // Compose regular expression
            if (reg.exec(inputStr)) // Make regular check
            {   // If holds
                inputStr = inputStr.replace(reg, rudeRepWords[i][1].toString());    // Replace the rude word with alternative
            }
            else
            {               
                var reg2 = new RegExp('\\b' + rudeRepWords[i][0].toString() + 's' + '\\b', ['gi']);  // Compose regular expression
                if (reg2.exec(inputStr)) // Make regular check
                {   // If holds                    
                    inputStr = inputStr.replace(reg2, (rudeRepWords[i][1] + 's') .toString());    // Replace the rude word with alternative
                }    
            }
            
        }
       return inputStr;
        
    }
}
