// SMS-Formular (Kontrolle der Zeichenzahl)

var maxLength = 140;

function doChange() {

	text = document.Message.theText.value;

	textlgth = count(text);

	document.Message.theLength.value = maxLength - textlgth;

	if (textlgth > maxLength) {

			changeValues(text, textlgth);

	}

	return true;
}

function count(theString) {

	var count = 0;

	for (i=0;i<theString.length;i++) {

		value = theString.charCodeAt(i);

		if (value >31 || value==13) count++; 

	}

	return count;
}

function changeValues(text, textlgth) {

	cutoff = find(text,maxLength);
	document.Message.theText.value=text.substring(0,cutoff);
	text=document.Message.theText.value;
	textlgth = text.length;
	document.Message.theLength.value = maxLength-count(text);
}

function find(theString,thenum) {

	var count = 0;
	var i=0;

	while (count < thenum) {

		value = theString.charCodeAt(i);
		if (value >31 || value==13) count++;
		i++;
	}

	return i;
}

// SMS-Formular versenden

function sendform() {

	if(document.Message.theText.value == "") {
	
    	alert("Ihre Nachricht hat keinen gültigen Inhalt!");
    	document.Message.theText.focus();
    }
	else {
	
		document.Message.submit();
    }
}

// Anfrageformular versenden

function sendform_applic() {

		if(document.Mailform.Mailtext.value == "") {
	
    	alert("Ihre Nachricht hat keinen gültigen Inhalt!");
    	document.Mailform.Mailtext.focus();
    }
	else {

		if(document.Mailform.sendname.value == "" && document.Mailform.sendadd.value == "") {
		
    		Check = confirm("Sie haben keine Angaben zum Absender gemacht! Wollen Sie die Nachricht trotzdem senden?");
			
    		if(Check == true) {
			
				document.Mailform.submit();
			}
    		else {
			
				document.Mailform.sendname.focus();
			}
    	}
		else {
		
			document.Mailform.submit();
    	}
    }
}
