function openWindow(wintype)
{
  var nwl = (screen.width-990)/2;
  var nwh = (screen.height-450)/2;
  popUp=window.open(wintype, 'Popup', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=990,height=450,left='+nwl+',top='+nwh+''); 
  popUp.window.focus(); 
}

var isOn=false;
function changeKontaktFields(fieldId){
if(isOn){
 document.getElementById(fieldId).style.display = "none";
 document.getElementById(fieldId).style.visibility = "hidden";
 isOn=false;
 
}else if(!isOn){
 document.getElementById(fieldId).style.display = "block";
 document.getElementById(fieldId).style.visibility = "visible";
 isOn=true;
}
}

function checkKontaktForm(theForm)
{
if(theForm.redirect.value=="") {
	alert("Bitte wählen Sie den Emailempfänger aus.");
	theForm.redirect.focus();
	return false;
}
if(theForm.vorname.value=="") {
	alert("Bitte geben Sie Ihren Vornamen an.");
	theForm.vorname.focus();
	return false;
}
if(theForm.name.value=="") {
	alert("Bitte geben Sie Ihren Namen an.");
	theForm.name.focus();
	return false;
}
if(theForm.email.value==""){
	alert("Bitte geben Sie Ihre Emailadresse an.");
	theForm.email.focus();
	return false;
}else if(theForm.email.value.length > 0){
	var emailString = theForm.email.value;
	if (!emailString.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i)){
			alert('Die Email-Adresse ist ungültig');
			theForm.email.focus();
			return false;
	}
}
if(theForm.captcha.value=="") {
	alert("Bitte geben Sie noch den Buchstabencode an.");
	theForm.captcha.focus();
	return false;
}
return true;
}


function checkFAQForm(theForm)
{
if(theForm.FrageVorname.value=="") {
	alert("Bitte geben Sie Ihren Vornamen an.");
	theForm.FrageVorname.focus();
	return false;
}
if(theForm.FrageName.value=="") {
	alert("Bitte geben Sie Ihren Namen an.");
	theForm.FrageName.focus();
	return false;
}
if(theForm.FrageEmail.value==""){
	alert("Bitte geben Sie Ihre Emailadresse an.");
	theForm.FrageEmail.focus();
	return false;
}else if(theForm.FrageEmail.value.length > 0){
	var emailString = theForm.FrageEmail.value;
	if (!emailString.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i)){
			alert('Die Email-Adresse ist ungültig');
			theForm.FrageEmail.focus();
			return false;
}
if(theForm.Frage.value=="") {
	alert("Bitte geben Sie Ihren Frage an.");
	theForm.Frage.focus();
	return false;
}
return true;
}


if(theForm.Frage.length=="") {
	alert("Bitte geben Sie noch Ihre Frage an.");
	theForm.Frage.focus();
	return false;
}
return true;
}

function changeFAQFields(theForm){

var selectedFieldFAQJa = document.getElementById("faqJa").checked;
var selectedFieldFAQNein = document.getElementById("faqNein").checked;

if(selectedFieldFAQJa && !selectedFieldFAQNein){
	var textfieldMitteilung = "";
	if(document.getElementById('textMitteilung') != null && !document.getElementById('textMitteilung').value=="") textfieldMitteilung = document.getElementById('textMitteilung').value;
	
	// erst wenn Textinhalt vorhanden wird das Element generiert
	if(!textfieldMitteilung == ""){
	 
	 // Textarea generieren
	 var newTextarea = document.createElement("textarea");
	 newTextarea.value=textfieldMitteilung;
	 newTextarea.style.display="none";
	 newTextarea.style.visibility="hidden";
	 
	 var TextareaName = document.createAttribute("name");
   TextareaName.nodeValue = "Frage";
   var TextareaID = document.createAttribute("id");
   TextareaID.nodeValue = "Frage";
  
   newTextarea.setAttributeNode(TextareaName);
   newTextarea.setAttributeNode(TextareaID);
   
	 theForm.appendChild(newTextarea);
	 
	 // Feld mit Namen generieren
	 var newFieldName = document.createElement("input");
   newFieldName.value=document.getElementById('name').value;
   newFieldName.style.display="none";
   newFieldName.style.visibility="hidden";

   var FieldNameName = document.createAttribute("name");
   FieldNameName.nodeValue = "FrageName";
   var FieldNameID = document.createAttribute("id");
   FieldNameID.nodeValue = "FrageName";

   newFieldName.setAttributeNode(FieldNameName);
   newFieldName.setAttributeNode(FieldNameID);

	 theForm.appendChild(newFieldName);
	 
	 // Feld mit Vornamen generieren
   var newFieldVorname = document.createElement("input");
   newFieldVorname.value=document.getElementById('vorname').value;
   newFieldVorname.style.display="none";
   newFieldVorname.style.visibility="hidden";

   var FieldVornameName = document.createAttribute("name");
   FieldVornameName.nodeValue = "FrageVorname";
   var FieldVornameID = document.createAttribute("id");
   FieldNameID.nodeValue = "FrageVorname";

   newFieldVorname.setAttributeNode(FieldVornameName);
   newFieldVorname.setAttributeNode(FieldVornameID);

	 theForm.appendChild(newFieldVorname);
	 
	 // Feld mit Email generieren
   var newFieldEmail = document.createElement("input");
   newFieldEmail.value=document.getElementById('email').value;
   newFieldEmail.style.display="none";
   newFieldEmail.style.visibility="hidden";

   var FieldEmailName = document.createAttribute("name");
   FieldEmailName.nodeValue = "FrageEmail";
   var FieldEmailID = document.createAttribute("id");
   FieldEmailID.nodeValue = "FrageEmail";

   newFieldEmail.setAttributeNode(FieldEmailName);
   newFieldEmail.setAttributeNode(FieldEmailID);

	 theForm.appendChild(newFieldEmail);
	 
   // Feld mit Wohnort generieren
   var newFieldWohnort = document.createElement("input");
   newFieldWohnort.value=document.getElementById('PLZOrt').value;
   newFieldWohnort.style.display="none";
   newFieldWohnort.style.visibility="hidden";

   var FieldWohnortName = document.createAttribute("name");
   FieldWohnortName.nodeValue = "FrageWohnort";
   var FieldWohnortID = document.createAttribute("id");
   FieldWohnortID.nodeValue = "FrageWohnort";

   newFieldWohnort.setAttributeNode(FieldWohnortName);
   newFieldWohnort.setAttributeNode(FieldWohnortID);

	 theForm.appendChild(newFieldWohnort);
	 
	} else {
	 alert("Bitte geben Sie noch einen Text ein, der für die FAQ übernommen werden kann!");
	 return false;
	}

 
}else if(!selectedFieldFAQJa && selectedFieldFAQNein){
 if(document.getElementById("Frage") != null){
	document.getElementById("formularKontakt").removeChild(document.getElementById("Frage"));
	document.getElementById("formularKontakt").removeChild(document.getElementById("FrageName"));
	document.getElementById("formularKontakt").removeChild(document.getElementById("FrageVorname"));
	document.getElementById("formularKontakt").removeChild(document.getElementById("FrageEmail"));
	document.getElementById("formularKontakt").removeChild(document.getElementById("FrageWohnort"));
 }
}

// Kontaktform nochmal checken
checkKontaktForm(theForm);
}
