// Build tree using DOM
 
function includeForm()
{

objFormContainer=document.getElementById("formcontainer"); // root element 


//FormHeader

	divFormHeader=document.createElement("div");
	divFormHeader.setAttribute("id", "formheader");
	objFormContainer.appendChild(divFormHeader);
	objFormHeader=document.getElementById("formheader");	
	
		divCloseButton=document.createElement("div");
		divCloseButton.setAttribute("id", "divclosebutton");
		objFormHeader.appendChild(divCloseButton);
		objDivCloseButton=document.getElementById("divclosebutton");

			inputHeader=document.createElement("input");
			inputHeader.setAttribute("id", "clbutton");
			inputHeader.setAttribute("type", "button");
			inputHeader.setAttribute("class", "closebutton");
			inputHeader.setAttribute("onclick", "closeformcontainer();");
			objDivCloseButton.appendChild(inputHeader);

		
// FormContent --- Ja eine Schleife wäre besser

	divFormContent=document.createElement("div");
	divFormContent.setAttribute("id", "formcontent");
	objFormContainer.appendChild(divFormContent);
	objFormContent=document.getElementById("formcontent");	
	
		formContent=document.createElement("form");
		formContent.setAttribute("id", "frmcontent");
		formContent.setAttribute("name", "requestForm");
		formContent.setAttribute("action", "process.php");
		formContent.setAttribute("method", "post");
		formContent.setAttribute("target", "_self");
		objFormContent.appendChild(formContent);
		
			objForm=document.getElementById("frmcontent");
			tableContent=document.createElement("table");
			tableContent.setAttribute("align", "center");
			objForm.appendChild(tableContent);
// -----------------------------------------------------------------------------------------------			
			tableContentTr1=document.createElement("tr");
			tableContent.appendChild(tableContentTr1);
			
				tableContentTdTxt1=document.createElement("td");
				tableContentTdTxt1.setAttribute("class", "formfieldcell");
				tableContentTdTxt1.innerHTML="Firma:";
				tableContentTr1.appendChild(tableContentTdTxt1);
				
				tableContentTdInp1=document.createElement("td");
				tableContentTr1.appendChild(tableContentTdInp1);
									
					tableContentInput1=document.createElement("input");
					tableContentInput1.setAttribute("id", "flCompany");
					tableContentInput1.setAttribute("class", "formfield");
					tableContentInput1.setAttribute("type", "text");
					tableContentInput1.setAttribute("size", "30");
					tableContentInput1.setAttribute("maxlength", "40");
					tableContentInput1.setAttribute("name", "cy");
					tableContentTdInp1.appendChild(tableContentInput1);
// -----------------------------------------------------------------------------------------------						
			tableContentTr2=document.createElement("tr");
			tableContent.appendChild(tableContentTr2);
			
				tableContentTdTxt2=document.createElement("td");
				tableContentTdTxt2.setAttribute("class", "formfieldcell");
				tableContentTdTxt2.innerHTML="Name:";
				tableContentTr2.appendChild(tableContentTdTxt2);
				
				tableContentTdInp2=document.createElement("td");
				tableContentTr2.appendChild(tableContentTdInp2);
									
				tableContentInput2=document.createElement("input");
				tableContentInput2.setAttribute("id", "flName");
				tableContentInput2.setAttribute("class", "formfield");
				tableContentInput2.setAttribute("type", "text");
				tableContentInput2.setAttribute("size", "30");
				tableContentInput2.setAttribute("maxlength", "40");
				tableContentInput2.setAttribute("name", "ne");
				tableContentTdInp2.appendChild(tableContentInput2);

// -----------------------------------------------------------------------------------------------	
			tableContentTr3=document.createElement("tr");
			tableContent.appendChild(tableContentTr3);
			
				tableContentTdTxt3=document.createElement("td");
				tableContentTdTxt3.setAttribute("class", "formfieldcell");
				tableContentTdTxt3.innerHTML="Telefon:";
				tableContentTr3.appendChild(tableContentTdTxt3);
				
				tableContentTdInp3=document.createElement("td");
				tableContentTr3.appendChild(tableContentTdInp3);
									
				tableContentInput3=document.createElement("input");
				tableContentInput3.setAttribute("id", "flTelefon");
				tableContentInput3.setAttribute("class", "formfield");
				tableContentInput3.setAttribute("type", "text");
				tableContentInput3.setAttribute("size", "30");
				tableContentInput3.setAttribute("maxlength", "40");
				tableContentInput3.setAttribute("name", "pe");
				tableContentTdInp3.appendChild(tableContentInput3);

// -----------------------------------------------------------------------------------------------	
			tableContentTr4=document.createElement("tr");
			tableContent.appendChild(tableContentTr4);
			
				tableContentTdTxt4=document.createElement("td");
				tableContentTdTxt4.setAttribute("class", "formfieldcell");
				tableContentTdTxt4.innerHTML="Email:";
				tableContentTr4.appendChild(tableContentTdTxt4);
				
				tableContentTdInp4=document.createElement("td");
				tableContentTr4.appendChild(tableContentTdInp4);
									
				tableContentInput4=document.createElement("input");
				tableContentInput4.setAttribute("id", "flEmail");
				tableContentInput4.setAttribute("class", "formfield");
				tableContentInput4.setAttribute("type", "text");
				tableContentInput4.setAttribute("size", "30");
				tableContentInput4.setAttribute("maxlength", "40");
				tableContentInput4.setAttribute("name", "el");
				tableContentTdInp4.appendChild(tableContentInput4);	

// -----------------------------------------------------------------------------------------------	
			tableContentTr5=document.createElement("tr");
			tableContent.appendChild(tableContentTr5);
			
				tableContentTdTxt5=document.createElement("td");
				tableContentTdTxt5.setAttribute("class", "formfieldcell");
				tableContentTdTxt5.innerHTML="Nachricht:";
				tableContentTr5.appendChild(tableContentTdTxt5);
				
				tableContentTdInp5=document.createElement("td");
				tableContentTr5.appendChild(tableContentTdInp5);
									
				tableContentInput5=document.createElement("textarea");
				tableContentInput5.setAttribute("id", "flMessage");
				tableContentInput5.setAttribute("class", "formmessage");
				tableContentInput5.setAttribute("cols", "4");
				tableContentInput5.setAttribute("rows", "3");
				tableContentInput5.setAttribute("name", "mee");
				tableContentTdInp5.appendChild(tableContentInput5);
				
// -----------------------------------------------------------------------------------------------	

			tableContentTr6=document.createElement("tr");
			tableContent.appendChild(tableContentTr6);
			
				tableContentTdTxt6=document.createElement("td");
				tableContentTdTxt6.setAttribute("class", "formfieldcell");
				tableContentTr6.appendChild(tableContentTdTxt6);
				
				tableContentTdInp6=document.createElement("td");
				tableContentTr6.appendChild(tableContentTdInp6);
									
				tableContentInput6=document.createElement("input");
				tableContentInput6.setAttribute("class", "nichtsichtbar");
				tableContentInput6.setAttribute("value", "");
				tableContentInput6.setAttribute("name", "ul");
				tableContentTdInp6.appendChild(tableContentInput6);	

// -----------------------------------------------------------------------------------------------	
			
			tableContentTr7=document.createElement("tr");
			tableContent.appendChild(tableContentTr7);
			
				tableContentTdTxt7=document.createElement("td");
				tableContentTdTxt7.setAttribute("class", "formfieldcell");
				tableContentTr7.appendChild(tableContentTdTxt7);
				
				tableContentTdInp7=document.createElement("td");
				tableContentTr7.appendChild(tableContentTdInp7);
									
				tableContentInput7=document.createElement("input");
				tableContentInput7.setAttribute("id", "email");
				tableContentInput7.setAttribute("class", "nichtsichtbar");
				tableContentInput7.setAttribute("value", "");
				tableContentInput7.setAttribute("name", "email");
				tableContentTdInp7.appendChild(tableContentInput7);
				
// -----------------------------------------------------------------------------------------------	
			tableContentTr8=document.createElement("tr");
			tableContent.appendChild(tableContentTr8);
			
				tableContentTdTxt8=document.createElement("td");
				tableContentTdTxt8.setAttribute("class", "formfieldcell");
				tableContentTr8.appendChild(tableContentTdTxt8);
				
				tableContentTdInp8=document.createElement("td");
				tableContentTdInp8.setAttribute("class", "formcell");
				tableContentTr8.appendChild(tableContentTdInp8);

				tableContentInput8=document.createElement("input");
				tableContentInput8.setAttribute("type", "button");
				tableContentInput8.setAttribute("class", "sendbutton");
				tableContentInput8.setAttribute("value", "");
				tableContentInput8.setAttribute("onclick", "validateForm();");
				tableContentTdInp8.appendChild(tableContentInput8);	

// -----------------------------------------------------------------------------------------------	
				

// FormFooter

			
	divFormFooter=document.createElement("div");
	divFormFooter.setAttribute("id", "formfooter");
	formContent.appendChild(divFormFooter);
	
	spanFormBorder=document.createElement("span");
	spanFormBorder.setAttribute("id", "formborder");
	objFormContainer.appendChild(spanFormBorder);

		
	
}


var startTime=new Date();

function duration()
{

 finish=new Date();
 var count=Math.round( (finish.getTime() - startTime.getTime() ) / 1000);
 //alert("Sekunden: "+count);
 return count;

}

function searchEmtpyFields()
{

    blankLine=0;
    for(i=0;i<5;i++){
 	
		objID=window.document.forms[0].elements[i].id;
		//alert(objID);	
		myOBJ=document.getElementById(objID);
		
		if(objID=="flMessage"){
			myOBJ.style.backgroundImage = "url(popup/idd_message.jpg)";
		} else {
			myOBJ.style.backgroundImage = "url(popup/idd_field.jpg)";
		}

		myValue=myOBJ.value;
		
		if(myValue==""){
			myOBJ.style.background="#e45e5e";
			blankLine++;
		}
 
    }
 
      if(blankLine>0){
		alert("Es wurden nicht alle Felder ausgefüllt. Bitte überprüfen Sie die roten Felder.");
		return true
	  } else {
		return false;
	  }

}

function validateEmail()
{
	myEmailOBJ=document.getElementById("flEmail");
	myEmailOBJ.style.backgroundImage = "url(popup/idd_field.jpg)";
	messageEmail="Bitte überprüfen Sie folgende Email-Adresse auf Ihre Korrektheit:\n\n"; 
	wrongEmail=0;
  
	reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    var emailAddressValue = myEmailOBJ.value;
	//alert(reg.test(emailAddressValue)); // debug
  if(reg.test(emailAddressValue) == false) {
  	messageEmail+=emailAddressValue+"\n";
    wrongEmail++;
  }
  if(wrongEmail>0){
	myEmailOBJ.style.background="#e45e5e";
    alert(messageEmail);
  } else {
  return false;
  }

}

function validateForm()
{
	if (searchEmtpyFields()==false && validateEmail()==false && duration() > 25){
		//alert(window.location.href);
		alert("Vielen Dank für Ihre Anfrage. Wir werden uns umgehend bei Ihnen melden.");
		document.getElementById('formcontainer').style.display='none';
		document.getElementById('formfilter').style.display='none';
		document.requestForm.ul.value = window.location.href;
		document.requestForm.submit();

	} else {
		alert("Die Daten wurden noch nicht gesendet. Bitte versuchen Sie es gleich erneut");
	}

}











