//Binary Code Generator (Javascript) is Copyright 2008 My-i-p.com

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

String.prototype.bincvt = function(){
var tobin = this;
tobin = tobin.split('');
tobinout = new Array();
tobinlen = tobin.length;
var sec = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*()-_+={}[]|:;<>?,."/\\\' ';
var rep = ['01000001','01000010','01000011','01000100','01000101','01000110','01000111','01001000','01001001','01001010','01001011','01001100','01001101','01001110','01001111','01010000','01010001','01010010','01010011','01010100','01010101','01010110','01010111','01011000','01011001','01011010',
'01100001','01100010','01100011','01100100','01100101','01100110','01100111','01101000','01101001','01101010','01101011','01101100','01101101','01101110','01101111','01110000','01110001','01110010','01110011','01110100','01110101','01110110','01110111','01111000','01111001','01111010',
'00110000','00110001','00110010','00110011','00110100','00110101','00110110','00110111','00111000','00111001',
'00100001','01000000','00100011','00100100','00100101','00100110','00101010','00101000','00101001','00101101','01011111','00101011','00111101','01111011','01111101','01011011','01011101','01111100','00111010','00111011','00111100','00111110','00111111','00101100','00101110','00100010','00101111','01011100','00100111','00100000'];
if (document.form_binary.add_space.checked == true) var space = ' '; else space = '';
for (var y = 0; y < tobinlen; y++){
tobinout[y] = rep[sec.indexOf(tobin[y])] + space;}
tobinout = tobinout.join('');
return tobinout;}

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

function ascii2binary(){
var text = document.form_binary.input_output.value;
var textout = new Array();
text = text.replace(/\r/g,'');
text = text.split('\n');
var linecnt = text.length;
for (var x = 0; x < linecnt; x++){
textout[x] = text[x].bincvt();}
textout = textout.join('\n');
document.form_binary.input_output.value = textout;}

String.prototype.chunk = function(n){
if (typeof n=='undefined') n=2;
return this.match(RegExp('.{1,'+n+'}','g'));};
String.prototype.asccvt = function(){
var toasc = this;
toasc = toasc.chunk(8).join(',||');
toasc = '||' + toasc;
toasc = toasc.split(',');
toascout = new Array();
toasclen = toasc.length;
var sec = '          ||01000001||01000010||01000011||01000100||01000101||01000110||01000111||01001000||01001001||01001010||01001011||01001100||01001101||01001110||01001111||01010000||01010001||01010010||01010011||01010100||01010101||01010110||01010111||01011000||01011001||01011010||01100001||01100010||01100011||01100100||01100101||01100110||01100111||01101000||01101001||01101010||01101011||01101100||01101101||01101110||01101111||01110000||01110001||01110010||01110011||01110100||01110101||01110110||01110111||01111000||01111001||01111010||00110000||00110001||00110010||00110011||00110100||00110101||00110110||00110111||00111000||00111001||00100001||01000000||00100011||00100100||00100101||00100110||00101010||00101000||00101001||00101101||01011111||00101011||00111101||01111011||01111101||01011011||01011101||01111100||00111010||00111011||00111100||00111110||00111111||00101100||00101110||00100010||00101111||01011100||00100111||00100000';
var rep = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','!','@','#','$','%','&','*','(',')','-','_','+','=','{','}','[',']','|',':',';','<','>','?',',','.','"','/','\\','\'',' '];
for (var y = 0; y < toasclen; y++){
toascout[y] = rep[sec.indexOf(toasc[y])/10-1];}
toascout = toascout.join('');
return toascout;}
String.prototype.cleantxt = function(){
var textin = this;
var clean = new Array();
textin = textin.split('');
var sec = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%&*()-_+={}[]|:;<>?,."/\\\' ';
if (document.form_binary.space4space.checked == true) var rep = ['','','','','','','','','','','','','','','','','','','','','','','','','','','0','1','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',' ']; else rep = ['','','','','','','','','','','','','','','','','','','','','','','','','','','0','1','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''];
for (var y = 0; y < textin.length; y++) {
clean[y] = rep[sec.indexOf(textin[y])];}
cleaned = clean.join('');
if (cleaned.length == 0) cleaned = '00100000'; else cleaned = cleaned;
return cleaned;}
Array.prototype.revemplin = 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 emptyshiftbit(){
var text = '';
document.form_binary.shift_temp.value = text;
document.getElementById('show_shift').innerHTML = text;
document.getElementById('show_shift').style.height = '0px';}
function loadshiftbit(){
var text = document.form_binary.input_output.value;
text = text.replace(/\r/g,'').replace(/\n/g,'');
if (document.form_binary.space4space.checked == true) text = text.replace(/ /g,'00100000'); else text = text;
text = text.cleantxt();
document.form_binary.shift_temp.value = text;}
function shiftbit(){
var text = document.form_binary.shift_temp.value;
text = text.replace(/\r/g,'');
text = text.split('');
text.shift();
text = text.join('');
textloadback = text;
if (text.length == 0) text = '0010000000100000'; else text = text;
textout = text.asccvt();
if (textout != 'A') document.form_binary.input_output.value = textout; else document.form_binary.input_output.value = '';
if (textloadback != '0100000') {if (textloadback.length != 0) document.getElementById('show_shift').style.height = '14px';}
document.getElementById('show_shift').innerHTML = textloadback;
document.form_binary.shift_temp.value = textloadback;}
function binary2ascii(){
var text = document.form_binary.input_output.value;
text = text.replace(/\r/g,'');
if (document.form_binary.input_output.value.length >= 8){var text = document.form_binary.input_output.value;} else{text = '010100000110110001100101011000010111001101100101001000000110010101101110011101000110010101110010001000000111100101101111011101010111001000100000011000100110100101101110011000010111001001111001001000000110001101101111011001000110010100101110';}
text = text.split('\n');
cleantext = new Array();
for (var x = 0; x < text.length; x++){
cleantext[x] = text[x].cleantxt();}
text = cleantext.revemplin('').join('\n');
var textout = new Array();
if (document.form_binary.space4space.checked == true) text = text.replace(/ /g,'00100000'); else text = text;
text = text.split(' ').join('');
text = text.split('\n');
var linecnt = text.length;
for (var x = 0; x < linecnt; x++){
textout[x] = text[x].asccvt();}
textout = textout.join('\n');
document.form_binary.input_output.value = textout;}

function buttonbin(){
var btext = document.form_binsearch.thebutton.value;
if (btext == 'Binary Google Search') btext = '010001110110111100100001'; else btext = 'Binary Google Search';
document.form_binsearch.thebutton.value = btext;}

String.prototype.bincvtsch = function(){
var tobin = this;
tobin = tobin.split('');
tobinout = new Array();
tobinlen = tobin.length;
var sec = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*()-_+={}[]|:;<>?,."/\\\' ';
var rep = ['01000001','01000010','01000011','01000100','01000101','01000110','01000111','01001000','01001001','01001010','01001011','01001100','01001101','01001110','01001111','01010000','01010001','01010010','01010011','01010100','01010101','01010110','01010111','01011000','01011001','01011010',
'01100001','01100010','01100011','01100100','01100101','01100110','01100111','01101000','01101001','01101010','01101011','01101100','01101101','01101110','01101111','01110000','01110001','01110010','01110011','01110100','01110101','01110110','01110111','01111000','01111001','01111010',
'00110000','00110001','00110010','00110011','00110100','00110101','00110110','00110111','00111000','00111001',
'00100001','01000000','00100011','00100100','00100101','00100110','00101010','00101000','00101001','00101101','01011111','00101011','00111101','01111011','01111101','01011011','01011101','01111100','00111010','00111011','00111100','00111110','00111111','00101100','00101110','00100010','00101111','01011100','00100111','00100000'];
if (document.form_binsearch.add_space.checked == true) var space = ' '; else space = '';
for (var y = 0; y < tobinlen; y++){
tobinout[y] = rep[sec.indexOf(tobin[y])] + space;}
tobinout = tobinout.join('');
return tobinout;}
function binsearch(){
var text = document.form_binsearch.bin_in.value;
if (document.form_binsearch.ext_sch.checked == true) var exactsch = '"'; else exactsch = '';
text = exactsch + text.bincvtsch() + exactsch;
text = text.replace(/ "/,'"');
document.form_binsearch.q.value = text;}

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