//Sort Text Lines (Javascript) is Copyright 2011 TextMechanic.com All Rights Reserved

function monofnt(){
var fonttype = document.getElementById('input_output').style.fontFamily.replace(/[^a-z]/gi,'');
if(fonttype == 'arial') document.getElementById('input_output').style.fontFamily = 'courier new';
else document.getElementById('input_output').style.fontFamily = 'arial';}
function cleartext(){
document.getElementById('input_output').value = '';}
function linecnt(){
setTimeout(linecnt2,500);}
function linecnt2(){
var text = document.getElementById('input_output').value;
var textlength = text.length;
var lncnt = text.split('\n').length;
if(textlength > 0) document.getElementById('line_count').value = lncnt; else document.getElementById('line_count').value = '0';}
Array.prototype.clean = function(remove_item){
var arr;
var len = this.length;
for(arr=0;arr<len;arr++){
if(this[arr] == remove_item){
this.splice(arr,1);arr--;}}
return this;}
function csdsort(){
var delimiter = document.getElementById('s_delimiter').value;
var snum = document.getElementById('s_num').value - 1;
function dsortcs(a,b){
x = a.toString().split(delimiter).slice(snum).join(delimiter);
y = b.toString().split(delimiter).slice(snum).join(delimiter);
if(x < y) return -1;
if(x > y) return 1;
return 0;}
var text = document.getElementById('input_output').value;
text = text.replace(/\r/g,'');
if(delimiter == '' && snum == '0') text = text.split('\n').sort().clean('').join('\n'); else text = text.split('\n').sort(dsortcs).clean('').join('\n');
document.getElementById('input_output').value = text;}
function cidsort(){
var delimiter = document.getElementById('s_delimiter').value;
var snum = document.getElementById('s_num').value - 1;
function rsortci(a,b){
x = a.toString().toLowerCase();
y = b.toString().toLowerCase();
if(x < y) return -1;
if(x > y) return 1;
return 0;}
function dsortci(a,b){
x = a.toString().toLowerCase().split(delimiter).slice(snum).join(delimiter);
y = b.toString().toLowerCase().split(delimiter).slice(snum).join(delimiter);
if(x < y) return -1;
if(x > y) return 1;
return 0;}
var text = document.getElementById('input_output').value;
text = text.replace(/\r/g,'');
if(delimiter == '' && snum == '0') text = text.split('\n').sort(rsortci).clean('').join('\n'); else text = text.split('\n').sort(dsortci).clean('').join('\n');
document.getElementById('input_output').value = text;}
function sortci(){
var delimiter = document.getElementById('s_delimiter').value;
var snum = document.getElementById('s_num').value - 1;
function cisort(x,y){
nC = String.fromCharCode(0);
xN = x.toString().toLowerCase().replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
yN = y.toString().toLowerCase().replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
for(var cLoc=0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++){
if((parseFloat(xN[cLoc]) || xN[cLoc]) < (parseFloat(yN[cLoc]) || yN[cLoc])) return -1;
else if((parseFloat(xN[cLoc]) || xN[cLoc]) > (parseFloat( yN[cLoc]) || yN[cLoc])) return 1;}
return 0;}
function dcisort(x,y){
nC = String.fromCharCode(0);
xN = x.toString().toLowerCase().split(delimiter).slice(snum).join(delimiter).replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
yN = y.toString().toLowerCase().split(delimiter).slice(snum).join(delimiter).replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
for(var cLoc=0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++){
if((parseFloat(xN[cLoc]) || xN[cLoc]) < (parseFloat(yN[cLoc]) || yN[cLoc])) return -1;
else if((parseFloat(xN[cLoc]) || xN[cLoc]) > (parseFloat( yN[cLoc]) || yN[cLoc])) return 1;}
return 0;}
var text = document.getElementById('input_output').value;
text = text.replace(/\r/g,'');
if(delimiter == '' && snum == '0') text = text.split('\n').sort(cisort).clean('').join('\n'); else text = text.split('\n').sort(dcisort).clean('').join('\n');
document.getElementById('input_output').value = text;}
function sortcs(){
var delimiter = document.getElementById('s_delimiter').value;
var snum = document.getElementById('s_num').value - 1;
function cssort(x,y){
nC = String.fromCharCode(0);
xN = x.toString().replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
yN = y.toString().replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
for(var cLoc=0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++){
if((parseFloat(xN[cLoc]) || xN[cLoc]) < (parseFloat(yN[cLoc]) || yN[cLoc])) return -1;
else if((parseFloat(xN[cLoc]) || xN[cLoc]) > (parseFloat( yN[cLoc]) || yN[cLoc])) return 1;}
return 0;}
function dcssort(x,y){
nC = String.fromCharCode(0);
xN = x.toString().split(delimiter).slice(snum).join(delimiter).replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
yN = y.toString().split(delimiter).slice(snum).join(delimiter).replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC);
for(var cLoc=0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++){
if((parseFloat(xN[cLoc]) || xN[cLoc]) < (parseFloat(yN[cLoc]) || yN[cLoc])) return -1;
else if((parseFloat(xN[cLoc]) || xN[cLoc]) > (parseFloat( yN[cLoc]) || yN[cLoc])) return 1;}
return 0;}
var text = document.getElementById('input_output').value;
text = text.replace(/\r/g,'');
if(delimiter == '' && snum == '0') text = text.split('\n').sort(cssort).clean('').join('\n'); else text = text.split('\n').sort(dcssort).clean('').join('\n');
document.getElementById('input_output').value = text;}
function sortbylength(){
var belong2 = 'pbclevtug grkgzrpunavp.pbz';
function complengths(a,b){
x = a.toString().length;
y = b.toString().length;
if(x < y) return -1;
if(x > y) return 1;
return 0;}
var text = document.getElementById('input_output').value;
text = text.replace(/\r\n/g,'\n');
text = text.split('\n').sort(complengths).clean('').join('\n');
document.getElementById('input_output').value = text;}
Array.prototype.shuffle = function (){
var x = this.length;
if(x == 0) return false;
var y = 0;
var temp_x = '';
var temp_y = '';
while(--x){
y = Math.floor(Math.random()*(x + 1));
temp_x = this[x];
temp_y = this[y];
this[x] = temp_y;
this[y] = temp_x;}
return this;}
function sortrandom(){
var text = document.getElementById('input_output').value;
text = text.replace(/\r\n/g,'\n');
text = text.split('\n').shuffle().clean('').join('\n');
document.getElementById('input_output').value = text;}
function reverseorder(){
var text = document.getElementById('input_output').value;
var belong2 = 'pbclevtug grkgzrpunavp.pbz';
text = text.replace(/\r\n/g,'\n');
text = text.split('\n').reverse().clean('').join('\n');
document.getElementById('input_output').value = text;}
function SelectAll(id){
document.getElementById(id).focus();
document.getElementById(id).select();}
