function d2b(form, len) { // Decimal to Binary
	j = form.decimal.value;
	if (isNaN(j)) {
		j = 0;
		form.decimal.value=0;
	}
 	for (i=0; i < len; ++i) {
		l = eval("form.bit" + i);
 		if (j & 1)
 			l.status=true;
 		else
 			l.status=false;
 	j >>>= 1;
	}
}

function d2bWithRange(form, decimal, len) { // Decimal to Binary
	j = decimal;
	if (isNaN(j)) {
		j = 0;
		form.decimal.value=0;
	}
 	for (i=0; i < len; ++i) {
		l = eval("form.bit" + i);
 		if (j & 1)
 			l.status=true;
 		else
 			l.status=false;
 	j >>>= 1;
	}
}

function b2d(form, len) { // Binary to Decimal
	j=0;
 	for (i=len; i >= 0; --i) {
		j <<= 1;
		l = eval("form.bit" + i);
 		if (l.status)
 			j |= 1;
	}
 	form.decimal.value=j;
}


function b2dWithRange(form, fromBit, len) { // Binary to Decimal
	j=0;
 	for (i=len - 1; i >= fromBit; --i) {
		j <<= 1;
		l = eval("form.bit" + i);
 		if (l.status)
 			j |= 1;
	}
 	return j;
}

function resetBits(form, len) {
	resetDecimal(form);
	d2b(form, len);
}

function resetDecimal(form)
{
	form.decimal.value=0;
}

function resetConcert(form)
{
	form.decimal.value="00000";
	form.soundabstimmung.value=0;
	form.land.value=0;
	form.bit0.checked=false;
	form.bit1.checked=false;
	form.bit2.checked=false;
	form.bose.checked=false;
	form.speaker[0].checked=false;
	form.speaker[1].checked=false;
	form.speaker[2].checked=false;
	form.speaker[3].checked=false;
}

function concert2d(form)
{
	var concertArray = new Array(5);
	for (i=0; i < concertArray.length; i++)	{
		concertArray[i]=0;
	}

	concertArray[0] = form.land.value; // 1. Ziffer
	concertArray[1] = form.soundabstimmung.value; // 2. Ziffer

	for (i = 0; i < 4; i++) { // 3. Ziffer
		if (form.speaker[i].checked)
		concertArray[2] = form.speaker[i].value;
	}

	if (form.bose.status)
		concertArray[3] = 1; // 4. Ziffer

	j = b2dWithRange(form, 0, 3);
	concertArray[4] = j; // 5. Ziffer

	form.decimal.value=concertArray[0] + concertArray[1] + concertArray[2] + concertArray[3] + concertArray[4];
}

function d2concert(form)
{
	j = form.decimal.value;
	if ((isNaN(j)) || (j.length < 5) || (j.length > 5))	{
		j = "00000";
		form.decimal.value=j;
		return;
	}

	form.land.value=j.charAt(0); // 1. Ziffer
	form.soundabstimmung.value=j.charAt(1); // 2. Ziffer

	for (i=0; i < 4; i++) // 3. Ziffer
		form.speaker[i].checked = false;
	if (j.charAt(2) == '0') // 3. Ziffer
		form.speaker[0].checked = true;
	else if (j.charAt(2) == '1')
		form.speaker[1].checked = true;
	else if (j.charAt(2) == '2')
		form.speaker[2].checked = true;
	else if (j.charAt(2) == '5')
		form.speaker[3].checked = true;

	if (j.charAt(3) == '1') { // 4. Ziffer
		form.bose.status = true;
	}
	else {
		form.bose.stauts = false;
	}

	d2bWithRange(form, j.charAt(4), 3); // 5. Ziffer


}