//Reverse Text Generator (Javascript) is Copyright 2010 TextMechanic.com All Rights Reserved

function cleartext(){
document.form_reverse.input_output.value = '';}

String.prototype.swapcase = function(){
var toswap = this;
var toswaplen = toswap.length;
var uplet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var lolet = 'abcdefghijklmnopqrstuvwxyz';
word = toswap.split('');
wordlen = word.length;
var first = word[0];
var last = word[wordlen-1];
if (uplet.indexOf(first) == -1) upperc = 0; else upperc = 1;
if (lolet.indexOf(last) == -1) lowerc = 0; else lowerc = 1;
if (upperc + lowerc == 2){
toswap = toswap.split('');
toswap = toswap.slice(1,toswaplen-1);
toswap.unshift(first.toLowerCase());
toswap.push(last.toUpperCase());
toswap = toswap.join('');
return toswap;} else return toswap;}
function reversetext(){
var text = document.form_reverse.input_output.value;
text = text.replace(/\r\n/g,'\n');
text = text.replace(/\(/g,'  (  ');
text = text.replace(/\)/g,'  )  ');
text = text.replace(/\[/g,'  [  ');
text = text.replace(/\]/g,'  ]  ');
text = text.replace(/\{/g,'  {  ');
text = text.replace(/\}/g,'  }  ');
text = text.replace(/\</g,'  <  ');
text = text.replace(/\>/g,'  >  ');
text = text.split('').reverse().join('');
text = text.replace(/  \(  /g,')');
text = text.replace(/  \)  /g,'(');
text = text.replace(/  \[  /g,']');
text = text.replace(/  \]  /g,'[');
text = text.replace(/  \{  /g,'}');
text = text.replace(/  \}  /g,'{');
text = text.replace(/  \<  /g,'>');
text = text.replace(/  \>  /g,'<');
document.form_reverse.input_output.value = text;}

function buttonrev(){
var btext = document.form_reverse.thebutton1.value;
if (btext == 'Reverse Text') btext = 'txeT esreveR'; else btext = 'Reverse Text';
document.form_reverse.thebutton1.value = btext;}

function fliptext() {
var text = document.form_reverse.input_output.value;
text = text.replace(/\r\n/g,'\n');
text = text.replace(/\(/g,'  (  ');
text = text.replace(/\)/g,'  )  ');
text = text.replace(/\[/g,'  [  ');
text = text.replace(/\]/g,'  ]  ');
text = text.replace(/\{/g,'  {  ');
text = text.replace(/\}/g,'  }  ');
text = text.replace(/\</g,'  <  ');
text = text.replace(/\>/g,'  >  ');
text = text.split('\n').reverse().join('\n');
text = text.split('').reverse().join('');
text = text.replace(/  \(  /g,')');
text = text.replace(/  \)  /g,'(');
text = text.replace(/  \[  /g,']');
text = text.replace(/  \]  /g,'[');
text = text.replace(/  \{  /g,'}');
text = text.replace(/  \}  /g,'{');
text = text.replace(/  \<  /g,'>');
text = text.replace(/  \>  /g,'<');
document.form_reverse.input_output.value = text;}

function buttonrevflp(){
var btext = document.form_reverse.thebutton2.value;
if (btext == 'Flip Text') btext = 'txeT pilF'; else btext = 'Flip Text';
document.form_reverse.thebutton2.value = btext;}

function reversewords(){
var text = document.form_reverse.input_output.value;
text = text.replace(/\r\n/g,'\n');
text = text.replace(/\./g,'  .  ');
text = text.replace(/\,/g,'  ,  ');
text = text.replace(/\?/g,'  ?  ');
text = text.replace(/\!/g,'  !  ');
text = text.replace(/\:/g,'  :  ');
text = text.replace(/\;/g,'  ;  ');
text = text.replace(/\(/g,'  (  ');
text = text.replace(/\)/g,'  )  ');
text = text.replace(/\[/g,'  [  ');
text = text.replace(/\]/g,'  ]  ');
text = text.replace(/\{/g,'  {  ');
text = text.replace(/\}/g,'  }  ');
text = text.replace(/\</g,'  <  ');
text = text.replace(/\>/g,'  >  ');
text = text.replace(/\"/g,' \" ');
text = text.replace(/\|/g,' | ');
text = text.replace(/\n/g,' \n ').split(' ').reverse().join(' ').replace(/ \n /g,'\n');
text = text.replace(/  \.  /g,'.');
text = text.replace(/  \,  /g,',');
text = text.replace(/  \?  /g,'?');
text = text.replace(/  \!  /g,'!');
text = text.replace(/  \:  /g,':');
text = text.replace(/  \;  /g,';');
text = text.replace(/  \(  /g,')');
text = text.replace(/  \)  /g,'(');
text = text.replace(/  \[  /g,']');
text = text.replace(/  \]  /g,'[');
text = text.replace(/  \{  /g,'}');
text = text.replace(/  \}  /g,'{');
text = text.replace(/  \<  /g,'>');
text = text.replace(/  \>  /g,'<');
text = text.replace(/ \" /g,'\"');
text = text.replace(/ \| /g,'|');
document.form_reverse.input_output.value = text;}

function buttonrevwrdng(){
var btext = document.form_reverse.thebutton3.value;
if (btext == 'Reverse Wording') btext = 'Wording Reverse'; else btext = 'Reverse Wording';
document.form_reverse.thebutton3.value = btext;}

function flipwords(){
var text = document.form_reverse.input_output.value;
text = text.replace(/\r\n/g,'\n');
text = text.replace(/\./g,'  .  ');
text = text.replace(/\,/g,'  ,  ');
text = text.replace(/\?/g,'  ?  ');
text = text.replace(/\!/g,'  !  ');
text = text.replace(/\:/g,'  :  ');
text = text.replace(/\;/g,'  ;  ');
text = text.replace(/\(/g,'  (  ');
text = text.replace(/\)/g,'  )  ');
text = text.replace(/\[/g,'  [  ');
text = text.replace(/\]/g,'  ]  ');
text = text.replace(/\{/g,'  {  ');
text = text.replace(/\}/g,'  }  ');
text = text.replace(/\</g,'  <  ');
text = text.replace(/\>/g,'  >  ');
text = text.replace(/\"/g,' \" ');
text = text.replace(/\|/g,' | ');
text = text.split('\n').reverse().join('\n');
text = text.replace(/\n/g,' \n ').split(' ').reverse().join(' ').replace(/ \n /g,'\n');
text = text.replace(/  \.  /g,'.');
text = text.replace(/  \,  /g,',');
text = text.replace(/  \?  /g,'?');
text = text.replace(/  \!  /g,'!');
text = text.replace(/  \:  /g,':');
text = text.replace(/  \;  /g,';');
text = text.replace(/  \(  /g,')');
text = text.replace(/  \)  /g,'(');
text = text.replace(/  \[  /g,']');
text = text.replace(/  \]  /g,'[');
text = text.replace(/  \{  /g,'}');
text = text.replace(/  \}  /g,'{');
text = text.replace(/  \<  /g,'>');
text = text.replace(/  \>  /g,'<');
text = text.replace(/ \" /g,'\"');
text = text.replace(/ \| /g,'|');
document.form_reverse.input_output.value = text;}

function buttonrevwrdngflp(){
var btext = document.form_reverse.thebutton4.value;
if (btext == 'Flip Wording') btext = 'Wording Flip'; else btext = 'Flip Wording';
document.form_reverse.thebutton4.value = btext;}

function reversewordletters(){
var text = document.form_reverse.input_output.value;
text = text.replace(/\r\n/g,'\n');
text = text.replace(/\./g,' . ');
text = text.replace(/\,/g,' , ');
text = text.replace(/\?/g,' ? ');
text = text.replace(/\!/g,' ! ');
text = text.replace(/\:/g,' : ');
text = text.replace(/\;/g,' ; ');
text = text.replace(/\(/g,' ( ');
text = text.replace(/\)/g,' ) ');
text = text.replace(/\[/g,' [ ');
text = text.replace(/\]/g,' ] ');
text = text.replace(/\{/g,' { ');
text = text.replace(/\}/g,' } ');
text = text.replace(/\</g,' < ');
text = text.replace(/\>/g,' > ');
text = text.replace(/\'/g,' \' ');
text = text.replace(/\"/g,' \" ');
text = text.replace(/\%/g,' % ');
text = text.replace(/\$/g,' $ ');
text = text.replace(/\#/g,' # ');
text = text.replace(/\@/g,' @ ');
text = text.replace(/\*/g,' * ');
text = text.replace(/\+/g,' + ');
text = text.replace(/\-/g,' - ');
text = text.replace(/\=/g,' = ');
text = text.replace(/\_/g,' _ ');
text = text.replace(/\|/g,' | ');
text = text.replace(/\&/g,' & ');
text = text.replace(/\//g,' / ');
text = text.replace(/\\/g,' \\ ');
text = text.replace(/\n/g,' \n ');
text = text.split(' ');
var len = text.length;
var textarr = new Array();
for (var x = 0; x < len; x++){
var text2 = text[x].swapcase();
text2 = text2.split('').reverse().join('');
textarr[x] = text2;}
text = textarr.join(' ');
text = text.replace(/ \n /g,'\n');
text = text.replace(/ \. /g,'.');
text = text.replace(/ \, /g,',');
text = text.replace(/ \? /g,'?');
text = text.replace(/ \! /g,'!');
text = text.replace(/ \: /g,':');
text = text.replace(/ \; /g,';');
text = text.replace(/ \( /g,'(');
text = text.replace(/ \) /g,')');
text = text.replace(/ \[ /g,'[');
text = text.replace(/ \] /g,']');
text = text.replace(/ \{ /g,'{');
text = text.replace(/ \} /g,'}');
text = text.replace(/ \< /g,'<');
text = text.replace(/ \> /g,'>');
text = text.replace(/ \' /g,'\'');
text = text.replace(/ \" /g,'\"');
text = text.replace(/ \% /g,'%');
text = text.replace(/ \$ /g,'$');
text = text.replace(/ \# /g,'#');
text = text.replace(/ \@ /g,'@');
text = text.replace(/ \* /g,'*');
text = text.replace(/ \+ /g,'+');
text = text.replace(/ \- /g,'-');
text = text.replace(/ \= /g,'=');
text = text.replace(/ \_ /g,'_');
text = text.replace(/ \| /g,'|');
text = text.replace(/ \& /g,'&');
text = text.replace(/ \/ /g,'/');
text = text.replace(/ \\ /g,'\\');
document.form_reverse.input_output.value = text;}

function buttonrevwrdlet(){
var btext = document.form_reverse.thebutton5.value;
if (btext == 'Reverse Each Word\'s Lettering') btext = 'Esrever Hcae Drow\'s Gnirettel'; else btext = 'Reverse Each Word\'s Lettering';
document.form_reverse.thebutton5.value = btext;}

function flipupsidedown(){
var text = document.form_reverse.input_output.value;
var len = text.split('').length;
if (len > 50001) {var overload = confirm("WARNING: You have entered over 50,000 characters of text which could slow down or even lock-up your computer! Please click \"Cancel\" to stop flip text upside down or click \"OK\" to proceed with flip text upside down at your own risk.");
if (overload == true) var result = flipString(text.toLowerCase());
if (overload == false) var result = 'Flip text upside down has been cancelled.';}
else var result = flipString(text.toLowerCase());
document.form_reverse.input_output.value = result;}
function flipString(aString){
var last = aString.length - 1;
var result = new Array(aString.length)
for (var i = last; i >= 0; --i){
var c = aString.charAt(i)
var r = flipTable[c]
result[last - i] = r != undefined ? r : c}
return result.join('')}
var flipTable = {
a : '\u0250',
b : 'q',
c : '\u0254',
d : 'p',
e : '\u01DD',
f : '\u025F',
g : '\u0183',
h : '\u0265',
i : '\u0131',
j : '\u027E',
k : '\u029E',
l : '\u05DF',
m : '\u026F',
n : 'u',
r : '\u0279',
t : '\u0287',
v : '\u028C',
w : '\u028D',
y : '\u028E',
'.' : '\u02D9',
'[' : ']',
'(' : ')',
'{' : '}',
'?' : '\u00BF',
'!' : '\u00A1',
"\'" : ',',
'<' : '>',
'_' : '\u203E',
'"' : '\u201E',
'\\' : '\\',
';' : '\u061B',
'\u203F' : '\u2040',
'\u2045' : '\u2046',
'\u2234' : '\u2235'}
for (i in flipTable){
flipTable[flipTable[i]] = i;}

function buttonrevupsdn(){
var btext = document.form_reverse.thebutton6.value;
if (btext == 'Flip Upside Down') btext = 'u\u028Dop \u01DDp\u0131sdn d\u0131\u05DF\u025F'; else btext = 'Flip Upside Down';
document.form_reverse.thebutton6.value = btext;}

function SelectAll(id) {
document.getElementById(id).focus();
document.getElementById(id).select();}