function immo_trim(zeichenkette)   {  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');  }


var popupErrors 			= false;

var anredeErrorString 		= "Bitte w&auml;hlen Sie eine Anredeform!";
var betreffErrorString 		= "Bitte w&auml;hlen Sie einen Betreff!";
var emailErrorString 		= "Bitte geben Sie eine g&uuml;ltige E-Mail Adresse an!";
var nameErrorString 		= "Bitte geben Sie Ihren Namen an!";
var nachnameErrorString 	= "Bitte geben Sie Ihren (Nach-)Namen an!";
var ortErrorString 			= "Bitte geben Sie Ihren Wohnort an!";
var plzErrorString 			= "Bitte geben Sie Ihre Postleitzahl an!";
var strasseErrorString 		= "Bitte geben Sie Ihre Stra&szlig;e an!";
var telefonErrorString 		= "Bitte geben Sie Ihre Telefonnummer an!";
var vornameErrorString 		= "Bitte geben Sie Ihren Vornamen an!";
var kontaktdatenSpeichernErrorString    = "Bitte best&auml;tigen Sie Ihren Kontaktwunsch!";


function nl_setFormAction() {
	/* Direkt zur Verarbeitung bei unsubsribe */
	if(document.nl_dataform.nl_action.value == "unsubscribe") {
		document.nl_dataform.action = "newsletter_folgeseite.php";
	}
}


function checkTheForm() {
	return checkInfopaketForm();
}


function checkInfopaketForm() {
	
	document.getElementById("anrede").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("betreff").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("f_email").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("nachname").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("ort").style.backgroundColor 		= "#FFFFFF";
	document.getElementById("plz").style.backgroundColor 		= "#FFFFFF";
	document.getElementById("strasse").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("vorname").style.backgroundColor 	= "#FFFFFF";
	
	//document.getElementById("telefon").style.backgroundColor	= "#FFFFFF";
	
	var theAnrede	= document.getElementById("anrede");
	var anredeIsSet	= false;
	var theValue	= "";
	for (var i = 0; i < theAnrede.options.length; i++) {
		if(theAnrede.options[i].selected == true) {
			var theValue = theAnrede.options[i].value;
		}
	}
	anredeIsSet = (theValue != "") ? true : false;

	var theBetreff		= document.getElementById("betreff");
	var betreffIsSet	= (theBetreff.value != "") ? true : false;
	
	var theName		= document.getElementById("nachname");
	var nameIsSet	= (theName.value != "") ? true : false;

	var theOrt		= document.getElementById("ort");
	var ortIsSet	= (theOrt.value != "") ? true : false;

	var thePLZ		= document.getElementById("plz");
	var plzIsSet	= (thePLZ.value != "") ? true : false;

	var theStrasse		= document.getElementById("strasse");
	var strasseIsSet	= (theStrasse.value != "") ? true : false;

	var theVorname		= document.getElementById("vorname");
	var vornameIsSet	= (theVorname.value != "") ? true : false;
	
	/*
	var theTelefon		= document.getElementById("telefon");
	var telefonIsSet	= (immo_trim(theTelefon.value) != "") ? true : false;
	*/
	
	var mailRegExp	= /^([0-9a-zA-Z]([\-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,4})$/;
	var theEmail	= document.getElementById("f_email");
	var emailIsSet = (theEmail.value != "" && theEmail.value != "noonehere@yahoo.com" && mailRegExp.test(theEmail.value)) ? true : false;
	
	var kontaktdatenSpeichernIsSet = document.getElementById("kontaktdaten_speichern").checked;

	var result = (anredeIsSet && betreffIsSet && emailIsSet && kontaktdatenSpeichernIsSet && nameIsSet && ortIsSet &&
					plzIsSet && strasseIsSet && vornameIsSet) ? true : false;
	
	//result = result && telefonIsSet;
	
	/* Fehlerausgabe im Dokument */
	var theErrorString = "<ul>";

	if(!anredeIsSet) {
		theErrorString += "<li>" + anredeErrorString + "</li>";
		document.getElementById("anrede").style.backgroundColor = "#FFE6E6";
	}

	if(!betreffIsSet) {
		theErrorString += "<li>" + betreffErrorString + "</li>";
		document.getElementById("betreff").style.backgroundColor = "#FFE6E6";
	}
	
	if(!emailIsSet) {
		theErrorString += "<li>" + emailErrorString + "</li>";
		document.getElementById("f_email").style.backgroundColor = "#FFE6E6";
	}
	
	if(!nameIsSet) {
		theErrorString += "<li>" + nameErrorString + "</li>";
		document.getElementById("nachname").style.backgroundColor = "#FFE6E6";
	}
	
	if(!ortIsSet) {
		theErrorString += "<li>" + ortErrorString + "</li>";
		document.getElementById("ort").style.backgroundColor = "#FFE6E6";
	}
	
	if(!plzIsSet) {
		theErrorString += "<li>" + plzErrorString + "</li>";
		document.getElementById("plz").style.backgroundColor = "#FFE6E6";
	}
	
	if(!strasseIsSet) {
		theErrorString += "<li>" + strasseErrorString + "</li>";
		document.getElementById("strasse").style.backgroundColor = "#FFE6E6";
	}
	
	if(!vornameIsSet) {
		theErrorString += "<li>" + vornameErrorString + "</li>";
		document.getElementById("vorname").style.backgroundColor = "#FFE6E6";
	}
		
	if (!kontaktdatenSpeichernIsSet) {
		theErrorString += "<li>" + kontaktdatenSpeichernErrorString + "</li>";
		document.getElementById("kontaktdaten-speichern-box").style.border = "solid #dd0000 3px";			
	} else {
		document.getElementById("kontaktdaten-speichern-box").style.border = "none";
	}
	
	/*
	if(!telefonIsSet) {
		theErrorString += "<li>" + telefonErrorString + "</li>";
		document.getElementById("telefon").style.backgroundColor = "#FFE6E6";
	}
	*/
	
	theErrorString += "</ul>";
	document.getElementById("outputdiv").innerHTML = theErrorString;
	//theOutputdiv.style.display = "block";
	window.scrollTo(0, 0);
		
	return result;
	
}//checkInfopaketForm


function checkAngebotForm() {
	
	document.getElementById("anrede").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("nachname").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("f_email").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("vorname").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("strasse").style.backgroundColor 	= "#FFFFFF";
	document.getElementById("plz").style.backgroundColor 		= "#FFFFFF";
	document.getElementById("ort").style.backgroundColor 		= "#FFFFFF";

	/*
		prfe ob Anrede gewhlt
	*/
	var theAnrede	= document.getElementById("anrede");
	var anredeIsSet	= false;
	var theValue	= "";
	for (var i = 0; i < theAnrede.options.length; i++) {
		if(theAnrede.options[i].selected == true) {
			var theValue = theAnrede.options[i].value;
		}
	}
	anredeIsSet = (theValue != "") ? true : false;

	/*
		prfe ob Name angegeben wurde
	*/
	var theName		= document.getElementById("nachname");
	var nameIsSet	= (theName.value != "") ? true : false;

	/*
		prfe ob EMail angegeben wurde
	*/
	var mailRegExp	= /^([0-9a-zA-Z]([\-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,4})$/;
	var theEmail	= document.getElementById("email");
	var emailIsSet = (theEmail.value != "" && theEmail.value != "noonehere@yahoo.com" && mailRegExp.test(theEmail.value)) ? true : false;

	/*
		Formulardaten OK?
	*/
	var result = (anredeIsSet && nameIsSet && emailIsSet) ? true : false;

	/*
		Zeige Fehlermeldungen, falls nicht
	*/
	if(popupErrors) {
		/* Fehlerausgabe via JavaScript alert() */
		var theErrorString = "";
		if(!anredeIsSet) {
			theErrorString += anredeErrorString + "\n";
			document.getElementById("anrede").style.backgroundColor = "#FFE6E6";
		}
		if(!nameIsSet) {
			theErrorString += nameErrorString + "\n";
			document.getElementById("nachname").style.backgroundColor = "#FFE6E6";
		}

		if(!emailIsSet) {
			theErrorString += emailErrorString + "\n";
			document.getElementById("email").style.backgroundColor = "solid #FFE6E6 1px";
		}
		if (theErrorString.length > 0) alert(theErrorString);
	} else {
		/* Fehlerausgabe im Dokument */
		var theOutputdiv = document.getElementById("outputdiv");
		var theErrorString = "<ul>";
		if(!anredeIsSet) {
			theErrorString += "<li>" + anredeErrorString + "</li>";
			document.getElementById("anrede").style.backgroundColor = "#FFE6E6";
		}

		if(!nameIsSet) {
			theErrorString += "<li>" + nameErrorString + "</li>";
			document.getElementById("nachname").style.backgroundColor = "#FFE6E6";
		}

		if(!emailIsSet) {
			theErrorString += "<li>" + emailErrorString + "</li>";
			document.getElementById("email").style.backgroundColor = "#FFE6E6";
		}

		theErrorString += "</ul>";
		theOutputdiv.innerHTML = theErrorString;
		theOutputdiv.style.display = "block";
	}

	/*
		Rckgabe
	*/
	return result;
}


function checkRueckrufForm(){
	
	document.getElementById("anrede").style.backgroundColor   = "#FFFFFF";
	document.getElementById("email").style.backgroundColor 	  = "#FFFFFF";
	document.getElementById("nachname").style.backgroundColor = "#FFFFFF";
	document.getElementById("tag").style.backgroundColor 	  = "#FFFFFF";
	document.getElementById("telefon").style.backgroundColor  = "#FFFFFF";
	document.getElementById("uhrzeit").style.backgroundColor  = "#FFFFFF";
	document.getElementById("vorname").style.backgroundColor  = "#FFFFFF";
	
	var theAnrede	= document.getElementById("anrede");
	var anredeIsSet	= false;
	var theValue	= "";
	for (var i = 0; i < theAnrede.options.length; i++) {
		if(theAnrede.options[i].selected == true) {
			var theValue = theAnrede.options[i].value;
		}
	}
	anredeIsSet = (theValue != "") ? true : false;

	var theVorname		= document.getElementById("vorname");
	var vornameIsSet	= (theVorname.value != "") ? true : false;
	
	var theName			= document.getElementById("nachname");
	var nameIsSet		= (theName.value != "") ? true : false;
	
	var theTelefon		= document.getElementById("telefon");
	var telefonIsSet	= (theTelefon.value != "") ? true : false;
	
	var mailRegExp		= /^([0-9a-zA-Z]([\-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,4})$/;
	var theEmail		= document.getElementById("email");
	var emailIsSet 		= (theEmail.value != "" && theEmail.value != "noonehere@yahoo.com" && mailRegExp.test(theEmail.value)) ? true : false;
	
	var theTag			= document.getElementById("tag");
	var tagIsSet		= (theTag.value != "") ? true : false;
	
	var theUhrzeit		= document.getElementById("uhrzeit");
	var uhrzeitIsSet	= (theUhrzeit.value != "") ? true : false;
	
	var kontaktdatenSpeichernIsSet = document.getElementById("kontaktdaten_speichern").checked;
	
	var result = (telefonIsSet && emailIsSet && kontaktdatenSpeichernIsSet) ? true : false;

	if (popupErrors) {
		var theErrorString = "";
		
		if(!telefonIsSet) {
			theErrorString += telefonErrorString + "\n";
			document.getElementById("telefon").style.backgroundColor = "solid #FFE6E6 1px";
		}
		
		if(!emailIsSet) {
			theErrorString += emailErrorString + "\n";
			document.getElementById("email").style.backgroundColor = "solid #FFE6E6 1px";
		}
		
		if (theErrorString.length > 0)
			alert(theErrorString);
	}
	else {
		var theOutputdiv = document.getElementById("outputdiv");
		//var theErrorString = "<ul>";
		var theErrorString = "<ul style=\"color:#DD0000; font-family:Arial,Helvetica,sans-serif; font-size:12px; font-weight:bold;\" >";
		
		if(!telefonIsSet) {
			theErrorString += "<li>" + telefonErrorString + "</li>";
			document.getElementById("telefon").style.backgroundColor = "#FFE6E6";
		}
		
		if(!emailIsSet) {
			theErrorString += "<li>" + emailErrorString + "</li>";
			document.getElementById("email").style.backgroundColor = "#FFE6E6";
		}
				
		if (!kontaktdatenSpeichernIsSet) {
			theErrorString += "<li>" + kontaktdatenSpeichernErrorString + "</li>";
			document.getElementById("kontaktdaten-speichern-box").style.border = "solid #dd0000 3px";			
		} else {
			document.getElementById("kontaktdaten-speichern-box").style.border = "none";
		}
		
		theErrorString += "</ul>";
		theOutputdiv.innerHTML = theErrorString;
		theOutputdiv.style.display = "block";
	}
	
	return result;
}


function checkNlForm(){
	
	document.getElementById("nl_anrede").style.backgroundColor   = "#FFFFFF";
	document.getElementById("nl_email").style.backgroundColor    = "#FFFFFF";
	document.getElementById("nl_nachname").style.backgroundColor = "#FFFFFF";
	document.getElementById("nl_titel").style.backgroundColor    = "#FFFFFF";
	document.getElementById("nl_vorname").style.backgroundColor  = "#FFFFFF";
	
	var theAnrede = document.getElementById("nl_anrede");
	var anredeIsSet = false;
	var theValue = "";
	for(var i = 0; i < theAnrede.options.length; i++) {
		if(theAnrede.options[i].selected == true) {
			var theValue = theAnrede.options[i].value;
		}
	}
	anredeIsSet = (theValue != "") ? true : false;
	
	var theTitel = document.getElementById("nl_titel");
	var titelIsSet = (theTitel.value != "") ? true : false;
	
	var theVorname = document.getElementById("nl_vorname");
	var vornameIsSet = (theVorname.value != "") ? true : false;
	
	var theNachname = document.getElementById("nl_nachname");
	var nachnameIsSet = (theNachname.value != "") ? true : false;

	var mailRegExp	= /^([0-9a-zA-Z]([\-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,4})$/;
	var theEmail = document.getElementById("nl_email");
	var emailIsSet = (theEmail.value != "" && theEmail.value != "noonehere@yahoo.com" && mailRegExp.test(theEmail.value)) ? true : false;

	var result = (anredeIsSet && nachnameIsSet && emailIsSet) ? true : false;
	
	if(document.nl_dataform.nl_action.value == "unsubscribe") {
		document.nl_dataform.action = "newsletter_folgeseite.php";
	}
	
	if(popupErrors){
		var theErrorString = "";
				
		if(!anredeIsSet) {
			theErrorString += anredeErrorString + "\n";
			document.getElementById("nl_anrede").style.backgroundColor = "solid #FFE6E6 1px";
		}
		
		if(!nachnameIsSet) {
			theErrorString += nachnameErrorString + "\n";
			document.getElementById("nl_nachname").style.backgroundColor = "solid #FFE6E6 1px";
		}
		
		if(!emailIsSet) {
			theErrorString += emailErrorString + "\n";
			document.getElementById("nl_email").style.backgroundColor = "solid #FFE6E6 1px";
		}
		
		var result = (anredeIsSet && nachnameIsSet && emailIsSet) ? true : false;
		
		if (theErrorString.length > 0)
			alert(theErrorString);
	}
	else{
		var theOutputdiv = document.getElementById("outputdiv");
		//var theErrorString = "<ul>";
		var theErrorString = "<ul style=\"color:#DD0000; font-family:Arial,Helvetica,sans-serif; font-size:12px; font-weight:bold;\" >";
		
		if(!anredeIsSet) {
			theErrorString += "<li>" + anredeErrorString + "</li>";
			document.getElementById("nl_anrede").style.backgroundColor = "#FFE6E6";
		}
		
		if(!nachnameIsSet) {
			theErrorString += "<li>" + nachnameErrorString + "</li>";
			document.getElementById("nl_nachname").style.backgroundColor = "#FFE6E6";
		}
				
		if(!emailIsSet) {
			theErrorString += "<li>" + emailErrorString + "</li>";
			document.getElementById("nl_email").style.backgroundColor = "#FFE6E6";
		}
		
		theErrorString += "</ul>";
		theOutputdiv.innerHTML = theErrorString;
		theOutputdiv.style.display = "block";
	}

	return result;
}

