function clickstate(id) {
	var tags = document.getElementsByTagName('input');
	for (var i=0; i < tags.length; i++) {
		if (tags[i].className == "check-"+id) {
			if (document.getElementById("check-"+id).checked == true) {
				tags[i].disabled = true;
				tags[i].checked = false;
			} else {
				tags[i].disabled = false;
			}
		}
	}
}

function check_branchen(id_array) {
	for (var i=0; i<id_array.length; i++) {
		clickstate(id_array[i]);
	}
	for (var j=1; j<5; j++) {
		document.getElementById('box-'+j).style.display = document.getElementById('flipstatus-'+j).value;
		if (document.getElementById('box-'+j).style.display == "none") {
			document.getElementById('main-'+j).style.backgroundImage = 'url("./images/ps-closed.gif")';
		} else if (document.getElementById('box-'+j).style.display == "block") {
			document.getElementById('main-'+j).style.backgroundImage = 'url("./images/ps-open.gif")';
		}
		document.getElementById('main-'+j).style.backgroundRepeat = "no-repeat";
	}
}

function check_adresstyp() {
	var status = [[0,0,0],[1,0,0],[0,1,0],[0,1,1]];
	var adresstyp = document.getElementsByName('adresstyp');
	for (var i=0; i<adresstyp.length; i++) {
		if (adresstyp[i].checked == true) {
			var j=i;
		}
	}
	//flip('abo', status[j][0]);
	flip('firmenlogo-set', status[j][1]);
	flip('freitext-set', status[j][2]);
}

function flip(id,status) {
	if (status == 0) { document.getElementById(id).style.display = 'none'; }
	if (status == 1) { document.getElementById(id).style.display = 'block'; }
	if (status == 2) {
		if (document.getElementById('box-'+id).style.display == 'none') {
			document.getElementById('box-'+id).style.display = 'block';
			document.getElementById('flipstatus-'+id).value = 'block';
		} else if (document.getElementById('box-'+id).style.display == "block") {
			document.getElementById('box-'+id).style.display = 'none';
			document.getElementById('flipstatus-'+id).value = 'none';
		}
	}
	
}

function arrow(id) {
	if (id.style.backgroundImage ==  'url("./images/ps-closed.gif")') {
		id.style.backgroundImage = 'url("./images/ps-open.gif")';
			id.style.backgroundRepeat = "no-repeat";
	} else if (id.style.backgroundImage == 'url("./images/ps-open.gif")') {
		id.style.backgroundImage = 'url("./images/ps-closed.gif")';
			id.style.backgroundRepeat = "no-repeat";
	}
}

function CheckAt(feld) {
   var max=250, textinhalt = feld.value;
   if (textinhalt.length >= max) {
      feld.value=textinhalt.substring(0,max);
   }
	 avchars = max-textinhalt.length;
	 if (avchars < 0) { avchars = 0; }
	 document.getElementById('textcount-span').innerHTML = avchars;
	 document.getElementById('textcount-hidden').value = avchars;
}

function check_agb(id) {
	if (id.checked === true) { var status = false; }
	if (id.checked === false) { var status = true; }
	document.getElementById('bestellen1').disabled = status;
	document.getElementById('bestellen2').disabled = status;
}
