// This script hereby is dedicated in the Public Domain
// as long as nobody else claims the copyright for it.
// origin: 2000-01-08 nospam@geht.net http://tools.geht.net/rot13.html
// Use at own risk.
var last="";
var rot13map;

// The problem is that JavaScript 1.0
// does not provide a Char to Numeric value conversion
// Thus we define a map.
// Because there are 64K UniCode characters, this map does not cover all characters.
function rot13init()
{
  var map = new Array();
  var s   = "abcdefghijklmnopqrstuvwxyz";
  
  for (i=0; i<s.length; i++)
    map[s.charAt(i)]			= s.charAt((i+13)%26);
  for (i=0; i<s.length; i++)
    map[s.charAt(i).toUpperCase()]	= s.charAt((i+13)%26).toUpperCase();
  return map;
}

function rot13(a)
{
  if (!rot13map)
    rot13map=rot13init();
  s = "";
  var flag;
  flag = 0;
  var c = ' ';
  for (i=0; i<a.length; i++)
    {
      var b = a.charAt(i);
      if ((b == '>' && c != 'b') || b == ';') flag = 0;
      if (b == '<' || b == '&') flag = 1;
      if (!flag) {
          s += (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
      } else {
          s += b;
      }
      c = b;
    }
  return s;
}

function reveal(id){
document.getElementById(id).innerHTML=rot13(document.getElementById(id).innerHTML);
}

//Reveals swear-words beginning with (currently) F, S, C, A and B. To work,
//each hidden word must start with the letter in question and be followed by
//the correct number of bleeped-out characters, the first of which must be '*'
//(e.g. f*** or f*%#, but not f#*% - two clicks will be needed for this case).
//A second click hides the word again, this time using only asterisks. Makes
//no change to text that does not fit any of the given patterns. Ampersands
//create problems because of their special role in the rot-13 function above.
//
//Good for isolated curses in otherwise innocent anagrams.
function foulup(a)
{
  var i;
  var b = a.charAt(0);
  d = "" + b;
  x = rot13(d);

  var c = b.toLowerCase();
  if (c == 'f') {
    if (a.length == 4) x += "hpx";
    else if (a.length == 6) x += "hpxrq";
    else if (a.length == 7) x += "hpxvat";
    else return a;
  } else if (c == 's') {
    if (a.length == 4) x += "uvg";
    else if (a.length == 5) x += "uvgr";
    else if (a.length == 7) x += "uvggrq";
    else return a;
  } else if (c == 'c') {
    if (a.length == 4) x += "hag";
    else return a;
  } else if (c == 'a') {
    if (a.length == 4) x += "efr";
    else if (a.length == 7) x += "ffubyr";
    else if (a.length == 8) x += "efrubyr";
    else return a;
  } else if (c == 'b') {
    if (a.length == 6) x += "httre";
    else if (a.length == 7) x += "httrel";
    else return a;
  } else {
    return a;
  }
  if (a.charAt(1) != '*') {
    for (i=0; i<a.length-1; i++) d += "*";
    return d;
  }
  return rot13(x);
}

function unSwear(id){
document.getElementById(id).innerHTML=foulup(document.getElementById(id).innerHTML);
}