function comment_show() {
	if(document.getElementById('comment_hide_block').style.display == "none"){
		document.getElementById('comment_hide_block').style.display = "block";
	}
	else {
		document.getElementById('comment_hide_block').style.display = "none";
	}	
}

function show_comment(comment_number){
	if(document.getElementById('comment' + comment_number + '_full').style.display == "none"){
		document.getElementById('comment' + comment_number + '_full').style.display = "inline";
		document.getElementById('open_comment' + comment_number).innerHTML = "schließen";
	}
	else {
		document.getElementById('comment' + comment_number + '_full').style.display = "none";
		document.getElementById('open_comment' + comment_number).innerHTML = "weiterlesen";
	}
}

function show_all_comments(von, bis){
	
	
	var status = 0;
	var hide_link;
	
	hide_link = document.getElementById('comment_hide_link');
	
	if(document.getElementById('show_all').innerHTML == "alle anzeigen"){
			status = 1;
			document.getElementById('show_all').innerHTML = "alle schließen";
			if (document.getElementById('show_all_bottom') != null) {
				document.getElementById('show_all_bottom').innerHTML = "alle schließen";
			}
	}
	else {
			document.getElementById('show_all').innerHTML = "alle anzeigen";
			if (document.getElementById('show_all_bottom') != null) {
				document.getElementById('show_all_bottom').innerHTML = "alle anzeigen";
			}
	}

	for(i = von; i <= bis; i++){
		if (document.getElementById('open_comment' + i) != null) {
			if(status == 1){
				document.getElementById('comment' + i + '_full').style.display = "inline";
				document.getElementById('open_comment' + i).innerHTML = "schließen";
			}
			else {
				document.getElementById('comment' + i + '_full').style.display = "none"
				document.getElementById('open_comment' + i).innerHTML = "weiterlesen";
			}
		}
	}
	if (document.getElementById('comment_hide_block') != null) {
		comment_show();
	}
}

function CountMax(maxwert){
	var wert;
	var text; //Beinhaltet den Text des Textarea
	var hasN = 0;
	var subStrEnd = 0;	
	var ua = navigator.userAgent.toLowerCase();
	
	text = document.comment_input_form.comment.value;
	text = trimText(text)[0];
	text_original = document.comment_input_form.comment.value;
	//wert = maxwert-document.comment_input_form.comment.value.length;
	wert = maxwert-text.length;
	
	if (wert < 0) {
		//alert("Der Eintrag ist auf " + maxwert + " Zeichen begrenzt!");
		
		//document.comment_input_form.comment.value = document.comment_input_form.comment.value.substring(0,maxwert);
		//alert(maxwert + " - " + wert + " - " + text.length + " - " + text_original.length);
		//document.comment_input_form.comment.value = document.comment_input_form.comment.value.substring(0,maxwert);
		//wert = maxwert-document.comment_input_form.comment.value.length;
		wert = maxwert-trimText(document.comment_input_form.comment.value)[0].length;
		var zeilenumbrueche = parseInt(trimText(document.comment_input_form.comment.value)[1]);
		subStrEnd = zeilenumbrueche+parseInt(maxwert);
		subStrEnd--;
		
		if(ua.indexOf("msie") != -1){
			document.comment_input_form.comment.value = document.comment_input_form.comment.value.substring(0,subStrEnd);
			//alert(subStrEnd);
		} else if(ua.indexOf("gecko") != -1){
			document.comment_input_form.comment.value = document.comment_input_form.comment.value.substring(0,maxwert);
			//alert(maxwert);
		}
		
		wert = maxwert-trimText(document.comment_input_form.comment.value)[0].length;
		document.comment_input_form.b_counter.value = wert;
	} else { 
		//document.comment_input_form.b_counter.value = maxwert - document.comment_input_form.comment.value.length;
		document.comment_input_form.b_counter.value = maxwert - trimText(document.comment_input_form.comment.value)[0].length;
	}
}

function trimText(text){
	//Zeilenumbrüche löschen	
	//Dieser Vorgang ist Browserspezifisch anders
	var ua = navigator.userAgent.toLowerCase();
	var zeilenumbrueche = 0;
	if(ua.indexOf("msie") != -1){
		//Internetexplorer
		hasN = text.search(/\n/);
		while(hasN != -1){
			text = text.replace(/\n/, "_");
			zeilenumbrueche++;
			hasN = text.search(/\n/);
		}
		hasN = text.search(/\r/);
		while(hasN != -1){
			text = text.replace(/\r/, "");
			hasN = text.search(/\r/);
		}
	} else if(ua.indexOf("gecko") != -1){
		//Firefox
		hasN = text.search(/\n/);
		while(hasN != -1){
			text = text.replace(/\n/, " ");
			hasN = text.search(/\n/);
		}
		hasN = text.search(/\r/);
		while(hasN != -1){
			text = text.replace(/\r/, "");
			hasN = text.search(/\r/);
		}

	}
	var infoObj =  new Array(2);
	infoObj[0] = text;
	infoObj[1] = zeilenumbrueche;
	return infoObj;
}