function WriteL(b,c)	{document.getElementById(b).innerHTML=c;}
function WriteB(c,d)	{document.getElementById(c).innerHTML=d;}
var type;
var strL = '';
var strB = '';
function numToBin(y)	{
	var output = '';
	var intArray = [128,64,32,16,8,4,2,1];
	for (var w = 0; w <= 7; w++)
		{if (y >= intArray[w])
			{output = output + '1';
			y = y - intArray[w]}
		else	{output = output + '0'}
	}
	return output;
}
function binToNum(x)	{
	var output = 0;
	var intArray = [128,64,32,16,8,4,2,1];
		for (var w = 0; w <= 7; w++)
			{if (x.charAt(w) == '1')
			{output = output + parseFloat(intArray[w]);}
		}
	return output;
}

function conLtr(d,e)	{
	e = getValue(e);
	if (e == '')
	  {window.alert('There are no letters or symbols to convert!');}
	else	  {
	var strL = '';
	var i = 0;
	for (var pos = 0; pos < e.length; pos++)
	{
		strL = strL + numToBin(e.charCodeAt(pos)) + ' ';
	}
  WriteB(d,strL);
  }
}

function getValue(e) {
 var x = document.getElementById(e);
 var y = x.innerHTML;
 var z = Trim(y);
 return z;
//return;
}

function conBin(e,f)	{
	f = getValue(f);
	if (f == '')
	  {window.alert('There are no binary sequences to convert!');}
	else  {		if (f.charAt(f.length) == '')	{f = f + ' '}
	//this is the bit that breaks the input into 8-bit Unicode!
	var pOne, ptwo, pThree, pFour, pFive, pSix, pSeven, pEight, pNine;
	var eightbit;
	pOne = 0;
	pTwo = 1;
	pThree = 2;
	pFour = 3;
	pFive = 4;
	pSix = 5;
	pSeven = 6;
	pEight = 7;
	var strB = '';
	eightbit = (f.charAt(pOne) + f.charAt(pTwo) + f.charAt(pThree) + f.charAt(pFour) + f.charAt(pFive) + f.charAt(pSix) + f.charAt(pSeven) + f.charAt(pEight));
	var j = 0;
	for (var pNine = 8; f.charAt(pNine) != ''; pNine = pNine + 9)
	{
		strB = strB + String.fromCharCode(binToNum(eightbit));
		pOne = pOne + 9;
		pTwo = pTwo + 9;
		pThree = pThree + 9;
		pFour = pFour + 9;
		pFive = pFive + 9;
		pSix = pSix + 9;
		pSeven = pSeven + 9;
		pEight = pEight + 9;
eightbit = (f.charAt(pOne) + f.charAt(pTwo) + f.charAt(pThree) + f.charAt(pFour) + f.charAt(pFive) + f.charAt(pSix) + f.charAt(pSeven) + f.charAt(pEight));
	}
WriteL(e,strB);
  }
}

function Trim(str) {
  return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function version() {
var vermsg = 'JavaScript 8-bit ASCII converter version 8.5\; \n copyright kaiserwilhelmdritten 2006\n\nJavaScript 8-bit ASCII converter version 8.5 updated 11.33 07/07/2006\nCurrent version 8.5';
//window.alert(vermsg);
document.getElementById("alert").innerHTML = vermsg;
}

/////////////////////////////////////////////////////////////////////////////////
//*                    Copyright Kaiserwilhelmdritten 2006                    *//
//*               http://kaiserwilhelmdritten.googlepages.com/                *//
/////////////////////////////////////////////////////////////////////////////////

