//Remove Duplicate Lines from Text (Javascript) is Copyright 2008 My-i-p.com

Array.prototype.clean = function(remove_item){
var a;
for (a = 0; a < this.length; a++){
if (this[a] == remove_item){
this.splice(a,1);a--;}
}return this;}

function space2line(){
var inputtext = document.form_rdup.input_output.value;
inputtext = inputtext.replace(/\r/g,'');
inputtext = inputtext.replace(/\n/g,' ');
inputtext = inputtext.split(' ');
inputtext = inputtext.clean('');
inputtext = inputtext.clean(' ');
inputtext = inputtext.join('\n');
document.form_rdup.input_output.value = inputtext;}

function line2space(){
var inputtext = document.form_rdup.input_output.value;
inputtext = inputtext.replace(/\r/g,'');
inputtext = inputtext.replace(/\n/g,' ');
document.form_rdup.input_output.value = inputtext;}

function sent2line(){
var inputtext = document.form_rdup.input_output.value;
inputtext = inputtext.replace(/\r/g,'');
inputtext = inputtext.replace(/\n/g,' ');
inputtext = inputtext.replace(/  /g,' ');
inputtext = inputtext.replace(/   /g,' ');
inputtext = inputtext.replace(/\. /g,'\.\n');
inputtext = inputtext.replace(/\.\n /g,'\.\n');
inputtext = inputtext.replace(/\! /g,'\!\n');
inputtext = inputtext.replace(/\!\n /g,'\!\n');
inputtext = inputtext.replace(/\? /g,'\?\n');
inputtext = inputtext.replace(/\?\n /g,'\?\n');
document.form_rdup.input_output.value = inputtext;}

function sent2space(){
var inputtext = document.form_rdup.input_output.value;
inputtext = inputtext.replace(/\r/g,'');
inputtext = inputtext.replace(/\n/g,' ');
document.form_rdup.input_output.value = inputtext;}

function disrem(){
if (document.form_rdup.find_mode.checked == false) var found_removed = 'removed';
if (document.form_rdup.find_mode.checked == true) var found_removed = 'found';
if (document.form_rdup.dis_rem.checked == true) document.getElementById('removed_div').innerHTML = '<br>Duplicate lines ' + found_removed + ':<br><textarea name="removed_output" style="width:99%; height:200px; overflow-y:scroll; overflow-x:scroll; padding:0;" class="mfrm2"  wrap="off"></textarea>';
if (document.form_rdup.dis_rem.checked == false) document.getElementById('removed_div').innerHTML = '';}

function cleartext(){
document.form_rdup.input_output.value = '';}

function inputcontrol(){
if (document.form_rdup.count_warning.value != 'Warned'){
var inputtext = document.form_rdup.input_output.value;
var len = inputtext.split('\n').length;
if (len > 10001) {var overload = confirm("WARNING: You have entered over 10,000 lines of text which could slow down or even lock-up your computer! Please click \"Cancel\" to stop text loading or click \"OK\" to proceed with text loading at your own risk. After clicking \"OK\" no more warnings will be issued.");
if (overload == true) {document.form_rdup.count_warning.value = 'Warned'; document.form_rdup.input_output.value = inputtext;} if (overload == false) {document.form_rdup.input_output.value = 'Text loading cancelled.'; document.form_rdup.count_warning.value = '';}}}}

function expand(){
var hgt = document.form_rdup.input_output.rows;
hgt = hgt + 5;
document.form_rdup.input_output.rows = hgt;}
function contract(){
var hgt = document.form_rdup.input_output.rows;
hgt = hgt - 5;
document.form_rdup.input_output.rows = hgt;}

function rduplin(){
if (document.form_rdup.find_mode.checked == false){
var count = 0;
var text = document.form_rdup.input_output.value;
text = text.replace(/\r/g,'');
var listvalues = new Array();
var newlist = new Array();
var removedlist = new Array();
if (document.form_rdup.rel.checked == true) listvalues = text.split('\n').clean('');
if (document.form_rdup.rel.checked == false) listvalues = text.split('\n');
var hash = new Array();
for (var i=0; i<listvalues.length; i++){
if (listvalues[i] != ''){
if (hash[listvalues[i].toLowerCase()] != 1) {newlist = newlist.concat(listvalues[i]); hash[listvalues[i].toLowerCase()] = 1}
else {count++; removedlist = removedlist.concat(listvalues[i]);}} else newlist = newlist.concat(listvalues[i]);}
document.form_rdup.input_output.value = newlist.join('\n');
if (document.form_rdup.dis_rem.checked == true) document.form_rdup.removed_output.value = removedlist.clean('').join('\n');
document.getElementById('removed').innerHTML = count + ' lines removed.';}

if (document.form_rdup.find_mode.checked == true){
var count = 0;
var text = document.form_rdup.input_output.value;
text = text.replace(/\r/g,'');
var listvalues = new Array();
var newlist = new Array();
var removedlist = new Array();
if (document.form_rdup.rel.checked == true) listvalues = text.split('\n').clean('');
if (document.form_rdup.rel.checked == false) listvalues = text.split('\n');
var hash = new Array();
for (var i=0; i<listvalues.length; i++){
if (listvalues[i] != ''){
if (hash[listvalues[i].toLowerCase()] != 1) {newlist = newlist.concat(listvalues[i]); hash[listvalues[i].toLowerCase()] = 1}
else {count++; var dupfound = 'DUPLICATE=>' + listvalues[i] + '<=DUPLICATE'; newlist = newlist.concat(dupfound); removedlist = removedlist.concat(listvalues[i]);}} else newlist = newlist.concat(listvalues[i]);}
document.form_rdup.input_output.value = newlist.join('\n');
if (document.form_rdup.dis_rem.checked == true) document.form_rdup.removed_output.value = removedlist.clean('').join('\n');
document.getElementById('removed').innerHTML = count + ' lines found.';}}

function rduplincs(){
if (document.form_rdup.find_mode.checked == false){
var count = 0;
var text = document.form_rdup.input_output.value;
text = text.replace(/\r/g,'');
var listvalues = new Array();
var newlist = new Array();
var removedlist = new Array();
if (document.form_rdup.rel.checked == true) listvalues = text.split('\n').clean('');
if (document.form_rdup.rel.checked == false) listvalues = text.split('\n');
var hash = new Array();
for (var i=0; i<listvalues.length; i++){
if (listvalues[i] != ''){
if (hash[listvalues[i]] != 1) {newlist = newlist.concat(listvalues[i]); hash[listvalues[i]] = 1}
else {count++; removedlist = removedlist.concat(listvalues[i]);}} else newlist = newlist.concat(listvalues[i]);}
document.form_rdup.input_output.value = newlist.join('\n');
if (document.form_rdup.dis_rem.checked == true) document.form_rdup.removed_output.value = removedlist.clean('').join('\n');
document.getElementById('removed').innerHTML = count + ' lines removed.';}

if (document.form_rdup.find_mode.checked == true){
var count = 0;
var text = document.form_rdup.input_output.value;
text = text.replace(/\r/g,'');
var listvalues = new Array();
var newlist = new Array();
var removedlist = new Array();
if (document.form_rdup.rel.checked == true) listvalues = text.split('\n').clean('');
if (document.form_rdup.rel.checked == false) listvalues = text.split('\n');
var hash = new Array();
for (var i=0; i<listvalues.length; i++){
if (listvalues[i] != ''){
if (hash[listvalues[i]] != 1) {newlist = newlist.concat(listvalues[i]); hash[listvalues[i]] = 1}
else {count++; var dupfound = 'DUPLICATE=>' + listvalues[i] + '<=DUPLICATE'; newlist = newlist.concat(dupfound); removedlist = removedlist.concat(listvalues[i]);}} else newlist = newlist.concat(listvalues[i]);}
document.form_rdup.input_output.value = newlist.join('\n');
if (document.form_rdup.dis_rem.checked == true) document.form_rdup.removed_output.value = removedlist.clean('').join('\n');
document.getElementById('removed').innerHTML = count + ' lines found.';}}

function SelectAll(id) {
document.getElementById(id).focus();
document.getElementById(id).select();}
